Kamis, 29 April 2010

OOP ( Object Oriented Programming )

Inheritance (Pewarisan)
OOP (Object Oriented Programming) atau Pemprograman berorientasi objek adalah suatu cara baru dalam berfikir serta berlogika dalam menghadapi masalah-masalah yang akan dicoba diatasi dengan bantuan komputer. OOP, tidak seperti pendahulunya (Pemprograman Terstruktur), mencoba melihat permasalahan lewat pengamatan dunia nyata dimana setiap objek adalah entitas tunggal yang memiliki kombinasi struktur data dan fungsi tertentu. Ini kontras dengan pemprograman terstruktur dimana struktur data dan fungsi didefinisikan secara terpisah dan tidak berhubungan secara erat.

http://www.digituck.com/konsep-oop-object-oriented-programming.html
http://www.digituck.com/konsep-oop-object-oriented-programming.html

Class Dan Atribut

      Class adalah cetak biru atau rancangan dari sebuah object. Object adalah instansiasi atau perwujudan dari sebuah class, sebuah class dapat di instan menjadi satu atau lebih object, sebuah class tidak dapat digunakan untuk menyimpan, memanipulasi dan menampilkan data. Kita bisa melakukan proces-proses tersebut terhadap object.

      Didalam class terdapat atribut atribut. Atribut adalah segala sesuatu yang berhubungan dengan objek. Misal didalam class rumah yang didalamnya  maka atribut atributnya adalah kayunya, warnanya, pintunya, teras, luas dll. 

     Sedangkan Metohode adalah hal hal yang dapat dilakukan oleh class, dalam pemrogaman prosecural methode dapat diartikan sebagai f uction atau procedure. dalam contoh class rumah diatas, methodenya adalah tempat bernaung.

Package

      Dalam rangka manajemen class, class-class yang secara fungsional sejenis bisa dikelompokkan kedalam suatu wadah atau kedalam suatu folder. ada banyak package bawaan java, sepeti java.awt, javax.swing. java.io, java.util. Namun demikian user diperbolehkan untuk membuat package sendiri. isi dari sebuah packagw adalah semua file class yang siap pakai. 

Hak Akses

      OOP memberikan beberapa tipe hak akses terhadap variable (atribut), methode bahkan class. Tipe tipe hak akses tersebut yaitu Public, Private, atau Protected. Ini adalah salah satu bagian terpenting dari OOP, sehingga programmer yang hendak belajar OOP wajib memahami konsep pengaksesan data ini dalam OOP.



Inheritance ( Pewarisan )

 Inheritance (Pewarisan) merupakan salah satu dari tiga konsep dasar OOP. Konsep inheritance ini mengadopsi dunia riil dimana suatu entitas/obyek dapat mempunyai entitas/obyek turunan. Dengan konsep inheritance, sebuah class dapat mempunyai class turunan. Suatu class yang mempunyai class turunan dinamakan parent class atau base class. Sedangkan class turunan itu sendiri seringkali disebut subclass atau child class.
Dalam dunia riil, suatu entitas turunan dapat mewarisi apa-apa yang dipunyai dari entitas induknya. Misalkan saja antara entitas Bapak dan entitas Anak. Entitas anak dapat mewarisi apa-apa yang dipunyai oleh entitas Bapaknya. Demikian juga dalam konsep inheritance, suatu subclass dapat mewarisi apa-apa yang dipunyai oleh parent class. Inilah yang terpenting dari konsep inheritance.
Karena suatu subclass dapat mewarisi apa-apa yang dipunyai oleh parent class-nya, maka member dari suatu subclass adalah terdiri dari apa-apa yang ia punyai dan juga apa-apa yang ia warisi dari class parent-nya. Kesimpulannya, boleh dikatakan bahwa suatu subclass adalah tidak lain hanya memperluas (extend) parent class-nya.


Polimorfisme

 melalui pengiriman pesan. Tidak bergantung kepada pemanggilan subrutin, bahasa orientasi objek dapat mengirim pesan; metode tertentu yang berhubungan dengan sebuah pengiriman pesan tergantung kepada objek tertentu di mana pesa tersebut dikirim. Contohnya, bila sebuah burung menerima pesan “gerak cepat”, dia akan menggerakan sayapnya dan terbang. Bila seekor singa menerima pesan yang sama, dia akan menggerakkan kakinya dan berlari. Keduanya menjawab sebuah pesan yang sama, namun yang sesuai dengan kemampuan hewan tersebut. Ini disebut polimorfisme karena sebuah variabel tungal dalam program dapat memegang berbagai jenis objek yang berbeda selagi program berjalan, dan teks program yang sama dapat memanggil beberapa metode yang berbeda di saat yang berbeda dalam pemanggilan yang sama. Hal ini berlawanan dengan bahasa fungsional yang mencapai polimorfisme melalui penggunaan fungsi kelas-pertama.

