Before diving headfirst into Java, here are a few basic Java concepts that one should know. First, we will see the structure of a Java program:

Structure of a Java program:

// Program to print "Hello World"    ---------> Comment statement
import java.io;                      --------> package statement

public class HelloWorld {   -------->   'Hello World' is the name of class    
   public static void main(String args[]){ ------>  'public' is a Java modifier
    System.out.println("Hello World");
}
}


I have given an explanation of each of the statements on the side.

  1. Comment statement: The first line that begins with a “//” is the comment statement. Here is an explanation of the “Comment” statement. Comment statements can appear anywhere in the program. Consider this example:

Eg. // Program to print “Hello World”

Comments are placed in any programming language for better readability of code. Comments are not executed by the compiler.

Comments in Java are placed by using these symbols:

/* */

The above symbols are multi-line comments

OR

//

The above symbol is a single line comment

2. Package statement: The second line in the code mentioned above is the package statement. Consider this example:

Eg: import java.io.*;

‘java.io’ is the name of the package. There are many, many packages in Java. You can view them here.

A package in Java is a combination of related classes, interfaces , enumerations, Exceptions and Errors(it is like a ‘package’ holding different things)

If there is an ‘import’ statement in a Java program, it must be the first statement in the program(barring the comment which can appear anywhere)

3. Primitive Data types:

There are eight different primitive data types in Java. Data types are locations where information is stored. This information can be in integer format or decimal format,

The eight different primitive data types are:

  1. byte, int, short, long (for storing numeric values which are positive and negative)
  2. float, double (for storing decimal values)
  3. char (for storing characters)
  4. boolean (for storing values such as ‘true’ or ‘false’)

4. Java modifiers:

The most important component of a Java program are the access modifiers. They are public, private, protected and default.

These are access modifiers which are applicable to classes, methods or variables. Their visibility is the differentiating factor when working with access modifiers.

There are other non-access modifiers such as final, static, abstract, transient, synchronized and volatile. Non-access modifiers can be used either by classes, methods or variables as applicable. We will see more of ‘Java access modifiers’ for the alphabet ‘J’ post.

4. Looping:

Java has different looping constructs that help to iterate over a set of statements till a particular condition is satisfied. The different looping constructs are:

a. ‘for’ loop

b. ‘ ‘while’ loop

c. ‘do…while’ loop

d. ‘if’ loop

We will discuss more about looping in later posts.

We have just scraped the basics of Java in this post! Hope this post has not been very mind boggling… do stay tuned as I simplify Java further! 🙂

I’m participating in #BlogchatterA2Z by Blogchatter 

(Visited 110 times, 1 visits today)

Related Posts

6 thoughts on “Basic Java concepts

Leave a Reply