An Overview Of Java

We all know that Java is a programming language and it is majorly used in Android applications. The creation of Java is much related to C++ but, the Object Oriented Programming is the core part of Java. Therefore, to understand the basic principles of Java, this blog begins with the theoretical concepts of OOP.

In this below video, you can understand the simple basics of Java. If you are a beginner, then it will be helpful to learn Java from the basics.

Before entering into the OOP concepts, let’s see what is meant by paradigms.

Paradigms: Generally in a programming language, a paradigm is termed as a method to solve problem or to do some task. It can be defined in two types.

Type 1: The first type is called as ‘ Process Oriented Model ‘. This approach characterizes a program as a series of linear
steps (codes). The popular C language employs this model to build programs. But the major disadvantage of this type is that as it goes more lines of code, it becomes more complex.

Type 2: The second type is called ‘ Object Oriented Programming ‘. This type of model is followed by most of the programming languages. It is also similar to the process-oriented model as it characterizes the series of codes linked with objects. The advantages of this type are:

  • It contains a set of well-defined structures
  • Easily manages the increasing complexity

Abstraction:

An essential element of object-oriented programming is an abstraction. It helps to reduce programming complexity and effort. In Java, abstraction is accomplished using Abstract classes and interfaces. It is one of the most important concepts of OOPs. In other words,  Abstraction is a process of hiding the implementation details and showing only functionality to the user.

For example, while sending SMS, you just type the text and send the message. Here, you do not care about the internal processing of the message delivery.

Advantages of Abstraction:

  • The main benefit of using an abstract class is that it allows you to group several related classes as siblings.
  • Abstraction helps to reduce the complexity of the design and implementation process of software.

Basic principles of OOP:

Encapsulation:

Encapsulation is the mechanism that binds together code and the data it manipulates, keeps both safe from outside interference and misuse. Also, encapsulation is a protective wrapper that prevents the code and data from being arbitrarily accessed by other code defined outside the wrapper. In java, the basis of encapsulation is class.

A Class defines the structure and behavior that will be shared by a set of objects. Each object of a class contains the structure and behavior defined by the class as if it were stamped out by a mold in the shape of the class. For this reason, objects are referred to as ‘Instance of Class’. In simple words, a class is a logical construct; an object has a physical entity.

Members: When you create a class, you will specify the code and data that constitute that class. Collectively, these elements are called members of the class.

Member Variables: The data defined by the class are referred to as member variables or instance variables.

Member Methods:  The code that operates on the data, is referred to as member methods or just methodsBasic understanding of Encapsulation

 

Inheritance:

Inheritance is a mechanism in which one class acquires the property of another class. For example, a child inherits the traits of his/her parents. With inheritance, we can reuse the fields and methods of the existing class. Hence, inheritance facilitates reusability and is an important concept of OOPs.

Some of the types of inheritance are:

  • Single
  • Multiple
  • Multilevel
  • Hierarchical
  • Hybrid

Polymorphism

It is a very simple concept. Polymorphism is the ability of an object to take on many forms.

For example, you have a smartphone for communication. The communication mode you choose could be anything. It can be a call, a text message, a picture message, mail, etc. So, the goal is common that is communication, but their approach is different. This is called Polymorphism.

Polymorphism is divided into two categories. They are:

  • Method Overriding
  • Method Overloading

Method Overriding: It is a feature that allows a subclass or child class to provide a specific implementation of a method that is already provided by one of its super class or parent class.

Rules for Method Overriding:

  • The method signature i.e. method name, parameter list, and return type have to match exactly.
  • The overridden method can widen the accessibility but not narrow it, i.e. if it is private in the base class, the child class can make it public but not vice versa.

Method Overloading: If a class has multiple methods having the same name but different in parameters, it is known as Method Overloading.

 A First Simple Program:

class Techi{
  public static void main(String[] arguments) {
    System.out.println(“We Love to Teach You More”);
  }
}

Now let’s move on the basics, the Lexical Issues.

Lexical Issues

It is time to more formally describe the atomic elements of Java. Java programs are a collection of whitespace, identifiers, comments, literals, operators, separators, and keywords.

White space:

Java is a free-form language. This means that you do not need to follow any special indentation rules. For instance, the Example program could have been written all on one line or in any other strange way you felt like typing it, as long as there was at least one white-space character between each token that was not already delineated by an operator or separator. In Java, white-space is a space, tab, or newline.

Identifiers:

Identifiers are the words used for class names, Method names and variable names. Identifiers can be a descriptive sequence of characters with lowercase, uppercase, numbers or dollar-sign characters. But we cannot start it with numbers. Also, Identifiers are case sensitive which means “TECH” is different from “Tech”.

Based on the above criteria, below we have mentioned few valid identifiers and invalid identifiers for your reference.

Valid Identifiers: AvgTemp                 count                     a4                    $test                        this_is_ok

Invalid Identifiers: 2count                  high-temp               Not/ok

Literals:

A constant value in Java is created by using a literal representation of it.

For example, here are some literals:       1080                      96.40                         ‘x’                         “This is a test”

Comments:

Comments are statements that are not executed by the compiler and interpreter. The comments can be used to provide information or explanation about the variable, method, class or any statement. It can also be used to hide program code for specific time. There are three types of comments defined by java. They are:

  • Single-line comments.
  • Multi-line comments.
  • Documentation comments.

Some people weren’t aware of documentation comments. This type of comment is used to produce an HTML file that documents your program. The documentation comment begins with a /** and ends with a */.

Separators:

In Java, there are some few characters that are used as separators. The most commonly used separator in Java is the semicolon. It is used to terminate statements. Some of the most used separators are:

  • Parentheses – ( )
  • Braces – { }
  • Brackets – [ ]
  • Semicolon – ;
  • Comma – ,
  • Period – .

If you are well deep into java, you can even create your own packages by modifying the core files. It is an easily understandable programming language which allows you to do modification from the base files. During the Engineering study under the major as Computer Science and Engineering, you will be learning Java as two phases. Java Programming and Advanced Java Programming will be there as major subjects or electives.

You can download & install Java on your system for free. Download Java Files Now! Once after Java Installation, you want to set the Path else it will not work. You can check the below video where we explained about how to set Java Path in Windows.