rakesh bijawat, bca 2nd year

19
1 Project Report Java Programme Submitted By: Rakesh Bijawat BCA Dezyne E’cole College www.dezyneecole.com Topic: Wrapper Class and Nesting Methods. INFORMATION TECHNOLOGY

Upload: dezyneecole

Post on 08-Jan-2017

14 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Rakesh Bijawat, BCA 2nd Year

1

Project Report

Java Programme

Submitted By:

Rakesh Bijawat

BCA

Dezyne E’cole College

www.dezyneecole.com

Topic:

Wrapper Class and

Nesting Methods.

INFORMATION

TECHNOLOGY

Page 2: Rakesh Bijawat, BCA 2nd Year

2

Project Report

On

Java Program

At

Dezyne E’cole College

Ajmer

Submitted To

Dezyne E’cole College

Towards The

Partial Fulfillment

BCA

(Bachelors of Computer Applications)

By

Rakesh Bijawat

Dezyne E’Cole College

106/10, Civil Lines, Ajmer

Tel.0145-2624679

www.dezyneecole.com

2016-2017

Page 3: Rakesh Bijawat, BCA 2nd Year

3

ACKNOWLEDGEMENT

I Am Rakesh Bijawat, Student Of Dezyne E’cole College, And 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.

Page 4: Rakesh Bijawat, BCA 2nd Year

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.

Page 5: Rakesh Bijawat, BCA 2nd Year

5

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

Package. Following table shows the simple data type and their

corresponding wrapper class type.

Wrapper classes for converting simple 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 objects. They are listed in the following

tables.

Converting Primitive Numbers to object Numbers using Constructor

methods

Constructor Calling Conversion action

Integer Interval=new Integer(i); 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.

Page 6: Rakesh Bijawat, BCA 2nd Year

6

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=Integer.toString(); Primitive integer to String Str=Float.toFloat(); Primitive float to String

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

Str=Long.toLong(); Primitive long to String

Converting String objects to numbers objects using the static method

value Of ()

Method calling Conversion

DoubleVal=Double.ValueOf(Str); Converts string to Double objects. FloatVal=Float.ValueOf(Str); Converts string to Float objects.

IntVal=Integer.ValueOf(Str); Converts string to Integer objects.

LongVal=Long.ValueOf(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.

long l=Long.parseLong(Str); Converts string to primitive long.

Page 7: Rakesh Bijawat, BCA 2nd Year

7

Converting Primitive Numbers to Object Numbers.

Output:-

Page 8: Rakesh Bijawat, BCA 2nd Year

8

Converting object Numbers to Primitive Numbers.

Output:-

Page 9: Rakesh Bijawat, BCA 2nd Year

9

Converting Numbers to String

Output:-

Page 10: Rakesh Bijawat, BCA 2nd Year

10

Converting String Object to Numeric Object.

Output:-

Page 11: Rakesh Bijawat, BCA 2nd Year

11

Converting Numeric String to Primitive Numbers.

Output:-

Page 12: Rakesh Bijawat, BCA 2nd Year

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

this feature to convert primitive data types to wrapper class types

automatically. The compiler generates a code implicity to convert

primitive types 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 auto boxing 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

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

Page 13: Rakesh Bijawat, BCA 2nd Year

13

Vector without using auto boxing and unboxing

Output:-

Page 14: Rakesh Bijawat, BCA 2nd Year

14

Vector with using auto boxing and unboxing

Output:-

Page 15: Rakesh Bijawat, BCA 2nd Year

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

Page 16: Rakesh Bijawat, BCA 2nd Year

16

Nesting of methods

Output:-

Page 17: Rakesh Bijawat, BCA 2nd Year

17

Nesting of methods

Output:-

Page 18: Rakesh Bijawat, BCA 2nd Year

18

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

method to call another method. That is, method1 may call method2,

which in turn may call method3.

Page 19: Rakesh Bijawat, BCA 2nd Year

19

Thank You