SlideShare a Scribd company logo
Java Library Classes & Data Types
An Introduction to Primitives, Composites, and Wrapper Classes
Slide 2: Agenda
 Introduction to Java Library Classes & Packages
 Data Types in Java: An Overview
 Primitive Data Types: Definition & Examples
 Composite Data Types: Definition & Examples
 Key Differences: Primitive vs. Composite
 Introduction to Wrapper Classes
 Why Use Wrapper Classes? (Need)
 Summary & Key Takeaways
Slide 3: Java Library Classes & Packages
 What are they? Pre-written code (classes and interfaces) bundled together into
packages. They provide standard functionality, saving developers time and effort.
 Why use them? Reusability, reliability (tested code), standardization.
 Packages: Organize related classes and interfaces. Think of them like folders for code.
 Important Examples:
o java.lang: Fundamental classes (loaded automatically).
E.g., Object, String, System, Math, Wrapper Classes (Integer, Double,
etc.).
o java.util: Utility classes. E.g., Collections framework
(ArrayList, HashMap), Date, Scanner.
o java.io: Input/Output operations. E.g., File, InputStream, OutputStream.
o java.net: Networking operations. E.g., Socket, URL.
o javax.swing / java.awt: GUI development (older).
Slide 4: Data Types in Java: Overview
Java has two main categories of data types:
1. Primitive Data Types:
o The most basic data types available.
o Predefined by the Java language.
o Serve as the building blocks for data manipulation.
2. Composite (or Reference) Data Types:
o Built using primitive types or other composite types.
o Refer to objects or arrays stored in memory.
o Include Classes, Interfaces, and Arrays.
Slide 5: 1. Primitive Data Types - Definition
 Definition: Predefined, fundamental data types directly supported by the Java language
and named by reserved keywords.
 They store the actual value directly in the memory location allocated to the variable.
 They are not objects.
 Java has 8 primitive data types.
Slide 6: Primitive Data Types - Examples
Type Description Size Example Code
byte Very small integers 8 bits byte b = 100;
short Small integers 16 bits short s = 30000;
int Integers (most common) 32 bits int age = 25;
long Large integers 64 bits long pop = 7_000_000_000L;
float Single-precision float 32 bits float price = 19.99f;
double Double-precision float 64 bits double pi = 3.14159;
boolean True or false values ~1 bit boolean isValid = true;
char Single character 16 bits char grade = 'A';
Slide 7: Primitive Data Types - Real-Time Examples
 int: Storing a user's age, counting items in a shopping cartQuantity,
an employeeID.
 double / float: Representing productPrice, calculating averageScore,
storing temperatureReading.
 boolean: Tracking login status (isLoggedIn), checking if a feature is enabled,
marking an item as isComplete.
 char: Storing a user's middleInitial, representing a gender ('M'/'F'/'O'), storing a
command key ('Y'/'N').
 long: Storing database record ids (when they can exceed 2 billion),
tracking timestamps in milliseconds.
 byte: Reading/writing binary data from files or networks, representing small
configuration flags.
Slide 8: 1. Composite (Reference) Data Types - Definition
 Definition: Data types created from primitive types or other composite types. They don't
store the actual object data directly in the variable's memory location.
 Instead, they store a reference (or memory address) pointing to where the object or
array is actually stored in the heap memory.
 Includes:
o Classes: (Built-in like String, Scanner, or user-defined like Person, Car)
o Arrays: (int[], String[], Object[])
o Interfaces: (List, Map, custom interfaces)
Slide 9: Composite Data Types - Examples
 String (Class): Represents a sequence of characters.
 String greeting = "Hello, World!";
String name = new String("Alice");
content_copydownload
Use code with caution.Java
 Arrays: Fixed-size collection of elements of the same type.
 int[] scores = { 90, 85, 92 };
String[] names = new String[5]; // Array of 5 null String references
content_copydownload
Use code with caution.Java
 User-Defined Class: Blueprint for creating objects.
 // Assuming a Person class exists with name and age fields
