Deepak Soni,BCA 2nd Year
-
Upload
dezyneecole -
Category
Technology
-
view
65 -
download
0
Transcript of Deepak Soni,BCA 2nd Year
2016
INFORMATION TECHNOLOGY
PROJECT REPORT
JAVA PROGRAMMING
TOPIC:
Wrapper classes & Nesting of methods
SUBMITTED BY:
Deepak soni
BCA
Dezyne E’cole College
www.dezyne e’cole college
G
pg. 1
Project Report
On
Java programming
Dezyne E’cole College
Ajmer
Submitted to: Dezyne E’cole College
Toward the
Partial fulfillment on
Bachelors of computer application
By
Deepak soni
Dezyne E’cole College
106/10, civil lines, Ajmer
Tele:-0145-2624679
www.dezyne E’cole College
2016-2017
pg. 2
Acknowledgment
I Deepak soni student of Dezyne E’cole College, an extremely
grateful to each and every individual who has contributed is
successful completion of my project.
I express my gratitude toward Dezyne E’cole College for their
guidance and constants supervision is well as for providing
the necessary information and support pergarding the
completion of project.
Thank You
pg. 3
SYMEPSIS
This project is a miner project made based on the theoretical
concepts of java. This project has made our basic concept on
java strong.
pg. 4
Wrapper Classes
As pointed out earlier, vector cannot handle primitive data type like int, float,
char, and double. Primitive data type may be converted into object type by using
the wrapper classes contained in 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 Chararcter double Double
float Float Int Int
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 Number 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(); Primitive long to Long Object
pg. 5
Converting Object Number to Primitive Number using type
Value() Method
Converting Number 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.to Double (i); Primitive double to string
Str=Long.toLong(i); Primitive long to string
Converting String Object to Number Object 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 double i=Double.ParseInt(str); Converts string to primitive double
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
pg. 11
Autoboxing & Unboxing
The autoboxing and unboxing feature introduced in J2SE 5.0,facility the process
of handling primitive data type in collection.We can use this feature to convert
primityive data type to wrapper class types automatically.
The compiler genrates a code implicity to convert primitive type to the
corresponding wrapper class type and vice-versa.for Example consider the
following statement.
Double d=98.42;
Double db=a.doubleValue();
Using the autoboxing and unboxing featre we can rewrite the above code as::
Double d=98.42;
Double db1=a;
How,the java compiler produces restiction to following conversion
Convert from null type to any primitive type.
Convert to null to other than the identity
convert.
Convert from any class type c to any array type
if c is not object
pg. 14
Nesting of method
We discussed earlier that a method of a class can be called only by an object (of
that class for class ifself, in the case of static methods)using the dot
operator.However , there is an exception to this.it method can be called by using
only its name by another method of same class.This is know as nesting of
methods.
Program illstrates the nesting of methods inside a class.the class nesting defines
one constructor and two methods,namely largest() and display calls the method
largest of the method largest() to determine the largest of the two number and
then dislay the result.