learn java
according to visual interaktif
dr. -ing. eueung mulyana
table of contents
picture list
table list
messenger
1 language java and oop
1.1 language component java
1.2 deeper with class and object
1.3 package and class book
2 identifications greenfoot
2.1 background
2.2 visual interface
2.3 direct interaction
2.4 scenario plane
2.5 scenario turtlegraphics
2.6 scenario ants
2.7 scenario lunarlander
3 modifications and programming
3.1 class wombat
3.2 class wombatworld
3.3 method turnrandom() for class wombat
3.4 change display / image
3.5 class modification wombatworld
3.6 add new class
4 scenarioes plane and turtlegrahics
4.1 scenario plane
4.2 several scenario modifications plane
4.3 scenario turtlegraphics
4.4 several scenario modifications turtlegraphics
5 scenarioes ants and lunarlander
5.1 scenario ants
5.2 scenario modification ants
5.3 scenario lunarlander
5.4 scenario modification lunarlander
6 furthermore with greenfoot framework and greenfoot fire
6.1 facilities exports to applet and application
6.2 make new scenario . . ”
41 pictures 3.1142 pictures 3.12
43 pictures 3.13
44 pictures 3.14
45 pictures 3.1546 pictures 3.1647 pictures 3.17
47 pictures 4.148 pictures 4.249 pictures 4.350 pictures 4.451 pictures 4.552 pictures 4.653 pictures 4.754 pictures 4.8
55 pictures 4.9
use load picture book greenfoot
execution sampe result populate() after class picture
wombat and leaf changed to pass “set image. . . ”
image that ( and ) used in scenario
wombats along with the size
method character change act() uses
setdirection() modified
execution sampe result randompopulate()
add class rock
display example randompopulate() with add
object rock
aeroplane object movement direction and constant interpretation speed
relokasi object controlknob may be
aeroplane movement direction control passes object position controlknob
inkonsistensi control in beginning condition
regulate object vertical position controlknob
aeroplane movement behaviour example after modification
description several variables in method drawpen()
experiment result display example with a few method
in class turtle
result display example that formed by object spiralturtle
with different parameter
56 pictures 4.10 result display example that formed by object circleturtle
with different parameter
57 pictures 4.11
58 pictures 4.1259 pictures 4.13
60 pictures 4.14
61 pictures 4.15
62 pictures 5.1
63 pictures
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)
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)
Langganan:
Postingan (Atom)