Test code


import java.util.*;

public class DijkstraASP{
	public static void main(String args[]){
		Main m =new Main();
	}
}
class Verteks{
	int no;
	int value;
	String color;
	Verteks(int no , int value){
		this.no = no;
		this.value = value;
	}
	Verteks(int no,String color){
		this.no = no;
		this.color = color;
	}
	public String getColor(){
		return color;
	}
	public void setColor(String color){
		this.color = color;
	}
	public int getValue(){
		return value;
	}
	public int getNo(){
		return no;
	}
	public void setValue(int a){
		value = a;
	}
}

class Main{
	public Main(){
		Scanner in = new Scanner(System.in);
		PriorityQueue<Verteks> pq = new PriorityQueue<Verteks>(n,new Comparator<Verteks>(){
			public int compare(Verteks a,Verteks b){
				if(a.getValue() < b.getValue())
					return -1;
				else
					return 1;
			}
		});
		Verteks d[][] = new Verteks[n][n];
		int edge[][] = new int[n][n];
		for(int i=0 ; i<n i="">
			Arrays.fill(edge[i] , 0);
			for(int j=0 ; j<n j="">
			d[i][j]=new Verteks(j,Integer.MAX_VALUE);
			}
		}
		for(int i=0 ; i<n i="">
			d[i][i].setValue(0);
		}
		edge[0][1] =edge[1][0]=2;
		edge[1][2]=edge[2][1]=1;
		edge[0][2]= edge[2][0]=4;
		int u=0;
		for(int i=0 ; i<n i="">
			pq.add(d[i][i]);
			while(!pq.isEmpty()){
				u = pq.poll().getNo();
				for(int j=0 ; j<n j="">
					if(edge[i][j]!=0){
						if((d[i][j].getValue()) > (d[i][u].getValue() + edge[u][j])){
							d[i][j].setValue(d[i][u].getValue()+edge[u][j]);
							pq.add(d[i][j]);
						}

					}
				}
			}
		}
		for(int i=0 ; i<n i="">
			for(int j=0 ; j<n j="">
				System.out.println(d[i][j].getValue());
			}
		}
	}
}	

New Posts

Hi,

2 years after last post, I didn’t expect that the traffic of this very-very limited knowledge web still hit more than 50 hits everyday.
So today I decided that I’m going to write more new posts, most likely will be about Data Structure and Algorithm topics which I can’t resist to learn until now (even though I don’t even use them much on my current role at IT Company).

Well, let’s see and hope the post is going to help and contribute more to the world.
Cheers ~

ferdidolot

WhatsApp FIX on CyanogenMod-6.1.1-Spica-a8.4 – NextGeneration

Today is the first day I flashed, rooted, and install new ROM (CyanogenMod-6.1.1-Spica-a8.4 – NextGeneration) on my Galaxy Spice I5700 phone. (Ah finally, my PM at office showed me how to do it easily.  Thank you Mas Ade). First impression is, WOW my phone is much better than before and it really saves battery energy.

The problem came when I installed WhatsApp from Market. At first it was good, until it came to screen registration (where you put the username), then tap ‘OK button’, I got force close and I couldn’t step to the next stage of WhatsApp registration.

