rounit mathur,bca 2nd year

15
PROJECT REPORT Submitted By Rounit Mathur BCA II year Java Programming www.dezyneecole.com Information Technology Topic: - Wrapper Classes and Nesting of Methods

Upload: dezyneecole

Post on 08-Jan-2017

61 views

Category:

Technology


2 download

TRANSCRIPT

Page 1: Rounit Mathur,BCA 2nd year

PROJECT

REPORT

Submitted By Rounit Mathur

BCA II year Java Programming

www.dezyneecole.com

Information Technology

Topic: - Wrapper Classes and Nesting of

Methods

Page 2: Rounit Mathur,BCA 2nd year

Partial Fulfillment

On

Java Programming

At

Dezyne E’cole College

Submitted to

Dezyne E’cole College

Partial Fulfillment on

BCA

Bachelors of Computer Application

By

Rounit Mathur

Dezyne E’cole College

106/10, Civil Lines Ajmer

Tel-Phone - 0145-2624679

www.dezyneecole.com

2016-2017

Page 3: Rounit Mathur,BCA 2nd year

Acknowledgement

I ROUNIT MATHUR STUDENT OF DEZYNE E’COLE COLLEGE,

AN EXTREMELY GRATEFUL TO EACH AND EVERY INDIVIDUAL

WHO HAS CONTRIBUTED IN SUCCESSFUL COMPLETION OF

MY PROJECT.

I EXPRESS MY GRATITUDE TOWARDS, DEZYNE E’COLE

COLLEGE TO THEIR GUIDELINES AND CONSTANT

SUPERVISION AS WELL FOR PROVIDING THE NECESSARY

INFORMATION AND SUPPORT REGARDING THE COMPLETION

OF PROJECT.

Thank you

Page 4: Rounit Mathur,BCA 2nd year

Synopsis

THIS PROJECT IS A MINOR PROJECT MADE BASED ON

THEORETICAL CONCEPTS OF JAVA. THIS PROJECT HAS

MADE OUR BASIC CONCEPTS ON JAVA STRONG.

Page 5: Rounit Mathur,BCA 2nd year

Wrapper Classes

As pointed out earlier, vectors cannot handle primitive data type 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 type 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 wrapper classes 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 Methods

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: Rounit Mathur,BCA 2nd year

Converting object Number 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

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

long l=LongVal.longValue(); Object to primitive long

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 ValueOf()

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 Strings to Primitive numbers using Parsing Methods

Method Calling Conversion Action

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

Long i=Long.parseLong(str); Converts string to primitive long

Page 7: Rounit Mathur,BCA 2nd year

Converting primitive number to object number

Output:

Page 8: Rounit Mathur,BCA 2nd year

Converting object number to primitive number

Output:

Page 9: Rounit Mathur,BCA 2nd year

Converting number to String

Output:

Page 10: Rounit Mathur,BCA 2nd year

Converting string object to numeric object

Output:

Page 11: Rounit Mathur,BCA 2nd year

Converting numeric string to primitive number

Output:

Page 12: Rounit Mathur,BCA 2nd year

Autoboxing and Unboxing

The autoboxing and unboxing feature, introduced in J2SE 5.0,facilities 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 tye to the corresponding wrapper class type and vice versa. For example,

consider the following statements:

Double d_object = 98.42;

Double d_primitive = d_object.doubleValue ();

Using the autoboxing and unboxing feature, we can rewrite the above code as:

Double d_object = 98.42;

Double d_primitive = d_object;

How, the java compiler provides restrictions to perform the following conversions:

1) Convert from null type to any primitive type.

2) Convert to the null type other than the identify conversion

3) Convert from any class type C to any array type if C is not object.

Vector Without using autoboxing & unboxing

Output:

Page 13: Rounit Mathur,BCA 2nd year

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 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 inside a class. The class Nesting defines one

constructor and two methods, namely largest() and display(). The method display

() calls the method largest() to derermine the two numbers and then displays the

result.

Page 14: Rounit Mathur,BCA 2nd year

Nesting of methods

Output:

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.

Page 15: Rounit Mathur,BCA 2nd year

Thank you