1Wrapper classes: classes that are dedicated to primitives
2Byte, Short, Integer, Long, Float, Double, Character, Boolean
3presented in "java.lang" package
4AutoBoxing: converting primitive values to wrapper class
5 int a = 100;
6 Integer b = a // auto boxing
7Unboxing: converting wrapper class value to primitives
8 Integer a = 100;
9 int b = a; // unboxing
10 int a = 100;
11 double b = a; // none
12
1public class CommandLineArguments {
2 public static void main(String[] args) {
3 int a = Integer.parseInt(args[0]);
4 int b = Integer.parseInt(args[1]);
5 int sum = a + b;
6 System.out.println("Sum is " + sum);
7 }
8}
9
1
2public class HelloWorld {
3 public static void main(String[] args) {
4
5 // how to use class in java
6 class User{
7
8 int score;
9 }
10
11 User dave = new User();
12
13 dave.score = 20;
14
15 System.out.println(dave.score);
16
17
18 }
19}
20
1In Java, for each Primitive type, there is a matching class type.
2 We call them Wrapper classes:
3 Primitive types are the most basic data types
4 available within the Java language.
5 There are 8: boolean , byte , char , short ,
6 int , long , float and double .
7 These types serve as the building blocks of
8 data manipulation in Java.
9 Wrapper classes: Byte, Short, Integer, Long,
10 Float, Double, Boolean, Character
11
12 All the wrapper classes are subclasses
13 of the abstract class Number.
14 The object of the wrapper class contains or
15 wraps its respective primitive data type.
16 Converting primitive data types into object
17 is called boxing, and this is taken care by the compiler.
18
19 Differences:
20 1. Wrappers classes are object
21 2. null can only be assigned to classes
22 3. Wrapper class does have methods
23 4. Primitives does have default values
24 default value of primitives:
25 byte, short, int, long ==> 0
26 float, double ==> 0.0;
27 boolean ==> false;
28 char ==> space
29 5. Default values of wrapper class: null
30