kaushal soni,bca,2nd year

Post on 23-Jan-2018

57 Views

Category:

Technology

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

1

INFORMATION TECHNOLOGY

JAVA PROGRAMME

TOPIC

Wrapper Class And

Nesting Method

SUBMITTED BY

Kaushal Soni

BCA-IInd Year

Dezyne E’cole College

www.dezyneecole.com

2

Project Report

On

Java Programme

At

Dezyne E’cole College

Ajmer

Submitted To

Dezyne E’cole College

Towards The

Partial Fulfillment

BCA

(Bachelor Of Computer Application)

By

Kaushal Soni

Dezyne E’Cole College

106/10, Civil Lines, Ajmer

Tel.0145-2624679

www.dezyneecole.com

2016-2017

3

ACKNOWLEDGEMENT

I Am Kaushal Soni, Student Of Dezyne E’Cole College, Am 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 Constants Supervision As Well As For Providing The

Necessary Information And Support Regarding The Completion Of Project.

4

SYNOPSIS

This Project Is A Miner. Project Made Based on the Theatrical Concepts of

JAVA .This Project Has Made Our Basic Concept on JAVA Strong

5

Wrapper classes

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

char and double. Primitive data types may be converted into object types by using

the wrapper classes contained in the java. 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 methods for handling primitive data

types and object. They are listed in the following tables.

Converting primitive numbers to object number using constructor method

Constructor calling Conversion action

Integer IntVal=new Integer() Primitive integer to Integer object.

Float FloatVal=new float(); 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 numbers 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 numbers to string using to string() method

Method calling Conversion action

Str=integertostring(); Primitive integer to string

Str=floattofloat(); Primitive float to string

Str=DoubletoDouble(); Primitive double to string

str=Long toLong(); Primitive long to string

6

Converting String Objects To Numbers Objects Using The Static Method

valueOff()

Method calling Conversion

Double val=Double valueOff(str); Converts string to Double objects.

Float val=Float valueOff(str); Converts string to Float objects.

Int val=Integer valueOff(str); Converts string to Integer objects.

Long val=Long valueOff(str); Converts string to Long objects.

Converting numeric string to primitive numbers using parsing methods

Method calling Conversion action

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

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

7

Converting Primitive Number To Object Number

8

Converting Object Number To Primitive Number

9

Convert Number To String

10

Converting String Object To Numeric Object

11

Converting Numeric String To Primitive Number

12

Auto boxing And Unboxing

The auto boxing and Unboxing feature, introduced in j2se 5.0, facilities the process of

handling primitive data types in collections. We can use the this feature to convert

primitive data types to wrapper class types automatically. The compiler generates a

code implicitly to convert primitive types 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;

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.

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

13

Vector Without Using Autoboxing And Unboxing

14

Vector With Using Autoboxing And Unboxing

15

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 illustrated the nesting of method 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 display the result.

16

Nesting Of Methods

17

Nesting Of Methods

18

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

to call another. This is method1 may call method2, which in turn may call method3.

19

Thank You

top related