bhanu pratap singh ,bca

15
SUBMITED BY Bhanu Pratap Singh Shekhawat Bachelor of Computer Application II YEAR Dezyne E’cole College www.dezyneecolecollege INFORMATION TECHNOLOGY PROJECT REPORT JAVA PROGRAMMING WRAPPER CLASS AND NESTING METHOD TOPIC

Upload: dezyneecole

Post on 08-Jan-2017

26 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Bhanu Pratap Singh ,BCA

SUBMITED BY Bhanu Pratap Singh Shekhawat

Bachelor of Computer Application II YEAR

Dezyne E’cole College

www.dezyneecolecollege

INFORMATION TECHNOLOGY PROJECT REPORT

JAVA PROGRAMMING

WRAPPER CLASS AND NESTING METHOD

TOPIC

Page 2: Bhanu Pratap Singh ,BCA

Project Report

On

Java Program

At

Dezyne E’cole College

Ajmer

Submitted to

Dezyne E’cole College

Towards the

Partial Fulfillment on

Bachelor of Computer Application

By

Bhanu Pratap Singh Shekhawat

Dezyne E’cole College

106/10 Civil Line, Ajmer

Tel – 0145-2624679

Www.dezyneecole.com

2016

Page 3: Bhanu Pratap Singh ,BCA

Acknowledgement

I Bhanu Pratap Singh Shekhawat, Student On 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 For Their. Guidance And

Contrast Supervision As Well As For Providing The Necessary

Information And Support Regarding The Completion Of Project

Thank You

Page 4: Bhanu Pratap Singh ,BCA

Synopsis

This Project Is A Minor. Project Made, Based On The Theoretical

Concept Of Java This Project Has Made Our Basic Concepts On Java

Strong

Page 5: Bhanu Pratap Singh ,BCA

Wrapper Classes

As pointed out earlier, vector cannot handle primitive data type like int, float,

long, char, and double. Primitive data type may be convert into object types by

using the wrapper classes contained in the java.lang packages. Following table

shows the simple data type their corresponding wrapper class types.

Wrapper Classes For Converting Types

Simple Type Wrapper Class boolean Boolean

char Character double Double

float Float int Int

long Long

The wrapper classes have a number of unique methods for handling primitive

data type and object. They are listed in the following tables.

Converting Primitive Numbers to Object Number

Using Constructor Method

Constructor Calling Converting 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 Object Number to Primitive Number Using

typeValue() Method

Page 6: Bhanu Pratap Singh ,BCA

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 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 Object to Number Using the Static

Method valueOf()

Method Calling Conversion Action DoubleVal = Double.valueOf(str); Converting string to Double object FloatVal = Float.valueOf(str); Converting string to Float object

IntegerVal = Integer.valueOf(str); Converting string to Integer object LongVal = Long.valueOf(str); Converting string to Long object

Converting Numeric String to Primitive Number Using

Parsing Methods

Method Calling Conversion Action int i = Integer.parseInt(str); Conveting string to primitive integer float f = Float.parseFloat(str); Conveting string to primitive float

long l = Long.parseLong(str); Conveting string to primitive long

double d = Double.parseDouble(str); Conveting string to primitive double

Converting Primitive Number to object Numbers

Page 7: Bhanu Pratap Singh ,BCA

Output :-

Converting Object Number to Primitive Number :-

Page 8: Bhanu Pratap Singh ,BCA

Output :-

Page 9: Bhanu Pratap Singh ,BCA

Converting Number to String

Output :-

Converting String Object to Numeric Object

Page 10: Bhanu Pratap Singh ,BCA

Output :-

Converting Numeric String to Primitive Number

Output :-

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 this feature to

convert primitive data type to wrapper class type automatically.

Page 11: Bhanu Pratap Singh ,BCA

The compiler generates a code implicity to convert primitive type to the

corresponding wrapper class type and vise-versa. For example consider the

following statement –

Double d=98.45;

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 if is not object.

Vector without using auto Boxing and Unboxing :-

Output :-

Page 12: Bhanu Pratap Singh ,BCA

Vector with using auto Boxing and 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

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 13: Bhanu Pratap Singh ,BCA

Nesting of methods

Output :-

Nesting Methods

Output :-

Page 14: Bhanu Pratap Singh ,BCA

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.

Page 15: Bhanu Pratap Singh ,BCA

THANK YOU