IDYN Solutions

Introduction to Java

November 10, 2006 · 10 Comments

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

Categories: Java

10 responses so far ↓

  • Classes, Methods and Objects « IDYN Solutions // February 8, 2007 at 7:37 am

    [...] pointing to the same object. A change to one will be reflected in the other. Related Post: Introduction to Java | Objects and Variables | Datatypes | Operators | Conditional Flow Control | Iterative Flow Control [...]

  • Objects And Variables « IDYN Solutions // February 8, 2007 at 7:52 am

    [...] are used to store a single value for all instances of a class. Related Posts: Introduction to Java | Classes, Methods & Objects | Datatypes | Operators | Conditional Flow Control | Iterative [...]

  • praveen // February 16, 2007 at 12:53 pm

    Its simply Excellent

  • k.selvakumar // May 21, 2007 at 11:23 am

    please explain the depth introduction in java

  • Hari Babu Yamala // October 9, 2007 at 3:31 pm

    It’s simply excellent and interested to read..

  • REVATHI.M // January 19, 2008 at 2:43 pm

    plz explain detail inroduction of java

  • jafar // January 28, 2008 at 7:37 am

    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

  • Maxwell Sebothoma // February 27, 2008 at 8:35 am

    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

  • mohit garg // April 21, 2008 at 12:17 pm

    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.

  • Ankit // June 25, 2009 at 4:56 pm

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

Leave a Comment