SlideShare a Scribd company logo
Chapter 10



Wrapper Class



                http://www.java2all.com
Introduction



               http://www.java2all.com
Java uses primitive types, such as int, char,
double to hold the basic data types supported by
the language.

   Sometimes it is required to create an object
representation of these primitive types.

    These are collection classes that deal only with
such objects. One needs to wrap the primitive type
in a class.


                                           http://www.java2all.com
To satisfy this need, java provides classes that
correspond to each of the primitive types. Basically,
these classes encapsulate, or wrap, the primitive types
within a class.
      Thus, they are commonly referred to as type
wrapper. Type wrapper are classes that encapsulate a
primitive type within an object.

    The wrapper types are Byte, Short, Integer,
Long, Character, Boolean, Double, Float.

     These classes offer a wide array of methods that
allow to fully integrate the primitive types into Java’s
object hierarchy.                              http://www.java2all.com
Wrapper classes for converting simple types


      Simple Type               Wrapper class

boolean             Boolean
char                Character
double              Double
float               Float
int                 Integer
long                Long



                                                http://www.java2all.com
Converting primitive numbers to Object
numbers using constructor methods
    Constructor
                                 Conversion Action
       calling
Integer IntVal =
                   Primitive integer to Integer object
new Integer(i);
Float FloatVal =
                   Primitive float to Float object
new Float(f);
Double DoubleVal
                   Primitive double to Double object
= new Double(d);
Long LongVal =
                   Primitive long to Long object
new Long(l);


                                                     http://www.java2all.com
Converting Numeric Strings to Primitive
numbers using Parsing method


 Method calling                    Conversion Action

int i =
Integer.parseInt(st Converts String str into primitive integer i
r);

long l =
Long.parseLong(st Converts String str into primitive long l
r);


                                                        http://www.java2all.com
NOTE :
           parseInt() and parseLong() methods throw
a NumberFormatException if the value of the str
does not represent an integer.




                                          http://www.java2all.com
Byte



       http://www.java2all.com
The Byte class encapsulates a byte value. It
defines the constants MAX_VALUE and
MIN_VALUE and provides these constructors:

   Byte(byte b)
   Byte(String str)

     Here, b is a byte value and str is the string
equivalent of a byte value.



                                               http://www.java2all.com
EX :
import java.util.*;
public class Byte_Demo
{
  public static void main(String args[])
  {
    Byte b1 = new Byte((byte)120);
    for(int i = 125; i<=135; i++)
    {
       Byte b2 = new Byte((byte)i);
       System.out.println("b2 = " + b2);
    }
    System.out.println("b1 Object = " + b1);
    System.out.println("Minimum Value of Byte = " + Byte.MIN_VALUE);
    System.out.println("Maximum Value of Byte = " + Byte.MAX_VALUE);
    System.out.println("b1* 2 = " + b1*2);
    System.out.println("b1* 2 = " + b1.byteValue()*2);
    Byte b3 = new Byte("120");
    System.out.println("b3 Object = " + b3);
    System.out.println("(b1==b3)? " + b1.equals(b3));
    System.out.println("(b1.compareTo(b3)? " + b1.compareTo(b3));
     /*Returns 0 if equal. Returns -1 if b1 is less than b3 and 1 if b1 is
    greater than 1*/
  }
}
                                                                             http://www.java2all.com
Output :
 b2 = 125
