Saturday, December 1, 2012

JAVA Fundamental

Fundamentals


Java Terminology 

* Java Virtual Machine(JVM) –set of computer software programs and data structures that use a virtual machine model for the execution of other computer programs and scripts.
* Java Runtime Environment(JRE) –A runtime environment which implements Java Virtual Machine, and provides all class libraries and other facilities necessary to execute Java programs. This is the software on your computer that actually runs Java programs
* Java Development Kit(JDK) –The basic tools necessary to compile, document, and package Java programs (javac, javadoc, and jar, respectively). The JDK includes a complete JRE.
* Application Programming Interface (API) –Contains predefined classes and interfaces for developing Java programs

Comments 

Comment-The contents of a comment are ignored by the compiler.  Three type of comment in java.
1. Single line comments(Slash-Slash) //text // This comment extends to the end of the line.
2. Multiple line comments  /* This comment, a "slash-star" comment, includes multiple lines.*/ 
3. Documentation Comments /** documentation */  The last type of comment is the
Javadocument. This comment type has some guidelines that allows a Javadocreader to display information about a Java method or class by using special tags 

Excercise
# Exercise:Write a simple Java program which displays following two lines on the screen.
I like Java programming.
So I do practical .

Operators 

* An operator is a symbol that tells the compiler to perform a specific mathematical or logical manipulation.
* Java has four general classes of operators: arithmetic, bitwise, relational, and logical
* Examples of expressions that include Java operators :
 1. n = 2
 2. n += 3
 3. ++n
 4. n / 3
5.  n % 3




Arithmetic Operators












Example
x = y / 2;
* in the above expression, x and y are variables, 2 is a literal and = and / are operators. 
* This expression states that the y variable is divided by 2 using the division operator (/), and the *result is stored in x using the assignment operator (=).Notice the expression was described from right to left. 
*It is how the compiler itself analyzes expressions to generate code.








It is also possible to use the shortcuts for arithmetic operators as given below.










class Arithmetic {

public static void main (String args[]) 
{

intx=17, y=5;

System.out.println(“x=“+x);

System.out.println(“y=“+y);

System.out.println(“x+y=“+(x+y));

System.out.println(“x-y=“+(x-y));

System.out.println(“x*y=“+(x*y));

System.out.println(“x/y=“+(x/y));

System.out.println(“x%y=“+(x%y));

}

}
Output
 










 Bitwise Operators







No comments: