15
BACHELOR OF COMPUTER APPLICATION Dezyne E’cole College JAVA PROGRAMMIG TOPIC: WRAPPER CLASSES & NESTING OF METHOD INFORMATION TECHNOLOGY Shaikh Mohammad Usman haider R Submitted By

Shaikh Mohammad Usman Haider ,BCA 2nd Year

Embed Size (px)

Citation preview

Page 1: Shaikh Mohammad Usman Haider ,BCA 2nd Year

BACHELOR OF COMPUTER APPLICATION Dezyne E’cole College

JAVA PROGRAMMIG TOPIC: WRAPPER CLASSES & NESTING OF METHOD

INFORMATION TECHNOLOGY

Shaikh Mohammad Usman haider

R

Submitted By

Page 2: Shaikh Mohammad Usman Haider ,BCA 2nd Year

1

Project Report

On

Java Program

At

Dezyne E’cole College

Ajmer

Submitted To

Dezyne E’cole College

Toward The

Practical Fulfillment On

BCA

By

Usman haider

Dezyne E’cole College

106/10, Civil Line Lines, Ajmer

Tel – 0145- 2624679

www.dezyneecole.com

2016-2017

R

Page 3: Shaikh Mohammad Usman Haider ,BCA 2nd Year

2

ACKNOWLEDGMENT

I Shaikh Mohammad Usman Haider, Student of Dezyne E’cole College,

an Externally Grateful To Each And Every Individual Who Has Contribute

In Successful Completion of My Project

I Express My Gratitude Towards Dezyne E’cole College For Their

Guidelines And Constant Supervision As Well For Providing The

Necessary Information And Support Regarding The Completion Of

Project.

Thank You.

Page 4: Shaikh Mohammad Usman Haider ,BCA 2nd Year

3

SYNOPSIS

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

Of JAVA This Project Has Made Our Basic Concepts Of Java Strong.

Page 5: Shaikh Mohammad Usman Haider ,BCA 2nd Year

4

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 type 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 Type Wrapper Class boolean Boolean

char Character

double Double

float Float

int Integer

long Long

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

data types and object. They are listed in the following table.

Converting Primitive Number to Object Number using Constructor Method

Converting Object Number to Primitive Number using typeValue() Method

Constructor Calling Conversion Action Integer IntVal=new Integer(i); Primitive integer to integer Object

Float floatVal=new flaot(f); Primitive float to float Object

Double DoubleVal=new Double(d); Primitive Double to Double Object

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

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

Page 6: Shaikh Mohammad Usman Haider ,BCA 2nd Year

5

Converting Number to String Using to Stirng() Method

Converting String object to Number Object Using to Static Method ValueOf()

Converting Number String To Primitive Number Using Parsing Methods

Method Calling Conversion Action Str=Integer.toStiring(i); Primitive integer to String

Str=Float.toFloat(f); Primitive Float to String

Str=Double.toDouble(d); Primitive Double to String

Str=Long.toStiring(l); Primitive Long to String

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

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

float f=Float.parseFlaot(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: Shaikh Mohammad Usman Haider ,BCA 2nd Year

6

Converting Primitive number to Object Number

Page 8: Shaikh Mohammad Usman Haider ,BCA 2nd Year

7

Converting Object Number to Primitive Number

Page 9: Shaikh Mohammad Usman Haider ,BCA 2nd Year

8

Converting Number to String

Page 10: Shaikh Mohammad Usman Haider ,BCA 2nd Year

9

Converting String Object to Numeric Object

Page 11: Shaikh Mohammad Usman Haider ,BCA 2nd Year

10

Converting Number String To Primitive Number

Auto Boxing and Unboxing

The auto boxing and unboxing feature, introduce in J2SE 5.0,

facilitates the process of handling primitive data types in collection.

We can use this feature to convert primitive data types to wrapper

class types automatically. The compiling generates code implicitly

to convert primitive type to the corresponding wrapper classes type

and vice versa for example consider the following statement

Double d_object=98.42;

double d_primitive = d_object.doubleValue();

Usimg the auto boxing and unboxing feature we can rewrite the

above code as:

Page 12: Shaikh Mohammad Usman Haider ,BCA 2nd Year

11

Double d_object=98.42;

double d_primitive = d_object;

How the java compile provides restriction to perform the following

conversion.

1. Convert from null type to any primitive type.

2. Convert to null type other than the identify conversion

3. Convert from and class type C to any array type if C is Not

object.

Vector Without using auto boxing and unboxing

Page 13: Shaikh Mohammad Usman Haider ,BCA 2nd Year

12

Vector With using auto boxing and unboxing

Nesting of Method

We discussed earlier that a method of class can be called only by

an object of that class (or class itself, in the class 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 class.

Program illustrate the nesting of class:

The class nesting define one constructor and two method, namely

largest() and display(). The method display() call the method

largest() to determine the largest of the two numbers and then

displays the result.

Page 14: Shaikh Mohammad Usman Haider ,BCA 2nd Year

13

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

called method to call another method. That is, Method 1 may call

Method 2, which in turn may call Method 3.

Page 15: Shaikh Mohammad Usman Haider ,BCA 2nd Year

14