Developed by Sun Microsystems in 1995, Java is a highly popular, object-oriented programming language. This platform independent programming language is utilized for Android development, web development, artificial intelligence, cloud applications, and much more.
Basic terminologies in Java
Class:The class is a blueprint (plan) of the instance of a class (object). It can be defined as a logical template that share common properties and methods. Object:The object is an instance of a class. It is an entity that has behavior and state. Method:The behavior of an object is the method. Instance variables:Every object has its own unique set of instance variables. The state of an object is generally created by the values that are assigned to these instance variables.
Java Data Types
Java has two categories in which data types are segregated 1.Primitive Data Type: such as boolean, char, int, short, byte, long, float, and double 2.Non-Primitive Data Type or Object Data type: such as String, Array, etc.
Operators in Java
Operators in Java are the symbols used for performing specific operations in Java. Operators make tasks like addition, multiplication, etc which look easy although the implementation of these tasks is quite complex.
Arithmetic Operators
Unary Operators
Assignment Operator
Relational Operators
Logical Operators
Ternary Operator
Bitwise Operators
Shift Operators
instance of operator
Types of Variables in java
Now let us discuss different types of variables which are listed as follows:
Local Variables
Instance Variables
Static Variables
Arrays in java
An array can contain primitives (int, char, etc.) and object (or non-primitive) references of a class, depending on the definition of the array. In the case of primitive data types, the actual values might be stored in contiguous memory locations (JVM does not guarantee this behavior). In the case of class objects, the actual objects are stored in a heap segment. To learn more about Java Array, go through Java programming course here.
Classes and Objects in Java
Java Classes
A class in Java is a set of objects which shares common characteristics/ behavior and common properties/ attributes. It is a user-defined blueprint or prototype from which objects are created. For example, Student is a class while a particular student named Ravi is an object.
Java Objects
An object in Java is a basic unit of Object-Oriented Programming and represents real-life entities. Objects are the instances of a class that are created to use the attributes and methods of a class.
Difference between Java Class and Objects
Class
Object
Class is the blueprint of an object. It is used to create objects.
An object is an instance of the class.
No memory is allocated when a class is declared.
Memory is allocated as soon as an object is created.
A class is a group of similar objects.
An object is a real-world entity such as a book, car, etc.
Class is a logical entity.
An object is a physical entity.
A class can only be declared once.
Objects can be created many times as per requirement.
An example of class can be a car.
Objects of the class car can be BMW, Mercedes, Ferrari, etc.
Access Modifiers in Java
There are four types of access modifiers available in Java:
Default – No keyword required
Private
Protected
Public
Four Main Object Oriented Programming Concepts of Java
Packages In Java
Package in Java is a mechanism to encapsulate a group of classes, sub packages and interfaces. Packages are used for:
Preventing naming conflicts. For example there can be two classes with name Employee in two packages, college.staff.cse.Employee and college.staff.ee.Employee
Making searching/locating and usage of classes, interfaces, enumerations and annotations easier
Providing controlled access: protected and default have package level access control. A protected member is accessible by classes in the same package and its subclasses. A default member (without any access specifier) is accessible by classes in the same package only.
Packages can be considered as data encapsulation (or data-hiding).