Showing posts with label Java. Show all posts
Showing posts with label Java. Show all posts

Saturday, January 26, 2013

Why THIS has to be THIS only ??

This post is a placeholder of references to certain questions for which there is no definitive answer, but always good to know.

1. Why do we need abstract classes in Java? In other words whats the difference between an abstract class and a concrete class?

Check out here : http://stackoverflow.com/questions/10211317/how-is-abstract-class-different-from-concrete-class

2. Why NULL isn't nothing or empty string in Oracle?

A lot of time and lot of effort has been spent on this. Well that's how Oracle behaves. However there are ways in which this can be handled.

Check out here : http://www.oracle.com/technetwork/issue-archive/2005/05-jul/o45sql-097727.html

Tuesday, May 10, 2011

NullPointerException and Java

When I first started programming in Java, that was like few years ago, with the little background that I had of C the first thing I learnt was, Java does not have Pointers

Why doesn't it have Pointers?
Structures were removed and gone, and arrays and strings are objects, the need for pointers to these constructs goes away.

Why Structures were removed?
You don't need structures and unions when you have classes; you can achieve the same effect simply by declaring a class with the appropriate instance variables.

So now we have enough reasons as to why Java didn't have Pointers.

Having said that it makes me wonder why is there an exception called NullPointerException when there is no Pointer in Java. I am very sure the Java developers would have some reason to have named this the way it is today. May be they could have named it NullReferenceException. But obviously they didn't. The following are my guesses as to why it can still be called so
  • Its not that Java does not have Pointers
  • In fact every reference in Java is ideally a Pointer (except for primitive types)
  • Its just that Java doesn't support Pointer arithmetic