wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Is their Two objects ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Is their Two objects ?" Watch "Is their Two objects ?" New topic
Author

Is their Two objects ?

Mahtab Alam
Ranch Hand

Joined: Mar 28, 2012
Posts: 258

How many objects are created .
I think Two


class Obj
{
public static void main(String args[])
{
Long l=1234593867L;
Long l2=l.longValue();
}
}


Oracle Java Programmer , Oracle SQL Expert , Oracle Java Web Component Developer
Anayonkar Shivalkar
Bartender

Joined: Dec 08, 2010
Posts: 1506
    
    5

Mahtab Alam wrote:How many objects are created .
I think Two


class Obj
{
public static void main(String args[])
{
Long l=1234593867L;
Long l2=l.longValue();
}
}

The simplest way to check this would be to do reference comparison (i.e. )
HIH.


Regards,
Anayonkar Shivalkar (SCJP, SCWCD, OCMJD, OCEEJBD)
Bhavesh Saraswat
Greenhorn

Joined: Jan 20, 2013
Posts: 18

the getLong() method of class Long returns a equivalant long value(primitive long). So in your code this primitive long value is autoboxed and wrapped into a new Long object.

So it is a new Long object!!


OCPJP SE6
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11314
    
  16

Do you count the String array that gets creates (i.e. the array that 'args' points to?)


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Is their Two objects ?