OOP

this time , I'll explain Object Oriented Programming Concept(OOP Concept), structure class, package, access control, inheritance, polymorphism, and little example of array and how to manipulate it.

OOP
The Object Oriented paradigms suggest we should model instructions in a computer program with the data they manipulate and store these as components together. One advantage of doing this is we get reusable software components. OOP paradigm aims to help overcome these problems by helping with the analysis and design tasks during the initial software development phase and by ensuring software is robust and maintanable.

Abstraction and encapsulation are fundamental principles of Object Oriented approach to software development. Abstraction allow us to consider complex ideas while ignoring irrelevant detail that would confuse us. Encapsulation allow us to focus on what something does without considering the complexities of how it works. Others fundamental principles of Object Orientation are Generalization/specialization ( which allow us to make use of inherintace ) and Polymorphism.
Generalisation allow us to consider general categories of objects which have common properties and then define specialised sub classes that inherit properties of the general categories. Polymorphism which is the ability to interact with a object as it's generalized category regardless of it's more specialised category.

Class
Class are the basic components of any object oriented software system. A class should typically be recognizable by a non-programmer domain even if associated with exixting problems and code contained in a class should be relatively independent

Package
A package is not just a visual representation of a group of classes instead a 'package' is a directory containing a group of related classes(and interfaces). Package allow us to provide a level of organisation and encapsulation above that of individual classes.

Access Control
OOP provides several types of access rights to the variable (attributes), the method and even class. Type of access rights, which are Public, Private, or Protected. This is one of the most important part of OOP, so that programmers who want to learn OOP required to understand the concept of accessing this data in OOP.

Inheritance
Giving the properties of a major class(super-class) to the other classes(sub-class) that have similiar properties. The main class is usually a genereal/global, while the sub-classes are specific/special

Polymorphism
The ablity of variables to be used as reference or a reference object of different type, and automatically can call the method specific to each type

Array
Substansial program would require a lot of variables. We can only declare variables one by one. Suppose that we need five variables with integer types, we can declared with int x,y,z.
This is still very small, what if we need 500 variables?
This would be inefficient. Thus we need or used arrays.
But before we decide to used array, we must also examine whether the data will be accessed sequentially? if yes then we can use arrays,  but the data will not be accessed sequentially, should declare itself .
 int [] arr = new int[100];

Source : OOP

UML Tutorial - Class Diagrams

Hey Fella, one week ago I learned about UML on OOP-II Class..now I try to share my knowledge about how to make class diagrams with Java also used NetBeans Apps for support this tutorial. Previously I given example that you can see here about class diagram. After you see my previous post, is it diffuclt or easy to realize that ? well, I'll lead you how accurate steps to make class diagram and if you don't mind, please follow these instructions :

  • First of all, installed NetBeans on your computer/PC whatever the series but I used NetBeans 6.7 for this time

  • After the main page of NetBeans appears, create new project: File > New Project 

  • Choose project, categories: Java , projects: Java Application and click Next

  • Fill Project Name:( DependOnYou ) ; Project Location: ( where the project will be saved actually on NetBeans Projects  Folder ) ; click Finish

  • This is the result after create JavaUML Project:

  • Then, create UML project (File > New  Project); Choose Project Categories: UML; Projects: Java-Platform Model; click Next
 
  • Fill Project Name: ( DependOnYou ); Project Location: ( where the preiviously main project JavaUML folder have been stored ); click Finish
  •  Choose Class Diagram and Fill Diagram Name as you want, click Finish
  •  Now lets make your own Class Diagram as you want. You can use all of pallete to helping you to do on the right side

  • Start from package, why package ? we need package diagrams to show the general architecture of a large system. Even modest systems can be broken down into a few basic components i.e packages. You can double click to give the name of package or fill Name section on Properties

  • Now, you can create class and choose how the relationship between the package. After that, you can create an attributes with right-click on class and you can decide where's field will be the primary key in every class (on properties)

  • This is the result if you combine class and the relationship like my previous post

  • The last steps, to see whether the class diagrams that we make is correct then, you can do Run Main Project (F6)


just share to all my friends, downloaded in here :

class diagram

this is one of simple implementation from Unified Model Language (UML) which is had four of the most common diagrams (class diagrams, object diagrams, sequence diagrams and package diagrams) but now, focus with simple example of class diagram !

e.g :





relational database

