Why there are no pointers in Java?

  • In Java there are references instead of pointers. These references point to objects in memory. But there is no direct access to these memory locations. JVM is free to move the objects within VM memory.
  • The absence of pointers helps Java in managing memory and garbage collection effectively. Also it provides developers with convenience of not getting worried about memory allocation and deallocation.

If there are no pointers in Java, then why do we get NullPointerException?

  • In Java, the pointer equivalent is Object reference. When we use a . it points to object reference. So JVM uses pointers but programmers only see object references.
  • In case an object reference points to null object, and we try to access a method or member variable on it, then we get NullPointerException.

最新文章

  1. 深入剖析tomcat 笔记——第8章 载入器
  2. 【温故Delphi】之VCL消息机制小结
  3. Html与CSS快速入门02-HTML基础应用
  4. Spring mvc web.xml中 urlpatten的配置问题
  5. [充电]C++ string字符串替换
  6. 如何在PHP里面连接数据库
  7. 不知还有人遇到这个问题没有:数据库 'xxx' 的版本为 706,无法打开。此服务器支持 661 版及更低版本。不支持降级路径。
  8. NSURLConnection、NSURLSession
  9. C#调用webservers实现天气预报
  10. sql加强练习
  11. hdoj 1166 敌兵布阵(树状数组)
  12. 【知识整理】这可能是RxJava 2.x 最好的入门教程(一)
  13. 区分javascript中的toString(),toLocaleString(),valueOf()方法
  14. go语言关于值类型和引用类型
  15. Spring AOP Capabilities ang goals
  16. 通过微信公众号API复制公众号自定义菜单同时增加子菜单方法
  17. 【XSY1602】安全网络 树形DP 数学
  18. IP地址在mysql的存储(IP地址和int的转换)
  19. Ubuntu下解决MySQL自启动,chkconfig list 全部off 情况
  20. Bigining

热门文章

  1. Fedora下Msitools使用
  2. java大神进阶之路
  3. h5模型文件转换成pb模型文件
  4. codevs 1993草地排水
  5. js组件化(转载)
  6. Python读写Excel表格
  7. 编译最新linux内核(version 4.4.2)
  8. eclipse svn 忽略target .project .classpath等目录文件
  9. ios Realm的使用 本地数据存储
  10. Javascript中常用方法简介