Array
Array adalah sebuah struktur dari sebuah data yang menyimpan value dari data yang memiliki tipe data yang sama. Setiap value bisa kita akses melalui angka-angka index. index suatu array dimulai dari indeks 0 bukan 1, masih bingung?? begini…
Sebagai contoh jika A merupakan sebuah array dengan tipe integer, maka notasi dari array A adalah: A[n], dengan n merupakan angka index dari array tersebut misal:
A[0]=100
A[1]=200
A[2]=300
A[3]=400
dari array di atas bisa kita simpulkan: array A di atas memiliki tipe data integer(bisa dilihat dari value yang ada), memiliki panjang array 4, array dengan indeks ke-0 memiliki value 100, indeks ke-1 bervalue:200, indeks ke-2 bervalue:300…dst… mudah bukan…:)

Kamis, 22 April 2010

UML Class Diagram

A Class diagram is a visual representation of an application showing its classes and the relationships between those classes. When you open a Class diagram, the IDE displays a specific selection of UML element icons in the Modeling Palette. Using the Class diagram model, you describe the static structure of the elements in your application. The IDE lets you graphically create diagrams that contain classes. The classes are arranged in hierarchies that share common structure and behavior and are associated with other classes.


  • Using Class Diagrams

    Classes define the attributes that are carried by each element instance and the operations that each element performs or undergoes. When representing a class in a UML model, you can do the following tasks:
  • Create the element representing the class
  • Name the class
  • Define class attributes
  • Define class operations
  • Depict links and associations
  • Add documentation
The following sections describe how to create a simple Class diagram for a hypothetical banking application. After you have completed the step-by-step procedures outlined in the tutorial, your Class diagram should look similar to Figure 1. The diagram is shown for reference only. Use the instructions beginning in the next section to draw your Class diagram.
If a procedure is labeled as optional, it is included to illustrate an additional task or alternate way of doing a task. You do not need to do the optional procedures to complete this tutorial successfully.

Creating Class Diagrams and Adding Elements

This tutorial uses the UML project that is created in the UML: Creating Use Case Diagrams tutorial. If you have not completed the use case tutorial, you can create a directory on your local system named UMLTutorial and create a Java-Platform Model UML project called UMLTutorialProject in that directory and proceed with this tutorial.
This section illustrates some basic UML tasks provided by UML to model a simple application using a Class diagram. This section contains the following procedures:

To Create the Class Diagram

  1. If necessary, start the IDE and open the previously created UMLTutorialProject project.
  2. In the Projects window, expand the UMLTutorialProject node and right-click the Model node.
  3. Choose Add >Diagram from the pop-up menu. The New Wizard opens and displays the Create New Diagram page.
  4. In the Diagram Type list, select Class Diagram.
  5. In the Diagram Name field, type ClassDiagram.
  6. Leave the default setting in the Namespace field and click Finish. The IDE does the following:
    • Creates the ClassDiagram node under the Model node
    • Displays the new diagram in the Diagram editor (the diagram is empty at this point)
    • Opens the Modeling Palette

To Add and Label Class Elements

  1. From the Basic section of the Modeling Palette, select the Class icon image of Class icon. and click once in the Diagram editor. This action places a Class element on the diagram.
  2. Deselect the icon by right-clicking anywhere in the Diagram Editor. Note: Each time that you select an icon, you can place multiple instances of that element in the Diagram editor by clicking more than once.
  3. If not already selected, select the newly added Class element by clicking it once.
  4. Type EntryStation and press Enter. The IDE does the following:
    • Labels the Class element with the name EntryStation
    • Creates a public operation named EntryStation()
    • Displays the Class properties in the Properties window
    • Adds a Class element with the name EntryStation under the Model node in the Projects window

To Add Attributes Using the Pop-Up Menu

Now that you have drawn and labeled the EntryStation element, you need to describe its attributes.
  1. If it is not already selected, select the EntryStation element in the Diagram editor.
  2. Right-click the word Attributes and choose Insert Attribute from the pop-up menu. A one-line editor opens and displays the following information:
    visibility type name[ranges]=initialValue{name=value}
  3. Type stationID and press Enter. An attribute named stationID of type int appears on the EntryStation class, and the following operations are created on the class: public int getStationID() public void setStationID(int val) Note that the get and set operations are created because you kept the default setting.

To Add Operations

  1. In the Diagram editor, Select the EntryStation Class element.
  2. Right-click the word Operations and choose Insert Operation from the pop-up menu. A one-line editor opens and displays the following information:
    visibility returnType name(parameter) {properties, ...}
  3. Type validateEntryStation and press Enter. The IDE creates a new operation.

