Difference between revisions of "Java: Berbagai Istilah"

From OnnoWiki
Jump to navigation Jump to search
 
(4 intermediate revisions by the same user not shown)
Line 52: Line 52:
 
===Instance Variable===
 
===Instance Variable===
  
Instance variable is associated with an instance of the class (also called object). Access works over these objects.
+
Instance variable berhubungan / berasosiasi dengan instance dari class (juga dikenal sebagai object). Akses bekerja menggunakan object ini.
  
Instance variables can have any access control and can be marked final or transisient. Instance variables marked as final can not be changed after assigned to a value.
+
Instance variable dapat mempunyai access control dan tanda akhir atau transisi. Instance variable yang bertanda final tidak dapat di ubah sesudah di berikan sebuah nilai.
  
 
===Local Variable===
 
===Local Variable===
  
Local (stack) variable declarations cannot have access modifiers.
+
Local (stack) variabel tidak punya access modifier.
  
final is the only modifier available to local variables
+
final adalah satu-satunya modifier yang tersedia bagi local variabel.
 +
 
 +
Local variabel tidak mempunyai nilai default, oleh karenanya harus di inisialisasi sebelum digunakan.
  
Local variables don't get default values, so they must be initialized before use.
 
  
 
==Modifier==
 
==Modifier==
Line 68: Line 69:
 
===Access Modifier===
 
===Access Modifier===
  
There are three access modifiers: public, protected and private
+
Ada tiga access modifier: public, protected dan private
  
There are four access levels: public, protected, default and private
+
Ada empat level access: public, protected, default dan private
  
protected and default are similar. Only difference: A protected class can get accessed from the package and sub-classes outside the package while a default class can get only access via the same package protected = package plus kids
+
protected dan default adalah sama. Perbedaannya: sebuah protected class dapat di akses daro package dan sub-class di luar package sedang default class hanya dapat di akses melalui package yang sama. Jadi protected = package plus anak-anak class lainnya.
  
 
===Other modifiers===
 
===Other modifiers===
  
final methods: cannot be overwritten in a subclass
+
final method: tidak dapat di overwritten di subclass
  
abstractmethod: no method body
+
abstractmethod: tanpa badan method
  
synchronized method: threat safe, can be final and have any access control
+
synchronized method: bermain aman, dapat merupakan final dan mempunyai akses ke access control.
  
native methods: platform dependent code, apply only to methods
+
native method: code untuk platform tertentu, hanya  berlaku untuk method.
  
stricttp: class or method
+
stricttp: class atau method
  
 
==Interface==
 
==Interface==
Line 98: Line 99:
 
Interfaces can have constants which are always implicitly public, static and final.
 
Interfaces can have constants which are always implicitly public, static and final.
  
==Additional Definitions==
+
==Definisi Lanjut==
  
 
===Method===
 
===Method===
  
A method can trigger a certain action.
+
Sebuah method dapat memicu aksi tertentu.
  
 
Method with var-args: Method declares a parameter which accepts from zero to many arguments (syntax: type .. name;) A method can only have one var-args parameter and this must be last parameter in the method.
 
Method with var-args: Method declares a parameter which accepts from zero to many arguments (syntax: type .. name;) A method can only have one var-args parameter and this must be last parameter in the method.

Latest revision as of 09:57, 9 September 2011

Sumber: http://www.vogella.de/articles/JavaTerminology/article.html

Tulisan ini menjelaskan berbagai istilah yang sering digunakan di Java

Sangat penting bagi kita untuk mengerti struktur dasar dari package, class dan object.

Dasar: Package, Class dan Object

Package

Java mengelompokan class menjadi package-package fungsional. Semua class di java.lang akan secara automatis tersedia di java program.

Tujuan utama akan adanya package adalah untuk menghindari adanya tabrakan nama. Seorang programmer mungkin akan membuat java class Test. Programmer lain mungkin akan membuat class dengan nama yang sama. Dengan menggunakan package kita dapat memberitahukan system class yang mana yang akan di panggil. Contoh, jika programme1 meletakan class Test di package programmer1 dan programme2 meletakan class-nya di package "xmlreader" maka kita dapat mengakses class ke dua tersebut melalui xmlreader.Test.

Salah satu alasan penting lainnya adalah melalui package kita dapat mengelompokan class kita menjadi unit logik.

Class

Defini: Sebuah template yang menjelaskan data dan perilaku yang berkaitkan dengan instance dari class tersebut.

