deepika mittal,bca ,2nd year
TRANSCRIPT
Project Report Java Programming
Information Technology
Topic
Wrapper Class and
Nesting of Methods
Submitted By
Deepika Mittal
BCA IInd Year
Dezyne E’cole College
www.dezyneecole.com
R
Project Report
On
Java Programming
At
Dezyne E’cole College
Ajmer
Submitted to
Dezyne E’cole College
Towards The
Partial Fulfillment on
Bachelor’s of Computer Application
By
Deepika Mittal
Dezyne E’cole College
106/10, Civil line, Ajmer
Tel:–0145-2624679
www.dezyneecole.com
2016-17
R
ACKNOWLEDGMENT
I Deepika Mittal, Student of Dezyne E’cole College, an Externally 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 of Project.
Thank You
SYNOPSIS
This Project is a Miner Project Mode, Based on the Theoretical Concepts
of Java. This Project Has Made our Basic Concepts on Java Strong.
Q. What is wrapper class and Methods of Nesting?
Ans.
Wrapper Classes
As pointed out earlier. Vector cannot handle primitive data types 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:-
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 type and
objects. 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 typeValue()
Method:-
Method Calling Conversion Action int i=IntVal.intValue(); Object to Primitive integer
float f=FloatVal.floatValue(); Object to Primitive float
long l=LongVal.longValue(); Object to Primitive long
double d=DoubleVal.doubleValue(); Object to Primitive double
Converting Numbers to String Using to String () Method:-
Method Calling Conversion Action 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 Objects to Numbers Objects 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
IntegerVal = Integer.ValueOf(str); Converts string to Integer object
LongVal = Long.ValueOf(str); Converts string to Long object
Converting Numeric String to Primitive Numbers Using Parsing Methods:-
Method Calling Conversion Action int i= Integer parseInt(str); Converts string to primitive integer
long l= Long parseLong(str); Converts string to primitive long
Autoboxing and Unboxing
The Autoboxing and unboxing feature, introduced in J2SE 5.0, facilitates the process of handling
primitive data types in collections. We can use this feature to convert primitive data types to
wrapper class types 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
statements:
Double d = 98.42;
double dbl = d.doubleValue();
Using the Autoboxing and Unboxing feature, we can rewrite the above code as
:-
Double d = 98.42;
double dbl = d;
How, the java compiler provides restrictions to perform the following conversion:-
Convert from null type to any primitive type.
Convert to the null type other than the identify conversion.
Convert from any class type C to any array type if C is not object.
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 only 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 displays the result.
2. Another Example
A method can call any number of methods. It is also possible for a called method to call another
method. That is, method1 may call method2, which in turn may call method3.