(Optional) To Edit Attributes or Operations

When you double-click an attribute or an operation in a class, a combo box editor opens as shown in the following figure.
image of Screen capture showing Combo Box Editor for Attribute
As you click each part of the attribute or operation, the label for that part appears in bold type in the combo box. If applicable, the selected part of the operation or attribute has a drop-down list of values.
For example:
  1. Double-click the stationID attribute in the EntryStation class.
  2. Click the word private. Notice that the word visibility appears in bold type.
  3. Press CTRL + down arrow. A drop-down list opens that displays values that you can select for the visibility attribute.
  4. Select a new value from the drop-down list and press Enter.
    The attribute is updated with the new value.

    Note: You can also type a new value directly in the editor. If you do not see what you need in the drop-down list, use the right and left arrow keys to position your cursor and type the appropriate value.
  5. For this tutorial, use the value private and press Enter to close the editor.

To Add and Define the Remaining Classes

Now you need to add more classes to complete a simple banking application Class diagram. After you add the classes, label them and add attributes and operations as described below using the techniques that you have learned so far in this tutorial.
  1. From the Basic section of the Modeling Palette, select the Class icon image of Class icon and click five times in the Diagram editor to place the additional class elements as shown in the following figure.
    image of Screen capture of Class Diagram showing several unnamed elements
  2. Deselect the Class icon by right-clicking anywhere in Diagram editor.

    Note: You can select and drag the new class elements to arrange them as shown in the preceding diagram, so that you can see each one clearly in the diagram.
  3. Select the first unnamed Class element below the EntryStation element and name it ATM.
  4. With the ATM Class element still selected, add an attribute as follows:
    private float cashOnHand
  5. Add a second attribute to the ATM class and define it as follows:
    private float dispensed
      
    The attributes appear in the Class diagram.

    Note: As you add attributes and operations to the classes, the size of the Class elements increases. To improve the appearance of the diagram, move the Class elements as needed so that you can see each element clearly. When doing this, be careful to select the Class element and not an individual attribute or operation.
  6. Select the first Class element located below the ATM class and name it Consortium.
  7. Add an operation to the Consortium class. Adding operations is similar to adding attributes. Right-click on the word Operations and select Insert Operations.
  8. Type validateAccountInfo and press Enter.
    The IDE creates the new operation as follows:
    public void validateAccountInfo()
  9. Select the Class element to the right of the ATM class and label it CashierStation.
  10. Add two operations for this class as follows:
    public int verifyCard()
    
    public float verifyAmountAvailable()
      
  11. Label the two remaining Class elements Branch and User.
    For the User class there are no attributes or operations.
  12. For the Branch class, add an attribute as follows:
    private char connected  

Generating and Editing Java Source Code

This section shows how you can generate Java source code for the Class diagram you just created in the previous section. Once you create your UML model, you can generate the corresponding Java source code for it. If you modify your model, you can re-generate the Java source code using the UML's Generate Code feature.

This section contains the following procedures:

To Generate Java Source Code

You can model your Java application and then generate the corresponding Java source code for your model. To generate the source code you need to create a Java project and use it to store the generated code for your UML project.
  1. From the main menu, choose File > New Project and then do the following:
    1. Under Categories, select General.
    2. Under Projects, select Java Application.
    3. Click Next.
  2. In the Project Name field, type JavaPrj1.
  3. For the Project Location, click Browse and select the directory UMLTutorial.
  4. Clear the Set as Main Project and Create Main Class checkboxes.
  5. Click Finish.
    A progress dialog box appears. When your JavaPrj1 project is created, it appears in the Projects window.
  6. In the Projects window, right-click the UMLTutorialProject node and choose Generate Code from the pop-up menu.
  7. In the Generate Code dialog box, click Browse.
  8. In the Choose the Target Source Folder dialog box, locate the source folder for the JavaPrj1 project you just created.
    For example: C:\Temp\UMLTutorial\JavPrj1\src
  9. Click Open.
  10. Back in the Generate Code dialog box, unselect the Backup Existing Source Files checkbox and click OK.
  11. In the Authorize UML Project Save dialog box, click Yes.
    The IDE generates the Java source code and the Output window displays the progress of the code generation process.
  12. In the Projects window, expand the JavaPrj1 > Source Package node and double-click on the node.
    Notice the folder contains the Java source files that are similarly named as the class elements you created in the ClassDiagram model.

To Add Attributes Using the Java Source Editor

