Upload
dezyneecole
View
14
Download
0
Embed Size (px)
Citation preview
R
INFORMATION TECHNOLOGY
PROJECT REPORT
Java programming
TOPIC:
WRAPPER CLASSES AND NESTING OF METHODS
SUMBITTED BY:
Aanchal Gupta
Bca (Bachelor of Computer Application)
Dezyne E’cole College,www.dezyneecole.com
Project report
On
Java program
At
Dezyne e’cole college
Ajmer
Submitted to Dezyne e’cole college
Toward the
Practical fulfillment on
BCA
By
Aanchal Gupta
Dezyne e’cole college
106/10, civil lines, ajmer
Tel-0145-2624679
www.dezyneecole.com
2016-2017
ACKNOWLEDGEMENT
I Aanchal Gupta Student Of Dezyne E’cole College. An Externally
Grateful To Each And Every Individual Who Has Contribute In
Successful Completion Of My Project.
I Express My Gratitude Towards Dezyne E’cole College For Their
Guidelines And Constant Supervision As Well For Providing The
Necessary Information And Support Regarding The Completion Of
Project.
Thank You.
SYNOPSIS
This Project Is A Minor Project Made,Based On The Theoretical
Concept Of Java This Project Has Made Our Basic Concept On JAVA
Strong.
Wrapper Classes:
As pointed out earlier,vectors cannot handle primitive data type like
int,float,char and double. Primative 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 types and their
corresponding wrapper class types.
Wrapper Classes For Converting types
Simple Type Wrapper 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 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(l); Primitive long to Long object
Converting object number to primitive number using
typeValue() method
Method calling Conversion action Int i=IntVal.intValue(); Object to primitive integer
Float f=FloatVal.floatVlue(); Object to primitive float
Long l=LongValue.longValue(); Object to primitive long
Double d =DoubleVal.doubleValue(); Object to primitive double
Converting number to string using to string()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 object to numbers object using static
method valeOf()
Method calling Conversion action DoubleVal=Double.ValueOf(str); Converts string to Double object
floatVal=Float.valueOf(str); Converts string to Float object
IntVal=Integer.ValueOf(str); Converts string to Integer object
LongVal=Long.valueOf(str); Converts string to Long object
Converting numeric string to primitive number using parsing
method
Method calling Conversion action Int i=Integer.parseInt(str); Converts string to Primitive integer Float f=float.parselong(str); Converts string to Primitive float Long l=long.parselong(str); Converts string to Primitive long Double d=double.parseDouble(str); Converts string to Primitive double
converting primitive number to object number
Converting object number to primitive number:
Converting number to string:
Converting string object to numeric object
Converting number to primitive numbers
Autboxing and unboxing
The Autboxing and unboxing feature,introduce 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 primitive type to
the corresponding wrapper class type and vice versa. For
example,consider the following statement:
Double d_object=98.42;
Double d_primitive=d_object.doubleValue();
Using the Autboxing and unboxing feature,we can rewrite the above
code as:
Double d_ object=98.42;
Double d_primitive=d_object;
How,the java compiler provides restrictions to perform the following
conversions:
1) Convert from null type to any primitive type.
2) Convert to the null type other than the identify conversion.
3) Convert from any class type c to any array type if c is not
object.
Vector without using autoboxing &unboxing
Vector with using autoboxing &unboxing
Nesting of methods
We discussed earlier that a method of a class can be called by an
object of that class (or class itself,in the case of static method)using
the dot operator.however, ther is an exception to this. A method can
be called by using only its name by another method of the class. This
is known as nesting of methods.
The class nesting defines one constructor and two methods, namely
largest() and display(). The method display() calls the method
largest() determine the largest of the two numbers and then
displays the result.
Largest value=50
A method can call any number of methods. It is also poosible for a
called method to call another method. That is, method1 may call
method2,which in turn may call method3.
THANK YOU