Академический Документы
Профессиональный Документы
Культура Документы
Pemrograman Java
Popular High-Level
Languages
Language Description
Ada Named for Ada Lovelace, who worked on mechanical general-purpose computers. The Ada
language was developed for the Department of Defense and is used mainly in defense projects.
BASIC Beginner’s All-purpose Symbolic Instruction Code. It was designed to be learned and used easily
by beginners.
C Developed at Bell Laboratories. C combines the power of an assembly language with the ease of
use and portability of a high-level language.
C++ C++ is an object-oriented language, based on C.
C# Pronounced “C Sharp.” It is a hybrid of Java and C++ and was developed by Microsoft.
COBOL COmmon Business Oriented Language. Used for business applications.
FORTRAN FORmula TRANslation. Popular for scientific and mathematical applications.
Java Developed by Sun Microsystems, now part of Oracle. It is widely used for developing platform-
independent Internet applications.
Pascal Named for Blaise Pascal, who pioneered calculating machines in the seventeenth century. It is a
simple, structured, general-purpose language primarily for teaching programming.
Python A simple general-purpose scripting language good for writing short programs.
Visual Visual Basic was developed by Microsoft and it enables the programmers to rapidly develop
Basic graphical user interfaces.
7
Apa itu Java
• Java merupakan bahasa pemrograman berorientasi objek dan lintas
platform yang dikembangkan oleh SUN Microsystem
Keunggulan java
• Java sebagai bahasa pemrograman memiliki berbagai keunggulan
antara lain:
1. mempunyai struktur yang sederhana (mirip C++)
2. object oriented
3. Multiplatform
4. secure
5. mendukung Distributed computing
6. mendukung Mission critical software
Terminologi
• Java Developers Kit (JDK)
merupakan kumpulan utilitas yang diperlukan untuk mengkompilasi
program java
• Java Software Development Kit (J2SDK)
merupakan gabungan dari JDK dan utilitas untuk menjalankan
program java pada PC
• Java API (Application Programming interface)
Merupakan kumpulan library pada Java yang menyediakan modul -
modul generik yang dibutuhkan dalam pengembangan program
JDK EDITIONS
• Java Card for smartcards.
• Java Platform, Micro Edition (Java ME) — targeting environments with
limited resources.
• Java Platform, Standard Edition (Java SE) — targeting workstation
environments.
• Java Platform, Enterprise Edition (Java EE) — targeting large
distributed enterprise or Internet environments.
JAVA IDE TOOLS
• Forte by Sun MicroSystems
• Borland JBuilder
• Microsoft Visual J++
• Netbean
• IBM Visual Age for Java
A Simple Java Program
Listing 1.1
// This program prints Welcome to Java!
public class Welcome {
public static void main(String[] args) {
System.out.println("Welcome to Java!");
}
}
20
Creating, Compiling, and Running
Programs
21
animation
22
animation
23
animation
24
Anatomy program java
• Class name
• Main method
• Statements
• Statement terminator
• Reserved words
• Comments
• Blocks
25
Class Name
Setiap program java harus memiliki minimal sebuah class.
Setiap class memiliki nama, sesuai konvensi nama sebuah
class dimulai dengan huruf kapital
26
Main Method
Baris kedua menyatakan method main. Untuk menjalankan
class maka sebuah class harus mengandung method
bernama main. Method main merupakan titik awal
eksekusi program
27
Statement
Statement menyatakan aksi atau urutan aksi. statement
System.out.println("Welcome to Java!") dalam listing
program dibawah adalah untuk mencetak teks
"Welcome to Java!“.
28
Statement Terminator
setiap statement dalam java diakhiri dengan tanda titik koma (;).
29
Reserved words
Reserved words or keywords are words that have a
specific meaning to the compiler and cannot be used for
other purposes in the program. For example, when the
compiler sees the word class, it understands that the
word after class is the name for the class.
30
Blocks
31
Special Symbols
" " Opening and closing Enclosing a string (i.e., sequence of characters).
quotation marks
; Semicolon Marks the end of a statement.
32
{ …}
38
Comment bermanfaat
Include a summary at the beginning of the program to
explain what the program does, its key features, its
supporting data structures, and any unique techniques it
uses.
39
Convensi nama
• Choose meaningful and descriptive names.
• Class names:
• Capitalize the first letter of each word in the name. For
example, the class name ComputeExpression.
40
Proper Indentation and
Spacing
• Indentation
• Indent two spaces.
• Spacing
• Use blank line to separate segments of the code.
41
Block Styles
Use end-of-line style for braces.
End-of-line
style
public class Test {
public static void main(String[] args) {
System.out.println("Block Styles");
}
}
42
Programming Errors
• Syntax Errors
• Detected by the compiler
• Runtime Errors
• Causes the program to abort
• Logic Errors
• Produces incorrect result
43
Syntax Errors
public class ShowSyntaxErrors {
public static main(String[] args) {
System.out.println("Welcome to Java);
}
}
44
Runtime Errors
public class ShowRuntimeErrors {
public static void main(String[] args) {
System.out.println(1 / 0);
}
}
45
Logic Errors
46
Identifier
• Identifier merupakan penamaan untuk entitas program seperti
variabel, method, konstan, class, dan package
• Aturan pemberian nama identifier antara lain :
- Dapat terdiri dari huruf, angka, underscore(_) dan (&)
- Harus diawali dengan huruf, angka atau tanda &
- Tidak dapat menggunakan keyword yang digunakan dalam java
Variabel
• Variabel digunakan untuk menyimpan data dalam program dan isinya dapat berubah
sepanjang program berjalan
contoh:
radius = 1.0;
area = radius * radius * 3.14159;
System.out.println("The area is " + area + " for radius " + radius);
• Mendeklarasikan variabel
Syntax : datatype variableName;
contoh :
int x;
double radius;
char a;
Konstanta
• Konstanta mengandung data yang sifatnya permanen dan tidak dapat
diganti sepanjang program berjalan
• Syntax:
final datatype CONSTANTNAME = VALUE;
• String bukan merupakan tipe data primitif tapi reference karena string merupakan sebuah class dalam java
• Untuk menyambung string(String concat) digunakan operator +
cth: String message = "Welcome" + "to" + "Java";
Masukan melalui input dialog
Untuk mengkonversi string ke integer value gunakan method parse Int dari class integer, seperti berikut
int intValue = Integer.parseInt(intString);