*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Why it is not 'null' ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Why it is not Watch "Why it is not New topic
Author

Why it is not 'null' ?

Moguluri Ravi Kiran
Ranch Hand

Joined: Apr 16, 2010
Posts: 62

Hello

this is kiran, I have a small doubt here,please share your views regarding this.



why ? when we are calling printArray() without any Argument/Argument list the lastline of output not null ?
why the refference is created ?

Thanks.
Prasad Kharkar
Ranch Hand

Joined: Mar 07, 2010
Posts: 438

hey ravi
this is really an interesting question
I am really attracted to a question like this
what I can infer from the question is that
when we are passing nothing to a method that takes an var-arg or the array type as parameter, then also the var-arg takes it as zero argument
I think so
even in the main method that we write in programs has the var-arg argument (String... args) or the (String [] args)
these arguments are meant to come from the command line isn't it
even when we do not pass any command line argument to the program it runs perfectly
isn't it?
now isn't it like calling the main method as follows, with no string arguments at all?

Now I tried to modify your problem here and found something interesting
I printed out the array length after each operation and see what I found
here is the code

when we call printArray(); i.e. method with no arguments, then also some array with no elements in it gets passed as in the main method which takes String arguments
when we print the size of the array in the method it says that size is 0 i.e it has accepted the array and when we print the object then it prints the usual hashcode representation of the object
well let us get it in short
but what I found more interesting is


husshhhhhhhh!!
thanks for the question Ravi got many things from it
happy preparation

SCJP 6 [86%] June 30th, 2010
OCPWCD [84%] March 26th, 2013
If you find any post useful, click the "plus one" sign on the right
Muneeswaran Balasubramanian
Ranch Hand

Joined: Mar 19, 2010
Posts: 138
Hi Kiran,
I think prasad explanation makes you clear on that.


Cheers Munees
My Blog
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Moguluri Ravi Kiran wrote:
printArray();
why ? when we are calling printArray() without any Argument/Argument list the lastline of output not null ?


when you call var-arg without argument i.e, printArray(); compiler create one Object array [which has zero lenth] and place in arument for you i.e,

*printArray(new Object[0])* . use decompiler , you will understand the scenario .

hth
sumit kothalikar
Ranch Hand

Joined: Apr 15, 2010
Posts: 91

Hi
,
Seetharaman Venkatasamy

use decompiler , you will understand the scenario


what is decompiler and how to use it


Thanks & Regards
Sumit Kothalikar
Samrat Debroy
Greenhorn

Joined: Oct 23, 2009
Posts: 13
sumit kothalikar wrote:
what is decompiler and how to use it


You may use javap also.

Command line:


The disassembled code is :


You may see that the last printArray() is getting called having the instance of Object as parameter.
John Francis
Greenhorn

Joined: May 06, 2010
Posts: 5
sumit kothalikar wrote:Hi
,
Seetharaman Venkatasamy

use decompiler , you will understand the scenario


what is decompiler and how to use it


Hi Sumit,
To put in simpler words. Compiler converts your java code (.java) into bytecodes(.class)
And decompiler converts your .class files into java code. All you have to do is open your .class file with a decompiler.
sumit kothalikar
Ranch Hand

Joined: Apr 15, 2010
Posts: 91

Hi
John
Is decompiler same as printStackTrace() method of Exception class which prints the method names according to there function call.
John Francis
Greenhorn

Joined: May 06, 2010
Posts: 5
sumit kothalikar wrote:Hi
John
Is decompiler same as printStackTrace() method of Exception class which prints the method names according to there function call.


No, decompiler is a software program just like a compiler but it converts the executable codes into high level language codes. Recompiling this codes again gives you the original executable code.
printStackTrace() of Exception class is a method which prints the stack trace.
sumit kothalikar
Ranch Hand

Joined: Apr 15, 2010
Posts: 91

Hi
Thanks a lot John and samrat

now i got the decompiler concept
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Why it is not 'null' ?
 
Similar Threads
Overloading doubt
Data retrivel from DB using Hibernate
Conversion of 'Array object'!
cant read the contents of the printed string
Var args once again......