CORE JAVA
Programming Language
The language which is used to write some instructions to get some work done by the System
is known as programming language.
Generally there are two types of programming languages,
1) Low Level Programming Language
2) High Level Programming Language
Low Level Programming Language
A language which is easily understandable and executable by the machine is known as Low
level programming language.
Eg:- Binary Language.
High Level Programming Language
A language which is easily readable, understandable and instructable by the programmer is
known as High Level Programming Language.
Eg:-C.C++,Java, Ruby, Python etc.
Note:-A machine cannot directly understand the instructions written in high level programming
language, therefore these instructions needs to be compiled with the help of compiler before
executing .
Java
Java is a High Level Programming Language which is developed by James Gosling and his
team under sun microsystems. The first version of java was released on Jan 23,1996.
Features of Java
High level programming language
Simple
Object oriented programming language
Comes with rich built in tools
Platform independent language
Secure
Robust
Multithreaded etc.
Why java is called as Platform independent Language?
Platform dependent language
Note:- In C language the program written( .c file) once compiled generates an executable file(.exe
file). This .exe file can be executed only in the platform in which the program is written, not in the
other platforms as shown in the above example. Therefore C is called platform dependent language.
Platform Independent Language
In java, the program written ( .java file) once compiled will not be converted to machine
understandable language. Instead it gets converted to an intermediate language called Byte Code.
This Byte code generated can be executed in any platform which is having JVM installed in it.
We cannot execute the bytecode in a system which is not having JVM installed in it. And there are
different versions of JVM available for different machines in the market. Therefore java is called
platform independent but JVM dependent language.
Steps to create, compile and execute the java program
Step1:- Create Source Code
Step2:- Compile the source code and generate byte code
Step3:- Execute the byte code
Step1:-Create Source Code
We can create the java source code with the help of editors.
Editor is a software which helps us to create files. Editor can be a plain editor(Eg:-Notepad, Editplus,
Notepad++ etc ) or advanced(Eg:-Eclipse, NetBeans , Atom etc).
The java sourcecode must have .java extension.
Step2:- Compile the source code and execute bytecode
We can compile the sourcecode (.java file) with the help of java compiler.
javac is the command used for compilation.
The compiler checks for the syntax and semantics, if everything is correct it generates the byte code.
Otherwise displays some error message.
This Byte code generated will be saved in a file called class file with .class extension.
Step3:Execute the Byte code
The Byte code or .class file generated can be executed with the help of java command.
Structure of a simple java program
class ClassName
public static void main(String[]args)
Write statements/Instructions to be executed here
Example
class A
{
public static void main(String[]args)
{
System.out.println(“Hello Shraddhaa!!!!”);
}
Step1:- As per the industry standards the name of the java file should be the same name which is
given to the class. And it must have .java extension.
Syntax to save java file Classname.java
Therefore the above program must be saved as A.java.
Step2:- We can compile this .java file with the help of java compiler as follows
Syntax to compile the .java file javac Classname.java or javac Filename.
javac A.java
After the successful compilation the compiler generates .class file, which will have the same name
given to class.
A.class
Step3:- We can execute the .class file generated as follows,
Syntax to execute .class file java Classname
java A
Note:- After successful execution we will get the output as shown bellow,
Hello Shraddhaa!!!!
Can we create a class without main method?
Answer:-Yes, we can create and compile a class without main method. But it cannot be executed.