16
ROJECT EPORT JAVA PROGRAMMING TOPIC Wrapper Class and Nesting Method Submitted by Brijesh peswani BCA -II Year Dezyne E’cole College www.dezyneecole.com INFORMATION TECHNOLOGY

Brijesh Peswani,BCA 2nd Year

Embed Size (px)

Citation preview

ROJECT EPORT

JAVA PROGRAMMING

TOPIC

Wrapper Class and

Nesting Method

Submitted by

Brijesh peswani

BCA -II Year Dezyne E’cole College

www.dezyneecole.com

INFORMATION TECHNOLOGY

Project report

On

Java program

At

Dezyne E’cole college

Ajmer

Submitted to

Dezyne E’cole college

Towards The

Partial Fulfillment on

BCA – II year

(Bachelor of computer application)

By

Brijesh peswani

Dezyne e’cole college

106/10,civil lines,ajmer

Tel-0145-2624679

www.dezyneecole.com

AKNOWLEDGEMENT

I Brijesh Peswani Student Of Dezyne e’cole College An Extremely Grateful To Each And Every

Individual Who Has Contributed In Success Full Compaction 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.

Thank You.

Synopsis This project is a minor project made, based on the theoretical concept of java. This project has

made our basic concept of java strong.

Wrapper classes: As pointed out earlier vector cannot handle primitive data types like int ,float, char and

double primitive data types may be converted into object types by using the wrapper classes

contained in the java language package following table show the simple data types and their

corresponding wrapper class type..

Wrapper class for converting types:--

Simple types Wrapper class Boolean Boolean

Char Char Double Double Float Float Int Int

Long Long

The wrapper classes have a number of unique methods for handling primitive data types and object.

they are listed in following table.

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(i); Primitive float to float object

Double doubleval=newdouble(d); Primitive double to double object Long long val=newlong(i); Primitive long to long object

Converting object number to primitive number using types value ()method

Method calling Conversion action Int i=intval intvalue(); Object to primitive integer Float f=floatval..float value(); Object to primitive float Long i=long val.longvalue(); Object to primitive long Double d=doubleval.double(); Object to primitive double

Converting number string to using string() method:-

Converting string objects to number object 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 number string to primitive number using parsing methods:-

Int i=integer.parseInt(str); Converts string to Primitive integer Float f=float.parseInt(str); Converts string to Primitive float Long f=long.parseInt(str); Converts string to Primitive long Doublef f=double.parseInt(str); Converts string to Primitive double

Method calling Conversion action Str-integer.toString(i); Primitive string to integer

Str-float.toFloat(f); Primitive float to string

Str-double.toDouble(d); Primitive double to string

Str-long.toLong(i); Primitive long to string

Converting primitive numbers to object numbers:-

output

converting object number to primitive number:-

Output:-

Converting number to string:-

Converting string object to number object:-

Output:-

Converting numeric string to primitive number:-

Autoboxing and unboxing

The autoboxing and unboxing feature,introduce in jase 5.0,features the process of handling primitive

data types in collection .we can use this feature to convert primitive data types to wrapper class types

automatically .the compiler generates a code implicity to convert primitive type to the corresponding

wrapper class type and vice …for example::=

Consider the following:-

Double a=98.42;

Double dbl=a.doublevalue();

Using the autoboxing and unboxing feature,we can return:

Double d=98.42

Double dbl=a;

How the java compiler provides restrictionms perform the following

conversion:

1.Convert from null type to any primitive type..

2.Convert to the null type other the identity conversion..

3.Convert from any class type a to any array if it is not object..

Vector without using autoboxing &unboxing:_

*Vector with using autobxing and unboxing:-

Nesting of method:- We discussed earlier that a method of a class can be called only by an object of that class for class ,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 name by

another method of some 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 display the result….

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

This is method 1 may called method 2 which in turn may call methods…

*Another example of nesting of project;-

s

Thank You Brijesh peswani

BCA -II Year