Now, add another attribute to the EntryStation using the Source Editor. After modifying the Java source file, you will use the Reverse Engineer feature to reflect the change in the corresponding UML model element.
  1. In the Projects window, expand the UMLTutorialProject node and the Model node if necessary.
  2. Right-click the EntryStation node and choose Navigate To Source from the pop-up menu.
    A Source Editor tab labeled EntryStation.java appears and displays the source code for the class.
  3. In the Source Editor, type the following code below the first attribute:
    private boolean isOperating
      
  4. Press Ctrl-S to save your change.
  5. Right-click in the Source Editor and choose Reverse Engineer from the pop-up menu.
    The Reverse Engineer dialog box appears.
  6. Select Use Existing UML Project in the Reverse Engineer dialog box and choose UMLTutorialProject as the target project.
  7. Click OK to invoke the reverse engineering process.
  8. In the Model Element Overwrite Authorization dialog box, click Yes to overwrite the existing model for the EntryStation class.
  9. Click the ClassDiagram tab to return focus to the Diagram editor.
    The isOperating attribute appears in the EntryStation class element.

    Note: Click the Fit to Window button image of Fit To Window icon. on the Diagram toolbar to center the diagram in the window. This button allows you to adjust the Zoom level if necessary to read labels or to make room to place more elements on the diagram.

Finding Diagram Elements

You can use several methods to quickly locate objects in a diagram or in the Projects window. All attributes and operations that you add to the Class elements in the Diagram editor appear in the Projects window. The attributes are represented by the attribute icon image of Attribute icon. The operations are represented by the operation icon image of Operation icon.

To Locate Objects in the Diagram Editor From the Projects Window

  • In the Projects window, double-click the EntryStation node.
    In the Diagram editor, the EntryStation Class element is selected and centered.

To Locate Objects in the Projects Window From the Diagram Editor

  1. In the Diagram editor, select the Consortium class and right-click it.
  2. Choose Select in Model from the pop-up menu.
    In the Projects window, the name of the target object is highlighted.

Documenting Classes and Diagrams

There are three different ways to choose from when you want to enter descriptive documentation for classes, attributes, operations, and diagrams. This section contains the following procedures that describe these three methods:

To Use the UML Documentation Window

  1. (Optional) If the UML Documentation window is not visible, choose Windows > Other > UML Documentation.
  2. In the Diagram editor, select the EntryStation class element.
  3. Click inside the UML Documentation window text box.
  4. Type Describes the actions of the EntryStation class.
  5. Right-click the EntryStation class element and select Generate Code from the pop-up menu.
  6. In the Generate Code dialog box, click OK.
  7. In the Authorize UML Project Save dialog box, click Yes.
    The new Java code is generated.
  8. Click the EntryStation.java Source Editor tab.
    You see that the text you typed in Documentation window has been added to the EntryStation.java source file.

To Document Attributes Using the Properties Window

  1. Click the ClassDiagram tab to return the focus to the Diagram editor.
  2. In the Projects window, expand the EntryStation node.
  3. Select the attribute node labeled private boolean isOperating.
    The properties for the attribute appear in the UML Properties window.
  4. In the Properties window, click the ellipsis button (...) on the Documentation row.
    A custom editor opens as shown in the following figure.
    image of Screen capture showing custom editor with OK and Cancel buttons
  5. Type the text Maintains if EntryStation is operating and click OK.
  6. In the Diagram editor, right-click the EntryStation class element and select Generate Code from the pop-up menu.
  7. In the Generate Code dialog box, click OK.
  8. In the Authorize UML Project Save dialog box, click Yes.
    The new Java code is generated.
  9. Click the Source Editor tab for EntryStation.java.
    You see the typed text in the source code right above the isOperating attribute.

To Document Diagrams Using the Comment Icon

You can add notes that describe specific information for a selected element in the diagram by using the Comment icon located on the Modeling Palette.
  1. Click the ClassDiagram tab to return to the Diagram editor.
  2. From the Comments section of the Modeling Palette, select the Comment icon image of Comment icon.
  3. Click once to the right and just above the CashierStation element.
    A Comment element is placed on the diagram.
  4. Deselect the icon by right-clicking anywhere in the Diagram editor.
  5. While the comment element is selected, type Cashier stations have limited funds and press Enter.
    The text appears in the Comment element.
  6. From the Comments section of the Modeling Palette, select the Link Comment icon image of Link Comment icon.
  7. Click once inside CashierStation and click again inside the Comment element.
    A link snaps into place between the Comment element and the Class element.
  8. Deselect the icon by right-clicking anywhere in the Diagram editor.
  9. Repeat steps 2-8 to place and link a second Comment element on the diagram for the Branch Class element.
    Use the following text: A branch belongs to a Member Institution.

Depicting Links and Associations

An association describes a group of links that share common structure and common semantics. The UML functionality supports not only associations, but also multiplicity of associations. Multiplicity specifies how many instances of one class can relate to a single instance of an associated class. Multiplicity constrains the numbers of related components. This section contains the following procedures:

