WHAT IS JAVA?
Java is an Object Oriented Programming language. James Gosling has designed and Oracle Corporation has developed Java. It reduces costs, drive innovation and improve application service.
There should be atleast one class in Java program otherwise it will not execute output.
OOP is a paradigm that provides concepts like Inheritance, Data binding, Polymorphism, Abstraction, Encapsulation, Coupling, Cohesion, Association, Aggregation,Composition,etc. in which abstraction, encapsulation, inheritance and polymorphism are 4 pillars of java.
As the byte code which can run on any system irrespective of its underlying operating system, Java is called as platform Independent.
Types of variable used in Java:
Static Variable,Non-Static Variable,Local Variable and Reference Variable.
Data Types:
String, long, short, byte, int, float, double and boolean.
Example:
class A
{
public static void main(String[] args)
{
System.out.println(“Hello World”);
}
}
Output: Hello World
Constructor in Java:
Constructor in Java is a block of code similar to method whose name is same as class name. It is always void as it does not contain any return type. It is initiallised automatically when object is created.
Example of constructor:
class B{
B(){
System.out.println(“Hello Constructor”);
}
public static void main(){
B b1= new B(); //Object is created and constructor is called
}
}
There are two types of constructors:
Default Constructor
Parameterized Constructor
Advantages:
Java is simple and secure language.
It is platform independent.
Cheap and economical to maintain.
Uses of java language:
Web development
Desktop app development
Games
Interview questions on java:
Explain JDK, JRE and JVM?
Why Java is platform independent?
What are constructors in Java?
Why Java is not 100% Object Oriented?
What are wrapper classes in Java?