Akshay Sharma,BCA,2nd year

15
Project Report Java Programing Topic Wrapper Class and Nesting Methods Submitted by: Akshay Sharma BCA II nd YEAR Dezyne E’cole College www.dezyneecole.com INFORMATION TECHNOLOGY

Transcript of Akshay Sharma,BCA,2nd year

Page 1: Akshay Sharma,BCA,2nd year

Project Report Java Programing

Topic Wrapper Class and

Nesting Methods

Submitted by:

Akshay Sharma

BCA IInd YEAR

Dezyne E’cole College www.dezyneecole.com

INFORMATION TECHNOLOGY

Page 2: Akshay Sharma,BCA,2nd year

P a g e 1 | 14

Project Report

On

Java Programing

At

Dezyne E’cole College

Ajmer

Submitted to

Dezyne E’cole College

Towards The

Practical Fulfillment on

BCA

By

Akshay Sharma

Dezyne E’cole College

106/10, Civil-lines, Ajmer

Tel: 0145-2624679

www.dezyneecole.com

Year

Page 3: Akshay Sharma,BCA,2nd year

P a g e 2 | 14

2016-2017

ACKNOWLEDGEMENT

I Akshay Sharma, Student Of Dezyne E’cole College, Am Extremely Who Has

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

Thank You

Page 4: Akshay Sharma,BCA,2nd year

P a g e 3 | 14

SYNOPSIS

This Project Is A Miner. Project Made, Based On The Theoretical Concepts Of

JAVA. This Project Has Made Our Basic Concepts On Java Strong.

Page 5: Akshay Sharma,BCA,2nd year

P a g e 4 | 14

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

Simply Type Wrapper class

boolean Boolean

char Character

double Double

float Float

Int Integer

long Long

The wrapper classes have a number of unique methods for handling primitive data type of objects.

They are listed in the following tables.

Converting Primitive Numbers to Objects 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=new Long(l); primitive long to Long Object

Converting Objects Numbers to Primitive Number Using typeValue () Method

Method Calling Conversion Action

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

float f=FloatVal.floatValue(); Object to Primitive float

long l=LongVal.lingValue(); Object to Primitive long

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

Page 6: Akshay Sharma,BCA,2nd year

P a g e 5 | 14

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(); primitive long to string

Converting String Objects to Numbers Objects Using the Static Method value Of ()

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 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.praseLong(str) Converts string to primitive Long

Double d=Double.praseDouble(str) Converts string to primitive Double

Converting Numeric String to Primitive Numbers Using Parsing Methods

Method Calling Conversion Action

int i=Integer.parseInt(str); Converts string to primitive Integer

long l=Long.parseInt(str); Converts string to primitive long

Page 7: Akshay Sharma,BCA,2nd year

P a g e 6 | 14

Converting Primitive Numbers to Object Numbers

Output:-

Page 8: Akshay Sharma,BCA,2nd year

P a g e 7 | 14

Converting Object Numbers to Primitive Numbers

Output:-

Page 9: Akshay Sharma,BCA,2nd year

P a g e 8 | 14

Converting Number to String

Output:-

Page 10: Akshay Sharma,BCA,2nd year

P a g e 9 | 14

Converting String Object to Numeric Object

Output:-

Page 11: Akshay Sharma,BCA,2nd year

P a g e 10 | 14

Converting Numeric String to primitive Number

Output:-

Page 12: Akshay Sharma,BCA,2nd year

P a g e 11 | 14

AutoBoxing and UnBoxing

The auto boxing and unboxing feature, introduced in J2SE 5.0, facilitates the process for

handling primitive data types in collections. We can use this feature to convert primitive data types

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

type to the corresponding wrapper class type and vice-versa.

For example:-

Consider the following statements:-

Double d=98.42;

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 provides restriction to perform the following conversions:

Converts from Null type to any primitive type.

Converts to the Null type 0ther than the identify conversion.

Converts from any class type c to any array type if c is not object.

Page 13: Akshay Sharma,BCA,2nd year

P a g e 12 | 14

Vector without using auto boxing and unboxing

Output:-

Page 14: Akshay Sharma,BCA,2nd year

P a g e 13 | 14

Vector with using auto boxing and unboxing

Output:-

Page 15: Akshay Sharma,BCA,2nd year

P a g e 14 | 14

THANK YOU