It's not a secret anymore!*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes String / float Question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "String / float Question" Watch "String / float Question" New topic
Author

String / float Question

Amardeep Salkar
Ranch Hand

Joined: May 22, 2008
Posts: 46
String str = "Amardeep";
String stra = new String("Amardeep);
or
String strb = new String();

Is String is A primitive or wrapper class ?

Similarly

float flt =10.08f;
Float flt = new Float();
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9280
    
  17

Originally posted by Amardeep Salkar:
String str = "Amardeep";
String stra = new String("Amardeep);
or
String strb = new String();

Is String is A primitive or wrapper class ?

Similarly

float flt =10.08f;
Float flt = new Float();


Neither is String a primitive nor a wrapper. It is a general class in java.util package which is used to work on string like char[] in C++(although char[] of C++ and String of Java are way different).

Float is a wrapper class...also Float constructor must be provided a double, float or String value.


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Amardeep Salkar
Ranch Hand

Joined: May 22, 2008
Posts: 46
As i know float is a primitive and double is a wrapper class

because primitive type of double is float. but what about Float

i.e
float ft = 10.64f
Float flt = new Float(ft);
or
Float flt = new Float();

Reply me if I'm wrong...
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9280
    
  17

As i know float is a primitive and double is a wrapper class


You are wrong. Both float and double are primitive.

type of double is float


Again Wrong...double and float are two separate primitive types.

what about Float


Well every primitive type has a corresponding Wrapper class..this is a list of primitive types and their corresponding wrapper classes.

+-----------+---------+
| primitive | wrapper |
+-----------+---------+
| boolean | Boolean |
| byte | Byte |
| short | Short |
| char |Character|
| int | Integer |
| long | Long |
| float | Float |
| double | Double |
+-----------+---------+
[ August 08, 2008: Message edited by: Ankit Garg ]
Dariusz Kordonski
Ranch Hand

Joined: Jul 11, 2008
Posts: 49
Amardeep, check out: http://java.sun.com/docs/books/tutorial/java/nutsandbolts/datatypes.html . You will find some useful basic information on primitives that should help you undertsand the topic better. Regards
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: String / float Question
 
Similar Threads
Runnable Interface
Float value
Regarding Array.
Float
java.lang