Configure Java Environment

Setting up Java envrionment will help in smooth functioning and save valuable time. Set the PATH environment variable if you want to be able to conveniently run the executables (javac.exe, java.exe, javadoc.exe, and so on) from any directory without having to type the full path of the command.

  • It is useful to set the environment PATH variable permanently. To make a permanent change to the PATH variable, use the System icon in the Control Panel. Procedure for setting up the environment variable varies depending on the version of Windows:
  • The following is an example of a PATH environment variable:

  • C:\Java\jdk1.7.0\bin; C:\Windows\System32\;C:\Windows\; C:\Windows\System32\Wbem

Windows XP:

  • Select Start from taskbar, select Control Panel. double click System, and select the Advanced tab.
  • Click Environment Variables. In the section System Variables, find the PATH environment variable and select it. Click Edit. If the PATH environment variable does not exist, click New.
  • In the Edit System Variable (or New System Variable) window, specify the value of the PATH environment variable. Click OK. Close all remaining windows by clicking OK.

Windows Vista:

  • From the desktop, right click the My Computer icon.
  • Choose Properties from the context menu.
  • Click the Advanced tab (Advanced system settings link in Vista).
  • Click Environment Variables. In the section System Variables, find the PATH environment variable and select it. Click Edit. If the PATH environment variable does not exist, click New.
  • In the Edit System Variable (or New System Variable) window, specify the value of the PATH environment variable. Click OK. Close all remaining windows by clicking OK.

Windows 7:

  • From the desktop, right click the Computer icon
  • Choose Properties from the context menu.
  • Click the Advanced system settings link.
  • Click Environment Variables. In the section System Variables, find the PATH environment variable and select it. Click Edit. If the PATH environment variable does not exist, click New.
  • In the Edit System Variable (or New System Variable) window, specify the value of the PATH environment variable. Click OK. Close all remaining windows by clicking OK.

Solaris and Linux

    To set the Java environment path permanently, set the path in your startup file.

  • For C shell (csh), edit the startup file (~/.cshrc):

  • set path=(/usr/local/jdk1.7.0/bin )

  • For bash, edit the startup file (~/.bashrc):

  • PATH=/usr/local/jdk1.7.0/bin:
    export PATH

  • For ksh, the startup file is named by the environment variable, ENV. To set the path:

  • PATH=/usr/local/jdk1.7.0/bin:
    export PATH
  • For sh, edit the profile file (~/.profile):

  • PATH=/usr/local/jdk1.7.0/bin:
    export PATH

    Then load the startup file and verify that the path is set by repeating the java command:

  • For C shell (csh):

  • % source ~/.cshrc
    % java -version

  • For ksh, bash, or sh:):

  • % . /.profile
    % java -version

Identifiers, Variable, Constant, Keywords & Data types

Identifiers, Variable and Constant reference program locations in computer memory that store values that are related to those identifiers.

A Keyword is a word or identifier that has a particular meaning to the programming language. Keywords are pre-defined in the programming languages.

Data type or simply type is a classification identifying one of various types of data, such as real-valued, integer or Boolean.

Identifiers

It is a name given to a class, variable, constant or method.
Rules for Declaring a Legal Identifier:
  • Identifier must start with a letter, $, _. Cannot start with number.
  • After the first letter, contain numeric.
  • No Limit to the number of characters an identifier can contain.
  • Cannot use keyword in identifier name.
  • Identifiers are case-sensitive.

Variable

  • A variable is just like a cup or container. It can hold something. It has a size and a type.
Variable

Constant

  • As the name implies , constants are fixed values which never change.
  • Example:
  • final int MAX=100;
  • final keyword is used to declare a constant in java.

Keywords

  • Keywords are reserved which has some special meaning for the compiler.
For Example:
abstract double int strictfp
boolean else interface super
break extends long switch
byte final native this
case finally new throw
catch float package throws
char for primitive transient
class goto protected try
const if public void
continue implements return volatile
default import short while
do instanceof static synchronized

Data types

Variable (Cup) can be of two type
  • Primitive Type
  • Reference Type
Primitive Type
  • Primitives are like the cups at the Coffee-House They come in different sizes and each has name like small , big, medium.
Primitive Type Example
byte x=10; /* Take 1 byte in memory */
short y=500; /* Take 2 bytes in memory */
int a=40000; /* Take 4 bytes in memory */
Type Bit/Bytes Range
boolean 1 bit True or False
char 16 bit/ 2 bytes 0 to 65535
byte 8 bit/ 1 byte -128 to 127
short 16 bit/ 2 bytes -32768 to 32767
int 32 bits/ 4 bytes -2147483648 to 2147483647
long 64 bits/ 8 bytes Huge To huge
float 32 bits/ 4 bytes varies
double 64 bits/ 8 bytes varies

Reference type

  • A Reference variable holds bits that represents a way to access an object.
  • It doesn't hold the object itself, but it holds something like a pointer, or an address.
Reference Type
Reference Type Example:
Reference Type Example