DevEX - reference for building teams, processes, and platforms
Mithlesh Singh Rawat, BCA 2nd Year
1. INFORMATION TECHNOLOGY
Project Report
Java Programming
TOPIC
Wrapper Class and
Nesting Method
Submitted By
Mithlesh Singh Rawat
BCA - || year
Dezyne E’cole College
www.dezyneecole.com
2. Project Report
On
Java Program
At
Dezyne E’cole College
Ajmer
Submitted To
Dezyne E’cole College
Towards The
Partial Fulfillment on
BCA
(Bachelor of Computer Application)
Mithlesh Singh Rawat
Dezyne E’cole College
106/10, Civil lines, Ajmer
Telephone – 0145-2624679
www.dezyneecole.com
2016-2017
3. ACKNOWLEDGEMENT
I Mithlesh Singh Rawat , student of Dezyne E’cole College an 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 constant supervision as well
as for providing the necessary information and support regarding the completion project.
Thank You.
4. Synopsis
This project is a Minor project made, based on the Theoretical concepts of java.
This project has made our basic concepts on java strong.
5. Wrapper Classes :
As pointed out earlier, vectors cannot handle primitive data types like int, char,
float and double. Primitive data type may be converted into object types by
using the wrapper classes contained in the java.lang Package. Following table
shows the simple data type and their corresponding wrapper class types.
Wrapper Classes For Converting Types
Simple Type Wrapper Class
boolean Boolean
Char Character
Double Double
Float Float
Int Integer
long Long
The wrapper classes have a number of unique method for handling primitive data
types and objects. They are listed in the following tables.
Converting Primitive Numbers to Objects 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(i); Primitive double to Double Object
Long LongVal=new Long(i); Primitive long to Long Object
Converting Objects Numbers to Primitive Number Using typeValue() Method
Method Calling Conversion Action
Int i=IntVal.IntValue(); Objects to Primitive Integer
Float f=floatVal.floatValue(); Objects to Primitive Float
Long l=LongVal.longValue(); Objects to Primitive Long
Double d=DoubleVal.doubleValue(); Objects to Primitive Double
6. Converting Numbers to String Using to String() Method
Method Calling Conversion Action
Str=Integer.toString(i); Primitive Integer to string
Str=Float.toFloat(i); Primitive Float to string
Str=Double.toDouble(i); Primitive Long to string
Str=Long.toLong(i); Primitive Double to string
Converting String Objects to Numbers Objects Using the Static Method
ValueOf()
Method Calling Conversion Action
DoubleVal=Double.valueOf(str); Converts string to Double objects
FloatVal=Float.valueOf(str); Converts string to Float objects
IntVal=Integer.valueOf(str) Converts string to Integer objects
LongVal=Long.valueOf(str); Converts string to Long objects
Converting Numeric string to primitive Numbers Using Parsing Methods
Method Calling Conversion Action
Int i=Integer.parseInt(str); Converts string to primitive integer
Float f=Float.parsefloat(str); Converts string to primitive float
Long l=Long.parselong(str) Converts string to primitive long
Doubled d=Double.parseDoubled(str); Converts string to primitive double
12. AutoBoxing and unboxing
The autobxing and unboxing feature, introduced in J2se 5.0, facilities the process of
handling primitive data type in collections. We can use this features to convert primitive
data type to wrapper class types automatically the compiler generates a code implicitly to
convert primitive type to the corresponding wrapper class type and vice-virsa for example,
consider the following statements :-
Double d=56.99;
Double dbl=d.doubleValue();
Using the autoboxing and unboxing features, we can rewrite the above code as :-
Double d=56.99;
Double dbl=d;
How, the java compiler provides restrictions to perform the following conversions.
Convert from null type to any primitive type.
Convert the null type other than the identify conversion:
Convert from any class type c to any array type if c is not object.
14. 7. Vector with using autoboxing and unboxing demo7.
OUTPUT :-
15. Nesting of Method :-
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 only its name by another method of
the same class. This is known as nesting of methods.
Program illustrates the nesting of method inside a class. The class nesting defines
one constructor and two methods, namely largest() and display(). The method largest() to
determine the largest of the two numbers and them display the result.
8. Nesting of method demo8.
OUTPUT :-