View
86
Download
2
Category
Preview:
Citation preview
1
INFORMATION TECHNOLOGY
PROJECT REPORT JAVA PROGRAMMING
TOPIC
Wrapper class and Nesting
Method
Submitted by- Karishma Dhanwani
BCA-Bechlor of Computer Application || year
Dezyne E’cole College, www.dezynee’cole.com
2
Project Report On
Java Program
At
Dezyne E’cole College
Ajmer
Submitted To
Dezyne E’cole College
Towards The
Partial Fullfillment on
BCA
Bachlores Of Computer Application
By
Karishma Dhanwani
Dezyne E’cole College
106/10 Civil Lines, Ajmer
Tel-0145-2624679
www.dezyne e’cole.com
2016-2017
3
ACKNOWLEDGEMENT I Karishma Dhanwani, Student Of Dezyne E’cole College, An Extremelly
Grantefull To Each And Every Individual Who Has Contiributed In Successful
Comletion 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
Synopsis This Project is a Minar Project Made, Based On The Theoretical Concepts of
Java This Project Has Made our Basic Cocepts On Java Strong.
5
Wrapper class :
As pointed out earlier, vectors 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 packages. Following table shows the simple data types and their corresponding wrapper class
types.
Simlpe 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 handeling primitive data type and object.
They are listed in the following tables.
Converting Primitive Numbers to Object Number Using Constructor Method
Constructor Calling Converting 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 Number to Primitive Number Using Type Value() Method
Method Calling Conversion Action
int i=IntVal.intValue(); Object to Primitive integer
Float f=FloatVal.floatValue(); Object to Primitive float
Long l=Long.longValue(); Object to Primitive long
Double d=DoubleVal.doubleValue(); Object to Primitive Double
6
Converting Number to String Using to String() Method
Method Calling Conversion Action
Str=Integer.toString(i); Primitive integer to string
Str=Float.toFloat(f); Primitive float to string
Str=Double.toDouble(d); Primitive double to string
Str=Long.toLong(l); Primitive long to string
Converting String Object to Number Using the Static Method value of()
Method Calling Conversion Action
DoubleVal = Double.ValueOf(str); Converting string to Double object
FloatVal = Float.ValueOf(str); Converting string to float object
Integer = Integer.ValueOf(str); Converting string to Integer object
LongVal = Long.ValueOf(str); Converting string to Long object
Converting Numeric String to Primitive Number Using Parseing Method
Method Calling Conversion Action
Int l = Integer.ParseInt(str); Converting string to primitive integer
float f = Float.ParseFloat(str); Converting string to primitive float
long l = Long.ParseLong(str); Converting string to primitive Long
double d = Double.ParseDouble(str); Converting string to primitive double
7
Converting Primitive Numbers to Object Numbers
Output:-
8
Converting Object Numbers to Primitive Numbers
Output:-
9
Converting Numbers to String
Output:-
10
Converting String Object to Numeric Object
Output:-
11
Converting Numeric String to Primitive Numbers
Output:-
12
Auto Boxing and Unboxing
The auto boxing and unboxing feature, introduced in J2SE 5.0, Facilitates the process of handeling
primitive data type in collectings. 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 statement:-
Double d = 98.42;
Double dbl = a.double value();
Using the auto boxing 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 id C is not object.
13
Vector without using Autoboxing and Unboxing
Output:-
14
Vector with Autoboxing and Unboxing
Output:-
15
Nesting of Methods:-
We dicussed 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 method
can be called by using only its name by another method of the same class. This is known a Nesting of
Methods.
Prongram 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
16
Nesting of Methods
Output:-
17
Another program of Nesting
Output:-
A method can call any number of methods. It is also possible for a called method to call also possible for
a called method to call another method. That is, method1 may call method2, which in turn may call
methods.
18
Thank you…
Recommended