Upload
dezyneecole
View
24
Download
0
Embed Size (px)
Citation preview
INFORMATION TECHNOLOGY
PROJECT REPORT
JAVA PROGRAMING TOPIC
Wrapper class & nesting method
SUBMITTED BY
RAVI SHARMA BCA (bachelor of computer application) SEC. YEAR
Dezyne E’cole College
106/10, Civil lines, Ajmer
www.Dezyneecole.com
Project report
On
JAVA programming
At
Dezyne E’cole college
Ajmer
Submitted to
Dezyne e’cole college
Towoard to
Partical fulfillment on
BCA (bachelor of computer application)
By
Ravi Sharma
Dezyne E’cole College
106/10, Civil lines, Ajmer
Telephone -0145-2624679
ACKNOWLEDGEMENT
I Am Ravi Sharma, Student Of Dezyne E’Cole College, Am
Extremely Grateful to Each And Every Individual Who Has
Contributed in Successful Completion of My Project. I
Express My Gratitude Towards Dezyne E’Cole College For
Their Guidance And Constants Supervision As Well As For
Providing The Necessary Information And Support
Regarding The Completion Of Project.
SYNOPSIS
This Project Is A Miner. Project Made Based on the
Theatrical Concepts of JAVA .This Project Has Made
Our Basic Concept on JAVA Strong
Wrapper classes: As pointed out earlier, vector cannot handle primitive data types like int , float, char and double.
Primitive data types may be converted into object types by using the wrapper classes contained in the java.lang package .following table show the simple data types and their corresponding wrapper class types.
Wrapper class for converting types
Simple types Wrapper class Boolean Boolean
char char
double Double
float Float
Int Int
Long Long
The wrapper classes have a number of unique methods for handling primitive data types and objects. They are listed in following table.
Converting primitive number to object number using constructor method
Constructor calling
Conversion action
Integer intVal=new Integer(i);
Primitive integer to integer object
Float floatVal=new float(i); Primitive float to float object
Double doubleVal=new double(d);
Primitive double to double object
Long long Val=new long(i); Primitive long to long object
Converting object number to primitive number using types value()method
Method calling Conversion action
Int i=intVal intValue(); Object to primitive integer
Float f=floatVal.float value(); Object to primitive float
Long l=long Val.longValue(); Object to primitive long
Double d=doubleVal.double(); Object to primitive double
Converting number string to using string () method
Method calling Conversion action
Str=Integer.toString(i); Primitive String to integer
Str=folat.toFloat(f); Primitive float to string
Str=double.toDouble(d); Primitive double to string
Str=long.toLong(i) Primitive long to string
Converting string objects to number object using the static method valueOf()
Method calling Conversion action
doubleVal=double.valueOf(str); Converts string to double object
floatVal=float.valueOf(str); Converts string to float object
intVal=integer.valueOf(str); Converts string to integer object
longVal=long.valueOf(str); Converts string to long object
Converting number string to number using parsing methods
Int i=integer.paseInt(str); Convert string to primitive integer
Float f=float.parsefloat(str);
Convert string to primitive float
long f=long.parselong(str); Convert string to primitive long
double f=double.parsedouble(str);
Convert string to primitive double
Method calling Conversion action
Auto boxing and unboxing:-
The auto boxing & unboxing feature , introduced in J2SE 5.0 facilitates the process of handling primitive
data types in collection .we can use this feature to convert primitive data type to wrapper class type
automatically .the compiler generates a code implicitly to convert primitive types to the corresponding
wrapper class type & vice versa .for example ,consider the following statement:-
Double d=98.42;
Double dbl=d.double value();
Using the autoboxing and unboxing feature , we can rewrite the above code as:-
Double=98.42;
Double dbl=d;
How, the java complier provides restriction to perform the following conversion:-
1. Convert from null type to any primitive type.
2. Convert to the null type other than the identify conversion.
3. Convert from any class type c to any array type if C is not object.
Vector without using autoboxing & unboxing :-
Nesting of methods:-
We discussed earlier that a method of a class can be called only by an object of that class (or
class itself in the case of static methods ) using the dot operator however , there is an exception
to this . A method can be called by using its name by another method of the same class , this is
known as nesting of methods
Program illustrated the nesting of methods inside a class. The class nesting defines one
constructor and two methods , namely largest () and display() . The method display calls the
method largest () to determine the Largest of
the two number & the display then display the
results.
Output: