Samarth Gaur ,BCA 2nd Year
-
Upload
dezyneecole -
Category
Technology
-
view
61 -
download
1
Transcript of Samarth Gaur ,BCA 2nd Year
INFORMATION TECHNOLOGY
PROJECT REPORT JAVA PROGRAMMING
TOPIC:-
WRAPPER CLASS AND NESTING METHODS
SUBMITTED BY- SAMARTH GAUR
CLASS BCA II YEAR
R
Project Report
On Java Program
At Dezyne E’cole College Ajmer
Submitted to Dezyne E’cole College
towards the Partial Fulfillment on
BCA By Samarth Gaur
Dezyne E’cole College
106/10, civil lines, Ajmer Tel-0145-2624679
www.dezyneecole.com 2016-17
R
ACKNOWLEDGEMENT
I Samarth Gaur, Student Of Dezyne E’ Cole College, An 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 Constant Supervision As Well As 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 Concepts Of JAVA This Project Has Made Our Basic Concepts On JAVA Strong.
Wrapper Classes: As pointed out earlier, vector cannot handle primitive data types like int, float 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 types and their corresponding wrapper class types.
Simple Type Wrapper Class
Boolean Boolean
Char Character
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 Numbers 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 Numbers 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=LongVal.longVaue(); Object to Primitive long double d=DoubleVal.doubleValue();
Object to Primitive double
Converting Numbers 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 Primitive double to string str=Long.toLong Primitive long to string
Converting String Objects to Numbers Objects 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
IntVal=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
float f=Float.parseFloat(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 Numbers to Object Numbers
Converting object Numbers to Primitive Numbers
Converting Numbers to String
Converting Numeric String to Primitive Numbers
Converting Numeric String to Primitive Numbers
Autoboxing and Unboxing: The autoboxing and unboxing feature, introduced 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 type automatically. Vector without using autoboxing and unboxing
Vector with using autoboxing and unboxing
Nesting of Methods
Nesting of Methods: We discussed earlier that a method of class can be called only by an object of that class (or class itself in the class of static methods) using the dot operator .However, there an exception to this. A method can be called by using only its same class. This is known as nesting of methods. Program illustrates the nesting of methods inside a class. The class nesting defines one constructor & two methods, namely largest() & display(). The method display() calls the method largest() to determine the largest of the two numbers & then display the result.
A method can call any numbers 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.