Introduction to Java and Object Oriented Programming
Here in this article let us try to get an overview of several key features of java. We will try to write a sample java program and understand the very basic keywords, identifiers, literals, seperaters etc to build a full fledge running program.
Introduction
As we know OOP is at the core of Java Programming language. We need to first understand the basic concepts and principles of the OOP before we can go ahead with writing our basic program.
Programming Models
There are two approaches a programmer can use build a program.
Process oriented programming model
This approach characterizes a program as a series of linear steps (that is, code). The process-oriented model can be thought of as code acting on data. Procedural languages such as C employ this model to considerable success.
Objected oriented programming model
Object-oriented programming organizes a program around its data (that is, objects) and a set of well-defined interfaces to that data. An object-oriented program can be characterized as data controlling access to code.
Object orientation programming is about behavior AND state management not just behavior. You can view object orientation as a way to better structure complex code so that it becomes more manageable and easier to reason with.
An essential element of object-oriented programming is abstraction. Abstraction is a way to hide the complexity of an object through hierarchical abstractions.
OOP Principles
Encapsulation
Encapsulation is the mechanism that binds together code and the data it manipulates, and keeps both safe from outside interference and misuse.
Inheritance
Inheritance is the process by which one object acquires the properties of another object. By use of inheritance, an object need only define those qualities that make it unique within its class. It can inherit its general attributes from its parent.
Polymorphism
Polymorphism (from Greek, meaning “many forms”) is a feature that allows one interface to be used for a general class of actions. More generally, the concept of polymorphism is often expressed by the phrase “one interface, multiple methods.”
When properly applied, polymorphism, encapsulation, and inheritance combine to produce a programming environment that supports the development of far more robust and scaleable programs than does the process-oriented model.
Java Programming Language Elements
Whitespace
Java is a free-form language. This means that you do not need to follow any special indentation rules.
Identifiers
Identifiers are used to name things, such as classes, variables, and methods. An identifier may be any descriptive sequence of uppercase and lowercase letters, numbers, or the underscore and dollar-sign characters.
Literals
A constant value in Java is created by using a literal representation of it.
Comments
Comments provides bried description about the class, method or statements whereever they are defined. There are three types of comments defined by Java. For more details follow java documentation.
Separators
In Java, there are a few characters that are used as separators. The most commonly used separator in Java is the semicolon.
There are 67 keywords currently defined in the Java language (see Table 2-1). These keywords, combined with the syntax of the operators and separators, form the foundation of the Java language.
Example Program
admin@fedser:Overview_of_Java$ cat Example.java
/**
* This is a sample helloworld progrma
*/
public class Example
{
public static void main(String[] args) {
System.out.println("Hello Java 17!!");
}
}
Compile
In java a source file is a compilation unit with a .java extension. It is a text file that contains (among other things) one or more class definitions. The name of the class defining the main method should match the source file name.
admin@fedser:Overview_of_Java$ javac Example.java
Execute
The javac compiler creates a file called Example.class that contains the bytecode version of the program. As discussed earlier, the Java bytecode is the intermediate representation of your program that contains instructions the Java Virtual Machine will execute.
admin@fedser:Overview_of_Java$ java Example
The Java environment relies on several built-in class libraries that contain many built-in methods that provide support for such things as I/O, string handling, networking, and graphics. The standard classes also provide support for a graphical user interface (GUI). Thus, Java as a totality is a combination of the Java language itself, plus its standard classes.
Hope you enjoyed reading this article. Thank you..
Leave a Reply
You must be logged in to post a comment.