Yashika Soni, BCA 2nd Year

18
Information Technology Project Report Java Programming TOPIC Wrapper class and nesting method Submitted By YASHIKA SONI BCA (Bachelors of Computer Application Dezyne E’cole College WWW.dezyneale.com

Transcript of Yashika Soni, BCA 2nd Year

Page 1: Yashika Soni, BCA 2nd Year

Information Technology

Project Report Java Programming

TOPIC Wrapper class and nesting method

Submitted By

YASHIKA SONI

BCA (Bachelors of Computer Application

Dezyne E’cole College

WWW.dezyneale.com

Page 2: Yashika Soni, BCA 2nd Year

Project Report

On

Project Report Java Program

At

Dezyne E’cole College

Ajmer

Submitted to

Dezyne E’cole College

To Word The

Partial Fulfillment On

BCA (Bachelors of Computer Application)

By

YASHIKA SONI

Dezyne E’cole College

106/10 Civil Lines Ajmer

Tel- 0145-2624679

WWW.dezyneale.com

YEAR- 2016-17

Page 3: Yashika Soni, BCA 2nd Year

Ackmoweledment

I YASHIKA SONI 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

Page 4: Yashika Soni, BCA 2nd Year

Synopsis

THIS PROJECT IS MINER. PROJECT MADE

BASED ON THE THEORETICAL CONCEPTS OF

JAVA THIS PROJECT HAS MADE OUR BASIC

CONCEPTS ON JAVA STRONG.

Page 5: Yashika Soni, BCA 2nd Year

Wrapper Class As pointed out earlier, vectors 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.lang

package. Following table shows the simple data types and their

corresponding wrapper class types.

Wrapper Classes For Converting Types

Simple Types Wrapper Class

Boolean Boolean

Char Character

Double Double

Float Float

Int Integer

Long Long

The Wrapper class have a number of unique methods for handling

primitive data types and objects. They are listed in the following tables.

Converting Primitive Numbers 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 DoubleVal=new Double(d);

Primitive double to Double Object

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

Page 6: Yashika Soni, BCA 2nd Year

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

double d=DoubleVal.doubleValue();

Object to Primitive double

Converting Numbers to String Using toString () Method

Method Calling Conversion Action

Str=Integer.toString(i); Primitive integer to string

Str=Float.toString(f); Primitive float to string

Str=Double.toString(d); Primitive double to string

Str=Long.toString(l); Primitive long to string

Converting String Objects to Numeric 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=Int.ValueOf(str); Converts string to Int object

LongVal=Long.ValueOf(str); Converts string to Long object

Page 7: Yashika Soni, BCA 2nd Year

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 Integer

Page 8: Yashika Soni, BCA 2nd Year

//Converting Primitive Numbers to Object Numbers

Page 9: Yashika Soni, BCA 2nd Year

//Converting Object Numbers to Primitive Numbers

Page 10: Yashika Soni, BCA 2nd Year

//Converting Numbers to String

Page 11: Yashika Soni, BCA 2nd Year

//Converting String Object to Numeric Object

Page 12: Yashika Soni, BCA 2nd Year

//Converting Numeric String to Primitive Numbers

Page 13: Yashika Soni, BCA 2nd Year

Auto boxing and Unboxing

The Autoboxing and Unboxing feature, introduced in J2SE 5.0,

facilitates the process of 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 data types to the

corresponding wrapper class type and vice versa.

For example, consider the following statement

Double d=98.42;

Double dbl=d;

How, the java compiler provides 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 if c is not object.

Page 14: Yashika Soni, BCA 2nd Year
Page 15: Yashika Soni, BCA 2nd Year
Page 16: Yashika Soni, BCA 2nd Year

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

Page 17: Yashika Soni, BCA 2nd Year
Page 18: Yashika Soni, BCA 2nd Year

Another Example:

A method can call any number of methods. It is also possible for

a called method to call another method. That is, method1 may

call method2, which in turn may call method3.