Monday , December 18 2017
Home / JAVA / Basic concepts of Java

Basic concepts of Java

Java is Object Oriented programming language which was developed at Sun Microsystems. By object-oriented we mean, it is a technique to develop logical modules, such as classes that contain properties, methods, fields and events. An object is created in the program to represent the class. Objects are used to access data and behaviors of different software modules like classes, namespaces, etc.

class NewClass     *
NewClass() // this act as a constructor **
System.out.println("Constructor"); // simple printing function which is predefined 
void Function()  // method ***
{           //  the implementation of method is defined inside the function.
System.out.println("Hello World");
public static void main(String args[])  // main function  ****
NewClass obj=new NewClass();            // object is created to access data and behavior *****
obj.Function();  // calling function through object
System.out.println("Know the Basics of Java"); // simple print statement to print something
}  // end of main
} // end of class


Also See:   program for display lower triangular matrix in java

*This statement defines the name of class which distinguishes each modular program with one another.

We can say that, Class is a template according to which objects of that class are created.

A class describes the attributes that each object will have and behavior it can exhibit through the functions defined in class.

**Constructor is a block of code which runs automatically when object of that class is created.

***Method which are inside class but outside the main function are Instance method .Instance methods cannot be directly used in main functions. We use objects for this purpose .We call the method by objects.

Also See:   Java program to print happy numbers for a given range

****In this statement as we use public access modifier in main function, so that it can be easily accessible from all classes .Public is an access modifier. We have 4 types of access modifies defined in Java to provide the access for data and behavior of class in terms of required security. The four  access modifiers are:

  1. Public:- Public members of a class are available to all the classes and to all the packages.
  2. Protected:-Protected members are accessible in the class, to the child class and also accessible to the classes of same packages. It is used in case of inheritance.
  3. Private:-This is the most restrictive access level. Private members are accessible only within the class.
  4. Default: – Default access modifier is set if u do not set any access modifier explicitly. And it is accessible to different members of same class and different classes of same package. If we do not provide any access modifier than it automatically consider it default access modifier.
Also See:   Java program for producing prime numbers for given range

->The main function is static which means that main function is common for all the class and for all the objects it executes in the similar manner.

->The main function is void which means it does not return anything.

-> The arguments in the main function are String by default.

*****Data are the variables in the program and behavior are the methods or function implementation which behaves accordingly.

Check Also

Java program to implement polymorphism

Java program to implement polymorphism: Polymorphism is a technique in java with which you can ...

Leave a Reply

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