Archive

Posts Tagged ‘Java’

Encode String to MD5 Encryption

April 27, 2009 azer89 1 comment

In cryptography, MD5 (Message-Digest algorithm 5) is a widely used cryptographic hash function with a 128-bit hash value. As an Internet standard (RFC 1321), MD5 has been employed in a wide variety of security applications, and is also commonly used to check the integrity of files. However, it has been shown that MD5 is not collision resistant; as such, MD5 is not suitable for applications like SSL certificates or digital signatures that rely on this property. An MD5 hash is typically expressed as a 32 digit hexadecimal number.


package md5;

import java.security.MessageDigest;

public class Main
{
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws Exception
    {
        String passwd = "azer89";

        MessageDigest m = MessageDigest.getInstance("MD5");
        m.update(passwd.getBytes("UTF8"));
        byte s[] = m.digest();
        String result = "";
        for (int i = 0; i < s.length; i++) {
          result += Integer.toHexString((0x000000ff & s[i]) | 0xffffff00).substring(6);
        }

        System.out.println(result);
    }

}

Source :
http://en.wikipedia.org/wiki/MD5

Categories: Java, Programming Tags: , ,

Simple Socket Program Using Java

April 22, 2009 azer89 1 comment

In this program, i’m using Netbeans 6.5 IDE

The client program presents a simple user interface and prompts for text input. When you click the “Send Message” button, the text is sent to the server program. The client program expects an echo from the server and prints the echo it receives on its standard output.

The server program presents a simple user interface, and when you click the “Receive Message” button, the text received from the client is displayed.

Here’s the project files :

project

Read more…

Categories: Java, Programming Tags: ,

Data Structures & Algorithms in Java

January 26, 2009 azer89 Leave a comment

Title : Data Structures & Algorithms in Java
Author: Mitchell Waite
Date: 1998
Language: English
Publisher: Sams
Size : 3124 KB

DOWNLOAD HERE !!!

Categories: Free Download, Java, Programming Tags: , ,

Simple Thread di Java (2)

January 26, 2009 azer89 1 comment

Nah, berikut ini contoh penggunaan thread lainnya :

Read more…

Categories: Java, Programming Tags: ,

Simple Thread di Java (1)

January 25, 2009 azer89 Leave a comment

Thread dalam ilmu komputer adalah singkatan dari “thread of execution”, didefinisikan sebagai sekumpulan instruksi yang dapat dieksekusi secara paralel dengan thread lainnya, dengan menggunakan metode time slice (ketika satu prosesor melakukan perpindahan antara satu thread ke thread lainnya) atau multiprocess (ketika thread-thread tersebut dieksekusi oleh prosesor yang berbeda dalam satu sistem). Thread sebenarnya mirip dengan proses, tapi cara berbagi sumber daya antara proses dengan thread adalah sangat berbeda. Multiplethread dapat dieksekusi secara pararel pada sistem komputer. Secara umum multithreading melakukan time-slicing (sama dengan time-division multipleks), dimana sebuah prosesor bekerja pada thread yang berbeda, dimana suatu kasus ditangani tidak sepenuhnya secara simultan, untuk prosesor singel pada dasarnya benar-benar melakukan sebuah pekerjaan pada satu waktu. Teknik switching ini memungkinkan prosesor seolah-olah bekerja secara simultan.
(wikipedia)

Read more…

Categories: Java, Programming Tags: ,

(Java GUI) Splash Screen

August 1, 2008 azer89 Leave a comment

Jframe memiki kemungkinan untuk dijadikan sebuah splash screen, tapi, sebaiknya kita menggunakan JWindow. Komponen ini didesain untuk membuat window tanpa title bar, sama seperti splash screen.
Untuk membuat splash scree, ada tiga langkah. Pertama, kita harus menampilkan sesuatu di splash screen tersebut, bisa saja teks ataupun gambar. kedua, kita set posisi dari splash screen tepat di tengah layar. Langkah terakhir, kita set berapa lama splash screen ditampilkan.


//SPLASH SCREEN

package musicplayerv2;

import java.awt.Dimension;
import java.awt.Toolkit;
import javax.swing.JWindow;
import javax.swing.JLabel;
import javax.swing.ImageIcon;

