Ads

Overview of JAVA Language Programming for Developers

Overview of JAVA Language Programming for Developers 

Java is high level programming language developed by Sun Micro systems and released in 1995.java runs on different platforms such as Mac OS,Windows,UNIX .

Java SE 8 is the latest java standard editions which has multiple configurations to suite various types of platforms.

Ex: J2EE for enterprise applications
      J2ME for mobile applications

The new versions of J2 are java EE,ME and SE .The main characteristic of java is write once ,run anywhere.

Java Main Features:

Object Oriented: everything can be defined  in object model.Objects means any real thing world like car,animal and planet etc..

Platform Independent: Every java programming language converted into Byte code which can be understood by java virtual machine (JVM) whichever platform it is being run.

Simple:if you learn the object oriented programming java concepts ,java would be very easy language to learn.

Secure: it enables the all virus,tamper and authentication with protected methods.

Interpreted: Java byte code is translated on the fly to native machine instructions and is not stored anywhere. The development process is vey fast and sophisticated since the linking is an incremental and light weight process.

High Performance: With the use of Just-In-Time compilers, Java enables high performance.

Distributed: Java is created for the distributed environment of the internet.

Dynamic: Java is  more dynamic than C or C++ so it is designed to adapt to an changing environment. Java programs can carry large amount of run-time information that can be used to verify and resolve accesses to objects on run-time.

Architectural-neutral: Java compiler creates an architecture-neutral object file format which makes the compiled code to be executable on many processors, with the help of Java run time system.

Portable:  Compiler in Java is written in ANSI C with a clean portability boundary which is a POSIX subset.

Robust: Java is strong  to eliminate error related situations by emphasizing mainly on compile time error checking and run time checking.

Multi-threaded:  it is possible to write programs that can do many tasks at a time. This  feature allows developers to build smoothly running interactive applications.

Tools for java programming execution:


We  need a Pentium 200-MHz device with a minimum of 128 MB of RAM .
We also need the following softwares:
Linux 7.1 or Windows xp/7/8 operating system.
Java JDK 8
Microsoft Notepad or any other text editor.

First java example program:


java language programming for developers



public class MyInitialJavaProgram {

    public static void main(String []args) {
       System.out.println("Hello you");
    }

Output: Hello you

How to install java Local Environment Setup


Here ,i am explaining  you, how to install java software in your local system.

Following steps are requiered to install java .

Download Java SE  version based on your operating system.

Run the .exe to install Java on your system. Once you installed Java on your system, you would need to set up environment variables to point to correct installation directories:

Building the the path for windows:


Assuming you have installed Java in c:\Program Files\java\jdk directory:

Right-click on 'My Computer' and select 'Properties'.

Click on the 'Environment variables' button under the 'Advanced' tab.

Now, alter the 'Path' variable so that it also contains the path to the Java executable. Example, if the path is currently set to 'C:\WINDOWS\SYSTEM32', then change your path to read 'C:\WINDOWS\SYSTEM32;c:\Program Files\java\jdk\bin'.

Setting up the path for Linux, UNIX, Solaris, FreeBSD:

Environment variable PATH should be set to point to where the Java binaries have been installed. Recommand to your shell documentation if you have trouble doing this.

If you use bash as your shell, then you would add the following line to the end of your '.bashrc: export PATH=/path/to/java:$PATH'

Well known Java Editors:

Write your Java programs, we will need a text editor.

Notepad: On Windows machine you can use any simple text editor like Notepad (Recommended for this tutorial), TextPad.

Netbeans: is a Java IDE that is open-source and free which can be downloaded from http://www.netbeans.org/index.html.

Eclipse: is also a Java IDE developed by the eclipse open-source community and can be downloaded from http://www.eclipse.org/.

How to undestand java program.


Java program can be defined as a collection of objects that communicate via invoking each other's methods. 

Object - Objects have states(variables) and behaviours(methods). Example: A car has states - colour, name, models as well as behaviours -driving, speed, breaks. 
An object is an instance of a class.

Class - A class can be defined as a template/ blue print that describes the behaviours/states that object of its type support.

Methods - A method is basically a behaviour. A class can contain many methods. It is in methods where the logics are written, data is manipulated and all the actions are executed.

Instance Variables - Each object has its unique set of instance variables. An object's state is created by the values assigned to these instance variables.

First Java Program:

we analyse the first java program which would print the words Hello you.

public class MyFirstJavaProgram {

