Translate

Introduction to Java
 

introduction to java programming,basic introduction to java language.
Java Programming

Java is a general purpose high-level programming language that creates software for various platforms. It is the most commonly used programming language for developing and delivering software.

 Java is an Object-Oriented Programming language that is derived from C and C++, it was introduced to remove many features that lead to common programming errors. Java is a language that is well suited for the use in World Wide Web.

History of Java


In in the year 1991, James Gosling, Mike Sheridan, and Patrick Naughton initiated the Java language project by SUN Micro Systems. It was originally called "Oak", named after the oak tree that was outside James Gosling's office. Since "Oak" was already a trademark of OakTechnologies, this new language was renamed to what the world knows today as Java. Finally Java was developed and released in the year 1995 .The term 'Java' refers to the name of a coffee seed.
Today ,Java is used in web programming, mobile devices, games, e-business solutions and anything that is related to the World Wide Web (WWW).
the four editions of Java language released so far are:
1) Java 2 Standard Edition(J2SE): This edition is used for developing desktop applications.
2)Java Enterprise Edition(J2EE): This is the edition released especially for developing web applications.
3)Micro or Mobile Edition (J2ME): This edition is used specifically for developing mobile applications.
4) Embedded Java: Used for micro-controllers,etc.

Object Oriented Programming (OOP)

Before we begin learning about Java and its features, we need to know about the concept of OOP.
OOP is the foundation of not only Java but also many other programming languages. the most fundamental purpose of many programming languages is to give commands to the computer and as a result the computer does the desired tasks for you.
Let's understand this in simpler terms with the help of an example. 
You go to school to gain knowledge.Is this knowledge given to you all at once?No, they are divided into subjects such as mathematics, science, social science etc. The subjects are in turn divided into number of chapters/units. In other words, the knowledge is passed by the teacher in small and logical portions. If all that amount of knowledge is passed on at one go, you will not be able to remember anything.It will be too much to taken in. 
In the same manner OOP helps in dividing the code in such a way that all the related data is kept together in one section and not meet with other data. Also, it is passed in a logical manner and not all at once. 
In OOP, a program in used as a collection of different units related to each other this units are called objects.
The fundamental concept of OOP are:

1) Object:- this is the basic unit of OOP. An object is a unit that has state and behaviour. Let us take the real world objects such as a bicycle or a dog. Both have state as well as behaviour. In case of a bicycle, the state would be break, paddle, wheels and the behaviour would be applying brakes or peddling. Likewise, the state of a dog would be name, colour or breed and behaviour would be barking, wagging tail or fetching.

Class: A class is the collection of objects that are of a similar type. Any number of objects can be created once a class is defined. For example, roses, lilies, orchards, etc. all of them are flowers that belong to the flower class. 

Abstraction: This concept of OOP means to hide the internal details from the user and show only the functionality It is not necessary to show the entire process or working of something to achieve the desired result. For example, a car. Even though we do not know the internal working of its engine and related components, we still use it.

Encapsulation: This is the process of bundling together the data and its functions into a single unit. For example, a sandwich, all the ingredients such as vegetables, cheese and bread are put together in it. A Java class is an example of encapsulation. 

Inheritance: As the name suggests, inheritance is the process by which a new object acquires the properties of objects of an existing class. This existing class,is called the base class and the new class created is called the derived class. Reusability is one of the most useful aspects of OOP and this is achieved with help of inheritance. This feature also helps to reduce the code size of a program. 

Polymorphism: This has been derived from the Greek words 'poly' which means many or multi and "morph" which means to change form. Therefore, together the meaning of the word "Polymorphism" is the ability to change many forms. In the context of Java, it means that two objects can have the same name but completely different forms. For example, orange; it can be a fruit or a colour.

Features of Java 

What makes Java different from all the other in languages is its features. Java today is the most widely used language for programming. Following are some the features of Java:

⚫In Java, everything is an object as it is based on the OOP model, Java is based on OOP model which means that it organises the software development and maintenance by providing some rules.

⚫Java is a platform independent programming language. 

⚫Programs created by Java are interpreted as well as compiled.

⚫Any code written in Java is stored in a file with .java as an extension, this is converted into a "bytecode" (saved as .class file) which is in turn compiled by the Java-compiler. The generation of bytecode makes Java platform independent. 

