DEV Community

Cover image for core java -Basics
Sahithi Puppala
Sahithi Puppala

Posted on

core java -Basics

DAY-3

Today we will discuss about object!

OBJECT:

==>Object are created from a Class.
==>An Object is a Real world entity.
==>In order to Create a class object first we need to write "new" keyword and initialize that object with the help of a constructor, constructor name will be same as class name.
==>We can create any number of object from a Class.

Example:
ClassA aobj = new ClassA(); //ClassA object
ClassB bobj = new ClassB(); //ClassB object
ClassC cobj = new ClassC(); //ClassC object

I write a simple program to understand the how to create Class Object.

public class First
{
public void msg()
{
System.out.println("HELLO WORLD");
}
private void display()
{
System.out.println("java is awesome");
}
public static void main(String[] args)
{
System.out.println("Start");
First obj=new First(); //Creating an object
obj.msg(); //Calling a method
obj.display(); //calling a method
System.out.println("End");
}
}

OUTPUT:
Start
HELLO WORLD
java is awesome
End

Every Program to Run in java we can do 2 specific tasks:
1)Compilation
2)Running

Compilation:

[java Compiler==>javac Filename.java]

  • Here Compilation do Java Compiler, java Compiler Command is Javac Filename.java.

  • Compilation means checking the code whether we have written according to the java language Syntax or not.

  • After Successful Compilation java Compiler is going to generate a .Class file .

  • The generated .Class File name will be same as Class name.

  • The generated .Class file Consists of bytecode instructions which are understand only by the machines , humans Can not understand them.

Running:

[JVM(Java Virtual Machine)==>java generated .Class File name]

  • In order to run our java program we need to send our generated .Class File as input to the JVM.

  • JVM is going to check whether all the byte code instructions present in the .Class file are Correct Or Wrong if Correct will be getting Output if Wrong we will be getting an Exception.

Waiting for Day-4-----------------------------------------------------

Top comments (0)