Ram Prasad ,BCA 2nd Year

16
INFORMATION TECNOLOGY TOPIC Wrapper class and Nesting Method SUBMITTED BY Ram Prasad Bachelor Of Computer Application II Year Dezyne E’cole college www.dezyneecolecollege.com JAVA PROGRAMMING

Transcript of Ram Prasad ,BCA 2nd Year

INFORMATION TECNOLOGY

TOPIC

Wrapper class and

Nesting Method

SUBMITTED BY

Ram Prasad

Bachelor Of Computer Application II Year

Dezyne E’cole college

www.dezyneecolecollege.com

JAVA PROGRAMMING

Project Report

On

Java programming

At

Dezyne E’cole college

Ajmer

Submitted to

Dezyne E’cole College

Towards

Practical fulfillment

Bca

By

Ram Prasad

Dezyne E’eole College

106/10, Civil line, Ajmer

Tel: 0145-2624679

www.dezyneecole.com

Year

2016-2017

ACKNOWLEDGMENT

I Ram Prasad student of Dezyne E’cole College an externally grate

full 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.

Thank You

SYNOPIS

This project is a miner project made based on the

theoretical concepts of JAVA .This project has made our

basic concepts on JAVA strang.

Wrapper Classes:-

As pointed out earlier, vectors cannot handle primitive data type 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 type and their corresponding wrapper class types.

Wrapper Classes For Converting Type

Simple Type Wrapper Class boolean Boolean

char Character

double Double

float Float

Interger Interger

Long Long

The wrapper classes have a number of unique methods for handing primitive data

Type and objects. They 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 FlaotVal=new Float(i); Primitive Float to Float Object

Double IntVal=new Double(i); Primitive Double to Double Object

Long FlaotVal=new Long(i); Primitive Long to Long Object

Converting object Number to Primitive Number Using

Type value() Method

Constructor Calling Conversion Action

Int i=IntVal.intValue(); Object to Primitive integer

float i=FloatVal.floatValue(); Object to Primitive Float

Long l=longVal.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.toFloat(f); Primitive Float to string

str=Double.todouble(i); Primitive Double to string

Str.Longtolong(i); 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

Int.Intger.tovalueof(str); Converts string to Integer object

Long.Long.tovalueof(str); Converts string to Long object

Converting Numeric String to primitive Number Using

parsing Methods

Method Calling Conversion Action Int i=Integer.perseInt(str); Converts string to Primitive Integer

float f=float.perseInt(str); Converts string to Primitive float

Long l=long.perseInt(str); Converts string to Primitive long

Double d=double.perseInt(str); Converts string to Primitive double

Converting Primitive Numbers to object Number:-

Output:-

Converting Object Number to primitive Number:-

Output:-

Converting Number to String :-

Output:-

Converting string object to numeric object:-

Output:-

Converting Number String to primitive Number:-

Output:-

Auto Boxing and unboxing

The auto boxing and unboxing feature in traduced in J2SE facilitables the process of

handing primitive data type in collection we can this features to convert primitive data type

to wrapper class types automatically the compailer generates a code implicitly to convert

primitive type to the corresponding wrapper classes type and vice-versa for example.

Consider the following statement:-

Double d=98.42;

Double dbl=a.double and unboxing feature we can rewrite the above code as:-

Double d=98.42;

Double dbl=d;

How the java compiler provider restriction to perform the

following conversion:-

Convert from null to any primitive type.

Convert to the null type other than the identify convert.

Convert from any type c to any type if c is not object.

Vector without using autoboxing & unboxing :-

Output:-

Vector with using autoboxing & Unboxing :-

Output:-

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 method ) using the dot operator. However There is an

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 ().the method display() calls the

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

Nesting of method:-

Output:-

Nesting of method:-

Output:-

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

method.

That is method 1 may call method 2 which in turn may call methods 3.

THANK YOU