samarth gaur ,bca 2nd year

19
INFORMATION TECHNOLOGY PROJECT REPORT JAVA PROGRAMMING TOPIC:- WRAPPER CLASS AND NESTING METHODS SUBMITTED BY- SAMARTH GAUR CLASS BCA II YEAR R

Upload: dezyneecole

Post on 16-Apr-2017

66 views

Category:

Technology


1 download

TRANSCRIPT

Page 1: Samarth Gaur ,BCA 2nd Year

INFORMATION TECHNOLOGY

PROJECT REPORT JAVA PROGRAMMING

TOPIC:-

WRAPPER CLASS AND NESTING METHODS

SUBMITTED BY- SAMARTH GAUR

CLASS BCA II YEAR

R

Page 2: Samarth Gaur ,BCA 2nd Year

Project Report

On Java Program

At Dezyne E’cole College Ajmer

Submitted to Dezyne E’cole College

towards the Partial Fulfillment on

BCA By Samarth Gaur

Dezyne E’cole College

106/10, civil lines, Ajmer Tel-0145-2624679

www.dezyneecole.com 2016-17

R

Page 3: Samarth Gaur ,BCA 2nd Year

ACKNOWLEDGEMENT

I Samarth Gaur, Student Of Dezyne E’ Cole College, An 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 Constant Supervision As Well As For Providing the Necessary Information And Support Regarding The Completion Of Project. Thank You.

Page 4: Samarth Gaur ,BCA 2nd Year

SYNOPSIS

This Project Is A Minor Project Made Based On The Theoretical Concepts Of JAVA This Project Has Made Our Basic Concepts On JAVA Strong.

Page 5: Samarth Gaur ,BCA 2nd Year

Wrapper Classes: As pointed out earlier, vector cannot handle primitive data types like int, float 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.

Simple Type Wrapper Class

Boolean Boolean

Char Character

Double Double

float Float

int Int

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 Object

Float FloatVal=new Float(f); 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: Samarth Gaur ,BCA 2nd Year

Converting Object Numbers to Primitive Number Using type Value() Method Method Calling Conversion Action

int i=IntVal.intValue(); Object to Primitive integer float f=FloatVal.floatValue(); Object to Primitive float long l=LongVal.longVaue(); Object to Primitive long double d=DoubleVal.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 str=Double.toDouble Primitive double to string str=Long.toLong Primitive long to string

Converting String Objects to Numbers Objects Using the Static Method valueof() Method Calling Conversion Action DoubleVal=Double.valueOf(str); Converts string to Double

object

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

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

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

Page 7: Samarth Gaur ,BCA 2nd Year

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

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

double d=Double.parseDouble(str);

Converts string to primitive double

Page 8: Samarth Gaur ,BCA 2nd Year

Converting Primitive Numbers to Object Numbers

Page 9: Samarth Gaur ,BCA 2nd Year

Converting object Numbers to Primitive Numbers

Page 10: Samarth Gaur ,BCA 2nd Year

Converting Numbers to String

Page 11: Samarth Gaur ,BCA 2nd Year

Converting Numeric String to Primitive Numbers

Page 12: Samarth Gaur ,BCA 2nd Year

Converting Numeric String to Primitive Numbers

Page 13: Samarth Gaur ,BCA 2nd Year

Autoboxing and Unboxing: The autoboxing and unboxing feature, introduced in J2SE 5.0, facilitates the process of handling primitive data types in collections. We can use this feature to convert primitive data types to wrapper class type automatically. Vector without using autoboxing and unboxing

Page 14: Samarth Gaur ,BCA 2nd Year

Vector with using autoboxing and unboxing

Page 15: Samarth Gaur ,BCA 2nd Year

Nesting of Methods

Page 16: Samarth Gaur ,BCA 2nd Year

Nesting of Methods: 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 an exception to this. A method can be called by using only its same class. This is known as nesting of methods. Program illustrates the nesting of methods inside a class. The class nesting defines one constructor & two methods, namely largest() & display(). The method display() calls the method largest() to determine the largest of the two numbers & then display the result.

Page 17: Samarth Gaur ,BCA 2nd Year
Page 18: Samarth Gaur ,BCA 2nd Year

A method can call any numbers 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: Samarth Gaur ,BCA 2nd Year