A relational database usually described by using two-dimensional tables consisting of rows and columns which data can be accessed or reassembled in many different ways without having to reorganize the database tables. Hence, a relational database matches data by using common characteristics found within the data set. The resulting groups of data are organized and are much easier for many people to understand. After the original database creation, a new data category can be added without requiring that all existing applications be modified. 
Several terms in the relational database include the following:


Relation   : A table consisting of several columns and several rows.
Attribute  : Column names in a relation
Tuple        : Rows in a relation ,represents an object and information 
                   about that object. Object are typically physical objects or 
                   concepts


Domain     : A valid set of value for one or more attributes
Degree      : The number of attributes in a relation
Cardinality: The number of tuples in a relation

Now, wanna show you  one of example which is how's the term and describing a relational database

 

Candidate Key and Alternate Key

Konsep dasar sistem basis data mengenal adanya Atribut/field, Record, File, Basis Data dan Key. Key merupakan Elemen Record yang digunakan untuk menemukan Record tersebut pada waktu akses.
Macam-macam key :

  • Primary Key
  • Secondary Key
  • Candidate Key
  • Alternate Key
  • Composite Key
  • Foreign Key
Namun pada kesempatan kali ini akan dibahas mengenai Candidate dan Alternate key berikut dengan contohnya


Candidate Key :
sebuah atau sekumpulan atribut minimum yang secara unik mengidentifikasi sebuah tuple dalam sebuah relasi
contoh
No. KTP dan No. Sim untuk mengidentifikasi entitas orang


Alternate Key :
kunci calon yang tidak dipilih sebagai kunci primer.
Setiap atribut dari candidate key yang tidak terpilih sebagai primary key akan dinamakan alternate key. Pada contoh sebelumnya bila untuk primary key dipilih No. KTP maka alternate key nya adalah No. Sim 

source : Candidate & Alternate Key

Data Modification Language (DML)

Statement DML adalah perintah-perintah yang digunakan untuk
mengoperasikan atau memanipulasi isi database.
SQL menyediakan 4 perintah DML yaitu Select, insert, update, dan
delete.

INSERT
Syntax : INSERT INTO nama_table [(nama_kolom,..)] VALUES
(data1,...);
Contoh : INSERT INTO MKUL VALUES (”KK222”,”BERKAS
Akses”,2);
Atau
INSERT INTO MKUL (KDMK,MTKUL,SKS) VALUES
(”KK222”,”BERKAS Akses”,2);
UPDATE
Syntax : UPDATE nama_tabel SET nama_kolom=ekspresi
WHERE kondisi;

Contoh :
1. Ubah alamat menjadi depok untuk mahasiswa yang memiliki
NPM ”12100748”
UPDATE MHS SET Alamat=”Depok” WHERE
NPM=”12100748”;
2. Ubah nilai mid dengan menambahkan nilai 10 untuk kode
mata kuliah ”KK021”
UPDATE NILAI SET MID+10 WHERE KDMK=”KK021”;

DELETE
Syntax : DELETE FROM nama_table [WHERE kondisi];
Contoh : DELETE FROM NILAI WHERE NPM=”12100748” AND
KDMK=”KK021’;

SELECT
Syntax : SELECT [(DISTINCT)] nama_kolom
FROM nama_table
[WHERE kondisi]
[GROUP BY nama_kolom]
[HAVING kondisi]
[ORDER BY nama_kolom [ASC/DESC]];
Contoh:
Satu table (simple query)

  • Tampilkan semua data mahasiswa
SELECT NPM,Nama,Alamat,Kota FROM MHS;
atau SELECT * FROM MHS;Tampilkan mata kuliah yang SKSnya 2
SELECT MTKUL FROM MKUL WHERE SKS=2;
  • Tampilkan semua data nilai untuk yang memperoleh nilai mid
sekurang-kurangnya 60 atau nilai final diatas 75
SELECT * FROM NILAI WHERE MID>=60 OR FINAL>75;
  • Tampilkan npm, kode mata kuliah dan nilai mid untuk nilai mid
antara 70 sampai dengan 100
SELECT NPM,KDMK,MID FROM NILAI WHERE BETWEEN 70 AND
100;
  • Tampilkan nama mahasiswa yang diawali denga huruf ”P”
SELECT Nama FROM MHS WHERE Nama LIKE ”P%”;
  • Tampilkan nama mahasiswa untuk nama mahasiswa yang tidak mengandung unsur huruf ”a”
