pemrograman berorientasi object · packages java. kumpulan class pada java. java virtual machine....
Post on 19-Oct-2020
27 Views
Preview:
TRANSCRIPT
10/15/2012
1
PEMROGRAMAN BERORIENTASI OBJECTPEMROGRAMAN BERORIENTASI OBJECTINTRODUCTION TO JAVA PROGRAMMING
I Made Suartana, S.Kom, M.Kom
A QUICK TOUR OF JAVA
Materi: Java Platform Java Platform. Elements dasar bahasa pemrograman Java:
Variabel Nama konstata Flow Control
Class dan Object Class dan Object. Bagaimana mengcompile dan melakukan
exekusi program java(menggunakan JCreator).
10/15/2012
2
INTRO JAVA
Arsitektur Java Dibagi atas Tiga Bagian, Yaitu:E i J (J2EE)Enterprise Java (J2EE)
Standar Java (J2SE)Micro Java (J2ME)
JAVA PLATFORM
Java Platform terdiri dari 3 komponen: 1. Bahasa Pemrograman Java. 2. Packages Java . 3. Java Virtual Machine (JVM) / JRE.
Bahasa Pemrograman Java – Disingkat Java. Sintaksis.
Packages Java. Kumpulan class pada java.
Java Virtual Machine. Virtual mesin sebagai environmen untuk menjalankan
program java (JRE).
10/15/2012
3
PACKAGES IN JAVA
PACKAGES JAVA
java.applet java.io Applet class
java.awt Windows, buttons, mouse,
etc.
java.awt.image image processing
System.out.print
java.lang length method for arrays;
exceptions
java.net sockets
java.awt.peer GUI toolkit
java.util System.getProperty
See http://java.sun.com/reference/api/for the current APIs
10/15/2012
4
EXAMPLE JAVA PACKAGE -1-
7
EXAMPLE JAVA PACKAGE -2-
8
10/15/2012
5
EXAMPLE JAVA PACKAGE -3-
9
GETTING STARTED
10/15/2012
6
LET’S START WITH “HELLO WORLD”
public class Hello{
/*** Program Java My first */public static void main( String[] args ){
//menampilkan String Hello world pada layarSystem.out.println(“Hello world”);
}}
Java programs are built from classes.
JAVA COMMENTS
Comments in Code – enable to write descriptive text.
/* Comment type 1 – This text is ignored by the compiler */ / Comment type 1 This text is ignored by the compiler / // Comment type 2 – The text up to the end of line is ignored
/** Documentation comment is extracted by javadoc tool */
10/15/2012
7
JAVA IDENTIFIER
Identifier (variabel, method, class, )C i i Case sensitive
Start withAlphabet “_” “$”
keyword Java
JAVA KEYWORDSabstract boolean breakbyte case catchchar class constcontinue default docontinue default dodouble else extendsfinal finally floatfor goto ifimplements import instanceofint interface longnative new packageprivate protected publicreturn short staticsuper switch synchronizedthis throw throwstransient try voidvolatile while
10/15/2012
8
VARIABLES
Java has build-in primitives to support boolean, character, integer and floating-point values.----------------------------------------------------------------------------------------- boolean either true or false boolean b = true;------------------------------------------------------------------------------------------ char 16-bit Unicode 1.1 character char ch = ‘J’;------------------------------------------------------------------------------------------ byte 8-bit integer (signed) byte bt = 127; short 16-bit integer (signed) short sh = 32767; int 32-bit integer (signed) int i = 2147483647; long 64-bit integer (signed) long l = 9223372036854775807L;------------------------------------------------------------------------------------------- float 32-bit floating-point (IEEE 754-1985) float f = 1.0f; double 64-bit floating-point (IEEE 754-1985) double d = 1.e-1;-------------------------------------------------------------------------------------------
NUMERIC OPERATORS IN JAVAPrec Operator Description Example1 ++ Increment by 1(or 1.0) k++1 -- Decrement by 1(or 1.0) k--ec e e by (o . )1 + Unary plus +value1 - Unary minus -value2 * Multiplication x * y2 / Division x / y2 % Modulo x % y3 + Addition x + y3 - Subtraction x - y5 < Less than x < y5 > Greater than x > y5 <= Less than/equal x <= y5 >= Greater than/equal x >= y6 == Equals (identical values) x == y6 != Is not equal to x != y13 op= op assignment(+ =, - =, *=, etc) x += y
10/15/2012
9
BITWISE AND LOGIC OPERATORSPrec Operator Type Description Example1 ~ Integral Unary bitwise complement ~x1 ! Logical Unary logical complement !b1 ! Logical Unary logical complement !b4 << Integral Left shift x << 24 >> Integral Right shift (keep sign) x >> 54 >>> Integral Right shift (zero fill) x >>> 35 instanceof Obj type Tests class membership o instanceof X6 == Object Equals (same object) x == y6 != Object Unequal (different object) x != y7 & Integral Bitwise AND x & y7 & Logical Logical AND b1 & b28 ^ Integral Bitwise XOR x ^ y8 ^ Logical Logical XOR b1 ^ b29 | Integral Bitwise OR x | y9 | Logical Logical OR b1 | b2
BITWISE AND LOGIC OPERATORS (CONTINUED)
Prec Operator Type Description Examp.10 && Logical Logical AND (conditional) b && c11 || Logical Logical OR (conditional) b1 || b211 || Logical Logical OR (conditional) b1 || b212 ?: Logical Conditional (ternary) b ? x : y13 = Variable,any Assignment x = 113 <<= Binary Left shift with assignment x <<= 213 >>= Binary Right shift with assignment x =>> 313 >>>= Binary Right shift, zero fill, assign x =>> 413 &= Binary Bitwise AND with assign x &= y13 &= Logical Logical AND with assign b1 &=b213 |= Binary Bitwise OR with assignment x |= y13 |= Logical Logical OR with assignment b1 |=b213 ^= Binary Bitwise XOR with assignment x ^= y13 ^= Logical Logical XOR with assignment b1 ^=b2
10/15/2012
10
FLOW OF CONTROL
Flow of control is the term used for describing which statements are executed in a programwhich statements are executed in a program.
Flow statements are: if – else for switch do – while While
IF, IF-ELSE, IF ELSE –IF ELSE1. if (boolean-expression) {
statements; }}
2. if (boolean-expression) { statements;
} else {statements;
}
3. if (boolean-expression) { statements;
} else if (boolean-expresion ) {statements;
} else {statements;
}
10/15/2012
11
FOR STATEMENT
A for statement should have the following form:for (initialization; condition; update) {for (initialization; condition; update) {
statements;}
Ex:for (k = 0 flag; k < 10 && flag; k++ ) {for (k 0, flag; k < 10 && flag; k++ ) {
. . .}
WHILE, DO - WHILE STATEMENTS
while, do-while and for control looping are classified as iteration statements.
while (condition) {statements;
}
do {statements;
} while (condition);
10/15/2012
12
SWITCH
The switch is classified as a selection statement.
switch (integral-selector) { case integral-value1:
statements; break; default:
statements; } .
EXECUTION
10/15/2012
13
TOOLS
Java Standard Edition Editor
Text Editor Integrated Development Environment (IDE)
This course use
CREATE CLASS
10/15/2012
14
EXAMPLE
Class Kalkulator
top related