To Depict a Class Association

  1. From the Association section of the Modeling Palette, select the Aggregation icon image of Aggregation icon.
  2. Click inside the ATM element, and then click the Consortium element.
    A link is drawn between the two classes.
  3. Right-click anywhere in the Diagram editor to deselect the icon.
  4. Select the Aggregation link between ATM and Consortium.
    When the link is selected, the color changes to blue.
  5. Point the cursor near the middle of the selected line and right-click.
  6. Choose Labels > Link Name from the pop-up menu.
  7. Type AccountVerification in the Name field and press Enter.
    The link is labeled as shown in the following figure.
    image of Screen capture showing the labeled Aggregation link
  8. From the Association section of the Modeling Palette, select the Association icon image of Association icon and draw a link from CashierStation to Branch.
  9. Right-click anywhere in the Diagram editor to deselect the icon.

To Depict a Qualified Association

A qualified association relates two classes and a qualifier. The qualifier is a special attribute that reduces the effective multiplicity of an association. You depict a qualified association as a small box on the end of the association line near the class it qualifies.
The next step shows you how to create a qualified association between the ATM class and the Consortium class.
  • Right-click the Aggregation link where it joins the Consortium class and choose Show Qualifier. A qualifier attaches to the Consortium class element as shown in the following figure.
    image of Screen capture showing qualified associaton between ATM and Consortium classes

To Set Multiplicity for the Association

You want to set the multiplicity for this association. However, by default, these labels are hidden. Use the following steps to display the labels on the association link.
  1. Right-click the link between Consortium and ATM and choose Labels > Both End Multiplicities.
    The pop-up menu closes and the labels for the link appear.
  2. Right-click the small diamond at the upper portion of the aggregation link (near the ATM element) and choose Set Multiplicity.

    Note: If you have difficulty making the correct pop-up menu appear, lengthen the aggregate arrow by moving the Consortium element farther away from the ATM element.
  3. Select 1..*.
    Notice that the lower portion of the link is labeled 1 as shown in the following figure.
    image of Screen capture showing labeled Aggregation Link with Multiplicities
  4. Follow a similar procedure and set the multiplicity for the Association link between CashierStation and Branch as shown in the following figure.
    image of Screen capture showing Association Link with Multiplicities

To Depict Generalization and Inheritance

Generalization is the relationship between a class and one or more refined versions of this class. The class being refined is named the superclass and each refined version is named the subclass. The attributes and operations of the superclass can be exhibited in its subclasses, as a result, each subclass is said to inherit the features of the superclass. You can organize classes by using inheritance to share common structure. A generalization link means that a class can inherit an array of attributes and operations from the parent class.
  1. From the Basic section of the Modeling Palette, select the Generalization icon image of Generalization icon.
  2. Click inside the ATM class element, and then click the EntryStation class element.
    The Select Methods to Redefine dialog box appears.
  3. Select the checkbox next to the ATM node to select all the methods and click OK.
    The selected methods are added to the ATM class element and a generalization link snaps in place between the two class elements.
  4. Draw another generalization link by first clicking CashierStation, and then clicking EntryStation.
  5. In the Select methods to Redefine dialog box, select the checkbox next to the CashierStation node to select all methods and click OK.
  6. Right-click anywhere in the Diagram editor to deselect the Generalization icon.
  7. Your finished diagram should look similar to the following figure.
    image of Screen capture showing the completed Class Diagram

Creating Dependency Diagrams

Using UML, you can create a diagram that shows all the dependencies for a classifier. The following types of relationships are depicted in the Dependency diagram:
  • Generalizations
  • Associations
  • Implementations
  • Operations with parameters of a given class type
Now, create a dependency diagram for the ATM class diagram.
  1. In the Projects window, right-click the ATM node.
  2. Select Generate Dependency Diagram from the pop-up menu.
    A dependency diagram named ATM Dependencies is created and opened in the Diagram editor as shown in the following figure.
    image of Screen capture showing the Dependency Diagram

Saving Diagrams and Updating Java Source Files

Do the following steps to save your completed diagrams and regenerate the Java source files for your diagrams. Do the following:
  1. After you complete your diagram, right-click the ClassDiagram tab and choose Save Document from the pop-up menu.
    The menu closes and the Class diagram is saved.
  2. In the Projects window, right-click the UMLTutorialProject node and choose Generate Code from the pop-up menu.
  3. In the Generate Code dialog box, accept the default JavaPrj1 source folder location and backup the existing source files.
    Optionally, you can click Browse to locate and use another source folder.
  4. Click OK.
    The IDE generates the code and the Output window displays the progress of the code generation process. The Java source folder for the JavaPrj1 project should have been updated with the changes you made to your diagrams.

    Note: The source folder for the JavaPrj1 project may also include the backup files that were created if you selected the Backup Existing Source Files checkbox in the Generate Code dialog box and you chose to use the same source folder. The backup files are similarly named as the original files, but the file extensions contain numbers. For example, the ATM.java has a backup file named ATM.java1.