I really thank to Internet and forum because after around several hours reading, summarizing, trying a lot of ways, one of them is WORKING! There is a thread in samdroid forum (http://forum.samdroid.net/f56/discussion-cyanogenmod-6-1-1-spica-a8-4-nextgeneration-4765/index18.html). One of the member  mention that he replace the libsqlite.so in /system/lib path and it worked for him. Then I try this way too. (PLEASE READ. Before replacing /system/lib/libsqlite.so file, please do a backup. Please know what you do to your phone)
To do this, you need the file libsqlite.so (thanks to xna-developers senior member who patch this) and do several command line using adb (Android Debug Bridge).

adb shell “mount -o remount,rw /dev/block/stl9 /system”

Command above is used to mount the system file so that you can copy file into the system. To replace the /system/lib/libsqlite.so, you will need to type this command:

adb push [yourPCpath/libsqlite.so] /system/lib

After you’ve finished, do reboot by typing

adb reboot

Try access your WhatsApp again, and It is working! If you have any trouble, just leave comment here. But mine is working perfectly now.

Have fun.

-ferdidolot-

Google Translate using Perl

In perl, there is a package called WebService::Google. You can use this package to translate from one language to any.

The use on this package is simple, just like when you are translating your language in http://translate.google.com. In this article, I’ll give an explain how to use WebService::Google package to translate from any language to English.

In your package manager, install the WebService::Google package. Then in your code, add following line :

use WebService::Google::Language;

For testing, we will just translate the word using command prompt by typing

perl filename.pl word1 word2 word3 …

First, we configure the service. We can specify the language to translate at the configuration of the service, or we can also just let the service detect the language. If you wish to detect language, you can use this configuration to the service :

$service = WebService::Google::Language->new(  ‘referer’ => ‘http://translator.local/&#8217; ,  ‘src’  => ”,  ‘dest’    => ‘en’,);

As we can see, the source language is not specified, so the service must detect the language on its own. If you want to specify, just define the src. For example, I want to translate from Indonesia to English, so my configuration is :

$service = WebService::Google::Language->new( ‘referer’ => ‘http://translator.local/&#8217;, ‘src’     => ‘id’,    ‘dest’    => ‘en’,);

Then the service will translate the word from Indonesia to English.

Then we loop for each word in @ARGV ( the arguments when we run perl ). The Code will look like this :

foreach $s (@ARGV){

	$result = $service->translate( $s );
	if ($result->error) {
		printf "Error code: %s\n", $result->code;
		printf "Message:    %s\n", $result->message;
	}
	else {
		print "We are translating ".$result->language . " to English \n";
		print "Query : ".$s . "\n";
		print "Translation : ".$result->translation . "\n";
	}
}

Take a look at the code. We loop every word in ARGV then we translate each of them. If you not specify the language source, then ” $result -> language ” will return any detected language. The result of the translation can be seen on $result -> translation.

Enjoy!

JavaApplet MySQL JDBC Tutorial Using Netbeans

Java Applet is a Java Program that can be embedded in HTML documents. Usually, we use an applet viewer  to show the result of our program. For java applet, we must create an HTML documents that specifies which applet class to execute. We will learn by making the applet class and making the simple HTML code that can embed our program.

This time, I only use the simple JApplet program, just to make sure that in Applet we can also make a connection to MySQL Database. :-)

In this Tutorial, we will use 2 class that we have created in past tutorial, Connect.java and Sqlstatement.java.

First, make sure that the webserver has been started. I use XAMPP 1.6.6a, and I use the database that we’ve made in the past JDBC tutorial.

Then, Create your java library Project from Netbeans :

JavaClassLibrary

After that, add the MySQL JDBC :

addLibrary

addLib

Then add a class named Blablabla.java, for this tutorial I use Welcome.java. This class in functioned as an Applet. The content is look like this :

import javax.swing.JApplet;
import javax.swing.JOptionPane;
import java.awt.Graphics;
/**
 *
 * @author ferdiansyah.dolot
 */
public class Welcome extends JApplet{
    String connection = "";
    String insertion ="";
    public void init(){

        try{
            Connect c = new Connect();
            connection = "Connection Established";
            Sqlstatement s = new Sqlstatement();
            s.insert("Dolot",3);
            s.insert("Gery",4);
            insertion = "Success";
        }
        catch(Exception e){
            insertion="Failed";
            connection="Connection Failed";
        }
    }
    public void paint(Graphics g){
		super.paint(g);
		g.drawString(connection,25,25);
                g.drawString(insertion,25,45);
	}
}

Samples method that we use in applet program above are  init ()  and paint(Graphics g). The applet container first called init() method when applet is loaded for exection, after that paint(Graphics g) method is executed. More about JavaApplet you can read here : http://java.sun.com/applets/ . The two method init() and paint(Graphics g) are JApplet life-cycle method that are called by an applet container during an applet’s execution. About JApplet life-cycle you can read them here : http://java.sun.com/docs/books/tutorial/deployment/applet/lifeCycle.html

After making the Applet class, then we must make the HTML file to specify which applet class we use. The simple HTML code is look like this :

<html>
<applet code=”Welcome.class” width=”250″ height=”80″></applet>
</html>

In HTML above, we specify the width of applet viewer is 250 and the height is 80, and we use Welcome class. Save this HTML document in the same folder of src in your Netbeans Project folder (example : …\NetBeansProjects\Project1\src), put the HTML code in src folder.

After that, run the Welcome class in Netbeans, then it works.

Applet

Then’ It’s possible to use applet with JDBC. :-)

Thanks for reading.

Past Tutorial to find the Java Past Program that we use in this tutorial :

Java MySQL JDBC Tutorial Using Netbeans Part 2

Java MySQL JDBC Tutorial Using Netbeans Part 1

Java MySQL JDBC Tutorial using NetBeans (Part 2)

In first part, we have already established connection to MySQL using Java. Now, we will discuss about how to modify the record of the database from program we make.

Make sure that you have read the previous part of the tutorial. In this tutorial, we will use Project that we have created in previous tutorial and Statement interface from java.sql.Statement.

First we must have a database and a table in MySQL. For example, we create a database school with attribute name and number (student number). Start your MySQL and make such database and table using this command :

create database school;
use school;
create table student (name varchar(30), number int);

Set student number to be the primary key on this table:

alter table student add constraint primary key (number);

After finishing with database, we move to our Java program.

In Statement interface, we can execute any SQL statemnt using our Java program. First, make a class named Sqlstatement in our previous tutorial Project. The content of Sqlstatement.java is :

package javasql;
import java.sql.*;
/**
 *
 * @author ferdiansyah.dolot
 */
public class Sqlstatement {
    private Statement statement;
    public Sqlstatement() throws SQLException{
        makeStatement();
    }
    public Statement makeStatement() throws SQLException{
        Connect c = new Connect();
        Connection conn = c.makeConnection();
        statement = conn.createStatement();
        return statement;
    }
    public void insert(String nama,int npm)throws SQLException{
        statement.execute("insert into student values(\""+name+"\",
                          "+number+")");
    }
    public static void main(String arg[]){
        try {
            Sqlstatement s = new Sqlstatement();
            s.insert("Ferdi",1);
            s.insert("Anca",2);
            System.out.println("Success");
        }
        catch(SQLException e){
            System.out.println("Failed");
            e.printStackTrace();
        }
    }
}

In class above, we use the Connect class that we have created in previous tutorial.

On this part :

statement = conn.createStatement();

Variable conn is instance of Connect class that we have made in the previous tutorial. After the connection has estabished, the conn call method createStatement(). The method returns Statement that we will use to send SQL statements to database.

To execute any SQL statement using our Java program, we use execute(String sqlstatement) in interface Statement. In our program above, the execution of the SQL statement can be seen on this part :

statement.execute(“insert into student values(\””+name+”\”,”+number+”)”);

After that, run the Sqlstatement program ( in Netbeans, press Shift+ F6). See what happened in you database record. You can see values in your database and table using command :

select * from student;

You can see the value you insert using Sqlstatment class will be in table values.

API for Statement interface in Java can be seen on http://java.sun.com/javase/6/docs/api/java/sql/Statement.html.

JavaFX Documentation CHM Version

Bagi anda yang sedang mempelajari JavaFX, akan lebih nyaman jika dokumentasi yang anda baca merupakan format CHM, yaitu Microsoft Compiled HTML Help.

Berikut terdapat File Dokumentasi JavaFX dalam format CHM. Silahkan diunduh disini :

javafxdoc.chm

Note : Setelah anda mengunduh file tersebut, rubah formatnya menjadi .chm saja (jangan .doc. Hal ini saya lakukan karena tidak dapat mengunggah file berformat .chm di wordpress). Kemudian, klik kanan file tersebut, lalu pilih Unblock agar file tersebut dapat berjalan dengan baik.

~feel free to distribute this file, enjoy ^_^

sumber : http://geekycoder.wordpress.com/2008/08/03/chm-version-of-javafx-documentation/

Install Windows, Ubuntu hilang?

Ya, jika anda melakukan instalasi windows pada komputer anda yang sudah terinstall Linux didalamnya (misalnya Ubuntu), akan terkesan seolah-olah Ubuntu yang sudah anda install menghilang.

Sebenarnya, Ubuntu yang anda install masih terdapat pada partisinya, tapi mengapa kita tidak dapat masuk ke dalam nya?

grub

grub

Ya, sebenarnya, anda tidak dapat mengakses ubuntu karena grub loader menghilang setelah instalasi dari windows.

Untuk dapat menggunakan linux seperti sedia kala, anda hanya perlu untuk menginstall kembali grub loader . Hal ini dapat dilakukan dengan cara sebagai berikut:

1. Boot menggunakan live CD

2. Masuk ke terminal (Application -> Accessoris ->Terminal ).

3. Setelah itu ketikkan perintah ini pada terminal:

sudo grub

4. Anda akan berada pada grub prompt,

[ Minimal BASH-like line editing is supported. For
the first word, TAB lists possible command
completions. Anywhere else TAB lists the possible
completions of a device/filename. ]

grub>

5. Untuk menemukan root partision, ketikkan perintah berikut

grub> find /boot/grub/stage1

6. Kemudian ketikkan perintah :

grub> root (hdM,N)

nilai dari M dan N didapatkan setelah melakukan eksekusi perintah No. 5

7. Lalu tulis perintah:

grub> setup (hd0)

grub> quit

8. Restart ulang komputer anda dan insya Allah grub loader akan kembali seperti sedia kala.

referensi : https://help.ubuntu.com/community/RecoveringUbuntuAfterInstallingWindows

Java MySQL JDBC Tutorial using NetBeans (Part 1)

Are you asking ‘Could I connect Java application/applet to database like MySQL?’ and the answer is definitely Yes.

You can use JDBC (Java Database Connectivity) to connect your Java application/applet with database. So Let’s start.

First, Create new Project named anything you want, for example Javasql by click File->New Project.

newProject

newProject

then you’ll be on this frame

javaapps

javaapps

then click next,  then give Project Name and set Project Localtion

nameProject

nameProject

then finish.

Second, you must have JDBC MySQL Driver before you can start to connect your Java program to database. But since we use Netbeans , this has been done. Just simply add the library to your project library. Right click in Library on the Project you use. addLibrary

Then choose MySQL JDBC Driver

addLib

Then Click Add Libary.

So now we can connect to MySQL database. Here is the example how you can connect to MySQL.

Here, we use interface Connection.

package javasql;
import com.mysql.jdbc.Driver;
import java.sql.*;
/**
 *
 * @author Ferdiansyah Dolot
 */
public class Connect {
    public Connect() throws SQLException{
        makeConnection();
    } 

    private Connection koneksi;  

     public  Connection makeConnection() throws SQLException {
        if (koneksi == null) {
             new Driver();
            // buat koneksi
             koneksi = DriverManager.getConnection(
                       "jdbc:mysql://localhost/databasename",
                       "username",
                       "password");
         }
         return koneksi;
     }  

     public static void main(String args[]) {
         try {
             Connect c = new Connect();
             System.out.println("Connection established");
         }
         catch (SQLException e) {
             e.printStackTrace();
             System.err.println("Connection Failure");
         }  

    }
}

In example above we create connection to MySQL from creating object of Driver and get connection from DriverManager (get Connection will return Connection Object type), with parameter the url, username, and password. The url above means the database is located in localhost and the name is databasename.You can also add port for MySQL so the url looks : “jdbc:mysql://localhost:3306/databasename”. (See port 3306).
So now we can make a connection to MySQL database. Now, how can we do SQL statement like update, delete, insert, etc?

We will discuss this in Java MySQL JDBC Tutorial using NetBeans (Part 2).

Change Serial Number in XP

This is the simplest way I ever known to change your Serial number in Windows XP.

Get the tools to change your license key by clicking here.

Then just follow the installation of the tools, then change your XP Serial Number. (You just only need a legal XP serial number .)

I have tried this and it works perfectly. (thanks to Mr.Bob Douglas)

Follow

Get every new post delivered to your Inbox.