20
INFORMATION TECHNOLOGY PROJECT REPORT J AVA P ROGRAMING TOPIC Wrapper classes& Nesting of method SUBMITTED BY Ravi Prakash yadav BCA 2 nd year Dezyne E’cole college www.dezyneecole.com

Ravi Prakash,BCA,2nd Year

Embed Size (px)

Citation preview

Page 1: Ravi Prakash,BCA,2nd Year

INFORMATION TECHNOLOGY

PROJECT REPORT

JAVA PROGRAMING

TOPIC

Wrapper classes& Nesting of

method

SUBMITTED BY

Ravi Prakash yadav

BCA 2nd year

Dezyne E’cole college

www.dezyneecole.com

Page 2: Ravi Prakash,BCA,2nd Year

pg. 1

Project Report

On

Java Programming

Dezyne E’cole College

Ajmer

Submitted

Dezyne E’cole College

Towards the

Partial Fulfillment on

Bachelors of computer application

By

Ravi Prakash Yadav

Dezyne E’cole College

106/10,civil lines, Ajmer

Tel-0145-2624679

www.dezyneecole.com

2016-2017

Page 3: Ravi Prakash,BCA,2nd Year

pg. 2

I Ravi Prakash, Student of Dezyne E’cole College, an externely 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

constant supervision as well as for providing the necessary information and

support regarding the completion of project.

Thank You

Page 4: Ravi Prakash,BCA,2nd Year

pg. 3

This project is a miner project made based on the

theoretical concepts of JAVA this project has made our basic

concept on java strong.

Page 5: Ravi Prakash,BCA,2nd Year

pg. 4

As pointed out earlier,vectors cannot 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 types and their corresponding wrapper class types

Wrapper Classes For Converting Types

Simpal Type Wrapper Class

boolean Boolean char Character

double

float int Integer

long

The Wrapper Classes hava a number of unique methods for handling primitive

data type and object.They are listed in the following tables.

Converting Primitive number to object number using Constructor for

methods

Page 6: Ravi Prakash,BCA,2nd Year

pg. 5

Converting Object Numbers to Primitive Number Using typeValue()

Method

Converting Number to Sting Using to string()Method valueOf()

Method calling Conversion Action

Converting String Object to Numbers Object Using the Ststic Method

valueOf()

Method Calling Conversion Action

Page 7: Ravi Prakash,BCA,2nd Year

pg. 6

Converting Numeric String to Primitive Number Using Parsing Methods

Converting Numeric String to Primitive noumbers using parsing methods.

Page 8: Ravi Prakash,BCA,2nd Year

pg. 7

Converting Primitive number to object number

OUTPUT

Page 9: Ravi Prakash,BCA,2nd Year

pg. 8

Converting object number to Primitive number

OUTPUT

Page 10: Ravi Prakash,BCA,2nd Year

pg. 9

Converting numbers to String.

OUTPUT

Page 11: Ravi Prakash,BCA,2nd Year

pg. 10

Coverting string object to numeric object

OUTPUT

Page 12: Ravi Prakash,BCA,2nd Year

pg. 11

Coverting numeric String to Primitive number.

OUTPUT

Page 13: Ravi Prakash,BCA,2nd Year

pg. 12

Auto Boxing and Unboxing

The auto boxing and unboxing feature, introduced in J2SE 5.0, facilities the process of

handling primitive data type in collection we can use this feature to convert primitive data

type to wrapper class type automatically.

The compiler generates a code implicity to convert primitive type to the corresponding

wrapper class type and vise-versa. For example consider the following statement –

Double d=98.45;

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 provide restrictions to perform the following conversions :-

Convert from null type to any primitive type

Page 14: Ravi Prakash,BCA,2nd Year

pg. 13

Vaetore without using auto bosing & unbosing:

OUTPUT

Page 15: Ravi Prakash,BCA,2nd Year

pg. 14

EXAMPAL

OUTPUT

Page 16: Ravi Prakash,BCA,2nd Year

pg. 15

Nesting of method

OUTPUT

Page 17: Ravi Prakash,BCA,2nd Year

pg. 16

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 methods can be called by using only its name by another method of the

same class. This is known as nesting of methods.

Program illustrates the nesting of methods inside a class. The class nesting defines one

constructor and two methods, namely largest () and display () calls the method largest () to

determine the largest of the two numbers and then displays the result.

Commented [B1]:

Page 18: Ravi Prakash,BCA,2nd Year

pg. 17

Exampal

OUTPUT

Page 19: Ravi Prakash,BCA,2nd Year

pg. 18

A method can call any number of methods.

It is also possible a called method to call another

Method. That is, method1 may call method2, which in turn may call method3.

Page 20: Ravi Prakash,BCA,2nd Year

pg. 19