Summary

In this tutorial, you learned how to create a class diagram for a simple banking application. You learned how to perform the following tasks:
  • Create a Class diagram
  • Use the icons from the Modeling Palette to add elements to the diagram
  • Add and define attributes and operations on the class elements
  • Document the diagrams and the diagram elements
  • Depict links and associations between the class elements
  • Create a Dependency diagram
  • Generate the Java source code files for the diagrams
  • Save your diagram



Minggu, 18 April 2010

istilah dalam basis data relasional

Istilah-Istilah Pada Model Relasional Beberapa istilah penting pada model data relasional adalah;
1. Entitas/Entity
2. Attibut
3. Data Value
4. Domain
5. Rekord/Tupel
6. Tabel/Relasi
7. Derajat (Degree) Relasi
8. Kardinalitas Relasi

1. Entitas/Entity, merupakan sesuatu yang memiliki nilai/data yang, seperti orang, tempat kejadian atau konsep yang data/informasinya perlu direkam dalam lingkup pembicaraan tertentu. Pada lingkup pembicaraan Sistem Informasi Administrasi Kemahasiswaan maka entitas yang tampil diantaranya adalah Mahasiswa, Dosen, Matakuliah, transaksi KRS dan absensi kelas.
2. Attribut, merupakan sebutan untuk mewakili suatu nilai/value dari suatu entitas. Seorang mahasisawa dapat memiliki attribut-attribut seperti NIM, Nama, Jenis Kelamin, Alamat dll. Attribut dapat juga disebut sebagai Data Elemen, Data Field atau Data Item.
3. Data Value, merupakan nilai/data aktual yang disimpan pada tiap attribut. Attribut Nama Mahasiswa menunjukkan tempat data nama seorang mahasiswa disimpan, sedangkan ‘ABU YAZID’, ‘ATO’ILLAH’, ‘DIAN AJI SUKMA’ dan ‘RETNO PALUPI’, merupakan data value dari attribut Nama Mahasiswa.
4. Domain, merupakan kumpulan/himpunan nilai-nilai yang diijinkan dan dapat dimiliki oleh suatu attribut. Setiap attribut pada basisdata relasional didefinisikan pada suatu domain. Domain tidak hanya sekedar tipe data, yang terkadang beberapa domain memiliki tipe data yang sama. Masing-masing attribut dalam suatu tabel/relasi dapat berbeda, namun sebaliknya, dapat juga dua atau lebih attribut mempunyai domain yang sama.
5. Rekord/Tupel, merupakan himpunan attribut yang saling berkaitan secara logik untuk menginformasikan tentang suatu entitas secara lengkap.
6. Tabel/Relasi, merupakan kumpulan rekord/tupel sejenis yang mempunyai panjang elemen dan attribut yang sama, namun dapat memiliki data value yang berbeda-beda. Kumpulan rekord/tupel yang sejenis tersebut didefinisikan dalam sebuah nama yang uniq untuk menunjukkan keberadaannya yang berbeda (baik nama maupun kegunaannya) dengan tabel-tabel/relasi-relasi lain dalam sebuah database.
7. Derajat (Degree) Relasi, merupakan jumlah attribut yang dimiliki oleh sebuah tabel/relasi
8. Kardinalitas Relasi, merupakan jumlah rekord/tupel yang dimiliki oleh sebuah tabel/relasi. Kardinalitas relasi otomatis berubah ketika tupel relasi ditambah atau dihapus. Nilai kardinalitas adalah kondisi suatu saat dari sabuah tabel/relasi.

Minggu, 11 April 2010

CANDIDATE KEY & ALTERNATIFE KEY

• Candidate Key
adalah super key yang himpunan bagian yang sebenarnya tidak ada yang menjadi super key juga. Berdasarkan contoh super key sebelumnya, candidate key yang mungkin adalah (NPM) dan (Nama, Alamat). Atribut Nama dan Alamat dapat dijadikan candidate key jika kombinasi keduanya bisa menjadi pengidentifikasi yang unik untuk sebuah tabel relasi.
contohnya :
File Pegawai berisi attribute:
· No Induk Pegawai (NIP)
· No KTP
· Nama
· Tempat Lahir
· Tanggal Lahir
· Alamat
· Kota

