Klik Di bawah Ini Untuk Mendapatkan Informasi Yang Akurat Dan Terbaik

Rabu, 22 April 2009

variable and data type

variable and type data
identifier

be name variable, class, interfaces, and periodi.

nomenclature condition identifier:
1. there is no long limitation
2. must be preced with hurus, underscore and or
3. doesn't be keyword java
4. has case sensitive



nomenclature convention


variable

be existing storage location mememori.

declaration variable:

;

variable in java consist of:
1. variable class that known as property that be state from object
2. code variable

data type
1. data type primitive that is: long(64), int(32), short(16), byte(8), double(64), float(32), char(16) iso unicode character set, boolean(8).
2. reference data type, be reference towards a object that be instance from a class.

example:

int covering; / type primitive
trilateral s = new segitiga(); / reference type


literal

be constant value that is seen according to explicit:
1. decimal: 1,2, 102. octal: 01,02,0123. hexadecimal: 0x1,0x2,0xa;
4. floating point: 10.2, 11.5, 99.99,7.12345e35. boolean: true, false
6. character: 'a, \ddd (character octal ddd), \uxxxx (character hexadecimal xxxx), \ double quotation mark, \” double double quotation mark, \\ sign \, \r carriage return, \n new lino, \f form feed, \t tab, \b backspace.


type casting

do data conversion from a type to type lai

(target type) value;

example:

double b = 10.5
int a = (int) b;

casting type floating point to integer will causes data truncation, and casting larger ones type to smaller menhasil modulus.

casting also wanted in distribution process towards data integer so much

example:

int a = 5;
double b = a/2; / the result 2, not 2.5

double b = (double) a/2; / the result 2.5

promotion type in java
java automatic will do promotion type in course of mathematics with guide as follows:
1. byte and short be promotinged to int
2. if one of [the] operand bertype long, so be promotinged to long
3. if one of [the] operand bertype float, so be promotinged to float
4. if one of [the] operand bertype double, so be promotinged to double
task:
1. make class mometercelcius that has behaviour (settemperature, getreamur, getkelvin, and getfahrenheit)
2. type program under this and run the result, what as according to your estimate, why?

class casting {
public static void main(string[ args)
{
int a = 99;
double b = a/2;
system. out. println(b);
}
}
3. type program under this and do compilation, what success, why?

class casting {
public static void main(string[ args)
{
byte a = 99;
byte b = a+2;
system. out. println(b);
}
}

inheritance

a mechanism to bequeath state and behaviour from superclass to subclass.

inheritance offered a concept reused in software development.

in our previous meeting has class trilateral, how if we want to develop a class segitigasamakaki, do we necessary design to return to begin from beginning? of course unnecessary, but enough develop it from class trilateral that there.

example:

class segitigakaki extends trilateral {
double getkeliling() {
return covering + math. sqrt(0.5*alas*alas + tinggi*tinggi);
}
}

class segitigakaki will inherit all state (covering and tall) and behaviour (setalas, settinggi, and getluas) from class trilateral, and we are enough add behaviour new getkelilng.
task:
1. develop class persegipanjang superly class square with add behaviour (getkeliling, and getdiagonal)

Tidak ada komentar:

Posting Komentar