Data dari dengan sebuah class di simpan dalam variable; perilaku dari sebuah class atau object di implementasikan dalam method.

Semua dapat di lihat dalam blueprint dari object.

Sebuah class

  • Di definisikan dengan kata kunci class.
  • Di mulai dengan huruf besar.
  • Badan class di tutup dengan {}

Object

Definisi: Sebuah object adalah sebuah instance dari sebuah class.

Sebuah class dapat dilihat sebagai blueprint untuk data dan perilaku sebuah object. Object itu sendiri adalah elemen sesungguhnya yang mempunyai data dan dapat melakukan tindakan.

Contoh, class mungkin blueprint dari sebuah car, sebuah object adalah car yang sesungguhnya.

Setiap object merupakan kembangan implisit dari Object "Object" dan memperoleh keterangan dari method yang di definisikan oleh class Object.

o.equals(o1) adalah Object sama dengan o1
o.getClass() memberikan class dari o
o.hashCode() memberikan ID yang unik o.toString()


Variable

Variable

Varabel dapat berupa sebuah primitive atau sebuah variable referensi. Sebuah variabel primitive berisi nilai sedang variabel referensi bersisi referensi (pointer) ke sebuah object. Oleh karena itu, jika kita ingin membandingkan dua variable referensi maka kita harus membandingkan bahwa kedua-nya menunjuk pada object yang sama. Untuk membandingkan object gunakan object1.equals(object2).

Instance Variable

Instance variable berhubungan / berasosiasi dengan instance dari class (juga dikenal sebagai object). Akses bekerja menggunakan object ini.

Instance variable dapat mempunyai access control dan tanda akhir atau transisi. Instance variable yang bertanda final tidak dapat di ubah sesudah di berikan sebuah nilai.

Local Variable

Local (stack) variabel tidak punya access modifier.

final adalah satu-satunya modifier yang tersedia bagi local variabel.

Local variabel tidak mempunyai nilai default, oleh karenanya harus di inisialisasi sebelum digunakan.


Modifier

Access Modifier

Ada tiga access modifier: public, protected dan private

Ada empat level access: public, protected, default dan private

protected dan default adalah sama. Perbedaannya: sebuah protected class dapat di akses daro package dan sub-class di luar package sedang default class hanya dapat di akses melalui package yang sama. Jadi protected = package plus anak-anak class lainnya.

Other modifiers

final method: tidak dapat di overwritten di subclass

abstractmethod: tanpa badan method

synchronized method: bermain aman, dapat merupakan final dan mempunyai akses ke access control.

native method: code untuk platform tertentu, hanya berlaku untuk method.

stricttp: class atau method

Interface

Within java an interface is a type just as a class is a type. Like a class an interface defines methods.

Interfaces are contracts for what a class can do but they say nothing about the way in which the class must do it.

Interfaces are per default public and abstract – explicit declaration of these modifiers is optional.

An interface can also have abstract methods, no concrete methods are allowed.

Interfaces can have constants which are always implicitly public, static and final.

Definisi Lanjut

Method

Sebuah method dapat memicu aksi tertentu.

Method with var-args: Method declares a parameter which accepts from zero to many arguments (syntax: type .. name;) A method can only have one var-args parameter and this must be last parameter in the method.

Overwrite of a superclass method: A method must be of the exact same return parameter and the same arguments. Also the return parameter must be the same. Overload methods: An overloaded method is a method with the same name, but different arguments. The return type can not be used to overload a method.

Constructor

classname (Parameter p1, ..) {}

The constructor is always called if the class is created. If no explicit constructor is defined the compiler adds implicitly a constructor. If the class is sub-classed then the constructor of the super class is always implicitly called.

Class method or class variable

Class method / variable is associated with the class and not the instance. To refer to it use the classname and the class method / variable together with a period ("."). Example System.out.println("Hello World"). The runtime environment associates one class variable for a class no matter how many instances exists.

Class method / variant does exists once for all instances. They are indicated with the word static. If a variable should be existing for all instances and be non-changeable (=CONSTANT) then also the word final is used.

The static method runs without any instance of the class. Does not depend on instance (non-static) variables. Can not use the this object or an instance variables.

The static variable is the same of all instances of the class (global variable)

Abstract class

If a class has one method which only contain the declaration of the method but not the implementation then this class is abstract and can not be initialized. Sub-classes need then to define the methods except if they also declared as abstract. method abstract double returnDouble();

If a class contains an abstract method it also needs to get defined as abstract.


Referensi

Pranala Menarik