Results 1 to 6 of 6

Thread: null pointer exception

  1. #1
    Junior Member
    Join Date
    Oct 2007
    Answers
    1

    Question null pointer exception

    Hai every1,

    we all know that java does not support pointers.Then how does it throw null pointer exception ?????


  2. #2
    Junior Member
    Join Date
    Sep 2007
    Answers
    1

    Re: null pointer exception

    yes JAVA does not support pointers but internal implementation of JVM or JAVA compiler uses pointers, as u know JVM consists of stack and heap, stack contains the normal variables and objects r kept in heap and those heap address are stored in stack those addresses r nothing but pointers to those objects in heap so when u write ur programs using java u yourself don't use pointers but compiler does for convenience


  3. #3
    Junior Member
    Join Date
    Oct 2007
    Answers
    1

    Re: null pointer exception

    Quote Originally Posted by Shashank Deo View Post
    yes JAVA does not support pointers
    This is not true. Java does in fact support pointers. When you allocate memory for an object by calling new, you get back a pointer.

    Quote Originally Posted by mokaprasad View Post
    we all know that java does not support pointers
    What you should say is, "We all know that Java does not support pointer arithmetic." The Java language does not allow you to add offsets to a pointer, as is often done in C or C++. People sometimes get confused about this and think that Java does not support pointers at all.


  4. #4
    Junior Member
    Join Date
    Sep 2007
    Answers
    7

    Re: null pointer exception

    hi,
    Who told you that java doesn't support pointers. Without pointers no programming language can allocate memory. So internally java also make use of pointers. But only thing is that, java doesn't allow you to get explicit control over Pointers. And it doesn't support pointer arithmetic. That is the most important thing.

    Java also needs memory to be allocated to objects, you will have to explicitly do that with 'new' operator. Thats why you are getting NullPointerException when you try to access a method of an object without instantiating the object. ptmidhun@gmail.com


  5. #5
    Junior Member
    Join Date
    Jan 2007
    Answers
    22

    Re: null pointer exception

    well what i think is it should have been called NULLREFERENCEEXCEPTION instead of null pointer..
    whether Java supports or does not support can be answerd just by answered " Can u use pointers in your program?"


  6. #6
    Junior Member
    Join Date
    Jun 2007
    Answers
    4

    Re: null pointer exception

    Java dont support pointer.
    Here NullPointerException means that it can't map any null object.
    Ex1: JButton but1
    but1.setSize(10,15) // There will be an NullPointerException because, without initializing it we can't use it.

    Now tht fress code::

    JButton but
    but=new JButton("Click")
    but.setSize(15,15)
    // There wil no exeption


    for more details call me @ :9333344452 (Susanta Ghosh)
    or mail me at amarmail . 999 @ gmail . com


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About us
Applying for a job can be a stressful and frustrating experience, especially for someone who has never done it before. Considering that you are competing for the position with a at least a dozen other applicants, it is imperative that you thoroughly prepare for the job interview, in order to stand a good chance of getting hired. That's where GeekInterview can help.
Interact