Person student = new Person("Bob", 20);
content_copydownload
Use code with caution.Java
 ArrayList (Class implementing List Interface): Dynamic array.
 ArrayList<String> cities = new ArrayList<>();
cities.add("London");
content_copydownload
Use code with caution.Java
Slide 10: Composite Data Types - Real-Time Examples
 String: Storing user names, addresses, product descriptions, file paths.
 Array (int[], double[], etc.): Storing a fixed set of examScores,
historical stockPrices, pixel data for an image.
 ArrayList<Product>: Managing a
dynamic shoppingCart containing Product objects.
 HashMap<String, User>: Storing userData mapped by username (String)
to User objects.
 Custom Classes (Customer, Order, BankAccount): Modeling real-world entities in an
application, holding multiple related pieces of data (primitives and other composites).
E.g., a Customer object might contain String name, int customerId, String
address.
Slide 11: 2. Difference: Primitive vs. Composite
Feature Primitive Data Types Composite (Reference) Data Types
Definition Predefined by Java language
Defined by programmers (or built-in
classes)
Storage Stores actual value directly
Stores memory address (reference) of
object
Memory
Area
Stack (usually)
Heap (objects), Stack (reference
variable)
Default
Value
Specific (0, 0.0, false, '
u0000')
null
Can
be null?
No Yes
Nature Simple values
Complex objects (can hold multiple
values)
Methods? No methods directly Can have methods
Size Fixed size Variable (depends on object state)
Examples int, float, boolean, char
String, Array, ArrayList, Custom
Classes
Slide 12: Introduction to Wrapper Classes
 So, primitives are simple and efficient, but they aren't objects.
 Composite types are objects, offering more capabilities but with some overhead.
 Sometimes, we need to treat primitive values as objects.
 This is where Wrapper Classes come in. They "wrap" a primitive value inside an object.
Slide 13: 3. Define Wrapper Class
 Definition: A set of classes in the java.lang package designed to encapsulate (wrap)
Java's eight primitive data types into objects.
 Each primitive type has a corresponding wrapper class.
Primitive Type Wrapper Class
byte Byte
short Short
int Integer
long Long
float Float
double Double
boolean Boolean
char Character
Example:
int primitiveInt = 10;
Integer wrapperInt = Integer.valueOf(primitiveInt); // Wrapping
// OR using autoboxing (see later slide)
Integer autoWrapperInt = 10;
content_copydownload
Use code with caution.Java
Slide 14: 4. Need of Using Wrapper Class (1/3)
Reason 1: Collections Framework & Generics
 Java's Collections Framework (like ArrayList, LinkedList, HashMap, etc.) only
works with objects.
 You cannot directly store primitive types in these collections.
 Wrapper classes allow you to store primitive values in collections by wrapping them in
objects.
Example:
//ArrayList<int> numbers = new ArrayList<>(); // Compile Error! Cannot use
primitive type.
ArrayList<Integer> numbers = new ArrayList<>(); // Correct! Uses Integer
wrapper class.
numbers.add(10); // Autoboxing: primitive int 10 -> Integer object
numbers.add(20);
int firstNumber = numbers.get(0); // Unboxing: Integer object -> primitive
int
content_copydownload
Use code with caution.Java
Slide 15: 4. Need of Using Wrapper Class (2/3)
Reason 2: Need for null Values
 Primitive types cannot hold a null value. They always have a default value
(e.g., 0 for int, false for boolean).
 Sometimes, null is needed to represent an unknown, missing, or inapplicable state
(e.g., a database field that allows nulls).
 Wrapper class objects, being objects, can hold a null reference.
Example:
// int userId = null; // Compile Error! Primitive cannot be null.
Integer userId = null; // Correct. Represents 'user ID not yet assigned'.
// Later...
if (userId != null) {
// Process the user ID
System.out.println("User ID: " + userId);
} else {
System.out.println("User ID is not available.");
}
content_copydownload
Use code with caution.Java
Slide 16: 4. Need of Using Wrapper Class (3/3)
Reason 3: Utility Methods
 Wrapper classes provide useful static utility methods for conversions and operations
related to the primitive types.
Examples:
 Parsing Strings: Convert a String representation to a primitive/wrapper type.
 String countStr = "123";
 int count = Integer.parseInt(countStr); // String to int

 String piStr = "3.14";
double pi = Double.parseDouble(piStr); // String to double
content_copydownload
Use code with caution.Java
 Converting to String:
 String intStr = Integer.toString(456); // int to String
String boolStr = Boolean.toString(true); // boolean to String
content_copydownload
Use code with caution.Java
 Constants: Provide useful constants like MIN_VALUE, MAX_VALUE.
 System.out.println("Max Int: " + Integer.MAX_VALUE);
System.out.println("Min Float: " + Float.MIN_VALUE);
content_copydownload
Use code with caution.Java
Slide 17: Autoboxing and Unboxing
 To make using wrapper classes easier, Java provides autoboxing and unboxing.
 Autoboxing: The automatic conversion that the Java compiler makes between primitive
types and their corresponding object wrapper classes.
Integer wrapperInt = 100; // Autoboxing (compiler converts int 100 to
new Integer(100))
content_copydownload
Use code with caution.Java
 Unboxing: The reverse of autoboxing. Converting an object of a wrapper type to its
