Updates
  • Starting New Weekday Batch for Java Full Stack Developer on 24th June 2024 @ 02:00 PM to 04:00 PM
  • Starting New Weekend Batch for Java Full Stack Developer on 06th July 2024 @ 11:00 AM to 02:00 PM
  • Starting New Weekday Batch for Java Full Stack Developer on 08th July 2024 @ 04:00 PM to 06:00 PM
  • Starting New Weekday Batch for Java Full Stack Developer on 29th July 2024 @ 10:00 AM to 12:00 PM
Join Course

Package java.lang

• In Java programming language java.lang package is a built-in package or we can say it’s a package included in Java by default.
• In application development using Java, java.lang package serves several important purposes.
• Since java.lang is a default package there is no need to import the package. The package is wholly available inside Java with its classes and interfaces and we don’t have to import these from other packages.

            
package com.P1;

class JTC{
	public static void main(String arg[]){
		Object o1 = new Object(); // java.lang.Object class object
		String s1 = new String(); // java.lang.String class object
	}
}
            

In this example we can see that we have JTC class in com.P1 package and we are creating an object of Object class and String class which is available in java.lang package and we should note here that we are not importing java.lang.Object class and java.lang.String class, it proves that java.lang package is a default package in Java.

• java.lang package contains many classes, interfaces or Enums.
• Here we have a list of some useful classes or interfaces list which we will cover in further tutorials.

1. java.lang.Object class
2. java.lang.String class
3. java.lang.StringBuffer class
4. java.lang.StringBuilder class
5. java.lang.System class
6. java.lang.Runtime class
7. java.lang.Class class
8. java.lang.Throwable class
9. java.lang.Exception class
10. java.lang.Error class
11. java.lang.RuntimeException class
12. java.lang.Math class
13. java.lang.Thread class
14. java.lang.Runable Interface

• In Java we have eight primitive data types which are byte, short, int, long, float, double, boolean, char; Java provides dedicated class for every primitive data type which is called Wrapper Class.
• All the wrapper classes are also available in java.lang package.

1. java.lang.Byte class [for byte primitive data type]
2. java.lang.Short class [for short primitive data type]
3. java.lang.Integer class [for int primitive data type]
4. java.lang.Long class [for long primitive data type]
5. java.lang.Float class [for float primitive data type]
6. java.lang.Double class [for double primitive data type]
7. java.lang.Boolean class [for boolean primitive data type]
8. java.lang.Character class [for char primitive data type]

Q. Why java.lang package is a default package in Java?

Ans.In Java java.lang package has been included in Java by default (there is no need to import) because it contains important classes or APIs- like System class, hashCode() method of Object class, toString() method of Object class etc.- that serve basic purposes like writing a basic Java program.