Upload
dezyneecole
View
29
Download
0
Embed Size (px)
Citation preview
Information Technology
Project Report Java Programming
TOPIC Wrapper class and nesting method
Submitted By
YASHIKA SONI
BCA (Bachelors of Computer Application
Dezyne E’cole College
WWW.dezyneale.com
Project Report
On
Project Report Java Program
At
Dezyne E’cole College
Ajmer
Submitted to
Dezyne E’cole College
To Word The
Partial Fulfillment On
BCA (Bachelors of Computer Application)
By
YASHIKA SONI
Dezyne E’cole College
106/10 Civil Lines Ajmer
Tel- 0145-2624679
WWW.dezyneale.com
YEAR- 2016-17
Ackmoweledment
I YASHIKA SONI STUDENT OF DEZYNE
E’COLE COLLEGE ,AN EXTREMELY GRATEFUL
TO EACH AND EVERY INDIVIDUAL WHO WAS
CONTRIBUTED IN SUCCESSFUL COMPLETION
OF MY PROJECT.
I EXPRESS MY GRATITUDE TO WARDS
DEZYNE E’COLE COLLEGE FOR THEIR
GRIEVANCE AND CONSTANT SUPERVISE AS
WELL AS FOR PROVIDING THE NECESSARY
INFORMATION AND SUPPORT REGARDING
THE COMPLETION OF PROJECT.
THANK YOU
Synopsis
THIS PROJECT IS MINER. PROJECT MADE
BASED ON THE THEORETICAL CONCEPTS OF
JAVA THIS PROJECT HAS MADE OUR BASIC
CONCEPTS ON JAVA STRONG.
Wrapper Class As pointed out earlier, vectors 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 shows the simple data types and their
corresponding wrapper class types.
Wrapper Classes For Converting Types
Simple Types 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 types 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 Numbers 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 toString () 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 Numeric Objects Using the Static Method
Value Of ()
Method Calling Conversion Action
DoubleVal=Double.ValueOf(str); Converts string to Double object
FloatVal=Float.ValueOf(str); Converts string to Float object
IntVal=Int.ValueOf(str); Converts string to Int 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.parseInt(str) Converts String to Primitive Integer
//Converting Primitive Numbers to Object Numbers
//Converting Object Numbers to Primitive Numbers
//Converting Numbers to String
//Converting String Object to Numeric Object
//Converting Numeric String to Primitive Numbers
Auto boxing 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 data types to the
corresponding wrapper class type and vice versa.
For example, consider the following statement
Double d=98.42;
Double dbl=d;
How, the java compiler provides restrictions to perform the
following conversions:
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 display the result.
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.