   /* This is my first java program.  
    * This will print 'Hello you' as the output
    */
    public static void main(String []args) {
       System.out.println("Hello you"); // prints Hello World
    }


and we learn  how to save the file, compile and run the program. 

Open notepad and write or copy  the code in the above program.

Save the file as: MyFirstJavaProgram.java.

Open a command prompt window and go to the directory where you saved the class. Assume it's C:\.

Type ' javac MyFirstJavaProgram.java' and press enter to compile your code. If there are no errors in your code, the command prompt will take you to the next line (Assumption : The path variable is set).

Now, type ' java MyFirstJavaProgram ' to run your program.

now we can see ' Hello you ' printed on the window.

C:\> javac MyFirstJavaProgram.java
C:\> java MyFirstJavaProgram 
Hello you


Basic Syntax:

About Java programs:


Case Sensitivity - Java is case sensitive, which means identifier Hello and hello would have different meaning in Java.

Class Names - For all class names the first letter should be in Upper Case. 

If you want to use several words to form a name of the class, each inner word's first letter should be in Upper Case.

Example class MyFirstJavaClass

Method Names - All method names should start with a Lower Case letter. 

If you want tp use several words to form the name of the method, then each inner word's first letter should be in Upper Case.

Example public void myMethodName()

Program File Name - Name of the program file should exactly match the class name. 

When you saving the file, you should save it using the class name (Remember Java is case sensitive) and append '.java' to the end of the name (if the file name and the class name do not match your program will not compile).

Example: Assume 'MyFirstJavaProgram' is the class name. Then the file should be saved as 'MyFirstJavaProgram.java'

public static void main(String args[]) - Java program processing starts from the main() method which is a mandatory part of every Java program.

Java Identifiers:

All Java components require names. Names used for classes, variables and methods are called identifiers.

In Java, there are several points to remember about identifiers. They are as follows:

All identifiers should begin with a letter (A to Z or a to z), currency character ($) or an underscore (_).

After the first character identifiers can have any combination of characters.

A key word cannot be used as an identifier.

Most importantly identifiers are case sensitive.

Examples of legal identifiers: age, $salary, _value, __1_value

Examples of illegal identifiers: 123abc, -salary

Java Modifiers:

Like other languages, it is possible to modify classes, methods, etc., by using modifiers. There are two categories of modifiers:

Access Modifiers: default, public , protected, private

Non-access Modifiers: final, abstract, strictfp


Java Variables:

We are look at different types of variables in Java:

Local Variables
Class Variables (Static Variables)
Instance Variables (Non-static variables)

Java Arrays:

Arrays are objects that store multiple variables of the same type. However, an array itself is an object on the heap. We will look into how to declare, construct and initialize in the upcoming chapters.

Java Enums:

Enums were introduced in java 5.0. Enums restrict a variable to have one of only a few predefined values. The values in this enumerated list are called enums.

With the use of enums it is possible to reduce the number of bugs in your code.

java Keywords:

The keywords in the table are  reserved words which may not be used as constant or variable or any other identifier names.

abstractassertbooleanbreak
bytecasecatchchar
classconstcontinuedefault
dodoubleelseenum
extendsfinalfinallyfloat
forgotoifimplements
importinstanceofintinterface
longnativenewpackage
privateprotectedpublicreturn
shortstaticstrictfpsuper
switchsynchronizedthisthrow
throwstransienttryvoid
volatilewhile



Comments in Java


Java supports single-line and multi-line comments and  All  comment words are ignored by Java compiler.

public class MyFirstJavaProgram{

   /* This is my first java program.
    * This will print 'Hello you' as the output
    * This is a multi-line comments.
    */

    public static void main(String []args){
       // This is a single line comment
       /* This is a single line comment. */
       System.out.println("Hello you");
    }
}

Using Blank Lines:

A line containing only white space, possibly with a comment, is known as a blank line, and Java totally ignores it.

Inheritance:

In Java, classes can be derived from parent classes. generally sometimes we  need to create a new class and there are already a classes that have some of the code we require, then it is possible to derive our new class from the already existing code.

This possibility allows us to reuse the fields and methods of the existing class without having to rewrite the code in a new class. In this case the existing class is called the superclass(parent class) and the derived(child class) class is called the subclass.

Interfaces:

In Java language, an interface can be defined as a relation between objects on how to communicate with each other. Interfaces play a vital role when it comes to the concept of inheritance.

An interface defines the methods, a deriving class(subclass or child class) should use. But the implementation of the methods is responsibility of the subclass.

In this post,we learnt the java programming language basics so in  the next post we learn the java object oriented concepts in detail.

Comments

Popular posts from this blog

BADI Interview Questions in SAP ABAP

Sample SAP ABAP Programming Examples for Practice

Module Pool Programming Interview Questions and Answers in SAP ABAP

Step by Step tutorial on BDC Session Method Program in SAP ABAP

SAP ABAP Interview Questions and Answers for 10 Years Experienced