Introduction to Java

Java is the key to developing platform-independant programs. Therefore, it is the ideal option when diverse hardware platforms and OSs need to be supported.

GOSSIP:
Java was designed at Sun Microsystems, Inc in 1991 and was initially called Oak. It was renamed Java in 1995.

Java was designed to be compatible with different platforms used by computers connected to the Internet. The compiled code of a Java Program can be executed on different platforms without any changes. This is possible because of bytecode that is generated during the compilation of source code. Bytecode is a highly optimized set of instructions that is executed by the Java run-time system called Java Virtual Machine (JVM). The JVM acts as an interpreter for bytecode.

Java Source Files


Fig 1.1 – Java Source Files

A Java source file contains three sections. The first setion is the package section that contains a single line of code that specifies the package to while the source file belongs. The package statement may be omitted, in which case the default package will be assumed.

The second section is the import section. This section includes import statements that tell the compiler which packages to include. The import section may be omitted. The compiler will automatically import the java.lang.package that includes the most commonly used Java classes and interfaces.

The third section includes the class or interface definition. This is where all of the remaining Java code for the source file will be placed. There can only be one top-level public class or a single public interface defined in a source file.

A Java source file must be named with the same name as the top-level class or interface, if that top level class or interface is defined as public. The extension .java is appended to the name to form the source file name. In our example, it would be HelloWorld.java

Java Compiler ignores extra white spaces. So you can use..hell lots of space to make your code more readable.

Comments are used to annotate the code. The compiler will strip the comments from the code during compilation. It is a good idea to use comments to explain code that may be confusing. Comments are also used for producing Javadoc documentation such as the Java API reference.

There are two types of comments that can be coded into a Java source file.

Type 1: Multiple line comments

Syntax:
/* blah blah blag */

Example:
/*
Blah
Blah
*/

Type 2: End-of-line comment

Syntax:
// Blah

Hello World Program

Java Keywords

Related Post: Classes, Methods & Objects | Objects and Variables | Datatypes | Operators | Conditional Flow Control | Iterative Flow Control | Jump Statements

Advertisements

10 responses to “Introduction to Java

  1. Pingback: Classes, Methods and Objects « IDYN Solutions

  2. Pingback: Objects And Variables « IDYN Solutions

  3. Its simply Excellent

  4. k.selvakumar

    please explain the depth introduction in java

  5. Hari Babu Yamala

    It’s simply excellent and interested to read..

  6. plz explain detail inroduction of java

  7. hi to all the member of this website.
    sir if you have any book to download from internet then send me their address, because i want to download them in
    my computer.
    thanks for help

  8. Maxwell Sebothoma

    Hello Sir/Madam

    I a am novice programmer, I find your explaining of Java easy to undestand. How do I download this lesson?

    Maxwell Sebothoma
    South Africa, Pretoria

  9. Hi,i am Mohit Garg an Software Enginner i saw
    your first java programebut the compiling method is not satisfying its takes too time and we have to open another notepad for compiling and run the java programe it takes too time.
    i suggest u that after saving the java programe
    u go in “command prompt write just javac file name .java”it creates its dot classfile and after creating the dot class file write in command programme again “java and file name” .i think this is the better option for running the java programme.

  10. Can you give explanation related to platform independence is it related to OS or MACHINE

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s