Powerful Google developer tools for immediate impact! (2023-24 C)
Sudarshan Joshi,BCA 2nd Year
1. INFORMATION TECHNOLOGY
Project Report
Java Programming
Topic
Wrapper Class and
Nesting Method
Submited By
Sudarshan Joshi
BCA - II year
Dezyne E’cole College
www.dezyneecol.com
2. 1
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)
By
Sudarshan Joshi
Dezyne E’cole College
106/10, Civil Lines, Ajmer
Tel.-0145-2624679
www.dezyneecole.com
2016-2017
3. 2
ACKNOWLEDGMENT
I Sudarshan Joshi, Student Of Dezyne E’cole College, An Extremely Granted 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 Of Project.
THANK YOU.
4. 3
Synopsis
This project is a Miner project Made, based on The Theoretical Concept of Java This
Project has made our Basic Concept on Java Strong.
5. 4
Wrapper Classes:-
As pointer out earlier, vectors cannot handle primitive data type like int, float, char 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 types
and their corresponding wrapper class types.
Wrapper Classes For Converting Types:-
Simply Type Wrapper Class
boolean Boolean
char Character
double Double
float Float
int Integer
long Long
The wrapper class have a number of unique methods for handling primitive data type and
objects. They are listed in the following table.
Converting Primitive number to object number using Constructor
method:-
Constructor Calling Conversion Active
Integer intval =new Integer(i); Primitive integer to Integer Object
Float floattval =new Float(f); Primitive float to Float Object
Double doubletval =new Double(d); Primitive double to Double Object
Long longval =new Long(l); Primitive long to Long Object
Converting object number to Primitive number using typevalue ()
method:-
Method Calling Conversion Active
Int i=Integer.intValue(); Object to primitive integer
float f=Float.floatValue(); Object to primitive Float
double d=Double.doubleValue(); Object to primitive Double
long l=Long.longValue(); Object to primitive Long
6. 5
Converting Number to String using toString () method:-
Method Calling Conversion Active
str=Integer.toString(i); primitive integer to string
str=Float.toString(f); primitive Float to string
str=Double.toString(d); primitive Double to string
str=Long.toString(l); primitive Long to string
Converting String object to Numeric objects using the String Method
valueOf ():-
Method Calling Conversion Active
IntegerVal=Integer.valueOf(str) Converts string to Integer object
FloatVal=Float.valueOf(str) Converts string to Float object
DoubleVal=Double.valueOf(str) Converts string to Double object
LongVal=Long.valueOf(str) Converts string to Long object
Converting Numeric String to Primitive Number using Parsing
method:-
Method Calling Conversion Active
Int i=Integer.parseInt(str); Converting String to Primitive integer
Long l=Long.parseLong(str); Converting String to Primitive long
12. 11
Auto Boxing and Unboxing:-
The auto boxing and unboxing feature, introduced in J2SE 5.0 facilitates the process of
handling primitive data type in collections. We can use this feature to convert primitive
data type to wrapper class type automatically. The compiler generates a code implicitly 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.doubleVlaue();
Using the auto boxing and unboxing feature, we can rewrite the avoid code as:
Double d=98.42;
Double dbl =d;
How, the java complier provides restrictions to perform the following conversions:-
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.
14. 13
7. Vector with using auto boxing and unboxing:-
Output:-
Method of Nesting:-
We discuss earlier that a method of the class can be called by an object of that class (or
class itself, in the case of static methods) using the dot operator. How’s, ever 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 illustrates 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 numbers and
then display the result.
15. 14
1.Nesting of method:-
Output:-
A method can call any number of methods. It is also possible for a called method to call
another method. This is, method 1 may call method 2, which is turn may call method 3.