• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Liutauras Vilda
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
Bartenders:
  • Himai Minh
  • Carey Brown
  • Frits Walraven

Why it is not 'null' ?

 
Ranch Hand
Posts: 63
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 446
1
Eclipse IDE MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Kiran,
I think prasad explanation makes you clear on that.
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Ranch Hand
Posts: 91
Notepad
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
,
Seetharaman Venkatasamy


use decompiler , you will understand the scenario


what is decompiler and how to use it
 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 91
Notepad
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
John
Is decompiler same as printStackTrace() method of Exception class which prints the method names according to there function call.
 
John Francis
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 91
Notepad
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
Thanks a lot John and samrat

now i got the decompiler concept
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic