reshma kodwani,bca,2nd year

15
INFORMATION TECHNOLOGY PROJECT REPORT JAVA PROGRAMMING TOPIC WRAPPER CLASS AND NESTED METHODS SUBMITTED BY RESHMA KODWANI BCA II YEAR DEZYNE E’COLE COLLEGE www.dezyneecole.com 2016-2017 R

Upload: dezyneecole

Post on 08-Jan-2017

40 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Reshma Kodwani,BCA,2nd Year

INFORMATION TECHNOLOGY

PROJECT REPORT JAVA PROGRAMMING

TOPIC

WRAPPER CLASS AND

NESTED METHODS

SUBMITTED BY

RESHMA KODWANI

BCA II YEAR

DEZYNE E’COLE COLLEGE

www.dezyneecole.com

2016-2017

R

Page 2: Reshma Kodwani,BCA,2nd Year

Project Report

On

Java Programming

At

Dezyne E’cole College

Ajmer

Submitted To

Dezyne E’cole College

Towards The

Partial Fulfillment On

BCA (Bachelor of Computer Application)

By

Reshma Kodwani

Dezyne E’cole College

106/10,Civil Lines, Ajmer

Tel-0145-2624679

Www.Dezyneecole.Com

2016-2017 Year

R

Page 3: Reshma Kodwani,BCA,2nd Year

ACKNOWLEDGMENT

I Reshma Student Of Dezyne E’cole College, 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 Constant Supervision As Well As

For Providing The Necessary Information And Support Regarding The

Completion Of Project.

Thank You

Page 4: Reshma Kodwani,BCA,2nd Year

Synopsis

This Project Is A Minor Project Made, Based On The Theoretical Concept

Of JAVA. This Project Has Made Our Basis Concepts On JAVA Strong.

Page 5: Reshma Kodwani,BCA,2nd Year

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 types and their corresponding

wrapper class types.

Wrapper Classes For Converting Types

Simple type Wrapper class boolean Boolean

Char Character

Double Double

Float Float

Int Integer

Long Long

The wrapper classes have a member of unique methods for handling primitive data type and

objects. They are listed in the following tables.

Constructor 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=newLong(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=Float Val.floatValue(); Object to primitive float

long l=LongVal.longValue(); Object to primitive long

double=DoubleVal.doubleValue(); Object to primitive double

Page 6: Reshma Kodwani,BCA,2nd Year

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(d); Primitive double to string

str=long toLong(l); Primitive long to string

Converting String Objects to Numbers Objects Using the Static Method valueOf()

Method Calling Conversion Action DoubleVal=Double.valueOff(str); Converts string to Double object

FloatVal=Float.valueOff(str); Converts string to Float object

IntVal=Integer.valueOff(str); Converts string to Integer object

longVal=Long.valueOff(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

Page 7: Reshma Kodwani,BCA,2nd Year

Converting Primitive Numbers to Object Number

Page 8: Reshma Kodwani,BCA,2nd Year

Converting Object Number to Primitive Number

Converting Number to String

Page 9: Reshma Kodwani,BCA,2nd Year
Page 10: Reshma Kodwani,BCA,2nd Year

Converting String Objects to Numberic Objects

Page 11: Reshma Kodwani,BCA,2nd Year

Converting Numeric String to Primitive Number

Page 12: Reshma Kodwani,BCA,2nd Year

Auto boxing and Unboxing

The autoboxing and unboxing features,introduced in J2SE5.0 facilitates the process of handing

primitive data type in collections.We can use this features to convert primitive data type to

wrapper class types automatically.The compiler generates the code implicitly to convert primitive

type to corresponding wrapper class type and vice-versa.For example ,consider the following

statement.

Double d_object =97.77;

Double d_primitive=d_object.doubleValue();

Using the autoboxing and unboxing feature,we can rewrite the above code as:

Double d_object =97.77;

Double d_primitive=d_object;

How,the Java compiler provides restrictions to perform the following conversions:

Convert form 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.

Vector without using Autoboxing and Unboxing

Page 13: Reshma Kodwani,BCA,2nd Year

Vector with using Autoboxing and Unboxing

Page 14: Reshma Kodwani,BCA,2nd Year

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 ,this is an exception to this.A

method can be called by using 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().The method display()calls the

method largest() to determine the largest of the two numbers and then displays the result.

Nesting of methods

Page 15: Reshma Kodwani,BCA,2nd Year

Another example of nesting of methods

A method can call any number of methods.it is also possible for a called method to call another

method.That is,method1 may call method 2,which in turn may call method 3.