New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Rakesh Bijawat, BCA 2nd Year
1. 1
Project Report
Java Programme
Submitted By:
Rakesh Bijawat
BCA
Dezyne E’cole College
www.dezyneecole.com
Topic:
Wrapper Class and
Nesting Methods.
INFORMATION
TECHNOLOGY
2. 2
Project Report
On
Java Program
At
Dezyne E’cole College
Ajmer
Submitted To
Dezyne E’cole College
Towards The
Partial Fulfillment
BCA
(Bachelors of Computer Applications)
By
Rakesh Bijawat
Dezyne E’Cole College
106/10, Civil Lines, Ajmer
Tel.0145-2624679
www.dezyneecole.com
2016-2017
3. 3
ACKNOWLEDGEMENT
I Am Rakesh Bijawat, Student Of Dezyne E’cole College, And Am
Extremely 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 Constants
Supervision As Well As For Providing The Necessary Information And
Support Regarding The Completion Of Project.
4. 4
SYNOPSIS
This Project Is a Miner Project Made Based on the Theatrical Concepts
of JAVA .This Project Has Made Our Basic Concept on JAVA Strong.
5. 5
Wrapper Classes:
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
Package. Following table shows the simple data type and their
corresponding wrapper class type.
Wrapper classes for converting simple 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 types and objects. They are listed in the following
tables.
Converting Primitive Numbers to object Numbers using Constructor
methods
Constructor Calling Conversion action
Integer Interval=new Integer(i); Primitive integer to Integer object
Float FloatVal=new float(); 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.
6. 6
Converting object numbers to primitive number using type value ()
method
Method calling Conversion action
Int i=IntVal.int value(); Object to primitive integer
float f=FloatVal.float value(); Object to primitive float
Long l=LongVal.long value(); Object to primitive long
Double d=DoubleVal.double
value();
Object to primitive double
Converting numbers to string using to String () method
Method calling Conversion action
Str=Integer.toString(); Primitive integer to String
Str=Float.toFloat(); Primitive float to String
Str=Double.toDouble(); Primitive double to String
Str=Long.toLong(); Primitive long to String
Converting String objects to numbers objects using the static method
value Of ()
Method calling Conversion
DoubleVal=Double.ValueOf(Str); Converts string to Double objects.
FloatVal=Float.ValueOf(Str); Converts string to Float objects.
IntVal=Integer.ValueOf(Str); Converts string to Integer objects.
LongVal=Long.ValueOf(Str); Converts string to Long objects.
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.
12. 12
Auto boxing and Unboxing
The auto boxing and unboxing feature, introduced in J2SE 5.0, facilities
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 implicity to convert
primitive types 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 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
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.
15. 15
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 illustrations 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.
18. 18
A method can call any number of methods. It also possible for a called
method to call another method. That is, method1 may call method2,
which in turn may call method3.