corresponding primitive value.
 Integer wrapperVal = new Integer(50);
int primitiveVal = wrapperVal; // Unboxing (compiler converts
wrapperVal to wrapperVal.intValue())
content_copydownload
Use code with caution.Java
 This makes code cleaner when working with collections or scenarios requiring objects.
Slide 18: Summary / Key Takeaways
 Java libraries (packages) provide reusable code like String, ArrayList, etc.
 Java has Primitive types (basic, store values, e.g., int, boolean)
and Composite/Reference types (objects, store references, e.g., String, arrays,
custom classes).
 Primitives are efficient but cannot be null or used in collections directly.
 Composites are flexible, can be null, work with collections, but have object overhead.
 Wrapper Classes (Integer, Boolean, etc.) bridge the gap by wrapping primitives into
objects.
 We need Wrapper Classes for:
o Using primitives in Collections/Generics.
o Representing null values for primitive concepts.
o Accessing utility methods (parseInt, toString, etc.).
 Autoboxing/Unboxing simplify conversions between primitives and wrappers.
Slide 19: Q&A / Thank You
Questions?
Thank You!
thumb_upthumb_down

More Related Content

DOCX
data types in java will help to clear the base
PPTX
DATATYPES IN JAVA primitive and nonprimitive.pptx
PPTX
This is a python data types ppt it is used for bca student also
PPTX
01 Java Language And OOP PART I
PPTX
Chapter class seven important notes-7.pptx
PPTX
Ch 2 Library Classes.pptx
PDF
Ch 2 Library Classes.pdf
data types in java will help to clear the base
DATATYPES IN JAVA primitive and nonprimitive.pptx
This is a python data types ppt it is used for bca student also
01 Java Language And OOP PART I
Chapter class seven important notes-7.pptx
Ch 2 Library Classes.pptx
Ch 2 Library Classes.pdf

Similar to Library methods class 10 NOTES FOR EXAM (20)

