19
Information Technology Project Report Java Programming Topic Wrapper Class and Nesting Method Submitted By Farhaan Ahmed Bachelor of Computer Applications Dezyne E’cole College www.dezyneecole.com TM

Farhaan Ahmed, BCA 2nd Year

Embed Size (px)

Citation preview

Information Technology

Project Report Java Programming

Topic Wrapper Class and Nesting Method

Submitted By Farhaan Ahmed

Bachelor of Computer Applications

Dezyne E’cole College

www.dezyneecole.com

TM

Project report

On

Wrapper Class and Nesting Method

At

Dezyne E’cole College,

Ajmer

Submitted to

Dezyne E’cole College

Towards the

Partial Fulfillment of

Bachelor of Computer Applications

By

Farhaan Ahmed

Dezyne E’cole College

106/10, civil lines, Ajmer

Tel – 0145 – 2624679

www.dezyneecole.com

2016 - 17

TM

ACKMOWELEDMENT

I Farhaan Ahmed student of Dezyne E’Cole College ,an extremely

grateful to each and every individual who was contributed in

successful completion of my project.

I express my gratitude to wards Dezyne E’Cole College for their

grievance and constant supervise as well as for providing the

necessary information and support regarding the completion of

project.

THANK YOU

SYNOPSIS

This project is miner. Project made based on the theoretical concepts

of JAVA this project has made our basic concepts on JAVA strong.

P a g e | 1

Wrapper Class

As Point out earlier vector cannot handle primate data type like int, float, char and double,

primate 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 a type and

their corresponding wrapper class types

Wrapper class for converting Types

Simple Text Wrapper Class

Boolean Boolean

Char Character

double Double

float Float Real Numbers

Int Integer

long Long

The wrapper Classes Have a number of unique methods for handing primitive data

type and objects they are listed in the following table

Converting primitive numbers to objects number using

constructor method

Constructor Calling Conversations Action

Integer IntVal=new Integer(i); Primitive Integer To Integer Object

Float Val=new float(i); Primitive float To float Object

Double DoubleVal=new double(i); Primitive Double To Double Object

Long LongVal=new long (i); Primitive Long To Long Object

P a g e | 2

Converting object number to primitive number using type

value() method

Method calling Conversions Action

Int i=Intval.intvalue(); Object to Primitive integer

float i=floatval.floatvalue(); Object to Primitive float

long i=longval.longvalue(); Object to Primitive long

Double i=doubleval.intvalue(); Object to Primitive double

Converting number to string using tostring() method Method Calling Conversion Action

Str=integer.tostring(i); Primitive Integer To String

Str=float.tostring(i); Primitive float To String

Str=long.tostring(i); Primitive long To String

Str=double.tostring(i); Primitive double To String

P a g e | 3

Converting String object To numric objects using the static

method valueof()

Method Calling Conversations Action

Doubleval=double.valueof(str); Converting to string Double object

floatval=float.valueof(str); Converting to string float object

intval=int.valueof(str); Converting to string integer object

longval=long.valueof(str); Converting to string long object

Converting numeric string to primitive numbers using parsing

methods

Method Calling Conversation Action

Int i=integer.parsing(str); Converting String To primitive integer

Long i=long.parsing(str); Converting String To primitive long

P a g e | 4

//Converting Primitive Numbers to Object Numbers

OUTPUT:-

P a g e | 5

//Converting Object Numbers to Primitive Numbers

OUTPUT:-

P a g e | 6

//Converting Numbers to String

OUTPUT:-

P a g e | 7

//Converting String Object to Numeric Object

OUTPUT:-

P a g e | 8

//Converting Numeric String to Primitive Numbers

OUTPUT:-

P a g e | 9

Auto Boxing and Unboxing-

The Auto boxing And Unboxing feature introduced in J2SE 5.0, facilitates the

process of handling primitive data type in collection we can use this feature

to convert primitive data type to wrapper class type automatically the

compiler generated a code

Implicitly to convert primitive type to corresponding wrapper class type and

wrapper class type and vice-verssa for example,

Consider the following statement

Double d=98.43;

Double dbl= a.double value();

Using auto boxing and unboxing feature we can rewrite the above code

us;-

Double d=98.42;

Double dbl=a;

How to java compiler provides restrictions to perform the following

conversation:-

Convert from null type to any primitive type

Convert to the null type other than the identify conversation

Convert from using class type c to any array type if c is not object

P a g e | 10

//Vector Without Using autoboxing & unboxing

OUTPUT:-

P a g e | 11

//Vector With Using autoboxing & unboxing

OUTPUT:-

P a g e | 12

Nesting of Methods:-

We Discussed earlier that a method of a class can be called only by an

object of that class for class itself, in the cause of static methods 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

knows as nesting of method.

Program illustrates the nesting of method inside a class

The class nesting defines one constructor and two methods namely

largest () and display ()

The method largest () to determine the largest of the two number and

then displays the result

P a g e | 13

//Class Nesting

OUTPUT:-

P a g e | 14

An Another Example

//Class Nesting

OUTPUT:-

A method Can call nay number of methods it is also possible for a called

method to called method to call another method that is method1 May call

method2, which in turn may call method

P a g e | 15

Thank you