Monday, December 20, 2010

Data type Default value

Data type Default value

byte 0

short 0

int 0

long 0L

float 0.0f

double 0.0d

char '\u0000'

String (or any object) null

boolean false

Java Primitive Data type

Java primitive data type is similar to those of C. Java usage eight primitive data type.

Definition: - A data type is a classification of data which store in specific data . Every primitive data type variable assigned a data type that determine what data type is declared. The term “data type “ and primitive data type” are often used interchangeable. Primitive data type are predefined type, means if we define preemptive data type , you should assign a value in a variable of those data type like.

int sum = 0;

Java have eight data tpe :-

1. boolean : boolean data type have two possible true and false. Using this data type is simple flag that track true or false condition.

2. char : char data type is single 16-bit Unicode character. char is minimum value of ‘\u0000’ (or 0) and maximum value of ‘\uffff ’ (or 65, 535 inclusive).

3. byte : byte data type is an 8-bit signed two’s complement integer. Byte data type have maximum value of 127 and minimum value of -128 . The byte data type can be use for large array. Where the memory saving matters.

4. short : short data type is 16-bit signed two’s complement integer. It has maximum value of 32,767 and minimum value of -32,768. It can be use for large array.. Where memory saving matter.

5. int : int data type 32-bit signed integer two’s complement integer. It has maximum value of

2,147,483,647 and minimum value of - 2,147,483,648. It has used wider range of integer type. If you need to wider range of this. You can use long instead of this.

6. long : long data type 64-bit signed two’s complements integer. It has maximum value of 9,223,372,036,854,775,807 and minimum value of -9,223,372,036,854,775,808. When you need a range of values wider than those provided by int.

7. float : The float data type is a single-precision 32-bit IEEE 754 floating point . It’s range of beyond the scope.

8. double : The double data type is a double-precision 64-bit IEEE 754 floating point. . It’s range of beyond the scope.




Wednesday, December 1, 2010

Variable in java

The variable is a container which store a value. Other words we can say that a variable can store some meaningful value, we do initialize when they are declared, it’s called field. A field can assign default value if they are not explicitly initialized.

Example : int velo = 3;

int speed = 40;

int km = 10;

Java have four types variable

1. Class variable; - A variable can initialize with static modifier that is called Class variable. i.e. private static String name; // It is Class variable.

2. Instance variable: - All non static fields which declare without static modifier this is called Instance variable. i.e. private int count =0; // It is instance variable

3. Local variable: - Objects store its state and field, a method store a temporary variable similar to declaring local variable in a method it said to be local variable. i.e. (int countEmp =0;)

4. Parameters :- Parameters of method is called Parameter, it signature is add(int count, float sum)

Here method of add have two parameter its type is int and float .

Thursday, November 25, 2010

Array in JAVA

Array is a group data which store same variable data type, Array has fixed length. It is declare syntax is below.

Example : int[] aArray = new int[10];

Here int[] aArray is an array declaration.

new int[10] means an array length is fixed and its allocate memory for 10 elements type int. Each item of array is called element. Array element accessed at index.

package example;

public class ExampleArray {

public static void main(String[] args) {

// Declare array of integer

int[] aArrays;

// Allocate memory for 10 Integer

aArrays = new int[10];

aArrays[0] = 100; // initialize first element

aArrays[1] = 101; // initialize second element

aArrays[2] = 102;

aArrays[3] = 103;

aArrays[4] = 104; // initialize fifth element

aArrays[5] = 105;

aArrays[6] = 106;

aArrays[7] = 107;

aArrays[8] = 108;

aArrays[9] = 109; // initialize 10th element

System.out.println("Element at 1st index is : "+aArrays[0]);

// -----

System.out.println("Element at 2nd index is : "+aArrays[2]);

// -----

System.out.println("Element at 9th index is : "+aArrays[9]);

}

}

Output is :

Element at 1st index is : 100

Element at 2nd index is : 102

Element at 9th index is : 109