Ronak Kachhawa,BCA 2nd Year

17
INFORMATION TECHNOLOGY PROJECT REPORT JAVA PROGRAMMING TOPIC Wrapper class and nesting of method SUBMITTED BY Ronak kachhawa Bachelors of Computer Application BCA IInd YEAR Dezyne E,cole college www.dezyneecole.com 2016-2017 R

Transcript of Ronak Kachhawa,BCA 2nd Year

Page 1: Ronak Kachhawa,BCA 2nd Year

INFORMATION TECHNOLOGY

PROJECT REPORT JAVA PROGRAMMING

TOPIC Wrapper class and nesting of method

SUBMITTED BY

Ronak kachhawa

Bachelors of Computer Application

BCA IInd YEAR

Dezyne E,cole college

www.dezyneecole.com

2016-2017

Your text here R

Page 2: Ronak Kachhawa,BCA 2nd Year

Project Report

On

Java programming

At

Dezyne E’cole College

Ajmer

Submitted to

Dezyne E’cole College

Towards The

Partial Fulfillment on

Bachelors of Computer Application

BCA IInd Year

By

Ronak kachhawa

Dezyne E’cole College

106/10, civil lines, Ajmer

Tel:-0145-2624679

www.dezyneecole.com

2016-2017

R

Page 3: Ronak Kachhawa,BCA 2nd Year

Acknowledgment

I Ronak Kachhawa ,Student Of Dezyne E’cole College, An Exteremely Greatfull To Each And Evey 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.

Page 4: Ronak Kachhawa,BCA 2nd Year

Synopsis

This Project Is A Minar Project Mode, Based On The Theorepical Concepts Of

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

Page 5: Ronak Kachhawa,BCA 2nd Year

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

pakage. Following table shows the simple data types 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 type 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 Objects

Float FloatVal=new Float(f); Primitive float to Float Objects

Double DoubleVal=new Double(d); Primitive double to Double Objects

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

Converting Object Number To Primitive Number Using Typevalue() Method

Method Calling Conversion Action Int I=Int val.intValue(); Object to primitive integer

float f=Float val.floatValue(); Object to primitive float

long l=Long val.longValue(); Object to primitive long

double d=Double val.doubleValue(); Object to primitive double

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

Page 6: Ronak Kachhawa,BCA 2nd Year

str=Double.toDouble(d); Primitive double to string

str=Long.toLong(l); Primitive long to string

Converting String Objects To Number Objects Using The Static Method Valueof()

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

FloatVal=Float.valueOf(str); Convert string to Float object

IntVal=Integer.valueOf(str); Convert string to Integer object

LongVal=Long.valueOf(str); Convert string to Long object

Converting Numeric String To Primitive Numbers Using Parsing Methods

Method Calling Conversion Action Int i=Integer.parseInt(str); Convert string to primitive integer

Float f=Float.parseFloat(str); Convert string to primitive float

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

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

Page 7: Ronak Kachhawa,BCA 2nd Year

Converting Primitive Numbers To Object Numbers

Page 8: Ronak Kachhawa,BCA 2nd Year

Converting Object Numbers To Primitive Numbers

Page 9: Ronak Kachhawa,BCA 2nd Year

Converting Numbers To String

Page 10: Ronak Kachhawa,BCA 2nd Year

Converting String Object To Numeric Object

Page 11: Ronak Kachhawa,BCA 2nd Year

Converting Numeric String To Primitive Numbers

Page 12: Ronak Kachhawa,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 genrates 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.doubleValue();

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 Restrictions To Perform The Following Conversion As:-

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 13: Ronak Kachhawa,BCA 2nd Year

Vector Without Using Autoboxing & Unboxing

Page 14: Ronak Kachhawa,BCA 2nd Year

Vector With Using Autoboxing & Unboxing

Page 15: Ronak Kachhawa,BCA 2nd Year

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

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

Example:- Nesting Of Methods

Page 16: Ronak Kachhawa,BCA 2nd Year

Another Program Of Nesting Of Method

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 Method

Page 17: Ronak Kachhawa,BCA 2nd Year

Thank you