PPT
PPTX
Java - Basic Datatypes.pptx
PPTX
PDF
Akshay Sharma,BCA,2nd year
PPT
Introduction to Java(basic understanding).ppt
PPTX
vectors.(join ALL INDIA POLYTECHNIC (AICTE)).pptx
PDF
Complete Java Course
PPTX
L9 wrapper classes
PPT
Java Tutorials
PPTX
Data types in java
PPT
Java SpringMVC SpringBOOT (Divergent).ppt
PPT
java training faridabad
PPTX
03 and 04 .Operators, Expressions, working with the console and conditional s...
PPTX
Java Unit 2(Part 1)
PPTX
ppt_on_java.pptx
PPTX
Java tutorial part 3
PDF
Kaushal Soni,BCA,2nd Year
PPT
Basic of java 2
PPTX
5. variables & data types
Java - Basic Datatypes.pptx
Akshay Sharma,BCA,2nd year
Introduction to Java(basic understanding).ppt
vectors.(join ALL INDIA POLYTECHNIC (AICTE)).pptx
Complete Java Course
L9 wrapper classes
Java Tutorials
Data types in java
Java SpringMVC SpringBOOT (Divergent).ppt
java training faridabad
03 and 04 .Operators, Expressions, working with the console and conditional s...
Java Unit 2(Part 1)
ppt_on_java.pptx
Java tutorial part 3
Kaushal Soni,BCA,2nd Year
Basic of java 2
5. variables & data types
Ad

Recently uploaded (20)

PDF
Sports Quiz easy sports quiz sports quiz
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PPTX
Pharma ospi slides which help in ospi learning
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PPTX
Cell Types and Its function , kingdom of life
PDF
VCE English Exam - Section C Student Revision Booklet
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PDF
RMMM.pdf make it easy to upload and study
PDF
O7-L3 Supply Chain Operations - ICLT Program
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PDF
Anesthesia in Laparoscopic Surgery in India
PDF
Basic Mud Logging Guide for educational purpose
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
Sports Quiz easy sports quiz sports quiz
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
Pharma ospi slides which help in ospi learning
2.FourierTransform-ShortQuestionswithAnswers.pdf
Module 4: Burden of Disease Tutorial Slides S2 2025
Cell Types and Its function , kingdom of life
VCE English Exam - Section C Student Revision Booklet
STATICS OF THE RIGID BODIES Hibbelers.pdf
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
RMMM.pdf make it easy to upload and study
O7-L3 Supply Chain Operations - ICLT Program
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
O5-L3 Freight Transport Ops (International) V1.pdf
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
Anesthesia in Laparoscopic Surgery in India
Basic Mud Logging Guide for educational purpose
Pharmacology of Heart Failure /Pharmacotherapy of CHF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
Ad

