Upload
dezyneecole
View
17
Download
0
Embed Size (px)
Citation preview
INFORMATION TECHNOLOGY
PROJECT REPORT
JAVA PROGRAMMING
TOPIC
Wrapper Class and Nesting of Methods
Submitted By
Kajal Gaharwal
Bachelors of Computer Application
2nd year
www.dezyneecole.com
Project Report
On
JAVA Program
At
Dezyne E'cole College
Ajmer
Submitted To
Dezyne E'cole College
Towards the
Partial fulfillment on
Bachelors of Computer Application
By
Kajal Gaharwal
Dezyne E'cole College
106/10, Civil Lines Ajmer
Tel-0145-2624679
www.dezyneecole.com
2016-17
ACKNOWLEDGEMENT I, Kajal Gaharwal, Student of Dezyne E'cole College, am extremely grateful to each other 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 minor project mode, based on the theoretical concept of JAVA. This project has made our basic concept on JAVA strong.
P a g e | 1
WRAPPER CLASS
As pointed out earlier, vectors cannot handle primitive data type like int, float, char
and double .Primitive data type may be converted into objet types by using the
wrapper classes contained in the java. Lang package. Following table shows the
simple data types and their corresponding wrapper class.
Wrapper class 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(); Primitive integer to object Integer Float FloatVal=new Float(); Primitive float to object Float
Double DoubleVal=new Double(); Primitive double to object Double
P a g e | 2
Converting object numbers to primitive numbers 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.float Value() Object to primitive long Double d=doubleVal.double Value() 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=Long.toString(l) Primitive long to string
Str=Double.toString(id Primitive double to string
Converting string object to Numeric object using the static method value
Of ()
Method calling Conversion action Double val=Double.valueOf(str) Converts string to Double object
Float val=Float.valueOf(str) Converts string Float object Int val=Int.valueOf(str) Converts string to Integer object
Long val=Long.valueOf(str) Converts string to Long object
Converting Numeric string to primitive Numbers using parsing method
Method calling Conversion action Int i=Integer.parseInt(str) Converts string to primitive Integer
long l=Long.parseLong(str) Converts string to primitive Long
P a g e | 8
Auto boxing and unboxing
The auto boxing and unboxing feature, introduced in J2SE 5.0,facilitates
the process of handling primitive data type in collection .We use this
feature to converts primitive data type to wrapper class type
automatically .The compiler generates a code implicitly to convert
primitive type to the corresponding wrapper class type and visa -versa.
For example, consider the following statement
Double d=98.42;
Double dbl=d.doubleValue ();
Using the auto boxing and unboxing feature, we can rewrite the above
statement.
The above code as-
Double d=98.42;
Double dbl =d;
How, java compiler provides restrictions to perform the following
conversions-
P a g e | 9
1. Converts from Null type to any primitive type.
2. Converts to the Null type other than the identify conversions.
3. Convert from any class type C to any array type if C is not object.
Vector without using auto boxing and unboxing
P a g e | 10
Vector with using auto boxing and unboxing
NESTING OF METHODS
We discuss 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
P a g e | 11
there is a 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 () calls the method
largest () to determine the largest of the two numbers and then display the result.
Example-
P a g e | 13
A method can call any number of methods .It is called method to call another
method .That is, method 1 may call method2, which in turn may call method3.