Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7852835
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T19:31:00+00:00 2026-06-02T19:31:00+00:00

String a[]=null; if(a[0]!=null) { System.err.println(dd-1); } if(a!=null) { System.err.println(dd-2); } } In first if

  • 0
String a[]=null;
    if(a[0]!=null)
    {
        System.err.println("dd-1");
    }

    if(a!=null)
        {
        System.err.println("dd-2");
        }
    }

In first if condtion its throwing null pointer exception, but in second if condition its not throwing null pointer exception? can anyone please explain me the same? is there is any concept behind this on Heap memory allocation.

also i got to know the problem becauese of Missing memory allocation,String a[]=new String.[10]; please expalain the concept?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T19:31:01+00:00Added an answer on June 2, 2026 at 7:31 pm

    In the first if condition you are trying to access the first element in the array, even thought there is no allocation done for it.

    In second condition you are just testing the reference.

    (Think of it as C pointers, char *str = NULL does not allocated any thing except a pointer pointing to NULL)

    String a[]=null;
    

    No memory is allocated for the array only reference is created.

    String a[] = new String[1]
    

    Memory to hold one String object is created on the Heap and a points to the allocated string object.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am able to export mysql to csv file but i am not getting
Exception is : Resources.NotFoundException 11-30 17:38:17.843: I/class fyp.proj.crud.DisplayProjects$ListAdapter(967): android.content.res.Resources$NotFoundException: String resource ID #0x9 Firstly,
First of all I am not too sure how to explain that without sounding
class Talk { String[] values; try { InputStream is = getAssets().open(jdata.txt); DataInputStream in =
I am trying to write a simple script that convert the first field of
I am doing a custom validation for text files. For the first time, validation
Playing with a few tutorials on sockets but struggling to connect. My tomcat server
Charset charset = Charset.forName(US-ASCII); try (BufferedReader reader = Files.newBufferedReader(file, charset)) { String line =
I've run into a very strange problem in Eclipse, and I'm not sure if
I am trying this code in java: try { String url = http://url.com/file.ext; InputStream

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.