New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Rahul Saini, BCA 2nd Year
1. PROJECT REPORT
JAVA PROGRAMMING
INFORMATION TECHNOLOGY
TOPIC
Wrapper class and
Nesting Method
SUBMITTED BY
RAHUL SAINI
BCA IInd
YEAR
Dezyne E’cole College
www.dezyneecole.com
2. P a g e | 1
PROJECT REPORT
On
Java programming
At
Dezyne E’cole College
Ajmer
Submitted
Dezyne E’cole College
Towards the
Partial fulfillment
Bachelor of computer application
By
Rahul Saini
Dezyne E’cole College
106/10, civil line, Ajmer
Tel-0145-2624679
www.dezyneecole.com
2016-2017
3. P a g e | 2
ACKNOWLEDGEMENT
I Rahul Saini Student Of Dezyne’ Ecole College
And Extremly Grateful To Each And Every
Individual Who Has Contribute In Sucessfull
Completion Of My Project I Express My Graditude
Towords Dezyne Ecole College For Their
Kindness.And Constant Supervision As Well As
Providing The Necessary Information And Support
Regarding The Completion Of Project.
Thank You
4. P a g e | 3
SYNOPSIS
This project is a minor project made based on the
theoretical concept of java this project has made
our basic concept on java strong.
5. P a g e | 4
Q .What is wrapper class? And explain nesting of method?
Ans.
WRAPPER CLASSES -> As point out earlier, vectors cannot handle
primitive data type types like int, float, char and double. Primitive data type’s likes may
be converted into object types by using the wrapper classes contained in the java.lang
package, following table shows the simple data types 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 methods for handling primitive data
types and object. They are listed in the following tables.
Converting primitive numbers to object number using constructor method
Constructor calling Conversion action
Integer IntVal=new Integer(i) Primitive integer to Integer object.
Float FloatVal=new Float(f); Primitive float to Float object.
Double DoubleVal=new Double(d); Primitive double to Double object.
Long LongVal=new Long(l); Primitive long to Long object.
Converting object numbers to primitive number using type value() method
Method calling Conversion action
int i=IntVal.int value(); Object to primitive integer
float f=FloatVal .float value(); Object to primitive float
long l=LongVal.long value(); Object to primitive long
double d=DoubleVal .double value(); Object to primitive double
6. P a g e | 5
Converting numbers to string using to string() method
Converting string objects to numbers objects using the static method
valueOf()
Converting numeric string to primitive numbers using parsing methods.
Method calling Conversion action
str=Integer.toString(); Primitive integer to string
str=Float.toString(); Primitive float to string
str=Double.toString(); Primitive double to string
str=Long.toString(); Primitive long to string
Method calling conversion
Double val=Double valueOf(str); Converts string to Double objects.
Float val=Float valueOf(str); Converts string to Float objects.
Int val=Integer valueOf(str); Converts string to Integer objects.
Long val=Long valueOf(str); Converts string to Long objects.
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.
Double d=Double.parseDouble(str); Converts string to primitive double.
7. P a g e | 6
//Converting primitive numbers to object numbers
Output
8. P a g e | 7
//Converting object numbers to primitive numbers
Output
9. P a g e | 8
//Converting numbers to string
Output
10. P a g e | 9
//Converting string object to numeric object
Output
11. P a g e | 10
//Converting numeric string to primitive numbers
Output
12. P a g e | 11
Autoboxing and unboxing->
The autoboxing and unboxing feature,introduced in j2se 5.0,facilitaes the process of
handling primitive data types in collection.we can use this feature to convert primitive
data types to wrapper class types automatically.
The compiler genrates a code implictly to convert primitive type to the corresponding
.
Wrapper class type and vice versa .
For example,consider the following statement:-
Double d=98.42;
double dbl=d.doubleValue();
Using the autoboxing and unboxing features ,we can rewrite the
above code as:-
Double d=98.42;
double dbl=d;
How the java compiler provide restriction to performe the following
conversion:-
-Convert from null type to any primitive type.
-Convert to the null type other than th identify conversion.
-Convert from any class type c to any array type if c is not object.
13. P a g e | 12
//Vector without using autoboxing &unboxing
Output
14. P a g e | 13
//Vectors with using autoboxing & unboxing
Output
15. P a g e | 14
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 method.
Progarm illustrated the nesting of methods,inside a class.
The class nesting defines one constructor and two methods,namely largest() and
display().The methods display() calls the methods largest() to determine the largest of
the two number and then display the result.
16. P a g e | 15
//Example of nesting of method
Output
17. P a g e | 16
//Another example of nesting of method
Output
A method can call any number of methods.it is also possible for a called methods to
call another method.That is methods to call method 2,which is turn may call methods3.