Library methods class 10 NOTES FOR EXAM

  • 1. Java Library Classes & Data Types An Introduction to Primitives, Composites, and Wrapper Classes Slide 2: Agenda  Introduction to Java Library Classes & Packages  Data Types in Java: An Overview  Primitive Data Types: Definition & Examples  Composite Data Types: Definition & Examples  Key Differences: Primitive vs. Composite  Introduction to Wrapper Classes  Why Use Wrapper Classes? (Need)  Summary & Key Takeaways Slide 3: Java Library Classes & Packages  What are they? Pre-written code (classes and interfaces) bundled together into packages. They provide standard functionality, saving developers time and effort.  Why use them? Reusability, reliability (tested code), standardization.  Packages: Organize related classes and interfaces. Think of them like folders for code.  Important Examples: o java.lang: Fundamental classes (loaded automatically). E.g., Object, String, System, Math, Wrapper Classes (Integer, Double, etc.). o java.util: Utility classes. E.g., Collections framework (ArrayList, HashMap), Date, Scanner. o java.io: Input/Output operations. E.g., File, InputStream, OutputStream. o java.net: Networking operations. E.g., Socket, URL. o javax.swing / java.awt: GUI development (older). Slide 4: Data Types in Java: Overview Java has two main categories of data types: 1. Primitive Data Types: o The most basic data types available. o Predefined by the Java language. o Serve as the building blocks for data manipulation.
  • 2. 2. Composite (or Reference) Data Types: o Built using primitive types or other composite types. o Refer to objects or arrays stored in memory. o Include Classes, Interfaces, and Arrays. Slide 5: 1. Primitive Data Types - Definition  Definition: Predefined, fundamental data types directly supported by the Java language and named by reserved keywords.  They store the actual value directly in the memory location allocated to the variable.  They are not objects.  Java has 8 primitive data types. Slide 6: Primitive Data Types - Examples Type Description Size Example Code byte Very small integers 8 bits byte b = 100; short Small integers 16 bits short s = 30000; int Integers (most common) 32 bits int age = 25; long Large integers 64 bits long pop = 7_000_000_000L; float Single-precision float 32 bits float price = 19.99f; double Double-precision float 64 bits double pi = 3.14159; boolean True or false values ~1 bit boolean isValid = true; char Single character 16 bits char grade = 'A'; Slide 7: Primitive Data Types - Real-Time Examples  int: Storing a user's age, counting items in a shopping cartQuantity, an employeeID.  double / float: Representing productPrice, calculating averageScore, storing temperatureReading.  boolean: Tracking login status (isLoggedIn), checking if a feature is enabled, marking an item as isComplete.  char: Storing a user's middleInitial, representing a gender ('M'/'F'/'O'), storing a command key ('Y'/'N').  long: Storing database record ids (when they can exceed 2 billion), tracking timestamps in milliseconds.
  • 3.  byte: Reading/writing binary data from files or networks, representing small configuration flags. Slide 8: 1. Composite (Reference) Data Types - Definition  Definition: Data types created from primitive types or other composite types. They don't store the actual object data directly in the variable's memory location.  Instead, they store a reference (or memory address) pointing to where the object or array is actually stored in the heap memory.  Includes: o Classes: (Built-in like String, Scanner, or user-defined like Person, Car) o Arrays: (int[], String[], Object[]) o Interfaces: (List, Map, custom interfaces) Slide 9: Composite Data Types - Examples  String (Class): Represents a sequence of characters.  String greeting = "Hello, World!"; String name = new String("Alice"); content_copydownload Use code with caution.Java  Arrays: Fixed-size collection of elements of the same type.  int[] scores = { 90, 85, 92 }; String[] names = new String[5]; // Array of 5 null String references content_copydownload Use code with caution.Java  User-Defined Class: Blueprint for creating objects.  // Assuming a Person class exists with name and age fields Person student = new Person("Bob", 20); content_copydownload Use code with caution.Java  ArrayList (Class implementing List Interface): Dynamic array.  ArrayList<String> cities = new ArrayList<>();
  • 4. cities.add("London"); content_copydownload Use code with caution.Java Slide 10: Composite Data Types - Real-Time Examples  String: Storing user names, addresses, product descriptions, file paths.  Array (int[], double[], etc.): Storing a fixed set of examScores, historical stockPrices, pixel data for an image.  ArrayList<Product>: Managing a dynamic shoppingCart containing Product objects.  HashMap<String, User>: Storing userData mapped by username (String) to User objects.  Custom Classes (Customer, Order, BankAccount): Modeling real-world entities in an application, holding multiple related pieces of data (primitives and other composites). E.g., a Customer object might contain String name, int customerId, String address. Slide 11: 2. Difference: Primitive vs. Composite Feature Primitive Data Types Composite (Reference) Data Types Definition Predefined by Java language Defined by programmers (or built-in classes) Storage Stores actual value directly Stores memory address (reference) of object Memory Area Stack (usually) Heap (objects), Stack (reference variable) Default Value Specific (0, 0.0, false, ' u0000') null Can be null? No Yes Nature Simple values Complex objects (can hold multiple values) Methods? No methods directly Can have methods Size Fixed size Variable (depends on object state)
  • 5. Examples int, float, boolean, char String, Array, ArrayList, Custom Classes Slide 12: Introduction to Wrapper Classes  So, primitives are simple and efficient, but they aren't objects.  Composite types are objects, offering more capabilities but with some overhead.  Sometimes, we need to treat primitive values as objects.  This is where Wrapper Classes come in. They "wrap" a primitive value inside an object. Slide 13: 3. Define Wrapper Class  Definition: A set of classes in the java.lang package designed to encapsulate (wrap) Java's eight primitive data types into objects.  Each primitive type has a corresponding wrapper class. Primitive Type Wrapper Class byte Byte short Short int Integer long Long float Float double Double boolean Boolean char Character Example: int primitiveInt = 10; Integer wrapperInt = Integer.valueOf(primitiveInt); // Wrapping // OR using autoboxing (see later slide) Integer autoWrapperInt = 10; content_copydownload Use code with caution.Java Slide 14: 4. Need of Using Wrapper Class (1/3)
  • 6. Reason 1: Collections Framework & Generics  Java's Collections Framework (like ArrayList, LinkedList, HashMap, etc.) only works with objects.  You cannot directly store primitive types in these collections.  Wrapper classes allow you to store primitive values in collections by wrapping them in objects. Example: //ArrayList<int> numbers = new ArrayList<>(); // Compile Error! Cannot use primitive type. ArrayList<Integer> numbers = new ArrayList<>(); // Correct! Uses Integer wrapper class. numbers.add(10); // Autoboxing: primitive int 10 -> Integer object numbers.add(20); int firstNumber = numbers.get(0); // Unboxing: Integer object -> primitive int content_copydownload Use code with caution.Java Slide 15: 4. Need of Using Wrapper Class (2/3) Reason 2: Need for null Values  Primitive types cannot hold a null value. They always have a default value (e.g., 0 for int, false for boolean).  Sometimes, null is needed to represent an unknown, missing, or inapplicable state (e.g., a database field that allows nulls).  Wrapper class objects, being objects, can hold a null reference. Example: // int userId = null; // Compile Error! Primitive cannot be null. Integer userId = null; // Correct. Represents 'user ID not yet assigned'. // Later... if (userId != null) { // Process the user ID System.out.println("User ID: " + userId);
  • 7. } else { System.out.println("User ID is not available."); } content_copydownload Use code with caution.Java Slide 16: 4. Need of Using Wrapper Class (3/3) Reason 3: Utility Methods  Wrapper classes provide useful static utility methods for conversions and operations related to the primitive types. Examples:  Parsing Strings: Convert a String representation to a primitive/wrapper type.  String countStr = "123";  int count = Integer.parseInt(countStr); // String to int   String piStr = "3.14"; double pi = Double.parseDouble(piStr); // String to double content_copydownload Use code with caution.Java  Converting to String:  String intStr = Integer.toString(456); // int to String String boolStr = Boolean.toString(true); // boolean to String content_copydownload Use code with caution.Java  Constants: Provide useful constants like MIN_VALUE, MAX_VALUE.  System.out.println("Max Int: " + Integer.MAX_VALUE); System.out.println("Min Float: " + Float.MIN_VALUE); content_copydownload Use code with caution.Java
  • 8. Slide 17: Autoboxing and Unboxing  To make using wrapper classes easier, Java provides autoboxing and unboxing.  Autoboxing: The automatic conversion that the Java compiler makes between primitive types and their corresponding object wrapper classes. Integer wrapperInt = 100; // Autoboxing (compiler converts int 100 to new Integer(100)) content_copydownload Use code with caution.Java  Unboxing: The reverse of autoboxing. Converting an object of a wrapper type to its corresponding primitive value.  Integer wrapperVal = new Integer(50); int primitiveVal = wrapperVal; // Unboxing (compiler converts wrapperVal to wrapperVal.intValue()) content_copydownload Use code with caution.Java  This makes code cleaner when working with collections or scenarios requiring objects. Slide 18: Summary / Key Takeaways  Java libraries (packages) provide reusable code like String, ArrayList, etc.  Java has Primitive types (basic, store values, e.g., int, boolean) and Composite/Reference types (objects, store references, e.g., String, arrays, custom classes).  Primitives are efficient but cannot be null or used in collections directly.  Composites are flexible, can be null, work with collections, but have object overhead.  Wrapper Classes (Integer, Boolean, etc.) bridge the gap by wrapping primitives into objects.  We need Wrapper Classes for: o Using primitives in Collections/Generics. o Representing null values for primitive concepts. o Accessing utility methods (parseInt, toString, etc.).  Autoboxing/Unboxing simplify conversions between primitives and wrappers. Slide 19: Q&A / Thank You