Kunci kandidat disini adalah:
· No Induk Pegawai (NIP), karena unik tidak mungkin ganda.
· No KTP, karena unik tidak mungkin ganda.
· Nama, sering dipakai sebagai kunci pencarian namun tidak dapat dikatakan kunci karena sering seseorang punya nama yang sama.
· Nama + Tanggal lahir, mungkin dapat dipakai sebagai kunci karena kemungkinan sangat kecil seseorang punya nama sama yang lahir pada hari yang sama.
· Nama + tempat lahir + tanggal lahir, dapat dipakai sebagai kunci Alamat, kota (bukan kunci).



• Alternate Key
adalah candidate key yang tidak dipilih sebagai primary key. Berdasarkan contoh candidate key sebelumnya, alternate key adalah (Nama, Alamat).



definisi DDL dan DML

*Data Definition Language (DDL) adalah bahasa dalam DBMS yang digunakan untuk membuat atau mendefinisikan obyek-obyek di dalam database. Secara umum digunakan untuk membuat obyek table dan view.
Secara khusus, di dalam DBMS tertentu digunakan untuk :
Membuat trigger
Membuat stored procedure
Membuat database, index, rule, schema dll (tergantung DBMS)
Contoh sintaks DDL :
DDL untuk tabel
* Untuk membuat tabel
CREATE TABLE (
|
)
* Untuk menghapus tabel
DROP TABLE
* Untuk memodifikasi tabel
- Menambahkan kolom baru
ALTER TABLE
ADD
- Menghapus kolom
ALTER TABLE
DROP
DDL untuk view
* Untuk membuat view
CREATE VIEW AS
* Untuk menghapus view
DROP VIEW
DDL untuk trigger
* Untuk membuat trigger
CREATE TRIGGER ON TABLE ON [DELETE] [,] [INSERT] [,] [UPDATE] AS
Objek basis data yang termasuk DDL adalah :
Tabel
Tabel terdiri dari field-field atau kolom-kolom dengan tipe data tertentu dan baris-baris yang digunakan sebagai penyimpan data.
Contoh : tabel Mahasiswa yang terdiri dari field-field : NRP (primary key), Nama, Alamat, JenisKel, NIPDosen (foreign key dari field NIP pada tabel Dosen).
Sintaks DDLnya :
CREATE TABLE Mahasiswa (
NRP char(8),
Nama varchar(20) NOT NULL,
Alamat varchar(30),
JenisKel char(1) DEFAULT “L”,
NIPDosen char(9),
PRIMARY KEY (NRP),
CONSTRAINT fk_mhs_dosen FOREIGN KEY (NIPDosen) REFERENCES Dosen(NIP) ON DELETE RESTRICT ON UPDATE CASCADE ON INSERT RESTRICT
);
View
View adalah tabel bayangan. Tidak menyimpan data secara fisik. Biasanya berupa hasil query dari tabel-tabel dalam sebuah database.
Contoh : view MahasiswaPria yang diambil dari tabel Mahasiswa di mana field JenisKel = “L”.
Sintaks DDLnya :
CREATE VIEW MahasiswaPria AS
SELECT * FROM Mahasiswa WHERE JenisKel = “L”


Trigger
Trigger adalah sebuah obyek dalam database yang berupa prosedur yang merespon setiap kali terdapat proses modifikasi (insert, update, dan delete) pada tabel.
Contoh : trigger tLogUbahNilai melakukan penambahan data pada tabel LogHistoris untuk setiap penambahan / update data pada tabel PesertaKul.
Sintaks DDLnya :
CREATE TRIGGER tLogUbahNilai ON TABLE PesertaKul
FOR UPDATE, INSERT AS
INSERT INTO LogHistoris (Tanggal, Proses) VALUES (getdate(), ‘Terjadi proses perubahan data nilai’)