b2 = 126
b2 = 127
b2 = -128
b2 = -127
b2 = -126
b2 = -125
b2 = -124
b2 = -123
b2 = -122
b2 = -121
b1 Object = 120
Minimum Value of Byte = -128
Maximum Value of Byte = 127
b1* 2 = 240
b1* 2 = 240
b3 Object = 120
(b1==b3)? true
(b1.compareTo(b3)? 0
                               http://www.java2all.com
Short



        http://www.java2all.com
The Short class encapsulates a short value.
It defines the constants MAX_VALUE and MIN_VALUE
and provides the following constructors:


           Short(short s)
           Short(String str)



                                             http://www.java2all.com
EX :


import java.util.*;
public class Short_Demo
{
  public static void main(String args[])
  {
    Short s1 = new Short((short)2345);
    for(int i = 32765; i<=32775; i++)
    {
       Short s2 = new Short((short)i);
       System.out.println("s2 = " + s2);
    }
    System.out.println("s1 Object = " + s1);
    System.out.println("Minimum Value of Short = " + Short.MIN_VALUE);
    System.out.println("Maximum Value of Short = " + Short.MAX_VALUE);
    System.out.println("s1* 2 = " + s1.shortValue()*2);
    Short s3 = new Short("2345");
    System.out.println("s3 Object = " + s3);
    System.out.println("(s1==s3)? " + s1.equals(s3));
    Short s4 = Short.valueOf("10", 16);
    System.out.println("s4 Object = " + s4);
  }
}


                                                                         http://www.java2all.com
Output :
s2 = 32765
s2 = 32766
s2 = 32767
s2 = -32768
s2 = -32767
s2 = -32766
s2 = -32765
s2 = -32764
s2 = -32763
s2 = -32762
s2 = -32761
s1 Object = 2345
Minimum Value of Short = -32768
Maximum Value of Short = 32767
s1* 2 = 4690
s3 Object = 2345
(s1==s3)? true
s4 Object = 16                    http://www.java2all.com
Integer



          http://www.java2all.com
Integer class :

     The Integer class encapsulates an integer value.
This class provides following constructors:

     Integer(int i)
     Integer(String str)

     Here, i is a simple int value and str is a String
object.



                                               http://www.java2all.com
EX :
import java.util.*;
public class Int_Demo
{
  public static void main(String args[])
  {
    Integer i1 = new Integer(12);
    System.out.println("I1 = " + i1);
    System.out.println("Binary Equivalent = " + Integer.toBinaryString(i1));
    System.out.println("Hexadecimal Equivalent = " + Integer.toHexString(i1));
    System.out.println("Minimum Value of Integer = " + Integer.MIN_VALUE);
    System.out.println("Maximum Value of Integer = " + Integer.MAX_VALUE);
    System.out.println("Byte Value of Integer = " + i1.byteValue());
    System.out.println("Double Value of Integer = " + i1.doubleValue());
    Integer i2 = new Integer(12);
    System.out.println("i1==i2 " + i1.equals(i2));
    System.out.println("i1.compareTo(i2) = " + i2.compareTo(i1));
    // Compareto - if it is less than it returns -1 else 1, if equal it return 0.
    Integer i3 = Integer.valueOf("11", 16);
    System.out.println("i3 = " + i3);
  }
}




                                                                                    http://www.java2all.com
Output :

I1 = 12
Binary Equivalent = 1100
Hexadecimal Equivalent = c
Minimum Value of Integer = -2147483648
Maximum Value of Integer = 2147483647
Byte Value of Integer = 12
Double Value of Integer = 12.0
i1==i2 true
i1.compareTo(i2) = 0
i3 = 17



                                         http://www.java2all.com
Long



       http://www.java2all.com
Long :

     The Long class encapsulates a long value. It
defines the constants MAX_VALUE and
MIN_VALUE and provides the following
constructors:

     Long(long l)
     Long(String str)


                                            http://www.java2all.com
EX :
import java.util.*;
 public class Long_Demo
{
  public static void main(String args[])
  {
    Long L1 = new Long(68764);
    Long L2 = new Long("686748");
    System.out.println("Object L1 = " + L1);
    System.out.println("Object L2 = " + L2);
    System.out.println("Minimum Value of Long = " + Long.MIN_VALUE);
    System.out.println("Maximum Value of Long = " + Long.MAX_VALUE);
    System.out.println("L1 * 2 = " + L1 * 2);
    System.out.println("L1.longValue() * 2 = " + L1.longValue() * 2);
    System.out.println("L1.compareTo(l2) = " + L1.compareTo(L2));
    System.out.println("L1==L2 ? = " + L1.equals(L2));
    Long L3 = Long.valueOf("10", 16);
    System.out.println("Object L3 = " + L3);
    System.out.println("Byte value of Long = " + L1.byteValue());
    System.out.println("int value of Long = " + L1.intValue());
    System.out.println("Double value of Long = " + L1.doubleValue());
    int i = 12;
    System.out.println("Binary equivalent of decimal " + i + "=" + Long.toBinaryString(i));
    System.out.println("Hexadecimal equivalent of decimal " + i + "=" + Long.toHexString(i));

    }
}
                                                                                 http://www.java2all.com
Output :

Object L1 = 68764
Object L2 = 686748
Minimum Value of Long = -9223372036854775808
Maximum Value of Long = 9223372036854775807
L1 * 2 = 137528
L1.longValue() * 2 = 137528
L1.compareTo(l2) = -1
L1==L2 ? = false
Object L3 = 16
Byte value of Long = -100
int value of Long = 68764
Double value of Long = 68764.0
Binary equivalent of decimal 12=1100
Hexadecimal equivalent of decimal 12=c
                                               http://www.java2all.com
Double



         http://www.java2all.com
Double class :

     The Double class encapsulates a double value. It
defines several constants.

   The largest and smallest values are saved in
MAX_VALUE and MIN_VALUE.

      The constant NaN (Not a Number) indicates that
a value is not a number.

                                           http://www.java2all.com
If you divide a double number by zero, the result
is NaN. This class defines these constructors:

     Double(double d)
     Double(String str)

     Here, d is a double value to be encapsulated in a
Double object. In the last form, str is the string
representation of a double value.




                                            http://www.java2all.com
EX :

import java.util.*;
class Double_Demo
{
   public static void main(String args[])
   {
     Double d1 = new Double(687642365.4563);
     Double d2 = new Double("686748");
     System.out.println("Object d1 = " + d1);
     System.out.println("Object d2 = " + d2);
     System.out.println("Minimum Value of Double = " + Double.MIN_VALUE);
     System.out.println("Maximum Value of Double = " + Double.MAX_VALUE);
     System.out.println("Byte value of Double = " + d1.byteValue());
     System.out.println("int value of Double = " + d1.intValue());
     System.out.println("Float value of Double = " + d1.floatValue());
     Double d3 = Double.parseDouble("765.89");
     System.out.println("Double value from the string "765.89"="+d3);

    }
}




                                                                            http://www.java2all.com
Output :

Object d1 = 6.876423654563E8
Object d2 = 686748.0
Minimum Value of Double = 4.9E-324
Maximum Value of Double = 1.7976931348623157E308
Byte value of Double = -3
int value of Double = 687642365
Float value of Double = 6.8764237E8
Double value from the string "765.89"=765.89




                                               http://www.java2all.com
Float



        http://www.java2all.com
Float class :
      The float class encapsulates a float value.
It defines several constants the largest and smallest
values are stored in MAX_VALUE and
MIN_VALUE.

      The constant NaN indicates that a value is not a
number. If you divide a floating – point number by
zero, the result is NaN.


                                              http://www.java2all.com
This class defines these constructors:

    Float(float f)
    Float(double d)
    Float(String str)

     Here, f and d are float and double types to be
encapsulated in a Float object.

str is the string representation of a float value.



                                                http://www.java2all.com
EX :

import java.util.*;

public class Float_Demo
{
  public static void main(String args[])
  {
    Float f1 = new Float(123.5626);
    Float f2 = new Float(854.32f);
    Float i = new Float(10);
    System.out.println("Object f1 = " + f1);
    System.out.println("Object f2 = " + f2);
    System.out.println("Minimum Value of Float = " + Float.MIN_VALUE);
    System.out.println("Maximum Value of Float = " + Float.MAX_VALUE);
    System.out.println("Byte value of Float = " + f1.byteValue());
    System.out.println("Short value of Float = " + f1.shortValue());
    System.out.println("Integer value of Float = " + f1.intValue());
    System.out.println("Double value of Float = " + f1.doubleValue());
    System.out.println("(f1==f2) ?= " + f1.equals(f2));
    System.out.println("f1.compareTo(f2) = " + f1.compareTo(f2));
    System.out.println("f1 is not a number = " + i.isNaN());

    }
}

                                                                         http://www.java2all.com
Output :

Object f1 = 123.5626
Object f2 = 854.32
Minimum Value of Float = 1.4E-45
Maximum Value of Float = 3.4028235E38
Byte value of Float = 123
Short value of Float = 123
Integer value of Float = 123
Double value of Float = 123.5625991821289
(f1==f2) ?= false
f1.compareTo(f2) = -1
f1 is not a number = false

                                            http://www.java2all.com
Character



            http://www.java2all.com
Character class :
     The Character class encapsulates a char value.
This class provides the following constructor.

     Character(char ch)

      Here, c is a char value. charValue() method
returns the char value that is encapsulated by a
Character object and has the following form:

char charValue()
                                            http://www.java2all.com
EX :

import java.util.*;

public class Char_Demo
{
  public static void main(String args[])
  {
    Character c1 = new Character('m');
    char c2 = 'O';
    System.out.println("Object C1 = " + c1);
    System.out.println("char value of Character Object = " + c1.charValue());
    System.out.println(c2 + " is defined character set ? " + Character.isDefined(c2));
    System.out.println("c2 is digit = " + Character.isDigit(c2));
    System.out.println("c2 is lowercase character = " + Character.isLowerCase(c2));
    System.out.println("c2 is uppercase character = " + Character.isUpperCase(c2));


    }
}




                                                                                    http://www.java2all.com
Output :

Object C1 = m
char value of Character Object = m
O is defined character set ? true
c2 is digit = false
c2 is lowercase character = false
c2 is uppercase character = true




                                     http://www.java2all.com
Boolean



          http://www.java2all.com
Boolean class :

      The Boolean class encapsulates a Boolean value.
It defines FALSE and TRUE constants.

     This class provides following constructors:

     Boolean(Boolean b)
     Boolean(String str)

     Here, b is a Boolean value and str is the string
equivalent of a Boolean value.
                                              http://www.java2all.com
The methods associated with Boolean Class
are as follows:


    1. Boolean booleanValue()
    2. Boolean equals(Boolean b)
    3. String toString(Boolean b)




                                       http://www.java2all.com
EX :

import java.util.*;

public class Boolean_Demo
{
  public static void main(String args[])
  {
    Boolean b1 = new Boolean(true);
    Boolean b2 = new Boolean(false);
    System.out.println("Object B1 = " + b1);
    System.out.println("Object B2 = " + b2);
    Boolean b3 = new Boolean("true");
    Boolean b4 = new Boolean("false");
    System.out.println("Object B3 = " + b3);
    System.out.println("Object B4 = " + b4);
    System.out.println("Boolean Value = " + b1.booleanValue());
    System.out.println("(b1==b2)? " + b1.equals(b2));
    String S1 = b1.toString();
    System.out.println("String S1 " + S1);

    }
}



                                                                  http://www.java2all.com
Output :

Object B1 = true
Object B2 = false
Object B3 = true
Object B4 = false
Boolean Value = true
(b1==b2)? false
String S1 true




                       http://www.java2all.com

More Related Content

What's hot (20)

Wrapper classes
Wrapper classesWrapper classes
Wrapper classes
Ravi_Kant_Sahu
 
Exception Handling in JAVA
Exception Handling in JAVAException Handling in JAVA
Exception Handling in JAVA
SURIT DATTA
 
Java I/o streams
Java I/o streamsJava I/o streams
Java I/o streams
Hamid Ghorbani
 
Java string handling
Java string handlingJava string handling
Java string handling
Salman Khan
 
Strings in Java
Strings in JavaStrings in Java
Strings in Java
Abhilash Nair
 
Java Collections Framework
Java Collections FrameworkJava Collections Framework
Java Collections Framework
Sony India Software Center
 
Java awt (abstract window toolkit)
Java awt (abstract window toolkit)Java awt (abstract window toolkit)
Java awt (abstract window toolkit)
Elizabeth alexander
 
Java Exception handling
Java Exception handlingJava Exception handling
Java Exception handling
kamal kotecha
 
Java Streams
Java StreamsJava Streams
Java Streams
M Vishnuvardhan Reddy
 
Generics
GenericsGenerics
Generics
Ravi_Kant_Sahu
 
Polymorphism In Java
Polymorphism In JavaPolymorphism In Java
Polymorphism In Java
Spotle.ai
 
Arrays in Java
Arrays in JavaArrays in Java
Arrays in Java
Naz Abdalla
 
Basic Concepts of OOPs (Object Oriented Programming in Java)
Basic Concepts of OOPs (Object Oriented Programming in Java)Basic Concepts of OOPs (Object Oriented Programming in Java)
Basic Concepts of OOPs (Object Oriented Programming in Java)
Michelle Anne Meralpis
 
Threads in JAVA
Threads in JAVAThreads in JAVA
Threads in JAVA
Haldia Institute of Technology
 
Classes, objects in JAVA
Classes, objects in JAVAClasses, objects in JAVA
Classes, objects in JAVA
Abhilash Nair
 
Exception handling
Exception handlingException handling
Exception handling
PhD Research Scholar
 
Constructor ppt
Constructor pptConstructor ppt
Constructor ppt
Vinod Kumar
 
Java 8 features
Java 8 featuresJava 8 features
Java 8 features
NexThoughts Technologies
 
itft-Decision making and branching in java
itft-Decision making and branching in javaitft-Decision making and branching in java
itft-Decision making and branching in java
Atul Sehdev
 
Java And Multithreading
Java And MultithreadingJava And Multithreading
Java And Multithreading
Shraddha
 

Viewers also liked (20)

L9 wrapper classes
L9 wrapper classesL9 wrapper classes
L9 wrapper classes
teach4uin
 
Wrapper class (130240116056)
Wrapper class (130240116056)Wrapper class (130240116056)
Wrapper class (130240116056)
Akshay soni
 
Vectors in Java
Vectors in JavaVectors in Java
Vectors in Java
Abhilash Nair
 
wrapper classes
wrapper classeswrapper classes
wrapper classes
Rajesh Roky
 
ppt on scanner class
ppt on scanner classppt on scanner class
ppt on scanner class
deepsxn
 
Banking structure of india and united kingdom(1)
Banking structure of india and united kingdom(1)Banking structure of india and united kingdom(1)
Banking structure of india and united kingdom(1)
Pooja Yadav
 
How to Get Started with Salesforce Lightning
How to Get Started with Salesforce LightningHow to Get Started with Salesforce Lightning
How to Get Started with Salesforce Lightning
Salesforce Admins
 
Salesforce Lightning Design System
Salesforce Lightning Design SystemSalesforce Lightning Design System
Salesforce Lightning Design System
Durgesh Dhoot
 
Built in classes in java
Built in classes in javaBuilt in classes in java
Built in classes in java
Mahmoud Ali
 
Lightning Components Introduction
Lightning Components IntroductionLightning Components Introduction
Lightning Components Introduction
Durgesh Dhoot
 
Packages and inbuilt classes of java
Packages and inbuilt classes of javaPackages and inbuilt classes of java
Packages and inbuilt classes of java
kamal kotecha
 
Introducing the Salesforce Lightning Design System
Introducing the Salesforce Lightning Design SystemIntroducing the Salesforce Lightning Design System
Introducing the Salesforce Lightning Design System
Salesforce Developers
 
Java Hibernate Programming with Architecture Diagram and Example
Java Hibernate Programming with Architecture Diagram and ExampleJava Hibernate Programming with Architecture Diagram and Example
Java Hibernate Programming with Architecture Diagram and Example
kamal kotecha
 
etapas del análisis,diseño y programacion orientada a objetos
etapas del análisis,diseño y programacion orientada a objetosetapas del análisis,diseño y programacion orientada a objetos
etapas del análisis,diseño y programacion orientada a objetos
222415
 
Introduction to Java Strings, By Kavita Ganesan
Introduction to Java Strings, By Kavita GanesanIntroduction to Java Strings, By Kavita Ganesan
Introduction to Java Strings, By Kavita Ganesan
Kavita Ganesan
 
Packages in java
Packages in javaPackages in java
Packages in java
Abhishek Khune
 
Trabajo de diseño de sistemas orientados a objetos
Trabajo de diseño de sistemas orientados a objetosTrabajo de diseño de sistemas orientados a objetos
Trabajo de diseño de sistemas orientados a objetos
douglimar89
 
Introduction to class in java
Introduction to class in javaIntroduction to class in java
Introduction to class in java
kamal kotecha
 
Java packages
Java packagesJava packages
Java packages
BHUVIJAYAVELU
 
Queue Data Structure
Queue Data StructureQueue Data Structure
Queue Data Structure
Zidny Nafan
 
L9 wrapper classes
L9 wrapper classesL9 wrapper classes
L9 wrapper classes
teach4uin
 
Wrapper class (130240116056)
Wrapper class (130240116056)Wrapper class (130240116056)
Wrapper class (130240116056)
Akshay soni
 
ppt on scanner class
ppt on scanner classppt on scanner class
ppt on scanner class
deepsxn
 
Banking structure of india and united kingdom(1)
Banking structure of india and united kingdom(1)Banking structure of india and united kingdom(1)
Banking structure of india and united kingdom(1)
Pooja Yadav
 
How to Get Started with Salesforce Lightning
How to Get Started with Salesforce LightningHow to Get Started with Salesforce Lightning
How to Get Started with Salesforce Lightning
Salesforce Admins
 
Salesforce Lightning Design System
Salesforce Lightning Design SystemSalesforce Lightning Design System
Salesforce Lightning Design System
Durgesh Dhoot
 
Built in classes in java
Built in classes in javaBuilt in classes in java
Built in classes in java
Mahmoud Ali
 
Lightning Components Introduction
Lightning Components IntroductionLightning Components Introduction
Lightning Components Introduction
Durgesh Dhoot
 
Packages and inbuilt classes of java
Packages and inbuilt classes of javaPackages and inbuilt classes of java
Packages and inbuilt classes of java
kamal kotecha
 
Introducing the Salesforce Lightning Design System
Introducing the Salesforce Lightning Design SystemIntroducing the Salesforce Lightning Design System
Introducing the Salesforce Lightning Design System
Salesforce Developers
 
Java Hibernate Programming with Architecture Diagram and Example
Java Hibernate Programming with Architecture Diagram and ExampleJava Hibernate Programming with Architecture Diagram and Example
Java Hibernate Programming with Architecture Diagram and Example
kamal kotecha
 
etapas del análisis,diseño y programacion orientada a objetos
etapas del análisis,diseño y programacion orientada a objetosetapas del análisis,diseño y programacion orientada a objetos
etapas del análisis,diseño y programacion orientada a objetos
222415
 
Introduction to Java Strings, By Kavita Ganesan
Introduction to Java Strings, By Kavita GanesanIntroduction to Java Strings, By Kavita Ganesan
Introduction to Java Strings, By Kavita Ganesan
Kavita Ganesan
 
Trabajo de diseño de sistemas orientados a objetos
Trabajo de diseño de sistemas orientados a objetosTrabajo de diseño de sistemas orientados a objetos
Trabajo de diseño de sistemas orientados a objetos
douglimar89
 
Introduction to class in java
Introduction to class in javaIntroduction to class in java
Introduction to class in java
kamal kotecha
 
Queue Data Structure
Queue Data StructureQueue Data Structure
Queue Data Structure
Zidny Nafan
 
Ad

Similar to Wrapper class (20)

Shiksharth com java_topics
Shiksharth com java_topicsShiksharth com java_topics
Shiksharth com java_topics
Rajesh Verma
 
vectors.(join ALL INDIA POLYTECHNIC (AICTE)).pptx
vectors.(join ALL INDIA POLYTECHNIC (AICTE)).pptxvectors.(join ALL INDIA POLYTECHNIC (AICTE)).pptx
vectors.(join ALL INDIA POLYTECHNIC (AICTE)).pptx
VivekSharma34623
 
DAY_1.3.pptx
DAY_1.3.pptxDAY_1.3.pptx
DAY_1.3.pptx
ishasharma835109
 
java Basic Programming Needs
java Basic Programming Needsjava Basic Programming Needs
java Basic Programming Needs
Raja Sekhar
 
Lecture 3 and 4.pptx
Lecture 3 and 4.pptxLecture 3 and 4.pptx
Lecture 3 and 4.pptx
MAHAMASADIK
 
Sdtl manual
Sdtl manualSdtl manual
Sdtl manual
qaz8989
 
JAVA Data Types - Part 1
JAVA Data Types - Part 1JAVA Data Types - Part 1
JAVA Data Types - Part 1
Ashok Asn
 
03 and 04 .Operators, Expressions, working with the console and conditional s...
03 and 04 .Operators, Expressions, working with the console and conditional s...03 and 04 .Operators, Expressions, working with the console and conditional s...
03 and 04 .Operators, Expressions, working with the console and conditional s...
Intro C# Book
 
Java tutorial part 3
Java tutorial part 3Java tutorial part 3
Java tutorial part 3
Mumbai Academisc
 
03-Primitive-Datatypes.pdf
03-Primitive-Datatypes.pdf03-Primitive-Datatypes.pdf
03-Primitive-Datatypes.pdf
KaraBaesh
 
Lecture20 vector
Lecture20 vectorLecture20 vector
Lecture20 vector
nurkhaledah
 
Java Day-4
Java Day-4Java Day-4
Java Day-4
People Strategists
 
PSI 3 Integration
PSI 3 IntegrationPSI 3 Integration
PSI 3 Integration
Joseph Asencio
 
Computer programming 2 Lesson 10
Computer programming 2  Lesson 10Computer programming 2  Lesson 10
Computer programming 2 Lesson 10
MLG College of Learning, Inc
 
Wrapper classes
Wrapper classesWrapper classes
Wrapper classes
simarsimmygrewal
 
3 jf h-linearequations
3  jf h-linearequations3  jf h-linearequations
3 jf h-linearequations
AboutHydrology Slides
 
03 expressions.ppt
03 expressions.ppt03 expressions.ppt
03 expressions.ppt
Business man
 
Chapter i(introduction to java)
Chapter i(introduction to java)Chapter i(introduction to java)
Chapter i(introduction to java)
Chhom Karath
 
Java Foundations: Data Types and Type Conversion
Java Foundations: Data Types and Type ConversionJava Foundations: Data Types and Type Conversion
Java Foundations: Data Types and Type Conversion
Svetlin Nakov
 
Pi j1.2 variable-assignment
Pi j1.2 variable-assignmentPi j1.2 variable-assignment
Pi j1.2 variable-assignment
mcollison
 
Shiksharth com java_topics
Shiksharth com java_topicsShiksharth com java_topics
Shiksharth com java_topics
Rajesh Verma
 
vectors.(join ALL INDIA POLYTECHNIC (AICTE)).pptx
vectors.(join ALL INDIA POLYTECHNIC (AICTE)).pptxvectors.(join ALL INDIA POLYTECHNIC (AICTE)).pptx
vectors.(join ALL INDIA POLYTECHNIC (AICTE)).pptx
VivekSharma34623
 
java Basic Programming Needs
java Basic Programming Needsjava Basic Programming Needs
java Basic Programming Needs
Raja Sekhar
 
Lecture 3 and 4.pptx
Lecture 3 and 4.pptxLecture 3 and 4.pptx
Lecture 3 and 4.pptx
MAHAMASADIK
 
Sdtl manual
Sdtl manualSdtl manual
Sdtl manual
qaz8989
 
JAVA Data Types - Part 1
JAVA Data Types - Part 1JAVA Data Types - Part 1
JAVA Data Types - Part 1
Ashok Asn
 
03 and 04 .Operators, Expressions, working with the console and conditional s...
03 and 04 .Operators, Expressions, working with the console and conditional s...03 and 04 .Operators, Expressions, working with the console and conditional s...
03 and 04 .Operators, Expressions, working with the console and conditional s...
Intro C# Book
 
03-Primitive-Datatypes.pdf
03-Primitive-Datatypes.pdf03-Primitive-Datatypes.pdf
03-Primitive-Datatypes.pdf
KaraBaesh
 
Lecture20 vector
Lecture20 vectorLecture20 vector
Lecture20 vector
nurkhaledah
 
03 expressions.ppt
03 expressions.ppt03 expressions.ppt
03 expressions.ppt
Business man
 
Chapter i(introduction to java)
Chapter i(introduction to java)Chapter i(introduction to java)
Chapter i(introduction to java)
Chhom Karath
 
Java Foundations: Data Types and Type Conversion
Java Foundations: Data Types and Type ConversionJava Foundations: Data Types and Type Conversion
Java Foundations: Data Types and Type Conversion
Svetlin Nakov
 
Pi j1.2 variable-assignment
Pi j1.2 variable-assignmentPi j1.2 variable-assignment
Pi j1.2 variable-assignment
mcollison
 
Ad

More from kamal kotecha (17)

Network programming in java - PPT
Network programming in java - PPTNetwork programming in java - PPT
Network programming in java - PPT
kamal kotecha
 
Java servlet life cycle - methods ppt
Java servlet life cycle - methods pptJava servlet life cycle - methods ppt
Java servlet life cycle - methods ppt
kamal kotecha
 
Java rmi example program with code
Java rmi example program with codeJava rmi example program with code
Java rmi example program with code
kamal kotecha
 
Java rmi
Java rmiJava rmi
Java rmi
kamal kotecha
 
Jdbc example program with access and MySql
Jdbc example program with access and MySqlJdbc example program with access and MySql
Jdbc example program with access and MySql
kamal kotecha
 
Jdbc api
Jdbc apiJdbc api
Jdbc api
kamal kotecha
 
Jdbc architecture and driver types ppt
Jdbc architecture and driver types pptJdbc architecture and driver types ppt
Jdbc architecture and driver types ppt
kamal kotecha
 
JSP Error handling
JSP Error handlingJSP Error handling
JSP Error handling
kamal kotecha
 
Jsp element
Jsp elementJsp element
Jsp element
kamal kotecha
 
Jsp chapter 1
Jsp chapter 1Jsp chapter 1
Jsp chapter 1
kamal kotecha
 
String and string buffer
String and string bufferString and string buffer
String and string buffer
kamal kotecha
 
Interface
InterfaceInterface
Interface
kamal kotecha
 
Inheritance chepter 7
Inheritance chepter 7Inheritance chepter 7
Inheritance chepter 7
kamal kotecha
 
Class method
Class methodClass method
Class method
kamal kotecha
 
Control statements
Control statementsControl statements
Control statements
kamal kotecha
 
Jsp myeclipse
Jsp myeclipseJsp myeclipse
Jsp myeclipse
kamal kotecha
 
basic core java up to operator
basic core java up to operatorbasic core java up to operator
basic core java up to operator
kamal kotecha
 
Network programming in java - PPT
Network programming in java - PPTNetwork programming in java - PPT
Network programming in java - PPT
kamal kotecha
 
Java servlet life cycle - methods ppt
Java servlet life cycle - methods pptJava servlet life cycle - methods ppt
Java servlet life cycle - methods ppt
kamal kotecha
 
Java rmi example program with code
Java rmi example program with codeJava rmi example program with code
Java rmi example program with code
kamal kotecha
 
Jdbc example program with access and MySql
Jdbc example program with access and MySqlJdbc example program with access and MySql
Jdbc example program with access and MySql
kamal kotecha
 
Jdbc architecture and driver types ppt
Jdbc architecture and driver types pptJdbc architecture and driver types ppt
Jdbc architecture and driver types ppt
kamal kotecha
 
String and string buffer
String and string bufferString and string buffer
String and string buffer
kamal kotecha
 
Inheritance chepter 7
Inheritance chepter 7Inheritance chepter 7
Inheritance chepter 7
kamal kotecha
 
basic core java up to operator
basic core java up to operatorbasic core java up to operator
basic core java up to operator
kamal kotecha
 

Recently uploaded (20)

Adam Grant: Transforming Work Culture Through Organizational Psychology
Adam Grant: Transforming Work Culture Through Organizational PsychologyAdam Grant: Transforming Work Culture Through Organizational Psychology
Adam Grant: Transforming Work Culture Through Organizational Psychology
Prachi Shah
 
Coleoptera: The Largest Insect Order.pptx
Coleoptera: The Largest Insect Order.pptxColeoptera: The Largest Insect Order.pptx
Coleoptera: The Largest Insect Order.pptx
Arshad Shaikh
 
How to Create Time Off Request in Odoo 18 Time Off
How to Create Time Off Request in Odoo 18 Time OffHow to Create Time Off Request in Odoo 18 Time Off
How to Create Time Off Request in Odoo 18 Time Off
Celine George
 
State institute of educational technology
State institute of educational technologyState institute of educational technology
State institute of educational technology
vp5806484
 
Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...
Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...
Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...
EduSkills OECD
 
SEXUALITY , UNWANTED PREGANCY AND SEXUAL ASSAULT .pptx
SEXUALITY , UNWANTED PREGANCY AND SEXUAL ASSAULT .pptxSEXUALITY , UNWANTED PREGANCY AND SEXUAL ASSAULT .pptx
SEXUALITY , UNWANTED PREGANCY AND SEXUAL ASSAULT .pptx
PoojaSen20
 
What are the benefits that dance brings?
What are the benefits that dance brings?What are the benefits that dance brings?
What are the benefits that dance brings?
memi27
 
MATERI PPT TOPIK 4 LANDASAN FILOSOFIS PENDIDIKAN
MATERI PPT TOPIK 4 LANDASAN FILOSOFIS PENDIDIKANMATERI PPT TOPIK 4 LANDASAN FILOSOFIS PENDIDIKAN
MATERI PPT TOPIK 4 LANDASAN FILOSOFIS PENDIDIKAN
aditya23173
 
Diptera: The Two-Winged Wonders, The Fly Squad: Order Diptera.pptx
Diptera: The Two-Winged Wonders, The Fly Squad: Order Diptera.pptxDiptera: The Two-Winged Wonders, The Fly Squad: Order Diptera.pptx
Diptera: The Two-Winged Wonders, The Fly Squad: Order Diptera.pptx
Arshad Shaikh
 
How to Manage Maintenance Request in Odoo 18
How to Manage Maintenance Request in Odoo 18How to Manage Maintenance Request in Odoo 18
How to Manage Maintenance Request in Odoo 18
Celine George
 
Webcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Webcrawler_Mule_AIChain_MuleSoft_Meetup_HyderabadWebcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Webcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Veera Pallapu
 
Rose Cultivation Practices by Kushal Lamichhane.pdf
Rose Cultivation Practices by Kushal Lamichhane.pdfRose Cultivation Practices by Kushal Lamichhane.pdf
Rose Cultivation Practices by Kushal Lamichhane.pdf
kushallamichhame
 
Unit 3 Poster Sketches with annotations.pptx
Unit 3 Poster Sketches with annotations.pptxUnit 3 Poster Sketches with annotations.pptx
Unit 3 Poster Sketches with annotations.pptx
bobby205207
 
Forestry Model Exit Exam_2025_Wollega University, Gimbi Campus.pdf
Forestry Model Exit Exam_2025_Wollega University, Gimbi Campus.pdfForestry Model Exit Exam_2025_Wollega University, Gimbi Campus.pdf
Forestry Model Exit Exam_2025_Wollega University, Gimbi Campus.pdf
ChalaKelbessa
 
Analysis of Quantitative Data Parametric and non-parametric tests.pptx
Analysis of Quantitative Data Parametric and non-parametric tests.pptxAnalysis of Quantitative Data Parametric and non-parametric tests.pptx
Analysis of Quantitative Data Parametric and non-parametric tests.pptx
Shrutidhara2
 
Pfeiffer "Secrets to Changing Behavior in Scholarly Communication: A 2025 NIS...
Pfeiffer "Secrets to Changing Behavior in Scholarly Communication: A 2025 NIS...Pfeiffer "Secrets to Changing Behavior in Scholarly Communication: A 2025 NIS...
Pfeiffer "Secrets to Changing Behavior in Scholarly Communication: A 2025 NIS...
National Information Standards Organization (NISO)
 
Search Engine Optimization (SEO) for Website Success
Search Engine Optimization (SEO) for Website SuccessSearch Engine Optimization (SEO) for Website Success
Search Engine Optimization (SEO) for Website Success
Muneeb Rana
 
"Hymenoptera: A Diverse and Fascinating Order".pptx
"Hymenoptera: A Diverse and Fascinating Order".pptx"Hymenoptera: A Diverse and Fascinating Order".pptx
"Hymenoptera: A Diverse and Fascinating Order".pptx
Arshad Shaikh
 
Nice Dream.pdf /
Nice Dream.pdf                              /Nice Dream.pdf                              /
Nice Dream.pdf /
ErinUsher3
 
POS Reporting in Odoo 18 - Odoo 18 Slides
POS Reporting in Odoo 18 - Odoo 18 SlidesPOS Reporting in Odoo 18 - Odoo 18 Slides
POS Reporting in Odoo 18 - Odoo 18 Slides
Celine George
 
Adam Grant: Transforming Work Culture Through Organizational Psychology
Adam Grant: Transforming Work Culture Through Organizational PsychologyAdam Grant: Transforming Work Culture Through Organizational Psychology
Adam Grant: Transforming Work Culture Through Organizational Psychology
Prachi Shah
 
Coleoptera: The Largest Insect Order.pptx
Coleoptera: The Largest Insect Order.pptxColeoptera: The Largest Insect Order.pptx
Coleoptera: The Largest Insect Order.pptx
Arshad Shaikh
 
How to Create Time Off Request in Odoo 18 Time Off
How to Create Time Off Request in Odoo 18 Time OffHow to Create Time Off Request in Odoo 18 Time Off
How to Create Time Off Request in Odoo 18 Time Off
Celine George
 
State institute of educational technology
State institute of educational technologyState institute of educational technology
State institute of educational technology
vp5806484
 
Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...
Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...
Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...
EduSkills OECD
 
SEXUALITY , UNWANTED PREGANCY AND SEXUAL ASSAULT .pptx
SEXUALITY , UNWANTED PREGANCY AND SEXUAL ASSAULT .pptxSEXUALITY , UNWANTED PREGANCY AND SEXUAL ASSAULT .pptx
SEXUALITY , UNWANTED PREGANCY AND SEXUAL ASSAULT .pptx
PoojaSen20
 
What are the benefits that dance brings?
What are the benefits that dance brings?What are the benefits that dance brings?
What are the benefits that dance brings?
memi27
 
MATERI PPT TOPIK 4 LANDASAN FILOSOFIS PENDIDIKAN
MATERI PPT TOPIK 4 LANDASAN FILOSOFIS PENDIDIKANMATERI PPT TOPIK 4 LANDASAN FILOSOFIS PENDIDIKAN
MATERI PPT TOPIK 4 LANDASAN FILOSOFIS PENDIDIKAN
aditya23173
 
Diptera: The Two-Winged Wonders, The Fly Squad: Order Diptera.pptx
Diptera: The Two-Winged Wonders, The Fly Squad: Order Diptera.pptxDiptera: The Two-Winged Wonders, The Fly Squad: Order Diptera.pptx
Diptera: The Two-Winged Wonders, The Fly Squad: Order Diptera.pptx
Arshad Shaikh
 
How to Manage Maintenance Request in Odoo 18
How to Manage Maintenance Request in Odoo 18How to Manage Maintenance Request in Odoo 18
How to Manage Maintenance Request in Odoo 18
Celine George
 
Webcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Webcrawler_Mule_AIChain_MuleSoft_Meetup_HyderabadWebcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Webcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Veera Pallapu
 
Rose Cultivation Practices by Kushal Lamichhane.pdf
Rose Cultivation Practices by Kushal Lamichhane.pdfRose Cultivation Practices by Kushal Lamichhane.pdf
Rose Cultivation Practices by Kushal Lamichhane.pdf
kushallamichhame
 
Unit 3 Poster Sketches with annotations.pptx
Unit 3 Poster Sketches with annotations.pptxUnit 3 Poster Sketches with annotations.pptx
Unit 3 Poster Sketches with annotations.pptx
bobby205207
 
Forestry Model Exit Exam_2025_Wollega University, Gimbi Campus.pdf
Forestry Model Exit Exam_2025_Wollega University, Gimbi Campus.pdfForestry Model Exit Exam_2025_Wollega University, Gimbi Campus.pdf
Forestry Model Exit Exam_2025_Wollega University, Gimbi Campus.pdf
ChalaKelbessa
 
Analysis of Quantitative Data Parametric and non-parametric tests.pptx
Analysis of Quantitative Data Parametric and non-parametric tests.pptxAnalysis of Quantitative Data Parametric and non-parametric tests.pptx
Analysis of Quantitative Data Parametric and non-parametric tests.pptx
Shrutidhara2
 
Search Engine Optimization (SEO) for Website Success
Search Engine Optimization (SEO) for Website SuccessSearch Engine Optimization (SEO) for Website Success
Search Engine Optimization (SEO) for Website Success
Muneeb Rana
 
"Hymenoptera: A Diverse and Fascinating Order".pptx
"Hymenoptera: A Diverse and Fascinating Order".pptx"Hymenoptera: A Diverse and Fascinating Order".pptx
"Hymenoptera: A Diverse and Fascinating Order".pptx
Arshad Shaikh
 
Nice Dream.pdf /
Nice Dream.pdf                              /Nice Dream.pdf                              /
Nice Dream.pdf /
ErinUsher3
 
POS Reporting in Odoo 18 - Odoo 18 Slides
POS Reporting in Odoo 18 - Odoo 18 SlidesPOS Reporting in Odoo 18 - Odoo 18 Slides
POS Reporting in Odoo 18 - Odoo 18 Slides
Celine George
 

Wrapper class

  • 1. Chapter 10 Wrapper Class http://www.java2all.com
  • 2. Introduction http://www.java2all.com
  • 3. Java uses primitive types, such as int, char, double to hold the basic data types supported by the language. Sometimes it is required to create an object representation of these primitive types. These are collection classes that deal only with such objects. One needs to wrap the primitive type in a class. http://www.java2all.com
  • 4. To satisfy this need, java provides classes that correspond to each of the primitive types. Basically, these classes encapsulate, or wrap, the primitive types within a class. Thus, they are commonly referred to as type wrapper. Type wrapper are classes that encapsulate a primitive type within an object. The wrapper types are Byte, Short, Integer, Long, Character, Boolean, Double, Float. These classes offer a wide array of methods that allow to fully integrate the primitive types into Java’s object hierarchy. http://www.java2all.com
  • 5. Wrapper classes for converting simple types Simple Type Wrapper class boolean Boolean char Character double Double float Float int Integer long Long http://www.java2all.com
  • 6. Converting primitive numbers to Object numbers using constructor methods Constructor Conversion Action calling Integer IntVal = Primitive integer to Integer object new Integer(i); Float FloatVal = Primitive float to Float object new Float(f); Double DoubleVal Primitive double to Double object = new Double(d); Long LongVal = Primitive long to Long object new Long(l); http://www.java2all.com
  • 7. Converting Numeric Strings to Primitive numbers using Parsing method Method calling Conversion Action int i = Integer.parseInt(st Converts String str into primitive integer i r); long l = Long.parseLong(st Converts String str into primitive long l r); http://www.java2all.com
  • 8. NOTE : parseInt() and parseLong() methods throw a NumberFormatException if the value of the str does not represent an integer. http://www.java2all.com
  • 9. Byte http://www.java2all.com
  • 10. The Byte class encapsulates a byte value. It defines the constants MAX_VALUE and MIN_VALUE and provides these constructors: Byte(byte b) Byte(String str) Here, b is a byte value and str is the string equivalent of a byte value. http://www.java2all.com
  • 11. EX : import java.util.*; public class Byte_Demo { public static void main(String args[]) { Byte b1 = new Byte((byte)120); for(int i = 125; i<=135; i++) { Byte b2 = new Byte((byte)i); System.out.println("b2 = " + b2); } System.out.println("b1 Object = " + b1); System.out.println("Minimum Value of Byte = " + Byte.MIN_VALUE); System.out.println("Maximum Value of Byte = " + Byte.MAX_VALUE); System.out.println("b1* 2 = " + b1*2); System.out.println("b1* 2 = " + b1.byteValue()*2); Byte b3 = new Byte("120"); System.out.println("b3 Object = " + b3); System.out.println("(b1==b3)? " + b1.equals(b3)); System.out.println("(b1.compareTo(b3)? " + b1.compareTo(b3)); /*Returns 0 if equal. Returns -1 if b1 is less than b3 and 1 if b1 is greater than 1*/ } } http://www.java2all.com
  • 12. Output : b2 = 125 b2 = 126 b2 = 127 b2 = -128 b2 = -127 b2 = -126 b2 = -125 b2 = -124 b2 = -123 b2 = -122 b2 = -121 b1 Object = 120 Minimum Value of Byte = -128 Maximum Value of Byte = 127 b1* 2 = 240 b1* 2 = 240 b3 Object = 120 (b1==b3)? true (b1.compareTo(b3)? 0 http://www.java2all.com
  • 13. Short http://www.java2all.com
  • 14. The Short class encapsulates a short value. It defines the constants MAX_VALUE and MIN_VALUE and provides the following constructors: Short(short s) Short(String str) http://www.java2all.com
  • 15. EX : import java.util.*; public class Short_Demo { public static void main(String args[]) { Short s1 = new Short((short)2345); for(int i = 32765; i<=32775; i++) { Short s2 = new Short((short)i); System.out.println("s2 = " + s2); } System.out.println("s1 Object = " + s1); System.out.println("Minimum Value of Short = " + Short.MIN_VALUE); System.out.println("Maximum Value of Short = " + Short.MAX_VALUE); System.out.println("s1* 2 = " + s1.shortValue()*2); Short s3 = new Short("2345"); System.out.println("s3 Object = " + s3); System.out.println("(s1==s3)? " + s1.equals(s3)); Short s4 = Short.valueOf("10", 16); System.out.println("s4 Object = " + s4); } } http://www.java2all.com
  • 16. Output : s2 = 32765 s2 = 32766 s2 = 32767 s2 = -32768 s2 = -32767 s2 = -32766 s2 = -32765 s2 = -32764 s2 = -32763 s2 = -32762 s2 = -32761 s1 Object = 2345 Minimum Value of Short = -32768 Maximum Value of Short = 32767 s1* 2 = 4690 s3 Object = 2345 (s1==s3)? true s4 Object = 16 http://www.java2all.com
  • 17. Integer http://www.java2all.com
  • 18. Integer class : The Integer class encapsulates an integer value. This class provides following constructors: Integer(int i) Integer(String str) Here, i is a simple int value and str is a String object. http://www.java2all.com
  • 19. EX : import java.util.*; public class Int_Demo { public static void main(String args[]) { Integer i1 = new Integer(12); System.out.println("I1 = " + i1); System.out.println("Binary Equivalent = " + Integer.toBinaryString(i1)); System.out.println("Hexadecimal Equivalent = " + Integer.toHexString(i1)); System.out.println("Minimum Value of Integer = " + Integer.MIN_VALUE); System.out.println("Maximum Value of Integer = " + Integer.MAX_VALUE); System.out.println("Byte Value of Integer = " + i1.byteValue()); System.out.println("Double Value of Integer = " + i1.doubleValue()); Integer i2 = new Integer(12); System.out.println("i1==i2 " + i1.equals(i2)); System.out.println("i1.compareTo(i2) = " + i2.compareTo(i1)); // Compareto - if it is less than it returns -1 else 1, if equal it return 0. Integer i3 = Integer.valueOf("11", 16); System.out.println("i3 = " + i3); } } http://www.java2all.com
  • 20. Output : I1 = 12 Binary Equivalent = 1100 Hexadecimal Equivalent = c Minimum Value of Integer = -2147483648 Maximum Value of Integer = 2147483647 Byte Value of Integer = 12 Double Value of Integer = 12.0 i1==i2 true i1.compareTo(i2) = 0 i3 = 17 http://www.java2all.com
  • 21. Long http://www.java2all.com
  • 22. Long : The Long class encapsulates a long value. It defines the constants MAX_VALUE and MIN_VALUE and provides the following constructors: Long(long l) Long(String str) http://www.java2all.com
  • 23. EX : import java.util.*; public class Long_Demo { public static void main(String args[]) { Long L1 = new Long(68764); Long L2 = new Long("686748"); System.out.println("Object L1 = " + L1); System.out.println("Object L2 = " + L2); System.out.println("Minimum Value of Long = " + Long.MIN_VALUE); System.out.println("Maximum Value of Long = " + Long.MAX_VALUE); System.out.println("L1 * 2 = " + L1 * 2); System.out.println("L1.longValue() * 2 = " + L1.longValue() * 2); System.out.println("L1.compareTo(l2) = " + L1.compareTo(L2)); System.out.println("L1==L2 ? = " + L1.equals(L2)); Long L3 = Long.valueOf("10", 16); System.out.println("Object L3 = " + L3); System.out.println("Byte value of Long = " + L1.byteValue()); System.out.println("int value of Long = " + L1.intValue()); System.out.println("Double value of Long = " + L1.doubleValue()); int i = 12; System.out.println("Binary equivalent of decimal " + i + "=" + Long.toBinaryString(i)); System.out.println("Hexadecimal equivalent of decimal " + i + "=" + Long.toHexString(i)); } } http://www.java2all.com
  • 24. Output : Object L1 = 68764 Object L2 = 686748 Minimum Value of Long = -9223372036854775808 Maximum Value of Long = 9223372036854775807 L1 * 2 = 137528 L1.longValue() * 2 = 137528 L1.compareTo(l2) = -1 L1==L2 ? = false Object L3 = 16 Byte value of Long = -100 int value of Long = 68764 Double value of Long = 68764.0 Binary equivalent of decimal 12=1100 Hexadecimal equivalent of decimal 12=c http://www.java2all.com
  • 25. Double http://www.java2all.com
  • 26. Double class : The Double class encapsulates a double value. It defines several constants. The largest and smallest values are saved in MAX_VALUE and MIN_VALUE. The constant NaN (Not a Number) indicates that a value is not a number. http://www.java2all.com
  • 27. If you divide a double number by zero, the result is NaN. This class defines these constructors: Double(double d) Double(String str) Here, d is a double value to be encapsulated in a Double object. In the last form, str is the string representation of a double value. http://www.java2all.com
  • 28. EX : import java.util.*; class Double_Demo { public static void main(String args[]) { Double d1 = new Double(687642365.4563); Double d2 = new Double("686748"); System.out.println("Object d1 = " + d1); System.out.println("Object d2 = " + d2); System.out.println("Minimum Value of Double = " + Double.MIN_VALUE); System.out.println("Maximum Value of Double = " + Double.MAX_VALUE); System.out.println("Byte value of Double = " + d1.byteValue()); System.out.println("int value of Double = " + d1.intValue()); System.out.println("Float value of Double = " + d1.floatValue()); Double d3 = Double.parseDouble("765.89"); System.out.println("Double value from the string "765.89"="+d3); } } http://www.java2all.com
  • 29. Output : Object d1 = 6.876423654563E8 Object d2 = 686748.0 Minimum Value of Double = 4.9E-324 Maximum Value of Double = 1.7976931348623157E308 Byte value of Double = -3 int value of Double = 687642365 Float value of Double = 6.8764237E8 Double value from the string "765.89"=765.89 http://www.java2all.com
  • 30. Float http://www.java2all.com
  • 31. Float class : The float class encapsulates a float value. It defines several constants the largest and smallest values are stored in MAX_VALUE and MIN_VALUE. The constant NaN indicates that a value is not a number. If you divide a floating – point number by zero, the result is NaN. http://www.java2all.com
  • 32. This class defines these constructors: Float(float f) Float(double d) Float(String str) Here, f and d are float and double types to be encapsulated in a Float object. str is the string representation of a float value. http://www.java2all.com
  • 33. EX : import java.util.*; public class Float_Demo { public static void main(String args[]) { Float f1 = new Float(123.5626); Float f2 = new Float(854.32f); Float i = new Float(10); System.out.println("Object f1 = " + f1); System.out.println("Object f2 = " + f2); System.out.println("Minimum Value of Float = " + Float.MIN_VALUE); System.out.println("Maximum Value of Float = " + Float.MAX_VALUE); System.out.println("Byte value of Float = " + f1.byteValue()); System.out.println("Short value of Float = " + f1.shortValue()); System.out.println("Integer value of Float = " + f1.intValue()); System.out.println("Double value of Float = " + f1.doubleValue()); System.out.println("(f1==f2) ?= " + f1.equals(f2)); System.out.println("f1.compareTo(f2) = " + f1.compareTo(f2)); System.out.println("f1 is not a number = " + i.isNaN()); } } http://www.java2all.com
  • 34. Output : Object f1 = 123.5626 Object f2 = 854.32 Minimum Value of Float = 1.4E-45 Maximum Value of Float = 3.4028235E38 Byte value of Float = 123 Short value of Float = 123 Integer value of Float = 123 Double value of Float = 123.5625991821289 (f1==f2) ?= false f1.compareTo(f2) = -1 f1 is not a number = false http://www.java2all.com
  • 35. Character http://www.java2all.com
  • 36. Character class : The Character class encapsulates a char value. This class provides the following constructor. Character(char ch) Here, c is a char value. charValue() method returns the char value that is encapsulated by a Character object and has the following form: char charValue() http://www.java2all.com
  • 37. EX : import java.util.*; public class Char_Demo { public static void main(String args[]) { Character c1 = new Character('m'); char c2 = 'O'; System.out.println("Object C1 = " + c1); System.out.println("char value of Character Object = " + c1.charValue()); System.out.println(c2 + " is defined character set ? " + Character.isDefined(c2)); System.out.println("c2 is digit = " + Character.isDigit(c2)); System.out.println("c2 is lowercase character = " + Character.isLowerCase(c2)); System.out.println("c2 is uppercase character = " + Character.isUpperCase(c2)); } } http://www.java2all.com
  • 38. Output : Object C1 = m char value of Character Object = m O is defined character set ? true c2 is digit = false c2 is lowercase character = false c2 is uppercase character = true http://www.java2all.com
  • 39. Boolean http://www.java2all.com
  • 40. Boolean class : The Boolean class encapsulates a Boolean value. It defines FALSE and TRUE constants. This class provides following constructors: Boolean(Boolean b) Boolean(String str) Here, b is a Boolean value and str is the string equivalent of a Boolean value. http://www.java2all.com
  • 41. The methods associated with Boolean Class are as follows: 1. Boolean booleanValue() 2. Boolean equals(Boolean b) 3. String toString(Boolean b) http://www.java2all.com
  • 42. EX : import java.util.*; public class Boolean_Demo { public static void main(String args[]) { Boolean b1 = new Boolean(true); Boolean b2 = new Boolean(false); System.out.println("Object B1 = " + b1); System.out.println("Object B2 = " + b2); Boolean b3 = new Boolean("true"); Boolean b4 = new Boolean("false"); System.out.println("Object B3 = " + b3); System.out.println("Object B4 = " + b4); System.out.println("Boolean Value = " + b1.booleanValue()); System.out.println("(b1==b2)? " + b1.equals(b2)); String S1 = b1.toString(); System.out.println("String S1 " + S1); } } http://www.java2all.com
  • 43. Output : Object B1 = true Object B2 = false Object B3 = true Object B4 = false Boolean Value = true (b1==b2)? false String S1 true http://www.java2all.com

Editor's Notes

  • #14: White Space Characters