0% found this document useful (0 votes)
37 views2 pages

Public Class Public Static Void New: Demo Example

This document contains code examples demonstrating boxing, unboxing, autoboxing, and parsing in Java. It defines a Demo class with a main method that creates a Demo object, calls its getWish method to return a greeting string, and prints the result. It also shows: boxing an int into an Integer; unboxing an Integer into an int; autoboxing an int into an Integer; and parsing Strings into primitive types like int, float, and long. The output of each converted value is printed.

Uploaded by

manee4u
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views2 pages

Public Class Public Static Void New: Demo Example

This document contains code examples demonstrating boxing, unboxing, autoboxing, and parsing in Java. It defines a Demo class with a main method that creates a Demo object, calls its getWish method to return a greeting string, and prints the result. It also shows: boxing an int into an Integer; unboxing an Integer into an int; autoboxing an int into an Integer; and parsing Strings into primitive types like int, float, and long. The output of each converted value is printed.

Uploaded by

manee4u
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
You are on page 1/ 2

Demo Example:public class Demo {

public static void main(String[] args) {


Demo d = new Demo();
String msg = d.getWish("Rama");
System.out.println(msg);
}
public String getWish(String name) {
return "good morning ! " + name;
}
}
Boxing, Un Boxing,Auto boxing,Parsing Example:public class Demo {
public static void main(String[] args) {
int a = 10; // Primitive data type
Integer b = 100; // Reference data type
Integer i = new Integer(a); // Boxing
int j = b.intValue(); // Unboxing
Integer k = a; // Auto Boxing
String s = "500";
int y = Integer.parseInt(s);// Parsing String to primitive type
int
float f = Float.parseFloat(s);// Parsing String to primitive
type float
long l = Long.parseLong(s); // Parsing String to primitive
type long
System.out.println("i value is.." + i);
System.out.println("j value is.." + j);
System.out.println("k value is.." + k);
System.out.println("y value is.." + y);
System.out.println("f value is.." + f);
System.out.println("l value is.." + l);

}
}

You might also like