*DML ( Data Manipulation Language) yaitu bahasa / perintah sql yang
digunakan untuk memanipulasi data seperti menampilkan data, menambah /
mengisi data, mengubah data dan menghapus data. Yang termasuk dalam perintah
ini adalah SELECT, INSERT, UPDATE, dan DELETE.
- INSERT
Perintah INSERT digunakan untuk menambahkan / menginputkan data ke
dalam tabel. Sintak secara umum adalah seperti berikut:
INSERT INTO Nama_Tabel(Daftar_Kolom) VALUES (Daftar_Nilai)
Yang perlu diperhatikan dalam perintah insert adalah sebagai berikut:
a. Jika tipe data yang akan diinputkan berupa string / karakter (Char,
Varchar, Text) maka gunakan tanda petik tunggal untuk mengapit data
tersebut.
b. Jika tipe data numeric / angka (Int, Numeric, Decimal) maka tidak boleh
menggunakan tanda petik tunggal.
c. Jika tipe data Datetime maka gunakan petik tunggal dengan format ‘mmdd-
yyyy’ (untuk setting tanggal Inggris/Amerika) atau ‘yyyy-mm-dd’.
d. Jika data autonumber maka data tidak perlu diisi.
Ada beberapa cara penulisan sintak insert, yaitu:
a. Tanpa menyebutkan daftar kolom, dengan catatan data yang diinputkan
harus terurut sesuai dengan urutan kolom dan semua data harus diisi
kecuali untuk kolom autonumber data tidak diisikan sebab data akan diisi
oleh system secara otomatis.
Contoh INSERT tanpa menyebutkan daftar kolom:
INSERT INTO Jurusan VALUES ('S1TI','Teknik Informatika Strata
1','Ir. Abbas Ali Pangera')
b. Menyebuatkan daftar kolom yang akan diisi saja datanya dengan catatan
jumlah kolom harus sama dengan jumlah data yang akan diisikan.
Contoh:
INSERT INTO Kelas (Kode_Kelas, Nama_Kelas) VALUES ('S1TI3E','
S1 TI Semester 3')
-SELECT
Perintah SELECT digunakan untuk menampilkan data dalam tabel. Secara
umun sintaknya adalah sebagai berikut:
SELECT Daftar_Kolom FROM Nama_Tabel WHERE Kondisi ORDER
BY Kolom
Contoh :
a. Menampilkan Data Mahasiswa
SELECT * FROM Mahasiswa
Ket : Tanda asterisk ( * ) menandakan bahwa semua kolom akan
ditampilkan
b. Menampilkan Nim dan Nama Mahasiswa
SELECT NIM, Nama FROM Mahasiswa
6.3.1 SELECT Dengan Klausa WHERE
WHERE digunakan untuk membatasi hasil SELECT yang ditampilkan
sesuai kondisi yang ditentukan. Secara umum sintaknya adalah sebagai berikut:
SELECT Daftar_Kolom FROM Nama_Tabel WHERE Kondisi
a. Operator relasional
OPERATOR ARTINYA
= Sama dengan
> Lebih dari
< Kurang dari <= Lebih dari atau sama dengan >= Kurang dari atau sama dengan
<> Tidak sama dengan
Contoh :
SELECT * FROM Mahasiswa WHERE NIM =’06.11.0123’
b. Operator logika
_ OR
_ Akan menampilkan data jika salah satu atau lebih syarat
terpenuhi.
Contoh :
SELECT * FROM Mahasiswa WHERE NIM = ’06.11.0123’ OR
Agama = ‘Islam’
_ AND
_ Akan menampilkan data jika semua syarat terpenuhi.
Contoh :
SELECT * FROM Mahasiswa WHERE NIM = ’06.11.0123’ AND
Agama = ‘Islam’
_ NOT
_ Akan menampilkan data yang sebaliknya (negasinya)
Contoh :
SELECT * FROM Mahasiswa WHERE NOT NIM = ’06.11.0123’
- DISTINCT
DISTINCT digunakan untuk menampilkan data secara unik artinya data
yang sama hanya akan ditampilkan satu kali saja.
Sintak : SELECT DISTINCT [Kolom] FROM Table
Contoh : SELECT DISTINCT NIM FROM KRS
- BETWEEN Dan NOT BETWEEN
BETWEEN digunakan untuk menampilkan data dalam nilai range tertentu
(diantaranya). BETWEEN hanya perlaku pada bilangan dan tanggal.
Sintak : SELECT [Daftar_Kolom] FROM Table WHERE Kondisi BETWEEN
Batas_Bawah AND Batas_Bawah
Contoh : SELECT * FROM Penagajar WHERE Id_Mengajar BETWEEN 2
AND 5
- TOP
TOP digunakan untuk menampilkan beberapa data paling atas dari hasil
perintah SELECT.
Sintak : SELECT TOP n [Daftar_Kolom] FROM Table
Contoh : SELECT TOP 3 * FROM Mahasiswa
- IS NULL Dan IS NOT NULL
IS NULL digunakan untuk menampilkan data – data null (Tidak Memiliki
Data). Null berbeda dengan 0 atau spasi.
Contoh : SELECT * FROM Mahasiswa WHERE Alamat IS NULL
- ORDER BY
ORDER BY digunakan untuk mengurutkan data dari hasil perintah
SELECT. Pengurutan dapat dilakukan secara Ascending (ASC) atau Descending
(DESC). Default-nya adalah secara ascending.
Contoh : SELECT * FROM Mahasiswa ORDER BY NIM ASC
- KOLOM ALIAS
Nama kolom hasil dari perintah SELECT dapat diganti namanya.
Sintak : SELECT kolom1 AS Alias1, Kolom2 AS Alias2,…dst FROM Table
Contoh : SELECT NIM AS Nim_MHS, Nama AS Nama_MHS, Gender AS
[Jenis Kelamin] FROM Mahasiswa