Java Basics

Basics in Java

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

  • Java Standard Edition (JSE)
  • Java Enterprise Edition (JEE)
  • Java Mobile Edition (JME)

Java Standard Edition (JSE)

Java Standard Edition (JSE) is used to create Standalone Applications as well as Graphical User Interface (GUI) Applications.

Java Enterprise Edition (JEE)

Java Enterprise Edition (JEE) is used to create Web Applications as well as Enterprise Applications.

Java Mobile Edition (JME)

Java Mobile Edition (JME) is used to create Mobile Applications.

What are 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

What are 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

The latest Java version contains important enhancements to improve performance, stability and security of the Java applications that run on your machine. Installing this free update will ensure that your Java applications continue to run safely and efficiently. You can learn more about Java Programming Language from Wikipedia.

Java Decision Making Statements

  1. if
  2. if - else
  3. switch

Java Looping or Iteration Statements

  1. for
  2. while
  3. do - while

Java Branching Statements

  1. break
  2. continue
  3. return

Commenting in Java

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

What are the Software Requirements to Create Java Programs ?

Any one of the following

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

What are the Software Requirements to Run Java Programs ?

  • Java Development Kit (JDK) for Compilation
  • Java Runtime Environment (JRE) for Running Java Programs

How to Run the Java Program ?

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.