Tuesday, April 28, 2009
Ubuntu hibernate suspend
pmi action hibernate
pmi action suspend
pm-hibernate
pm-suspend
/etc/acpi/sleep.sh
/etc/acpi/hibernate.sh
/usr/lib/hal/scripts/linux/hal-system-power-hibernate-linux
/usr/lib/hal/scripts/linux/hal-system-power-suspend-linux
BONUS:
gnome-screensaver-command --lock
sudo apt-get install uswsusp && sudo s2ram --force
sudo apt-get install uswsusp && sudo s2disk
Tuesday, April 07, 2009
Remote Desktop Redmond
Monday, April 06, 2009
English Talking Practice
Dĩ nhiên là có rồi :-)
Nhưng nên nhớ có nhiều phương pháp học tiếng Anh và bạn có thể áp dụng vài cách trong số đó miễn là bạn cảm thấy phù hợp với mình và có hiệu quả.
Điều quan trọng là không nên áp dụng TẤT CẢ quy tắc hoặc cách học của người khác. Khi học theo một cách nào đó, nên thử chỉ 1 cách đó hoặc tối đa là 2, 3 cách; đừng dại dột mà thử nhiều cách mới cùng lúc, bởi khi đó bạn sẽ khó nhận thấy kết quả.
Sau đây là một số quy tắc quan trọng để học tiếng Anh, chủ yếu giúp cải thiện khả năng Talking, mà bản thân tôi cảm thấy rất hiệu quả. Nếu bạn đã có căn bản về ngữ pháp tiếng Anh thì áp dụng những cách này sẽ giúp bạn cải thiện việc giao tiếp với người nước ngoài trong thời gian ngắn !
1/ Từ vựng: học theo CỤM TỪ (câu ngắn cũng có thể xem là 1 cụm từ)
REASON:
2/ Gặp người nước ngoài: đừng bận tâm ngữ pháp
REASON:
3/ Trong lớp học: chỉ dùng tiếng Anh (các địa điểm như English Club cũng vậy)
REASON:
4/ Nghiền ngẫm: nghe lặp đi lặp lại để hiểu (ko dùng thiết bị thì tự mình đọc)
REASON:
5/ Ngữ pháp: nắm vững cơ bản (Simple Past, Simple Present, Present Perfect, Simple Future) qua các đoạn kể.
REASON:
6/ Cập nhật: học từ vựng thực tế, hiện đại qua các bản tin và Internet sites.
REASON:
7/ Phản xạ với tiếng Anh: bằng các đoạn Hỏi Đáp đơn giản thực tế
REASON:
Have fun ! and Good Luck !
Thursday, March 05, 2009
Ubuntu screensaver hang
Khi gap cac tinh huong nhu tren, tuy theo muc do nang hay nhe ma ap dung cac giai phap:
* Alt+F2
* Ctrl+Alt+D
* Ctrl+Alt+F1 , sau do Ctrl+Alt+F7
* Ctrl+Alt+F9 , sau do go lenh sudo startx hoac sudo xinit -- :1
* Ctrl+Alt+Backspace , works 99% :-)
* giu nut Power cua may it nhat 4 giay :D
good luck,
(sry I will fix Vietnamese later)
Thursday, February 26, 2009
Ubuntu APT deb
APT = Advanced_Packaging_Tool
sudo apt-get update
sudo apt-get upgrade
sudo apt-get dist-upgrage
sudo apt-get install envyng
sudo apt-cache search envyng
The deb files are stored at /var/cache/apt/archives
sudo dpkg -i xvnkb-0.2.9a-utf_i386.deb
man dpkg
Wednesday, February 18, 2009
Win startup script
Friday, January 23, 2009
Linus on Git
Tuy nhiên tương lai của SCM/VCS sẽ là distributed SCM, trong đó ứng cử viên sáng giá nhất hiện nay là Git, kế đến là Bazaar và Mercurial.
Git là một VCS mã nguồn mở dạng phân tán , được Linus Torvard viết ra nhằm thay thế 1 DSCM khác là BitKeeper , khi tác giả BK quyết định đổi license của BK. Và hiện nay Git được sử dụng thay cho BitKeeper trong việc phát triển kernel Linux, cũng như đang mở rộng ra nhiều ứng dụng khác (X-server, Samba, Qt, WINE, Perl, Android, RoR, VLC, Prototype, ...) .
Các bạn có thể xem đoạn Linus Torvards giới thiệu về Git tại Google Tech Talk:
Điều ấn tượng nhất với tôi qua cuộc nói chuyện này, đó là Linus không hề có vẻ gì là "geek" hay "anti-social" như nhiều người vẫn nghĩ, trái lại kỹ năng dẫn dắt vấn đề thu hút, trình bày dễ hiểu và hấp dẫn của anh đáng để khâm phục và học hỏi.
Một người có sức sáng tạo dĩ nhiên là một người thích khôi hài rồi, có phải không ?
Wednesday, December 31, 2008
Java annotations revisit
=== Java Annotations ===
Annotations are presented as metadata – that is data about data. In the case of Java this means that they provide information about various elements of a Java class. For example, they may annotate a method, class or instance variable. One example of an annotation is to note that a method has been deprecated, or that it overrides a method in the superclass. These annotations can then be used by an annotation processing tool (such as APT), or an IDE (such as Eclipse) or indeed a framework, to validate, configure or add to the original Java. For example, if you have annotated a method as overriding a parent class method, then the annotation processing can confirm that you are indeed overriding a method.
There are seven annotations provided in the J2SE 5.0 release (see the annotations guide here; these are provided in two packages, java.lang and java.lang.annotation:
In the package java.lang there is:
• @Deprecated – indicates that the associated Java element has been deprecated. It is an alternative to using the Javadoc @deprecated element. A deprecated method or class is essentially one that should no longer be used and that is not guaranteed to be available in future versions of the software. It is thus often useful to know that you are using “old” versions of an API. Although the use of the Javadoc tag already allows many tools (such as Eclipse) to indicate that a language feature is deprecated, the use of the @Deprecated annotation makes this simpler and allows a wider range of tools to report on the use of deprecated features.
• @Override - indicates that the method should override a method in the superclass.
• @SuppressWarning – directs the compiler to suppress the specified warning.
In the package java.lang.annotaiton:
• @Documented – directs tools to automatically generate Javadoc for the annotated element (e.g. a method or variable).
• @Inherited – this indicates that the associated annotation is inherited by subclass of the current class.
• @Retention – indicates how long annotations with the annotated type are to be retained. For example, a retention type of RUNTIME indicates…
• @Target – This indicates the Java element to which associated annotations apply.
It is also possible to extend the set of annotations available by defining your own annotations. This enables project, task and company specific annotations to be created.
=== What are annotations for? ===
Annotations are intended to provide three basic facilities. These facilities are:
• The provision of additional semantics for various class elements. This additional semantic information can help developers to understand the intent behind some feature or implementation detail.
• The execution of additional compile time checks that ensure various constraints are met.
• The support of additional code analysis by annotation-aware tools.
None of these requirements are new and indeed many developers have found ways of overcoming the lack of any annotation-like feature in previous versions of Java.
For example, I have tended to make extensive use of Marker Interfaces over the last few years. These are interfaces that may not contain any methods, but are used to denote a particular concept or entity within an application. This is not a particularly radical idea and indeed there is an example of such an interface in the Java language itself - the java.io.Serializable interface. This interface is a marker interface in that it does not require any methods to be implemented but indicates that a class is capable of being serialized via the Java Serialization mechanism.
Such marker interface can now be replaced with annotations. We can define our own annotation that can be used to mark a class as being a particular concept or entity etc.
=== Using annotations ===
Annotations are straightforward to use; they merely require that an appropriate annotation type be placed directly before the Java language element being annotated. For example:
@Override
public String getName() {
return this.name;
}
}
This means that when this code is compiled, or when it is analysed by tools such as Eclipse, a check can be made to ensure that the method getName() does override a method in the class Person’s superclass. In this particular case, the class Person extends the class Object as a default. The class Object does not contain a method getName() and thus it does not override such a method. This therefore results in an error message being generated. For example, in figure 1 Eclipse has identified that the method getName() should override a method in the parent class and has provided a pop up to this effect.
However, marking which methods you expect to override parent class methods is probably a step two far for many developers. A rather more useful annotation may be the @SuppressWarnings annotation.
The @SuppressWarnings annotation can be very useful if you have some code that uses a deprecated method or class (possibly because it has been in your system since before that method was deprecated) and you do not want the compiler to churn out lots of warnings about using deprecated APIs. By using the @SuppressWarning annotation and the parameter value “deprecation” it is possible to suppress (turn off) the production of the deprecated warning. For example:
public static void terminateProcess() {
Thread.currentThread().stop();
}
=== Defining your own annotations ===
You can easily create your own annotations by defining a new annotation type. This is done using a new piece of language syntax, the @interface key word. For example, to define a new annotation @Auditor we would define the following annotation type.
}
Note that although the syntax for this is almost exactly the same as for a standard interface, the “@” symbol at the start of the keyword changes this to be an annotation declaration. When you compile the resulting Auditor.java file this creates a standard Auditor.class file. If you place this class file on your class path, then you can use this new annotation type within your Java code. For example, if you place the @Auditor just before the class declaration, this marks the class as being of the entity type Auditor. This is illustrated in Figure 2.
You can also define parameters that can be used with annotations, and accessor methods for retrieving information about the options specified with an annotation.
=== Drawbacks of Annotations ===
Annotations are not without their drawbacks. Not least of which is that they are not really metadata – that is they are not data about data – they are data about classes, methods, instance and static variables etc.
=== Window dressing ===
As such annotations are syntactic sugar – they coat the elements of a class without actually telling you anything in detail about that class (you can use the reflection API for some of that). Thus they provide guidance to processors, tools and frameworks to help in the analysis, compilation or deployment of that software.
Inheritance
One of the major features of an object-oriented system is inheritance. You can subclass a class, and subclass an interfaces – but you can’t subclass annotations.
=== Null values ===
If a null value should be treated as an un-initialized value then annotations are somewhat awkward in the way they handle these – rely on the developer to provide a way of indicating un-initialised rather than initialised to null.
=== Values in General ===
These are somewhat limited in what you can use – although in the main this is fine.
=== Annotations hold constants ===
The values used with annotations are hard coded rather than variable. Thus if an annotation takes a literal value of 40 – then that value is now hard coded into your program.
=== Annotations and code synchronization ===
Just as with Javadoc comments themselves, annotations need to be maintained to reflect any code changes that may occur. However, as we all know, it is all too easy to change the source code and not to update the associated Javadoc (even when they are next to each other). Exactly the same is true for annotations. If the code relating to an annotation changes, then the associated annotation may also need modification. This may not be as straightforward as it seems. For example, if I rename a method in a class I am working on, then this may impact on another class, that I may know nothing about; if that class requires that one of its methods overrides mine (due to the use the @Override annotation). Of course this may be what is desired or it may not! As you can define your own annotations this situation may become much worse, with significant repercussions for on-going maintenance, clarity and general stability of the code.
=== Summary ===
So where does that leave the question “To Annotate or not to Annotate?”. In essence, as with many things in life, annotations can be very useful but should not be over used or abused. They can add extremely useful additional information to Java code that can be analysed by tools, frameworks, analysers as well as developers themselves – but they should not be used without due consideration.
(main reference: TheRegister)
See also :
http://javabeat.net/articles/30-annotations-in-java-50-1.html
http://www.developer.com/java/other/article.php/10936_3556176_1
http://www.oracle.com/technology/pub/articles/hunter_meta.html
...
Friday, December 12, 2008
Javascript Libraries Overview
Hiểu biết về JavaScript đã trở thành 1 skill không thể thiếu với những ai làm lập trình web, và cũng là 1 skill khá quan trọng của các hacker. Tuy nhiên với web-development hiện nay thì lời khuyên là bạn nên nắm vững 1 thư viện nào đó, hơn là đi tìm kiếm các đoạn script mẫu ngắn phục vụ cho 1 mục đích nào đó.
Các thư viện JS mã mở và hữu ích hiện nay có thể kể: jQuery, mooTools, Prototype + Scriptaculous, YUI + ExtJS , Dojo, ...
(ngoài ra còn 1 số công nghệ JS có cả phần server side như : qooxdoo, echo2, GWT, DWR, jMaki, Qcodo, AjaxCFC, ... )
Dưới đây là 1 slideshow so sánh cơ bản các thư viện JS trên để bạn có thể chọn cho mình 1 cái phù hợp :
Have fun :D !
Monday, November 24, 2008
VIM for dummies [2]
Bài này sẽ ôn lại một số điểm trong post trước và giới thiệu thêm một số thao tác thường gặp của vim . Hy vọng sau bài này thì các bạn yêu thích máy tính sẽ cảm thấy hứng thú với việc dùng vim trên Linux/BSD.
=== Khởi động vim ===
Ôn lại bài trước:
Bài này thì ta khởi động cách khác:
Khởi động kiểu này sẽ thấy hiện giữa màn hình các thông tin về tác giả (Bram Moolenaar - hiện đang làm cho Google), phiên bản (7.x.yz) , cách quit bằng :q , cách xem trợ giúp bằng :h , ...
Bây giờ để bắt đầu soạn thảo 1 file (giả sử tên myfile.txt) , ta gõ lệnh
:edit myfile.txt
hoặc đơn giản hơn chỉ cần :e myfile.txt .
Trong trường hợp bạn muốn mở nhiều file cùng lúc (ví dụ: file1.js , file2.cpp, file3.java, ...), thì vim cũng hỗ trợ nhiều cách. Nếu phiên bản vim của bạn hỗ trợ tab các file, thì nên mở bằng cách sau:
Hoặc khi đang ở trong chế độ normal của vim, bạn dùng lệnh:
:tabedit file3.java
thì vim sẽ mở cho bạn file3.java trong 1 tab mới :) .
(Để ngắn gọn hơn có thể gõ :tabe file3.java )
=== Di chuyển / Cuộn màn hình ===
Ôn lại bài trước:
* còn xuống , lên : là "j" , "k"
Di chuyển bằng các phím (ở normal mode):
+ Đến tab kế tiếp: gt , tab trước đó: gT
+ Đến file mà tên nằm ở dấu nháy: gf (để trở lại, dùng Ctrl+o hoặc Ctrl+6 )
+ Đến đầu file: gg
+ Đến (đầu) dòng cuối file: G (tức là Shift+g )
+ Đến dòng thứ 17: 17G
+ Đến cuối dòng: $
+ Đến đầu dòng (ký tự đầu): ^
+ Đến đầu dòng (cột 0): 0
Cuộn màn hình :
+ Cả trang : Ctrl+f (forward), Ctrl+b (backward)
+ Nửa trang : Ctrl+d (down), Ctrl+u (up)
+ Từng dòng : Ctrl+n (next), Ctrl+p (previous) . Hoặc phím cũ là Ctrl+e và Ctrl+y
Lưu ý: các tổ hợp phím scroll màn hình này cũng giống như khi dùng lệnh man, more hoặc less , nên khi xem manpage hay file nào các bạn cũng có thể scroll bằng các tổ hợp phím kể trên.
=== Tìm kiếm / Thay thế ===
Ôn lại bài trước:
phím ?: tìm từ dưới lên (thường dùng để tìm cụm từ có chứa / )
Khi đã tìm thấy thì có thể bấm tiếp phím n hoặc N để tìm đến từ kế tiếp (next) .
Tìm ngay các từ giống từ đang ở dấu nháy (cursor) : phím * , hoặc #
Thay thế (substitute) thì dùng cú pháp mới gần giống sed: ( s/OLD/NEW/option )
+ thay toàn bộ chuỗi "OLD" bằng chuỗi "NEW" trong cả file:
:%s/OLD/NEW/g
+ thay toàn bộ chuỗi "OLD" bằng chuỗi "NEW" trong đoạn từ dòng 5 đến dòng 17 :
:5,17s/OLD/NEW/g
+ thay toàn bộ chuỗi "OLD" bằng chuỗi "NEW" trong 1 dòng (đang chứa cursor) :
:s/OLD/NEW/g
+ chỉ thay chuỗi "OLD" đầu tiên trong dòng bằng chuỗi "NEW" thì ko cần "g" :
:s/OLD/NEW
+ nếu muốn có xác nhận (confirm) trước khi thay thì ta thêm option là "c" :
:%s/OLD/NEW/gc
Các thao tác tìm kiếm và thay thế trên VIM cũng hỗ trợ biểu thức chính quy (Regular Expression) khá tốt. Các Regex được hỗ trợ trên vim hiện nay giống như của egrep, khá giống của perl . Nhưng để tránh phức tạp cho người mới dùng thì tớ chưa nêu ví dụ ở đây :D .
=== Sao chép / Xóa / Dán ===
Đơn giản:
- chép (copy/yank) : phím y
- xóa : phím d (hoặc phím x)
- dán : phím p
btw, trong VIM thì xóa (delete) luôn có nghĩa là cắt (cut), tức là mất đi trên màn hình hiển thị , nhưng ngay lúc đó đã lưu lại trong vùng nhớ nào đó (gọi là vùng register hoặc còn gọi là vùng buffer). Khi đó có thể dán (paste) lại màn hình soạn thảo của vim bằng phím p .
Để xóa 1 đoạn thì ta có thể làm các cánh sau:
1/ chuyển qua chế độ visual rồi chọn vùng cần xóa và bấm phím xóa
2/ dùng chức năng đánh dấu (mark) bằng phím m , đánh dấu 2 điểm rồi xóa từ điểm đầu đến điểm cuối
3/ chuyển sang chế độ chuột
set mouse=a
hoặc
set mouse=i
rồi dùng chuột để chọn vùng cần xóa, rồi bấm phím xóa.
4/ Ánh xạ các thao tác xóa thành tổ hợp phím nào đó (VD: kiểu Ctrl+C của Windows) , để chọn và xóa dễ hơn.
5/ Chuyển sang chế độ soạn thảo giống các chương trình trên Windows , tức là dùng lệnh behave mswin để nó chuyển chế độ chuột và các phím tắt giống kiểu Notepad++ trên Windows.
Đại khái như vậy, nhưng phần này tớ khoan nói rõ, ai quan tâm sẽ tự tìm hiểu :D .
=== Thiết lập / vimrc ===
Ôn lại bài trước:
:colorscheme murphy
* Bật syntax highlight màu cho các ngôn ngữ lập trình, script :
:syntax on
* Bật số dòng (line number) lên cho dễ theo dõi:
:set number
* Bật chức năng hiện các lệnh (show command) đã gõ :
:set showcmd
* Bật "cây thước" để hiện số dòng, số cột, số ký tự đã gõ:
:set ruler
* Bật chức năng highlight các từ được search :
:set hlsearch
* Bật chức năng ignore case của từ được search để tìm được nhiều hơn :
:set ignorecase
=== Ánh xạ phím tắt ===
Ôn lại bài trước:
=== Một số tham khảo ===
Ôn lại bài trước:
(với "word" là từ mà mình muốn coi help)
vim cũng có built-in sẵn 1 cái tutor về cách dùng VIM:
$ vimtutor
Saturday, November 22, 2008
Double-clicked Java
http://javalobby.org/articles/java2exe/
"How do I make an .EXE file from my Java application?",
"Need help converting jar to exe",
"Is it possible to create a Windows executable using Java?"
--- these and similar questions are among the most popular topics on Java developer forums. Should you start such a topic today, you are likely to encounter the following three types of replies:
1/ "You cannot"
2/ "You should not, because that would kill the very purpose of Java"
3/ "You can do that with third party software X and Y"
The truth is that there exist two completely different approaches to the creation of native executables from Java applications, addressing different sets of problems. Moreover, under certain conditions some of those problems may be solved without making an EXE. So the most correct way to reply to such a post would be a request for more information, namely what is the goal of conversion to EXE. And the most frequent answer would be
=== Simplify Java Application Deployment ===
Java compiles to platform-independent bytecode (.class files), which is not directly supported by PC hardware. So a Java program needs a Java Runtime Environment (JRE) to run, which would either interpret the bytecode instructions or compile them to native code on the fly. This in turn means that the author of that program has to ensure somehow that the proper version of the JRE is installed on an end user system.
In a general case you may not expect that your end users will know what a JRE is, how to check its version, and how to download and install it. This is especially true for consumer applications, such as games or multimedia. And those who already have a JRE installed may not like the idea about installing a different version, because it may break their existing Java applications and favorite applets.
Then, even if you can make sure the right version of the JRE is properly installed on enduser systems, which is quite possible in a classroom or enterprise environment, the command line required to launch your Java application can be quite long:
java -Xmx200m -cp whatever.jar -Dsome.property MyApp
Yes, you may put that line into a batch file and call it runme.bat, but it looks so much easier to give your program to a friend, teacher or colleague as a single file that can be run by a double-click. Or, even better, enable it to be installed and uninstalled in a native manner without affecting other applications.
So it comes as no surprise that the primary motivation for seeking a way to convert a Java application into an EXE file is to make its deployment and use simpler and safer for an average user, that is, a Windows user. What surprises newbie Java developers is that the JDK does not offer such functionality. Before J2SE 1.4, all you could make with JDK tools were
=== Executable Jars ===
You can make your Java application runnable via a double-click by packaging it into a so called executable jar. You do that by specifying the main class of your application, any extra jar files it may require and so on in the jar's manifest file
Main-Class: MyAppMain
Class-Path: mylib.jar
Then you use the jar utility from the Java SDK to package your classes and resource files, specifying the m option and the name of your manifest file:
jar cvfm MyApp.jar MyApp.mf *.class *.gif
This will result in the creation of MyApp.jar. Now, if you type
java -jar MyApp.jar
the Java launcher will read the manifest from MyApp.jar and invoke the main method from the class MyAppMain. Moreover, if you double-click that jar file on a system that has JRE installed, the java launcher will be invoked automatically.
Note: As of J2SE 5.0, jar files are associated with the javaw launcher on Windows, which does not open a console on startup. If your application needs a console, write a batch file which would start it using the java launcher.
If your application consists of more than one jar file, there is an open source tool called One-JAR that claims to correctly repackage multiple jars into one.
The major problem with executable jars is compatibility. The default JRE may be of an older version than is required by your application or may not have the necessary Java Optional Packages (previously known as Standard Extensions) installed. For instance, if your app uses the java.nio package introduced in Java 2 version 1.4, it will not work on JRE 1.3.x. Similarly, if it uses JavaMail 1.3, and the default JRE has JavaMail 1.2 or JavaMail is not present at all, the double-clicked jar will not run.
Fortunately, Sun has created a Java application deployment technology that eliminates this compatibility problem and adds some nice features. It is part of the Java 2 platform since version 1.4 and is called
=== Java Web Start ===
Java Web Start (JWS) and the underlying Java Network Launch Protocol (JNLP) enable Java application delivery from a standard Web server. The end user initiates application installation by clicking on an URL. If the Java Web Start engine is not present on the system, the user is prompted to download and install it. Once Java Web Start is in place, clicking on the same URL will initiate the application download and installation procedures. It may involve download and installation of the required version of the JRE and Optional Packages. Upon their successful completion, the application is launched. The application will be cached on the user's system so next time the user clicks on the same URL, the JWS engine will launch the local copy of the application from the cache, if it detects that the computer is offline or the application was not updated on the Web site.
Another important feature of JWS is its ability to run your application in a sandbox - a restricted container based on Java security architecture. But, unlike an applet, your application can gain access to local system resources like the filesystem, printer and system clipboard using the JNLP API even if it comes from an untrusted environment, after prompting the user for confirmation.
Java Web Start is available for Windows, Linux, and Solaris, and is part of MacOS X since v10.1. There are also third-party implementations of the JNLP protocol, some of them also include tools that assist you in the creation and maintenance of JNLP packages.
That was the bright side. Now, what is not so good about JNLP? First off, for seamless operation both the browser and the Web server that hosts the JNLP-enabled application must support application/x-java-jnlp-file MIME type. Some hosting providers do not support it. Moreover, versioning and incremental updates require additional support from the Web server, which has to be implemented using servlets, cgi-bin scripts, etc.
On the client side, a major browser would be configured to recognize the above MIME type during installation of the JWS engine, but users of less popular browsers, such as Opera, may have to do that manually.
JNLP-enabling an application may involve minor changes in its code and (re)packaging it into a set of jar files.
Before J2SE 5.0, JWS had very little to offer in terms of desktop integration - all it could do was create a desktop icon and/or a Start Menu entry for the application. On Windows, the application will not show up in Add/Remove Programs, so end users would have to run the Java Web Start application manager in order to remove your application.
Finally, JWS user interface needs much polishing. As of J2SE 5.0, users still complain about ugly windows with incomprehensible messages.
To sum it up, JWS can be a viable option in a controlled environment, such as corporate intranet, but it is not ready for the consumer market, where you may be better off using
=== Custom Java Launchers And Wrappers ===
When a Java program is invoked using one of the methods discussed above (batch file, executable jar, or Java Web Start/JNLP), the operating system runs a Java launcher from the JRE. The Windows version of the JRE has separate launchers for command-line and GUI apps, called java.exe and javaw.exe respectively.
As a result, all running Java applications have the same Taskbar/Alt-Tab icons and appear in the Windows Task Manager as either java.exe or javaw.exe. If you have two or more Java apps running, you have no means to distinguish between multiple instances of the standard Java launcher in the Task Manager.
In fact, those launchers are just small native programs that load the Java Virtual Machine from a DLL/shared library and then feed your program to that JVM using the Invocation API. That API is part of the Java Native Interface (JNI), so it is standardized, and it is also very simple. This makes it relatively easy to write your own launcher with a unique name and icon. What it has to do is find a suitable JRE on the end user's system (unless you bundle the JRE with your application), load and initialize the JVM, and run your application on it.
If you do not have the right tools, skills, or time to develop a custom launcher for your Java application, there are quite a few third-party Java launcher generators listed in the Tools section of the frame. Some of them provide additional features such as instant splash screen, stdout and stderr redirection, and so on, the most notable being wrapping.
A Java wrapper is essentially a custom Java launcher that is also a self-extracting archive containing all the application's classes, jars and auxiliary files. The wrapper unpacks those files on startup and removes on termination. This way, your application is distributed as a single executable.
A wrapper normally looks up the JRE upon startup. If the JRE is not present or its version does not match the application's compatibility requirements, some wrappers may install the JRE (if you have included it when wrapping your application) and/or download and install the required version of the JRE.
The most sophisticated wrappers may also setup file associations and create shortcuts on first run. But if you need something more complex, such as support for automatic updates or uniform cross-platform deployment, have a look at
=== Java-Aware Setup Authoring Tools ===
If all you need is install a private copy of the JRE alongside your application and create shortcuts that run your application on that JRE, you may use any setup generator. However, using a Java-aware tool may give you the following benefits:
* Install-time JRE detection and download
* Generation of native launchers
* User-editable JVM parameter files
* Redirection of stderr and stdout for saving logs and exception stack traces.
* Registration of Java applications as Windows services and Unix daemons
This category is the most diversified in terms of tool pricing and functionality. The differences are explained below by example.
Windows-centric tools, such as Advanced Installer for Java enable you to build MSI (Windows Installer) packages.
Multi-platform tools can generate native installers for multiple platforms - Windows, Linux, Mac OS X, as well as RPMs and tarballs. install4j is one such tool.
There exist also Java-based setup authoring tools enabling you to create cross-platform installations, Those installations are essentially executable jars with platform-specific logic selected at run time. InstallAnywhere is perhaps the most well known tool of this type, but if its pricing is beyond your budget, consider the cheaper JExpress or the open source IzPack.
Finally, there is One Tool to Rule Them All - InstallShield, which can create both Windows desktop (MSI) and cross-platform installations, plus server and mobile ones, for any type of application and for a multitude of platforms. And yes, it does support JRE lookup and bundling, native launchers, and so on.
For straightforward installations, however, InstallShield is an overkill. Also note that InstallAnywhere and InstallShield are aimed at the enterprise developer and are priced accordingly.
All the above solutions do not change the fundamental principle mentioned in the first section of this article. Whether you make an executable jar or create a sophisticated installer, your Java program is still deployed as platform-independent bytecode. In the early days of Java, the only way to execute a Java program on a common PC hardware was to interpret that bytecode. Today, any decent J2SE implementation contains a Just-In-Time (JIT) compiler that compiles frequently executed methods to native code. So it sounds quite natural to take one step further and compile the entire application down to native code before it is deployed. Such tools exist and they are called
=== Ahead-Of-Time Compilers ===
AOT compilers are known also as "static compilers" and "native code compilers". The latter term is the most used and, as it often happens, the least correct from the technical standpoint, because JIT compilers also produce native code.
An Ahead-Of-Time (AOT) compiler takes as input your jars and class files and produces a conventional native executable for the target platform, such as Windows EXE or Linux ELF binary. Just like any other technical solution, this has its advantages and drawbacks.
Advantages
* Performance. A JIT compiler works at application's runtime and shares CPU and memory resources with the application it compiles and possibly other applications. An AOT compiler runs on the developer's system with no resource or compilation time constraints. Therefore it can potentially use more powerful resource-intensive optimizations, yielding better code.
This advantage is amplified if you application will be deployed to embedded systems or low-end desktop PCs, where the JIT compilers simply may not have enough resources to work.
* Intellectual Property Protection. Java bytecode is very easy to decompile - just google for "download java decompiler" and you will get your source code back in 5 minutes. Yes, you may obfuscate names of public classes and methods not accessed via reflection, but control flow obfuscation can render your bytecode unverifiable on future JVMs and hinders optimizations implemented in JIT compilers. Finally, encrypting your Java bytecode does not protect it at all regardless of the encryption algorithm you use.
In contrast, native code produced by an optimizing AOT Java compiler is about as hard to reverse engineer as if you have coded the original program in C++. Needless to say, there is no performance loss. If you are concerned about protecting your intellectual property, have a closer look at native compilation.
* User Perception. Java client applications often suffer from the so called warm-up cycle syndrome. Starting up a Java application involves bytecode interpretation, profiling and JIT-compilation. So Java programs tend to start much longer than their native counterparts and the initial response time of a Java app GUI element is much worse than after it has been used several times, which are the two major reasons for Java still being perceived as slow by many users.
A native executable runs directly on hardware, without the interpret-profile-compile overhead, so it may start faster and immediately demonstrates the best response times.
* Native deployment. Even the most sophisticated Java-aware setup tools have to generate native launchers for better desktop integration, and may need to take care of the JRE download and installation.
Executables produced by an AOT Java compiler do not depend on the JRE and can be deployed using any setup authoring tool available for the target platform. Moreover, AOT compilers may come with specifically tailored setup generators that create compact, professional installers.
Drawbacks
* Dynamic applications. Classes that the application loads dynamically at runtime may be unavailable to the application developer. These can be third-party plug-ins, dynamic proxies and other classes generated at runtime and so on. So the runtime system has to include a Java bytecode interpreter and/or a JIT compiler.
Moreover, in the general case only classes that are loaded by either system or application classloader may be precompiled to native code. So applications that use custom classloaders extensively may only be partially precompiled.
* Hardware-specific optimizations. A JIT compiler has a potential advantage over AOT compilers in that it can select code generation patterns according to the actual hardware on which the application is executing. For instance, it may use Intel MMX/SSE/SSE2 extensions to speedup floating point calculations. An AOT compiler must either produce code for the lowest common denominator or apply versioning to the most CPU-intensive methods, which may result in code size increase.
FYI, there used to be half a dozen AOT Java compilers on the market in the year 2000, but the only two that have survived are Excelsior JET and GCJ (GNU Compiler for Java).
./.
To discuss about this article, please go to JavaLobby forum :-)
Sunday, November 16, 2008
Computer hackers exposed !
Alan Cox là lập trình viên máy tính và là người đóng góp chính vào sự phát triển của nhân Linux từ thuở sơ khai 1991.
John Gilmore là một trong những người sáng lập ra Electronic Frontier Foundation, Cypherpunks và Cygnus Solutions. Ông tạo ra thuyết phân cấp alt.* trong Usenet và là người đóng góp chính của dự án GNU.
Jon “maddog” Hall là Giám đốc điều hành của Linux International, một tổ chức phi quyền lợi lập nên từ những nhà cung cấp máy tính muốn hỗ trợ và đẩy mạnh hệ điều hành Linux.
Grace Murray Hopper là một nhà khoa học máy tính Mỹ và sĩ quan Hải quân Mỹ. Bà là một trong những lập trình viên kì cựu của Harvard Mark I, và phát triển trình biên dịch đầu tiên cho một ngôn ngữ lập trình. Do những thành tích đó mà người ta còn gọi bà là “Amazing Grace”.
David Korn, sáng lập ra Korn Shell, thường mặc áo thun in hình ban nhạc Korn. (Cool)!
Eric Steven Raymond là một lập trình viên, nhà văn và luật sư nổi tiếng trong cộng đồng mã nguồn mở. Ông nổi tiếng với câu nói: “Câu văn luộm thuộm thì tư duy cũng luộm thuộm”.
Richard Matthew Stallman là một nhà phát triển phần mềm kiêm hacker. Năm 1983, ông khởi xướng dự án GNU tạo nên Hệ điều hành Unix. Ông còn là người phát triển trình soạn thảo Emacs gốc, GNU Compiler Collection (GCC), và GNU Debugger.
Bjarne Stroustrup là một nhà khoa học máy tính Đan Mạch. Ông đã thiết kế và phát triển ngôn ngữ lập trình C++ vào năm 1983.
Linus Benedict Torvalds - cha đẻ của chim cánh cụt Linux khi còn là 1 SV trường ĐH Helsinki (Phần Lan).
Larry Wall là lập trình viên, nhà ngôn ngữ học và nhà văn. Ông tạo ra ngôn ngữ nổi tiếng Perl. Các hacker ngày nay cần phải cám ơn ông rất nhiều.
Stephan Gary “Woz” Wozniak - đồng sáng lập Apple cùng Steve Jobs.
Dennis MacAlistair Ritchie và Kenneth Lane Thompson - cha đẻ Unix. Ken Thompson tạo ra ngôn ngữ B còn Dennis Ritchie tạo ra ngôn ngữ C.
Bill Gates và Paul Allen - miễn bình luận!
Loyd Blankenship, biệt danh: The Mentor (người cố vấn) được biết đến như 1 hacker khét tiếng và là nhà văn từ những năm 1980, khi ông còn là thành viên của các tổ chức hacker Extasyy Elite và Legion of Doom.
Riley Eller, biệt danh: Caezar, là thành viên của Ghetto Hackers.
Dan Farmer là 1 chuyên viên an minh máy tính. Sau khi tốt nghiệp ĐH Purdue, ông bắt đầu phát triển chương trình COPS, chương trình này giải thích tại sao Unix bảo mật đến như vậy. Năm 1995, ông và Wietse Venema sáng lập ra SATAN (Security Administrator Tool for Analyzing Networks). Nhìn ông này trông giống tay vocal của Kreator.
Susan Lynn Headley, biệt danh: Thunder, là 1 trong số ít ỏi các nữ hacker, cô là thành viên của Roscoe Gang.
Richard Pryce - khi mới 16 tuổi, cậu sinh viên âm nhạc này đã nổi danh như cồn vì thành tích phá vỡ hệ thống hàng trăm máy tính của Griffiths Air Force Base, NASA và Korean Atomic Research Institute.
Bruce Schneier là một chuyên gia an minh mạng, 1 nhà mật mã học. Ông là tác giả 1 vài cuốn sách viết về bảo mật và mật mã. Ông phát minh ra các thuật toán Blowfish và Twofish.
Kết luận :
Hackers là những người... tóc dài hoặc rậm râu ! (hoặc cả 2)
Con đường thành nerd/geek vẫn còn xa quá !!
Monday, November 03, 2008
Ubuntu post-installation notes [2]
Now what?
Well, some more basic steps for those who are new to Ubuntu:
(assumed you have done the adding repositories by the steps 5, 6, 7 in previous post)
1/ Install graphic drivers (of ATI/Nvidia): by using EnvyNG
then go to menu Applications->EnvyNG
+ 2nd method: from deb repositories
(using Synaptic Package Manager, from menu System->Administration->Hardware Drivers)
2/ Make a bridge connection : (useful for cross-cable ones, such as Laptops)
+ Firstly, install bridge-utils :
+ Then enable 2 ethernet cards and add it to the bridge. I wrote a simple script (bridge-utils.sh) for doing this instead of manually typing each command :
## Tao interface br0 cho bridge va enable no len
sudo brctl addbr br0
ifconfig br0 up
ifconfig br0 0
echo 1 > /proc/sys/net/ipv4/conf/br0/forwarding
echo 1 > /proc/sys/net/ipv4/conf/br0/proxy_arp
## Bat (enable) 2 card mang
ifconfig eth0 up
ifconfig eth0 0
ifconfig eth1 up
ifconfig eth1 0
## Gan eth0 va eth1 vao br0
brctl addif br0 eth0
brctl addif br0 eth1
## Cau hinh ip address, netmask, gateway
ifconfig br0 192.168.1.33 netmask 255.255.255.0 ##NOTE: change to your IP and NETMASK addresses
route add default gw 192.168.1.1 dev br0 ##NOTE: change to your GATEWAY address
## Bonus: them DNS server vao danh sach trong resolv.conf
#echo "nameserver 4.2.2.2" >> /etc/resolv.conf
#echo "nameserver 208.67.222.222" >> /etc/resolv.conf
#### END
+ After you have edit the IP addresses in the script to yours, save the file (in my case the name is "bridge-utils.sh") . Then change the mode of it so that it can be executable:
and run it either by:
or
Apply the password if prompted ! And it's DONE !
3/ Install SAMBA client (to access Windows networks) :
4/ Install SAMBA server (to share directories/files for Windows network):
5/ Install wireless driver :
(chắc mọi người cài được cho laptop của mình rồi, nên tui khỏi ghi :D )
Thursday, October 09, 2008
Linux directory structure
+ Cấu trúc thư mục của Linux KHÔNG cần khái niệm các ổ đĩa: Cho dù bạn có bao nhiêu phân vùng thì đường dẫn tuyệt đối của một thư mục cũng bắt đầu từ một thư mục gốc có tên là '/' (đọc là 'root') , chứ không phải là C: hay D: ^^ . Bởi các phân vùng luận lý hoặc các ổ đĩa vật lý đều có thể được sẽ được "map" (ánh xạ) vào một thư mục con riêng biệt bất kỳ .
(thực sự thì Windows cũng map tự động các phân vùng logic thành các tên C:\ , D:\ , ... )
+ Trong đường dẫn của Linux, các thư mục được phân cách nhau bằng ký hiệu slash (sổ trái) / , trong khi với DOS/Windows là ký hiệu sổ phải \ (backslash)
+ Tên của các tập tin hoặc thư mục trong Linux phân biệt chữ hoa và chữ thường, VD: 'abc', 'Abc', 'ABC' là khác nhau. (trong khi trong Windows thì không phân biệt)
Từ thư mục root ta sẽ có các thư mục con, mỗi thư mục con lại có một số thư mục con nữa, cứ thế tạo thành 1 cấu trúc thư mục dạng cây (và đó cũng là lý do tại sao thư mục đầu tiên được gọi là gốc/rễ: 'root' ) . Tuy nhiên do tính cơ động cao, dễ mount/unmount và không tự phân thành các phân vùng con, cấu trúc thư mục của Linux có thể trở thành rất lớn (big tree) và khó nhớ . Vì thế người ta đã cố gắng tạo một cấu trúc thư mục đồng nhất, tổ chức sắp xếp phân cấp thành các nhóm theo chức năng.
Cho đến nay hầu như cách tổ chức thư mục trên Linux/Unix đã được chuẩn hóa, mỗi dòng phân phối Linux đều giống nhau ở một số phần chung (kể cả các BSD và Unix khác cũng tương tự), có thể nói là thống nhất mặc dù số lượng dòng phân phối Linux lên đến hàng trăm !
Bây giờ ta sẽ lược sơ qua các thư mục chủ yếu mà hệ thống Linux nào cũng đặt làm mặc định (default) : / , /boot , /bin , /home , /usr , /opt, /etc , /dev, /var, /tmp , ...
* Thư mục /
Đây thường được gọi với tên 'root directory' - nghĩa là thư mục gốc. Đây là nơi sẽ chứa mọi thư mục con khác. Đây là thư mục bắt buộc phải có cho bất cứ một hệ thống linux nào.
* Thư mục /boot
Thường được dùng để chứa kernel, và các cấu hình để boot hệ thống. Chẳng hạn có thư mục con /boot/grub là nơi chứa GRUB giúp cho việc multi-boot giữa nhiều hệ điều hành, đây là 1 thư mục đáng chú ý khi bạn cài song song Linux với Windows.
* Thư mục /home
Là nơi chứa tất cả các dữ liệu cá nhân cho từng user trên hệ thống (ngoại trừ user root). VD: tạo /home/CuTi là thư mục riêng cho user CuTi, /home/CuTeo là thư mục riêng cho user CuTeo ^^ . Cũng có thể phân ra kiểu khác: như có phòng ban SV và phòng ban GV thì ta đặt /home/SV/CuTi , /home/SV/CuTeo và /home/GV/Ninja, /home/GV/Mediocre , ...
* Thư mục /media và /mnt
Hai thư mục này thường được dùng để đặt các mount point, tức là điểm để mount thủ công các thiết bị. Như đã bàn ở trên, một partition muốn dùng được phải được mount. Các mount point đó thường được đặt trong /mnt. Một số các chương trình ứng dụng mới không dùng /mnt mà dùng /media là nơi default để đặt các mount point. Do đó, rất nhiều distro cung cấp cả hai thư mục, và sử dụng link để tương thích cho thói quen của user và các application.
(VD: phân vùng cài Windows của bạn thường được mount ở 1 trong 2 thư mục trên, USB flash disk cắm vào cũng thường được mount ở đây)
* Thư mục /usr
Là nơi chứa rất nhiều các chương trình được cài đặt trên hệ thống. Ngoài ra, các thư mục con của /usr còn dùng để chứa các tập tin chạy (binary), các library, các tập tin include, các manual pages, vân vân... Chẳng hạn từ điển StarDict thường được cài vào thư mục /usr/share/stardict , các tài liệu manual thì nằm trong /usr/man hoặc /usr/doc
(đây cũng là lý do mà sau khi cài Win tôi cài toàn bộ ứng dụng vào D:\usr thay vì C:\Program Files)
* Thư mục /dev
/dev là nơi kernel đặt các thiết bị (device) file. Trong linux và các hệ điều hành Unix-like, mỗi device đều được gán cho một file và các file này sẽ được đặt trong /dev. Chẳng hạn các ổ đĩa cứng ATA sẽ được nhận là /dev/hda , /dev/hdb, /dev/hdc... , còn các ổ SCSI và flash (USB) thì nhận là /dev/sda , /dev/sdb , ...
Ngoài các file device dành cho các hardware trên hệ thống, ở /dev còn có thêm một số file rất tiện dụng như /dev/zero, /dev/null, /dev/random.
Lưu ý: /dev là một pseudo fileSystem. Nghĩa là directory /dev là một file system ảo. Kernel sẽ tự tạo và đặt các device file vào /dev nếu như kernel nhận ra device đó. Bất kỳ một device nào cũng cần có driver để tương tác với kernel. Driver cho linux thường đã được nằm sẵn trong kernel. Bạn nào có config và rebuild kernel sẽ nhận ra có rất nhiều driver được support.
* Thư mục /etc
Nơi chứa các file cấu hình hệ thống, lưu dạng text để user dễ chỉnh sửa. Các tập tin đáng chú ý gồm có:
/etc/inittab : là một file định rõ những process nào được khởi động cùng hệ thống.
Ví dụ: bạn có thể cấu hình X –Windows có thể khởi động cùng với hệ thống hay ko, hoặc điều gì xảy ra khi bạn nhấn tổ hợp phím (CTRL+ALT+BACKSPACE).
/etc/fstab : file chứa thông tin mount tự động các thiết bị ngoại vi: HDD, CDROM ...
/etc/password : lưu giữ thông tin về user và password tương ứng
* Thư mục /bin
Đây là thư mục chứa các chương trình nhị phân (binary) thực thi cơ bản nhất trong hệ thống. Các file thực thi (executable) này thường là các chương trình thiết yếu và đủ để hệ thống có thể khởi động và làm việc ở mức căn bản.
(ngoài ra còn /usr/bin chứa nhiều utilities cho người dùng hơn, và một số hệ thống tạo ra /sbin , /usr/sbin dành cho các super user )
* Thư mục /lib
/lib thường là nơi chứa các library cần thiết cho hệ thống hoạt động. Một số thư mục khác cũng dùng để đặt lib gồm có: /usr/lib, /usr/local/lib.
Một thư mục đáng quan tâm khác trong /lib là /lib/modules. /lib/modules chứa các modules của kernel đang dùng. Nếu trên máy tính có nhiều hơn 1 kernel, trong /lib/modules sẽ có các directory khác tương ứng cho từng version của kernel.
* Thư mục /opt
/opt thường được dùng làm nơi cài đặt thêm các chương trình mang tính 'optional', có nghĩa là không có mặt mặc định chung cho hệ thống (server != desktop) . Chẳng hạn các gói như XAMPP thường được cài vào đây.
* Thư mục /tmp
Dùng để chứa các file tạm (temporary). Các file này thường được tạo khi chạy chương trình và xóa sau khi chương trình đã hoàn tất và thoát. (Nhưng các file tạm cỡ lớn và hay thay đổi thì thường lưu trong /var hơn là trong /tmp , chẳng hạn các file tạm của server , database)
Một điểm lưu ý là các users đều phải có quyền write và read trên /tmp. Một user bình thường hoàn toàn cần có /tmp để chứa các file tạm khi user đó sử dụng hệ thống.
* Thư mục /var
/var thường được gọi là 'kho chứa log' cho cả hệ thống. Mặc định, rất nhiều chương trình sẽ có log ở một trong các thư mục nằm trong /var. Để tránh bị "phình to" quá khổ thì thường sẽ có 1 script viết chạy thường trực kiểm tra dung lượng var và khi lớn đến mức nào đó sẽ report, gởi mail để có biện pháp clean hoặc tăng mount thêm ổ cứng vật lý ^^
* Thư mục /proc
/proc cũng là một pseudo fileSystem. Các file hoặc thư mục trong /proc sẽ được kernel khởi tạo trong lúc hoạt động. Trong /proc sẽ có các file hoặc thư mục tương ứng cho các process đang chạy, và ngay cả kernel. Rất nhiều kernel parameters có thể được xem và thay đổi bằng cách edit trực tiếp các file tương ứng trong /proc mà không cần dùng sysctl .
* Thư mục /root
/root là home directory cho account có quyền cao nhất trong hệ thống Linux, mặc định account này tên là 'root' . Thư mục này cũng tương tự như các home directory khác trên hệ thống. Chỉ khác ở điểm thư mục này không nằm trong /home/username mà được đặt ngay trong /
* [Bonus]
Ngoài các thư mục chính kể trên, Linux có thể còn một số thư mục khác nằm ngay trong / . Và thường Linux còn cần có một phân vùng hoán chuyển (swap) để làm vùng nhớ tạm khi RAM không đủ. Trước đây swap thường chiếm khoảng 1.5 đến 2.5 lần dung lượng RAM, nhưng bây giờ hệ thống nào cũng dư RAM, nên máy cá nhân chỉ cần 200-500 MB cho swap là đủ rồi :-)
(Cái Virtual Memory của Windows cũng là bắt chước từ cái swap này)
(Tổng hợp từ "Lập trình Linux" tập 1, khoaimi, và Wiki)