Monday, March 23, 2009

Assignment Operator In JAVA

The assignment operator in java is the most frequently used operator. This operator is used to assign the value on its right to the variable on the left. The general format for the assignment operator is given below.

variable_name = expression;

where,
expression is an arthmetic expression built using constants, variables and binary operators.
variable_name is the name of the variable to which the expression should be assigned.

For Example

a = 3;
x = 1*3;
num - x+8;
num1 = (4*a)+(21-a)

Note
It is also possible to assgn single value to multiple variables as shown below.

i = j = k = 10;
which will assgn the value 10 to the variables i, j and k.

Binary Operators In JAVA

As the name itself indicates, binary operators are operators that operate on two operand. The following table gives lists the different binary operator available in java.

Operator

Operation

Example

+

Addition

2+3 is 5

-

Subtraction

8-2 is 6

*

Multiplication

2*5 is 10

/

Division

8/8 is 1

%

Modulo

15%2 is 1

Example Program


class binaryoperatorexample

{

public static void main(String args[])

{

int a=10,b=5,c,d,e,f,g;

c=a+b;

d=a-b;

e=a*b;

f=a/b;

g=a%b;

System.out.println("Addition:"+c);

System.out.println("Subtraction:"+d);

System.out.println("Multiplication:"+e);

System.out.println("Division:"+f);

System.out.println("Modulo:"+g);

}

}

Please make sure to include all the necessary header files before compiling the program. The output of the program will be as below.


Addition: 15

Subtraction: 5

Multiplication: 50

Division: 2

Modulo: 0




Wednesday, March 18, 2009

What Is A Variable?

A variable is a name of memory location , which can store one constant at a time. Like constants, variable can also be any one of the eight primitive data types.
Every variable is identified by a variable name. The following points should be kept in mind when deciding the variable name.

  1. The variable name must start with an alphabet and can contain only alphabets , numbers,underscores and $ sign.
  2. It cannot have a blank spaces.
  3. Java keywords should not be used as variable names.
  4. Java is a case sensitive so a variable in uppercase is diffrent from the variable in lowercase.

What Is A Constant?

A constant is a any data that cannot be changed. In JAVA, constants can be of any basic eight data types.
For example,
  • -23 is a byte constant.
  • 3213 is an integer constant.
  • 13.654 is a float constant.
  • true is a Boolean constant.

Integer constant can also be represented in octal and hexadecimal forms. An octal number should begin with the digit 0 and can contain the digits 0 to 7. A hexadecimal must start with the character sequence 0x and can contain the digits 0 to 9 and the alphabets A,B,C,D,E and F.

Data Types In Java

Data type in java can be of 8 basic type and these data types are called as primitive data types. The Following table contains the primitive data types.

Data Type

Size

Description

Boolean

1 Bit

Can be either true or false

Char

16 Bits

Can be single character enclosed with single ‘.

Byte

8 Bits

Integers between -128 to 12

Short

16 Bits

Integers between -32768 to 32767

Int

32 Bits

Integers between -2147483648 to 2147483647

Long

64 Bits

Integers between -9223372036854775808 to 9223372036854775807

Float

32 Bits

Single precision numbers in the range 3.4e-38 to 3.4e38

Double

64 Bits

Double precision number in the range from 1.7e-308 to 1.7e308

Thursday, March 12, 2009

Java Developers Kit

The Java Developers Kit is known as JDK, is a collection of tools and necessary documents for making java application and applets. The JDK consist of

  • The java compiler javac.exe to convert java programs into bytecode.
  • The java interpreter java.exe translates bytecode into program action to be executed by JVM.
  • The Java debugger jdb.exe to debug the programs.
  • The Java disassembler javap.exe to display certain specific interfaces.
  • The Java header file generator javah.exe.
  • The Java documentation javadoc.exe.
  • AppletViewer.

what is an array?

An array is a group of variables of same data type. These variables are grouped together under a common name. Each individual variable is called as an array element and it is numbered as 0,1,2,3 and so on. These numbers are called the subscripts. An array element is referred to by the common name and its subscript enclosed in square brackets[].

For example, if the num is an integer array of size 5, these numbers would be referred as num[0], num[1],... num[4] where the number 0,1,2,3,4 are called the subscripts.

Important Rules In Array

  • The Subscripts of an array always begins with 0.
  • It is an integer.
  • It cannot be a negative number.
  • The subscripts should be enclosed with [].