Java Basics

Java is a simple, portable, distributed, robust, secure, dynamic, architecture neutral, object oriented programming language. And its syntax is like C/C++ Language syntax. It is divided into three categories.

  1. Java Standard Edition (JSE)
  2. Java Enterprise Edition (JEE)
  3. Java Mobile Edition (JME)

Java Standard Edition (JSE)

It is used to create Standalone Applications as well as Graphical User Interface (GUI) Applications.

Java Enterprise Edition (JEE)

It is used to create Web Applications as well as Enterprise Applications.

Java Mobile Edition (JME)

It is used to create Mobile Applications.

Java Data Types

Data Type Range Memory
(in bytes)
boolean true or false 1 bit false
byte -128 to 127 1 0
char any character or 0 to 65535 2 '\u0000'
short -32768 to 32767 2 0
int -2147483648 to 2147483647 4 0
float 1.40129846432481707e-45 to 3.40282346638528860e+38 4 0.0f
long -9223372036854775808 to 9223372036854775807 8 0L
double 4.94065645841246544e-324d to 1.79769313486231570e+308d 8 0.0d

Java Keywords

These are reserved words. So you cannot use as identifiers.

The keywords const and goto are reserved, even though they are not currently used. Java compiler produce error messages if these are appear in programs.


Operators in Java

Arithmetic+, -, *, /, %
Arithmetic Assignment+=, -=, *=, /=
Logical!, ||, &&
Relational==, !=, >, <, >=, <=
Increment and Decrement++, --
Bitwise&, |, ^, <<, >>, >>>
Conditional (Ternary)?:

Java Control Flow Statements

It is sometimes necessary to perform repeated actions or skip some statements in a program. For these actions certain control statements are available. These statements control the flow of execution of the programs.

Decision Making Statements

  • if
  • if - else
  • switch

Looping or Iteration Statements

  • for
  • while
  • do - while

Branching Statements

  • break
  • continue
  • return


  1. //          Single Line Comment
  2. /* */      Multi Line Comment
  3. /** */    Documentation Comment

Software Requirements for Creating Java Programs

Any one of the following

  • Notepad or any Text Editor
  • NetBeans IDE
  • Eclips IDE

Software Requirements to Run Java

  • Java Development Kit (JDK) for Compilation
  • Java Runtime Environment (JRE) for Running Java Programs
Your First Java Program
public class MyFirstJavaProgram
	public static void main(String args[])
		System.out.println("WELCOME to");

Before going to execute the above program, we have to know the rules of Java program.

Rule 1: Java Program name should be the class name. MyFirstJavaProgram in the case of above program with .java extension.

So you should type the above program in Notepad of windows OS. And save the file with in the location C:\\

Before running the above program you should know how to run dos prompt and some basic commands. Go to start menu ⇒ Programs ⇒ Accessories ⇒ click on Command Prompt

You will get the DOS command prompt window. Type MD C:\ at the command prompt then press enter.

After type CD C:\ press again enter. Your prompt changes to C:\> here we knowing the MD command which is creates a directory and another command is CD it is changing the current directory.

Type java –version at your command prompt and then press enter, it shows which Java version is installed on your computer. The recommended Java Version is it is called as Java 6 Version.

Then type javac at your command prompt and then press enter. It shows some text that means your environmental variables are working fine.

If you want to run your first Java program, you should follow following steps.

  1. Compile the Java program.
  2. Run the Java program.


Type javac then press enter. It does not show any message that means your Java program compiled successfully. If any text showing except your command prompt there are some errors in your program. Check the program then correct the errors then compile again.

After successful compilation the javac compiler creates MyFirstJavaProgram.class file in c:\ To check if class file is created type DIR then press enter at your dos prompt.


Type java MyFirstJavaProgram then press enter. It shows the message WELCOME to You are successfully compiled and ran the program.

Explanation for

Like C programs Java program execution starts from public static void main(String args[]) method. The System.out.println("WELCOME to"); print the message WELCOME to on the screen.