public class Splash extends JWindow
{
    public Splash(int timeOut)
    {
        add(new JLabel(new ImageIcon("images/nineTail.jpg")));  // Menambahkan label gambar

        pack();

        Dimension dim=Toolkit.getDefaultToolkit().getScreenSize();  // Mendapatkan ukuran layar

        int x=(dim.width-getSize().width)/2;  // Mendapatkan posisi tengah
        int y=(dim.height-getSize().height)/2;

        setLocation(x, y);  // Menetapkan lokasi window
        setVisible(true);  // Tampilkan window

        try
        {
            Thread.sleep(timeOut);  // Menunggu hingga waktu yang telah ditetapkan
        }
        catch (InterruptedException ex)
        {
            System.err.println(ex.getMessage());
        }
        dispose();  // Tutup dan bersihkan resource window
    }

}
Categories: Java, Programming Tags: ,

(Java) Tower of Hanoi

July 31, 2008 azer89 Leave a comment

He he he..now, i make Tower of Hanoi in Java Language, if you want more explanation about what is Tower of Hanoi, click HERE.

import java.util.Scanner;

public class Main
{

    public static void main(String[] args)
    {
        Scanner S=new Scanner(System.in);
        int x;
        char from='A', to='B', help='C';

        do{
            try
            {
                System.out.println("  input number of disk: ");
                x = Integer.parseInt(S.nextLine());
            }
            catch (NumberFormatException e)
            {
                x = -10;
            }
        }while(x==-10 || x>10);

        System.out.println("n  from = A, to = B, help = Cn");
        hanoi(x, from, to, help);
    }

    static void hanoi(int x, char from, char to, char help)
    {
        if (x > 0)
        {
            hanoi(x - 1, from, help, to);
            move(x, from, to);
            hanoi(x - 1, help, to, from);
        }

    }

    static void move(int x, char from, char to)
    {
        System.out.println("  move disk "+x+" from "+from+" to "+to);
    }

}
Categories: Java, Programming Tags: ,

Java Media Framework

July 29, 2008 azer89 Leave a comment

JMF adalah API hasil kerjasama Sun dengan IBM, degan JMF kita bisa membuat program yang bisa memainkan mp3 dengan lancar, namun sayangnya JMF sudah tidak dikembangkan lagi. Namun tidak ada salahnya kan kalau kita mempelajarinya?mungkin buat tugas kuliah? he he he
Pertama Download JMF-nya:
Download JMF

ini dia source code-nya:
Download Source Code

Categories: Java, Programming Tags: ,

Huffman Algorithm

July 28, 2008 azer89 Leave a comment

The Algorithm:

So how is this wonderful, magical Huffman tree created, you ask? Here is the algorithm, as taken from “The Data Compression Book”:

First count the amount of times each character appears, and assign this as a “weight” to each character, or node. Add all the nodes to a LIST.

Then, repeat these steps until there is only one node left:

Find the two nodes with the lowest weights.
Create a parent node for these two nodes. Give this parent node a weight of the sum of the two nodes.
Remove the two nodes from the list, and add the parent node.
This way, the nodes with the highest weight will be near the top of the tree, and have shorter codes. Try the algorithm on the following characters:

a: 7
b: 6
c: 5
d: 2
e: 1

You should get a tree similar to the one above.

From this point, you simply get the codes for each character and send the encoded string along with the tree. So the string ‘abc’ will be 000110.

The decoder then can use the Huffman tree to decode the string by following the paths according to the string and adding a character every time it comes to one.

Download Source Code

Categories: Java, Programming Tags: ,

The Binary Tree

July 28, 2008 azer89 Leave a comment

Binary Tree memiliki banyak sekali keuntungan di dalam struktur data:

1. memiliki gabungan kelebihan dari array dan linked list

2. fungsi search yang cepat

3. fungsi insert dan delete yang cepat (walaupun saya mengakui fungsi delete sangat compicated)

Oke, tanpa basa-basi, kata Einstein belajar yang paling efektif adalah belajar melalui contoh,

karena itu disini saya sediakan source kodenya dalam bahasa Java yang dibuat memakai Netbeans 6.0 :

Download Source Code

selamat ngoding !!!

Categories: Java, Programming Tags: ,