jQuery in Action, 2nd edition
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes String / float Question Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply 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
Saloon Keeper

Joined: Aug 03, 2008
Posts: 9189
    
    2

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
Saloon Keeper

Joined: Aug 03, 2008
Posts: 9189
    
    2

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
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: String / float Question
 
Similar Threads
Regarding Array.
Runnable Interface
Float
java.lang
Float value