Java is a platform-independent language. First it we write a source code. Source code is something whose file extension is .java. The compiler compiles the program checks for an error and won’t let you compile till the code is error-free compiler compiles the source code into byte code any this byte code is platform-independent. Any device which is capable of running this byte code will translate this byte code into their own code which they can understand very easily. That’s why we call java is a platform-independent language. In fact this is a very popular interview question.
So basically source file contains a class. The class contains a
method. Methods contain a set of statements.
In simple words, we can say that JVM is a device that
provides a run time environment to java byte code which was produced by the compiler
after processing source code.
When JVM starts running we look for a class that contains the main method. And JVM starts executing everything which is present in the main
method of the class. Every java application has at least one main method.
The main method looks like the below example.
public static void main(String[] args){
}
Let's discuss keywords of the main class one by one.
public - is an access modifier(everyone can see this)
static - can be instantiated without creating an object.
void - there is no return type of this method.
String[] - arguments which are passed to this method will be an array of strings named args.
Everything in bracket {} will be executed by the compiler.
Difference between System.out.println and System.out.print.
println print gives a line break after printing while print
doesn’t give a line break after printing.
A java class consists of instance variables and methods.
1. Instance variables are
simply variables defined outside the method.
2. Method is a simple to set of
statements.
Class - Class is
basically a structure. This is a generic form.For example human skeleton.
Every human hair colour, language. nationality,
Objects - An object is a specific form. For example colour of
hair can be brown, black, red or white, there are many languages in the world.
It can be English, Hindi etc. The nationality of a person can be different.
How to create an object
Class Human{
Private
String hairColor;
Private
String language;
Private
String nationality;
Public
Human(String hairColor1, String language1, String nationality1){
this.hairColor
= hairColor1;
this.language=
language1;
this.nationality=
nationality1;
}
void printTest(){
System.out.println(“Haircolor:
”+ hairColor + “language”+language);
}
}
Class test{
Public
static void main(String[] args){
Human
human1 = new Human(); // object created
}
}
Thank you for sharing this informative and valuable content here.
ReplyDeleteGet the awesome coding snippets at
http://dilsecodie.com/
Visit for more Education repositories
Nice coding
ReplyDeletethanks you
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteGood coding
ReplyDeleteNice coding
ReplyDeleteNice info
ReplyDeleteGood work my friend
ReplyDeleteThank uu for such a good information
ReplyDeleteGood codding
ReplyDeleteAwesome information
ReplyDeleteIt's a very good coding
ReplyDeleteBeautifully explained loved it
ReplyDeleteBeautifully and explained coading
ReplyDeleteGood work
insightful...
ReplyDeleteGood work
ReplyDeleteyou always succeed and keep going
ReplyDeleteGood coding
💯
ReplyDeleteGood work done ✅
ReplyDeleteGood work
ReplyDelete