Introduction to java programming

Posted: June 6, 2012 by makaranddalal in JAVA

It was developed by Sun Microsystems, released in 1995.

Features of java

  • Object Oriented: Everything in java is an object.
  • Platform independent: Java code is compiled into platform independent byte code and interpreted by JVM on whichever platform it is run.
  • Simple: Easy to learn and understand.
  • Secure: Helps to develop virus-free code. Public key encryption is provided for authentication.
  • Architectural- neutral: Architecture-neutral object file format which makes the compiled code to be executable on many processors.
  • Portable: Compiler and Java is written in ANSI C with a clean portability boundary which is a POSIX subset.
  • Robust: Supports both compile time error checking and runtime checking.
  • Multi-threaded: Possible to write programs that can do many tasks simultaneously.
  • Interpreted: Java byte code is translated on the fly to native machine instructions and is not stored anywhere.
  • High Performance: With the use of Just-In-Time compilers.
  • Distributed: Designed for the distributed environment of the internet.
  • Dynamic: Designed to adapt to an evolving environment. Resolves accesses to objects on run-time.

Requirements

  • Windows 95/98/2000/XP or Linux 7.1 operating system.
  • Java JDK 5
  • Microsoft Notepad / Netbeans 7.1

Software Download

Steps to be followed

1. Write a java program:
Components of a java program include:

  • Class: A class can be defined as a template that describe the behaviors and states that object of its type support.
  • Methods: Behavior is defined in the methods. A class can contain many methods. It is in methods where the logics are written, data is manipulated and all the actions are executed.
  • Instance Variables: Each object has its unique set of instance variables.
  • Object: Objects have states and behaviors. An object is an instance of a class.

Points to be remembered:

  • Everything is enclosed in a class (including main() method).
  • No terminating semicolon for a class.
  • At least one main method.
  • Execution starts at main.
  • main() method takes one argument – array of strings.
  • Each statement ends with a semicolon.
  • In Netbeans, new project is created using ctrl+shift+N and new file using ctrl+N.

2. Save the program:

  • File name should be same as class name.
  • Include the extension “.java”.
  • The file should be saved in the bin folder (eg. in C:\Program Files\Java\jdk1.7.0\bin) or proper path is provided by setting the environment variables of the system.

3. Compile the program:

  • A “.class” file is created containing the byte code.
  • Open the command prompt and change the directory to the one in which the program file is saved.
  • Compile the code using the command “javac programname.java”.
  • If you are using Netbeans, press F11.

4. Run the program:

  • Use the command “java programname”.
  • Specify command line arguments, if any, using a space as separator.
  • In Netbeans, command line arguements are specified in properties/run of the project. Program is run using F6.
Advertisements

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