Label

Thứ Hai, 29 tháng 11, 2010

Trail: Custom Networking

Trail: Custom Networking


http://download.oracle.com/javase/tutorial/networking/TOC.html

Thứ Sáu, 19 tháng 11, 2010

parameters in constructor

        // Create a JList that displays strings from an array
javax.swing.JList myList = new javax.swing.JList(data);
javax.swing.ListModel model = myList.getModel();
jList1.setModel(model);

//javax.swing.JList myList = new javax.swing.JList(Planets.values())

constructor của JList có thể tạo bất kì array nào, không quan tâm đến data type, vì sao vậy?

Thứ Tư, 17 tháng 11, 2010

The Swing Tutorial

Trail: Creating a GUI With JFC/Swing: Table of Contents
http://download.oracle.com/javase/tutorial/uiswing/TOC.html

Trail: Graphical User Interfaces: Table of Contents
http://download.oracle.com/javase/tutorial/ui/TOC.html

Thứ Hai, 15 tháng 11, 2010

How many way to input data from keyboard in java?

from Console

System.in <-- how to use?

Scanner sc = new Scanner(System.in).useDelimiter("\n");

How many way to input data from keyboard in java?

Thứ Ba, 9 tháng 11, 2010

JAR

run jar file need Entry Point

use [cfe] to set Entry Point, without editing or creating manifest file.

jar  cfev  filename.jar  package.ClassName *.class audio image

http://download.oracle.com/javase/tutorial/deployment/jar/index.html

Executable JAR Files


On Microsoft Windows systems, the Java 2 Runtime Environment's installation program will register a default association for JAR files so that double-clicking a JAR file on the desktop will automatically run it with javaw -jar. Dependent extensions bundled with the application will also be loaded automatically. This feature makes the end-user runtime environment easier to use on Microsoft Windows systems.

Thứ Tư, 3 tháng 11, 2010

Question 2 - Interface's Exercise

public interface TimeClient {
public void setTime(int hour, int minute, int second);
public void setDate(int day, int month, int year);
public void setDateAndTime(int day, int month, int year,
int hour, int minute, int second);
}

Suppose that you have written a time server, which periodically notifies its clients of the current date and time. Write an interface that the server could use to enforce a particular protocol on its clients.

Trong ví dụ này, đây là lớp interface được TimeServer implements,  tại sao ko là một interface từ TimeServer được lớp TimeClient triển khai, đúng theo tinh thần đã học ở đầu lesson interface, là tạo 1 protocol chung cho các nhà lập trình riêng biệt, không cầ n biết gì về công việc của nhau và hợp tác thông qua interfaces để tạo sản phẩm???

Thứ Ba, 2 tháng 11, 2010

Is the following interface valid?

Question 4: Is the following interface valid?

public interface Marker {
}


Answer 4: Yes. Methods are not required. Empty interfaces can be used as types and to mark classes without requiring any particular method implementations. For an example of a useful empty interface, see java.io.Serializable.

Thứ Hai, 1 tháng 11, 2010

Inner Class Example

public class DataStructure {
private static final int SIZE = 15;
private static int[] arrayOfInts = new int[SIZE];

public DataStructure() {
for (int i = 0; i < SIZE; i++) {
arrayOfInts[i] = i;
}
}

public int getSIZE() {
return SIZE;
}

public static int getValueOfArray(int index) {
return arrayOfInts[index];
}

public void printEven() {
InnerEvenIterator iterator = new InnerEvenIterator();
while (iterator.hasNext(getSIZE())) {
System.out.print(iterator.getNext() + " ");
}
}

//Inner Class
/* private class InnerEvenIterator {
private int next = 0;

public boolean hasNext() {
return (next <= SIZE - 1);
}

public int getNext() {
int valueNext = arrayOfInts[next];
next += 2;
return valueNext;
}
} */

public static void main(String[] args) {
DataStructure ds = new DataStructure();
ds.printEven();
}
}

public class InnerEvenIterator {
private int next = 0;

public boolean hasNext(int S) {
return (next <= S - 1);
}

public int getNext() {
int valueNext = DataStructure.getValueOfArray(next);
next += 2;
return valueNext;
}
}

Các điểm giống và khác nhau khi dùng cách 1 và 2.