Dasar pemograman java
Upcoming SlideShare
Loading in...5
×
 

Dasar pemograman java

on

  • 1,051 views

 

Statistics

Views

Total Views
1,051
Views on SlideShare
1,043
Embed Views
8

Actions

Likes
1
Downloads
78
Comments
0

2 Embeds 8

http://ziehand.blogspot.com 7
http://feeds.feedburner.com 1

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • true, false, null reserved word const, goto is keyword not in used

Dasar pemograman java Dasar pemograman java Presentation Transcript

  • Dasar Pemrograman Java My Collections 06/22/11 Ah. Handoyo Collections
  • Topik:
    • Menggunakan komentar di file sumber.
    • Membedakan antara valid dan invalid identifiers.
    • Mengetahui Java technology keywords.
    • Mengetahui 8 tipe data primitif.
    • Mendefinisikan literal value untuk tipe data numerik dan tekstual.
    • Mendefinisikan primitive dan reference variable.
    • Mendeklarasikan variabel bertipe class.
    • Membuat obyek dengan menggunakan operator new.
    • Mengetahui nilai inisialisasi default.
    • State-state pada saat assign nilai pada variabel bertipe class
    • Garbage collection
    06/22/11 Ah. Handoyo Collections
  • Source Files
    • Java source files must end with the .java extension.
    • Three top-level elements known as compilation units may appear in a file.
      • Package Declaration
      • Import Statements
      • Class Definitions
    06/22/11 Ah. Handoyo Collections
  • 06/22/11 Ah. Handoyo Collections
  • Class Fundamentals: main method
    • The main() Method
    • public static void main(String[] args)
    •      Public : method main() dapat diakses oleh apa saja, termasuk java
    • technology interpreter.
    •      Static : keyword ini berfungsi untuk memberi tahu kompiler bahwa
    • method main bisa langsung digunakan dalam contex class yang
    • bersangkutan. Untuk mengeksekusi/menjalankan method yang
    • bertipe static, tidak diperlukan instance nya.
    •       Void : menunjukkan bahwa method main() tidak mengembalikan nilai
    •       Main : merupakan nama method utama dari program java
    •       String [] a rgs : Menyatakan bahwa method main() menerima single
    • parameter yaitu args yang bertipe array. Digunakan pada saat memasukkan
    • parameter pada saat menjalankan program.
    • Contoh: java TestGreeting args[0] args[1] …
    06/22/11 Ah. Handoyo Collections
  • 06/22/11 Ah. Handoyo Collections
  • 06/22/11 Ah. Handoyo Collections
  • 06/22/11 Ah. Handoyo Collections
  • Java Keywords and Reserved Words
    • are considered as reserved keywords
    • may not be used as identifiers.
    • None of the reserved words have a capital letters
    • 2 keyword that are reserved in Java but which are not used : const dan goto
    06/22/11 Ah. Handoyo Collections
  • 06/22/11 Ah. Handoyo Collections
  • 06/22/11 Ah. Handoyo Collections
  • 06/22/11 Ah. Handoyo Collections
  • Public class TestDog{ public static void main(String args[]){ Dog d = new Dog(); d.setWeight(42); System.out.println(“Dog d’s weight is “ + d.getWeight() ); } } 06/22/11 Ah. Handoyo Collections
    • Modifier : public, private, protected, dan default
    • Constructor adalah bukan method , sehingga tidak punya return values dan tidak diturunkan/diwariskan
    06/22/11 Ah. Handoyo Collections
    • Note:
    • Jika kita mendeklarasikan constructor pada suatu class yang sebelumnya tidak mempunyai constructor, maka default constructor class tersebut akan hilang.
    • Sehingga bila constructor yang kita buat tadi mempunyai argumen, kemudian kita buat obyek dengan cara new Xxx(), proses kompilasi akan menghasilkan error.
    06/22/11 Ah. Handoyo Collections
  • Identifiers
    • Nama yang digunakan oleh programer untuk memberi nama pada variable, class, atau method.
    • Can start with a Unicode letter, underscore (_), or dollar sign ($)
    • Are case-sensitive and have no maximum length
    • Examples:
      • 1. foobar // legal
      • 2. BIGinterface // legal: embedded keywords
      • 3. // are OK.
      • 4. $incomeAfterExpenses // legal
      • 5. 3_node5 // illegal: starts with a digit
      • 6. !theCase // illegal: must start with
      • 7. // letter, $, or _
    06/22/11 Ah. Handoyo Collections
  • Primitive Types
    • The Java programming language defines eight primitive types:
      • Logical - boolean
      • Textual - char
      • Integral - byte , short , int , and long
      • Floating - double and float
    06/22/11 Ah. Handoyo Collections
  • Primitive Types 06/22/11 Ah. Handoyo Collections
  • Literals
    • is a value
    • cannot appear on the left side of assignments.
    06/22/11 Ah. Handoyo Collections
  • Logical literals
    • The boolean data type has two literals, true and false .
    • For example, the statement:
      • 1. boolean isBig = true;
      • 2. boolean isLittle = false;
    Note: boolean literal tidak boleh berharga 0 atau 1 06/22/11 Ah. Handoyo Collections
  • Textual Literals
    • The range: 0 ~ 2 16 - 1.
    • Java characters are in Unicode character (16-bit encoding).
    06/22/11 Ah. Handoyo Collections
  • char literals
    • Expressed by enclosing the desired character in single quotes (‘ ‘).
    • Example:
    • char c = ‘w’;
    • Express as a Unicode value specified using four hexadecimal digits, preceded by u
    • Example:
    • char c = ‘u 0063 ’;
    06/22/11 Ah. Handoyo Collections
  • char literals
    • Special Characters
      • ‘ n’ for new line
      • ‘ r’ for return
      • ‘ t’ for tab
      • ‘ b’ for backspace
      • ‘ f’ for formfeed
      • ‘ ’’ for single quote
      • ‘ ”’ for double quote
      • ‘ ’ for backslash
    06/22/11 Ah. Handoyo Collections
  • String literals
    • Is not a primitive data type; it is a class
    • Represent sequences of characters
    • Has its literal enclosed in double quotes (“ ”)
    • Example:
    • String s = “Characters in strings are 16-bit Unicode.”;
    • String s = “Good Morning !! n”;
    06/22/11 Ah. Handoyo Collections
  • Integral literals  byte, short, int and long
    • Expressed in decimal, octal, or hexadecimal.
      • 2 The decimal value is 2
      • 077 The leading 0 indicates an octal value
      • 0xBAAC The leading 0x indicates a
      • hexadecimal value
    • Specify a long integer by putting an 'L' or 'l' after the number.
      • 'L' is preferred as it cannot be confused with the digit '1'.
      • Example:
        • long x = 25L;
    • Has a default type of int
    06/22/11 Ah. Handoyo Collections
  • Integral 06/22/11 Ah. Handoyo Collections
  • Floating-Point literals
    • Floating point literal includes either a decimal point or one of the following:
      • E or e (add exponential value)
      • F or f (float)
      • D or d (double)
      • 3.14  a simple floating point value (a double)
      • 6.02E23  a large floating point value
      • 2.718F  a simple float size value
      • 123.4E306D  a large double value
    • Default is double
    • Specify a float by putting an ‘F' or ‘f' after the number.
      • Example:
        • float x = 2.5F;
    06/22/11 Ah. Handoyo Collections
  • Note:
    • Semua tipe data primitif yang numerik (selain char dan boolean) adalah signed .
    06/22/11 Ah. Handoyo Collections
  • Member Variables Initialization 06/22/11 Ah. Handoyo Collections
  • Reference variable 06/22/11 Ah. Handoyo Collections
  • 06/22/11 Ah. Handoyo Collections
  • 06/22/11 Ah. Handoyo Collections
  • 06/22/11 Ah. Handoyo Collections
  • 06/22/11 Ah. Handoyo Collections
  • 06/22/11 Ah. Handoyo Collections
  • 06/22/11 Ah. Handoyo Collections
  • 06/22/11 Ah. Handoyo Collections
  • Argument Passing
    • The Java programming language only passes arguments by value
    • When an object instance is passed as an argument to a method, the value of the argument is a reference to the object
    • The contents of the object can be changed in the called method, but the object reference is never changed
    06/22/11 Ah. Handoyo Collections
  • > java PassTest Int value is: 11 MyDate: 22-7-1964 MyDate: 4-7-1964 06/22/11 Ah. Handoyo Collections
  • 06/22/11 Ah. Handoyo Collections
  • 06/22/11 Ah. Handoyo Collections
  • Garbage Collection
    • Allocated memory that is no longer needed should be deallocated
    • In other languages, deallocation is the programmer's responsibility
    • The Java programming language provides a system-level thread to track memory allocation
    • Garbage collection:
      • Checks for and frees memory no longer needed
      • Is done automatically
      • Can vary dramatically across JVM implementations
    • “ run the garbage collector.”
      • System.gc() and Runtime.gc()
    06/22/11 Ah. Handoyo Collections
  • http://java.sun.com/javaee/5/docs/api/ http://java.sun.com/j2se/1.5.0/docs/api/ 06/22/11 Ah. Handoyo Collections