Java .lang package in Java

Classes are present in java .lang package:
object class, string class, string buffer class , string builder class, wrapper class
for writing any java program the most commonly required classes and interfaces are encapsulated in seperate package which is nothing but java.lang package
It is not required to import java.lang package in our program because it is available by default to every program.

Java.lang.object class:

for any java object whether it is predefined or customise the most commonly required methods are encapsulated into a seperate class which is nothing but object class

an object class acts as a root or parent

Object class

1.public string to string()

2.public int hashcode()

3.public boolean equals()

4.public final class get class()

String:

it is a type where it is defined as sequence of characters and it is immutable.

whenever ,we try to print any object reference internally to string()method it will be executed.

package object class:

class student{

string name;

int rollno;

student(string name ,int rollno) {

this.name=name;

this,rollno=rollno;}}

public class App1{

public static void main(string ,args[]) {

student s1=new student(“Joe”,103);

student s2=new student(“Pan”,101):

System .out .println(s1);

System.out.println(s1 to sring());

System.out.println(s2);}}

String constant:

Garbage collector cant access this,as it doesnot have any reference.

all will be destroyed at time of JVM shutdown

String buffer:

string buffer sb=new string buffer(“xyz”)

default capacity is 16

class string bufferdemo{

public static void main(String[] args) {

string buffer sb=new string buffer();

System .out. println(“abc”);

sb.append(“q”);

System .out. println(sb.capacity());

there are important classes in java package

  • double
  • enum
  • package
  • process builder
  • runtime
  • short
  • void
  • thread
    String constant:
    example:
    String s1=new String("Sai");
    String s2=new String("Sai");
    String s3="Sai";
    String s4="Sai";

     

 

 

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top