17
0 | Page 11/26/2016 PROJECT REPORT JAVA PROGRAMING TOPIC WRAPPER CLASS AND METHOD OF NENNESTING SUBMITTED BY Gaurav Singh Chouhan BCA- II year Dezyne E’cole College INFORMATION TECHNOLOGY www.dezyneecole.com

Gaurav Singh Chouhan, BCA 2nd Year

Embed Size (px)

Citation preview

Page 1: Gaurav Singh Chouhan, BCA 2nd Year

0 | P a g e

11/26/2016

PROJECT REPORT JAVA PROGRAMING

TOPIC

WRAPPER CLASS AND

METHOD OF NENNESTING

SUBMITTED BY

Gaurav Singh Chouhan

BCA- II year

Dezyne E’cole College

INFORMATION TECHNOLOGY

www.dezyneecole.com

Page 2: Gaurav Singh Chouhan, BCA 2nd Year

1 | P a g e

Project Report

On

JVA PROGRAM

At

Dezyne E’cole College

Ajmer

Submitted to

Dezyne E’cole College

To words the

Practical Fulfillment on

BACHLAR OF COMPUTER APPLICATION

By

Gaurav singh chouhan

Dezyne E’cole Collage

106/10 civil lines, Ajmer

www.dezyneecole.com

Year

2016-2017

Page 3: Gaurav Singh Chouhan, BCA 2nd Year

2 | P a g e

ACKNOWLEDGMENT

I Gaurav singh chouhan, student of Dezyne E’ Cole College, on?

Extremely Grateful to each and every individual who has

contributed in Successful completion of my Project.

I Express my Gratitude top word Dezyne E’cole college for

their. Guidance and Constant Super vision as well as for

providing the necessary information and Support Regarding

the Completion of project.

Thank you.

Page 4: Gaurav Singh Chouhan, BCA 2nd Year

3 | P a g e

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

Page 5: Gaurav Singh Chouhan, BCA 2nd Year

4 | P a g e

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 type 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 wappera classes have a number of unique methods for handling primitive

data type and object. They are 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 FloatVal=new Float(f); Primitive float to Float Object

Double Doubleva=new Double(d); Primitive double to Double Object

Long LongVal=new Long(l); Primitive long to Long Object

Converting Object Number 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.longValue(); Object to Primitive long

Double d=DoubleVal.doubleValue(); Object to Primitive double

Page 6: Gaurav Singh Chouhan, BCA 2nd Year

5 | P a g e

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

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

Converting String objects to Number Object Using the Static Method valueOf()

Method Calling Converion 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 Number Using Parsing Methods

Method Calling Conversion Action

Int I =Integer.ParseInt(str); Converts string to primitive integer

float f =Integer.ParseFloat(str); Converts string to primitive float

long l =Integer.ParseLong(str); Converts string to primitive long

double d =Integer.ParseDouble(str); Converts string to primitive double

Page 7: Gaurav Singh Chouhan, BCA 2nd Year

6 | P a g e

Converting Primitive Number to object

Numbers

Output :-

Page 8: Gaurav Singh Chouhan, BCA 2nd Year

7 | P a g e

Converting Object Number to Primitive

Number :-

Output :-

Page 9: Gaurav Singh Chouhan, BCA 2nd Year

8 | P a g e

Converting Number to String

Output :-

Page 10: Gaurav Singh Chouhan, BCA 2nd Year

9 | P a g e

Converting String Object to Numeric Object

Output :-

Page 11: Gaurav Singh Chouhan, BCA 2nd Year

10 | P a g e

Converting Numeric String to Primitive Number

Output :-

Page 12: Gaurav Singh Chouhan, BCA 2nd Year

11 | P a g e

Auto Boxing and Unboxing:-

The auto boxing and Unboxing feature, introduced in J2SE 5.0, facilities the

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

convert primitive data type to wrapper class type automatically.

The compiler generates a cade implicitly to convert primitive type to the

corresponding wrapper class type and vise-versa. For Example, Consider the

Following Statements:

Doubled=98;

Double dbl=d.doubleValue();

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

as:-

Double d=98.42;

Double dbl=d;

How, the java compiler provide restrictions to perform the following

conversions:-

Convert from 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 id C is not object.

Page 13: Gaurav Singh Chouhan, BCA 2nd Year

12 | P a g e

Vector without using auto Boxing and Unboxing:-

Output :-

Page 14: Gaurav Singh Chouhan, BCA 2nd Year

13 | P a g e

Vector with using auto Boxing and Unboxing :-

Output :-

Page 15: Gaurav Singh Chouhan, BCA 2nd Year

14 | P a g e

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, there is an

exception to this. A methods 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() calls the method largest() to

determine the largest of the two numbers and then displays

the result.

Page 16: Gaurav Singh Chouhan, BCA 2nd Year

15 | P a g e

Nesting of methods

Output :-

Page 17: Gaurav Singh Chouhan, BCA 2nd Year

16 | P a g e

Nesting Methods

Output :-

A method can call any number of methods.

It is also possible a called method to call another

Method. That is, method1 may call method2, which in turn may call method3.