⚫Java can distinguish between uppercase as well as lowercase, therefore it can be said that Java is case-sensitive, which increases the scope of variables. 

⚫Java is portable which means that we can carry Java bytecode to all platforms such as Windows, Linux, Sun Solaris, Mac OS, etc. 
⚫Java is multi-threaded as we can write Java programs that deal with many tasks at the same time. 

⚫Java is architecture neutral, that is it does not depend on the computer architecture unlike other programming languages such as C or C++. 

⚫Java is a very simple programming language, unlike other languages that have very confusing and ambiguous concepts Java has a syntax that is simple, clean and easy to understand. 

⚫In Java, the compilation happens just once and the interpretation can be done every time the program is executed. This makes the program flexible and widens its range of possibilities. 

Some of the new feature recently been introduced in Java are as follows: 

⚫Enhanced productivity by providing optional classes feature.

⚫Ease of use.

⚫ Java now supports polyglot programming technique. A polyglot is a program or script which perform the operation in multiple programming languages. The script of a polyglot is valid in multiple programming languages.

⚫ Upgradation in security and performance.

The Java Virtual Machine (JVM)
 
The JVM is the run-time engine that runs Java applications. The concept of Java "write once and run everywhere" (WORA) is executed by JVM. When a Java code (saved with .java extension) is compiled it is translated into byte codes and then placed in class files (saved with extension .class). This .class file is input into the JVM, which in turn loads and executes the .class file. 

Creating and Compiling a Java Program 

Let's create our first Java program. Before that, ensure that you have the latest version of Java Development Kit (JDK) installed on your system. You can easily download the same from authentic website.
 After installing the JDK: 
⚫Set the path of the bin directory of JVM ⚫Create a program 
⚫Save the program with the class name and .java extension 
⚫Open the Command Prompt 
⚫Compile the program using javac command 

AJava program is written using any text editor, the most common being the Notepad. So, for creating your first Java program, write the following code in a Notepad: 

public class MyJavaProgram                             //1
{                                                                             //2
   public static void main(String[args)               //3
  {                                                                           //4
     System.out.println("This is my java program");
                                                                               //5
  }                                                                           //6
}                                                                             //7
  Before moving further, let's first understand the above program. It is a simple Java program, which prints a simple line when executed 

Line 1:A Java program starts with the class keyword and next we provide the class name .Our class name is MyJavaProgram. Remember that all the coding in Java program is done within a class.

Line 2: Opening of the class with curly bracket ({}). 

Line 3: We create the main method, which is written as public static void main(String args[]). The execution of any Java program starts with the main method. String args[]is the argument of this function. The other terms used in this function are public, static, void, main and String args[]. 
The public keyword is called as the access modifier and defines that this method can be accessed by any class. 

The static keyword is included to specify that the method is class related and not instance related. 

The void keyword defines that the method will not return any value. 

The main keyword defines the name of the method. 

The String args[] keyword is the parameter to the main method. 

Line 4: Opening of the main() method. 

Line 5: For showing the output on the screen (in this case, we are printing a line), we use System. out.println() command and write the statement which we want to print. 

Line 6: End of main() method. 

Line 7: End of class. 

Now, save the program with the name "MyJavaProgram.java". Once you have saved the program, open the command prompt and change the directory location to where you have saved your program. Next, a compile the program using the javac command.

Type the followingcommand in the command prompt:
               javac MyJavaProgram.java.

Run the program using the java command.Type the following command in the command prompt :
java MyJavaProgram.
The output of is as follows:




Comments

A comment is a very important part of any programming language. It is a small description about the program that is written within the program. The purpose of adding comment is to make it easy to understand for somebody who has not created that program. 
Comments are added within a Java Program and they start with double slash (//) symbol.Note that in the program created ,we have numbered each line of the program using comments. Comments are not executed when you run a program. In other words, anything that you write after // in a Java Program will not executed by JVM.

Hope you like this post "introduction to Java programming"
If you like share this post to your friends to spread knowledge.

Post a Comment

Comment me if you have any doubts related to technology or if you want any answer through our site.
Regards
KR Learning

Previous Post Next Post