• 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
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

question on return type

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi all
Byte is a wrapper object, not a primitive. But in the code given below if we
try to catch that wrapper object with the primitive 'int', then there will not be any error. why!!!
class C1
{
int m1()
{
Byte b=7;
return b;
}

public static void main(String arg[])
{
C1 c=new C1();
int p=c.m1();
System.out.println(p);
}
}
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thats the new feature of J2SE 5.0 called auto-boxing and auto-unboxing, before J2SE 5.0 that code will give a compiler error
 
ritwik roy
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi!Aurelio
what is this auto-boxing and auto-unboxing. It is applicable to all wrapper Objects and primitives or in some particular cases???
plz send some related links......
 
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi all

if u people r preparing for scjp 1.4, plz don't use jdk1.5 because here this type of code will compile and run without error due to autoboxing and autounboxing.

prior to jdk1.5 :

this code

Byte b = 26; //1
System.out.printlnn(b); //2

was an error but in jdk1.5

when we compile, the compiler automatically create an object of type Byte(called autoboxing).

bye
 
Ranch Hand
Posts: 1609
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ritwik!
You can find about boxing and unboxing in JLS, here.

I dont know under what circumstances these conversions are automatic and non-automatic. Any further links???
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by ritwik roy:
...plz send some related links......



Sun - Java 1.5 in a Nutshell
 
ritwik roy
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks Naresh!
i m preparing for scjp1.4 ,but i have been using jdk1.5 for the last 2 months. now my question is that suppose in the real exam(scjp1.4) i face such type of problem, then what should i do. go for the compiler error option.....or utilize this type of latest technology.....
what r the other things which i have not got any error in jdk1.5 but will get if i use jdk1.4..
if u know some points, plz send me..
 
Ranch Hand
Posts: 1228
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No you should go for only "compiler error " if you are writing 1.4
 
Naresh Saw
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
srinivan is right. don't confuse with such question and keep in mind we r going for 1.4 not 1.5 dear.
 
reply
    Bookmark Topic Watch Topic
  • New Topic