SELECT Nama FROM MHS WHERE Nama NOT LIKE ”%a%”;
  • Tampilkan nama mahasiswa untuk nama mahasiswa yang karakter keduanya huruf ”u”SELECT Nama FROM MHS WHERE Nama LIKE ”_U%”;

  • Tampilkan alamat mahasiswa, dimana alamat yang sama hanyaditampilkan satu kali saja
SELECT DISTINCT Alamat FROM MHS;
  • Tampilkan semua data mahasiswa dengan nama terurut dari ”z”ke ”a”
SELECT * FROM MHS ORDER BY Nama DESC;
  • Tampilkan alamat dan jumlah mahasiswa yang bertempat tinggaldialamat tersebut
SELECT Alamat, COUNT(*) FROM MHS GROUP BY Alamat;
  • Tampilkan alamat dan jumlah mahasiswa yang bertempat tinggalpada alamat yang jumlahnya lebih dari 1
SELECT Alamat, COUNT (*) FROM MHS GROUP BY ALAMAT
HAVING COUNT (*) > 1;
  • Tampilkan nilai mid tertinggi dan terendah untuk mata kuliah”KD132”
SELECT MAX(MID), MIN(MID) FROM NILAI WHERE KDMK=”KD
132”;
  • Tampilkan rata-rata dan jumlah nilai final mata kuliah ”KD132”
SELECT AVG(FINAL), SUM(FINAL) FROM NILAI WHERE
KDMK=”KD132”;
Contoh lebih dari 1 tabel
1. Tampilkan nama mahasiswa yang mempunyai nilai mid < 60
SELECT NAMA FROM MHS WHERE NPM IN
(SELECT NPM FROM NILAI WHERE MID < 60);
JOIN : penggabungan kolom
SELECT NAMA FROM MHS, NILAI
WHERE MHS.NPM = NILAI.NPM AND NILAI.MID < 60;

2. Tampilkan nama mahasiswa yang mengambil mata kuliah SIM
SELECT NAMA FROM MHS WHERE NPM IN
(SELECT NPM FROM NILAI WHERE KDMK IN
(SELECT KDMK FROM MKUL WHERE MTKUL = ”SIM”));
JOIN : penggabungan kolom
SELECT NAMA FROM MHS, NILAI, MKUL
WHERE MKUL.MTKUL = ”SIM” AND
NILAI.KDMK = MKUL.KDMK AND MHS.NPM = NILAI.NPM;

3. Tampilkan nama mahsiswa yang tidak mengambil mata kuliah
”KK021”
SELECT NAMA FROM MHS WHERE NOT EXISTS
(SELECT * FROM NILAI WHERE NILAI.NPM = MHS.NPM AND
KDMK = ”KK021”);

4. Tampilkan npm mahasiswa yang bernama Budi atau yang
memiliki nilai final > 75
SELECT NPM FROM MHS WHERE NAMA = ”BUDI”
UNION SELECT NPM FROM NILAI WHER FINAL > 75;

source : DML

Data Definition Language

Data Definition Language (DDL) is the language of the DBMS (Database Management System) which is used to create or define the objects in the database. In other words, the DDL is used to define the framework of the database.  
Statement which is often used from DDL include the following :

  • Create database, drop database
  • Create table, drop table, alter table
  • Create view, drop view 
Implementation:


Create database :
Syntax : CREATE DATABASE db_name;
e.g : CREATE DATABASE sentra;

Create table :

Syntax : CREATE TABLE table_name
(column1_name, column1_type,
column2_name, column2_type,…);
e.g : CREATE TABLE MHS
(NRM char(8) not null,
Name char(25) not null,
Address char(30) not null);
Note :
Not null are optional.

Create view :

Syntax : CREATE VIEW view_name [(column1, column2,… )]
AS SELECT statement FROM table_name [WITH CHECK OPTION];
e.g : CREATE VIEW MHSv AS SELECT * FROM MHS;
Note :
View_name: a view which will be made.
Column: name attribute for the view.
Statement: attributes that will be selected from a database table.
Table_name: database table name.

Drop database :

Syntax : Drop database db_name;
e.g : Drop database sentra;

Drop table :

Syntax : Drop table table_name;
e.g : Drop table MHS;

Drop view :
Syntax : Drop view view_name;
e.g : Drop view MHSv;

Alter table : to change the table

Syntax : ALTER TABLE table_name
ADD (column_name_new type_column
[BEFORE column_name])
MODIFY (column_name _ previous type_column)
DROP (nama_kolom_lama type_kolom);
e.g : ALTER TABLE MHS ADD (PHONE number(15));

source : DDL