shivani chouhan ,bca ,2nd year

13
INFORMATION TECHNOLOGY PROJECT REPORT JAVA PROGRAMMING TOPIC WRAPPER CLASS & NESTING OF METHOD SUBMITTED BY:- SHIVANI CHOUHAN BACHELORS OF COMPUTER APPLICATION 2 ND YEAR

Upload: dezyneecole

Post on 08-Jan-2017

40 views

Category:

Technology


2 download

TRANSCRIPT

Page 1: Shivani Chouhan ,BCA ,2nd Year

INFORMATION TECHNOLOGY

PROJECT REPORT

JAVA PROGRAMMING

TOPIC WRAPPER CLASS & NESTING OF METHOD

SUBMITTED BY:-

SHIVANI CHOUHAN BACHELORS OF COMPUTER APPLICATION

2ND YEAR

Page 2: Shivani Chouhan ,BCA ,2nd Year

PROJECT REPORT

ON

JAVA PROGRAM

AT

DEZYNE E’COLE COLLEGE

AJMER

SUBMITTED TO

DEZYNE E’COLE COLLEGE

TOWARDS THE PARTIAL FULFILLMENT ON

BACHELOR’S OF COMPUTER APPLICATION

BY

SHIVANI CHOUHAN

DEZYNE E’COLE COLLEGE

106/10 CIVIL LINES AJMER

TEL. 0145-2624679

W.W.W.DEZYNEECOLE.COM

2016

Page 3: Shivani Chouhan ,BCA ,2nd Year

ACKNOWLEDGMENT

I Shivani chouhan, student of Dezyne E’cole College, an

Extremely Grateful to each other 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 of project.

Thank you.

Page 4: Shivani Chouhan ,BCA ,2nd Year

SYNOPSIS This project is a minor project mode, based on the

Theoretical concepts of java .This project made our basic

concepts on java strong.

Page 5: Shivani Chouhan ,BCA ,2nd Year

P a g e | 1

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

also wrapper classes contained in the in the java lang. package .Following table

shows the simple data type and their corresponding wrapper classes types.

Wrapper classes for converting simple types .

Simple type Wrapper class

Boolean Boolean

Char Character

Integer Integer

Double Double

Float Float

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 Doubleval=new Double(d); Primitive Double to Double object Long longval=new Long(); Primitive long to long object

Converting object number to primitive number using type value() method

Method calling Conversion action Int i=Intval.int value(); object to Primitive Integer Float f=floatval.float value(); object to Primitive float Long l=longval.long value(); object to Primitive long Double d=doubleval.double value(); object to Primitive double

Converting number to string using to string() method

Method calling Conversion action Str=Integer. to string(i); Primitive Integer to string Str=Float.to string(i); Primitive Float to string Str=Double.to string(i); Primitive Double to string Str=Long.to string(i); Primitive Long to string

Page 6: Shivani Chouhan ,BCA ,2nd Year

P a g e | 2

Converting string objects to numeric objects using the static method value of()

Method calling Conversion action Double val=Double.value of (str); Converts string to Double object Float val=Float.value of (str); Converts string to Float object Int val=Integer.value of (str); Converts string to Integer object Long val=Long.value of (str); Converts string to Long object

Converting numeric string to primitive numbers using the parsing methods.

Method calling Conversion Action Int i=Integer.parseInt(str); Converts string to primitive Integer Long l=long.parseLong(str); Converts string to primitive long

Page 7: Shivani Chouhan ,BCA ,2nd Year

P a g e | 3

Output:-

Page 8: Shivani Chouhan ,BCA ,2nd Year

P a g e | 4

Output:-

Page 9: Shivani Chouhan ,BCA ,2nd Year

P a g e | 5

Output:-

Page 10: Shivani Chouhan ,BCA ,2nd Year

P a g e | 6

Output:-

Output:-

Page 11: Shivani Chouhan ,BCA ,2nd Year

P a g e | 7

Auto boxing and unboxing

The auto boxing and unboxing feature, introduced in J2Se 5.0, facilitates the

process of handling primitive data type in collection. We can use this feature to

converts primitive data types to wrapper class types automatically.the compiler

generates a code implicity 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.double value();

Using the autoboxing 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 conversion:-

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

Nesting of method

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

Page 12: Shivani Chouhan ,BCA ,2nd Year

P a g e | 8

Programs 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 displays the result.

Output:-

Page 13: Shivani Chouhan ,BCA ,2nd Year

P a g e | 9

Another example of nesting of method

Output:-