Thứ Ba, 25 tháng 12, 2007

Giới thiệu lập trình Java

JDK 6u1 The Java SE Development Kit (JDK) includes the Java Runtime Environment (JRE) and command-line development tools that are useful for developing applets and applications. Mình down bản jdk-6u1-windows-i586-p.exe . Cài đặt tại thư mục C:\Java\J2SDK .Trong thư mục bin (nằm trong thư mục J2SDK) có chứa file + javac.exe : Đây là trình biên dịch của java. Bạn muốn biên dịch HelloWorld.java thì cần phải gọi chương trình này ra. Như sau: C:\>Java\J2SDK\bin\javac.exe C:\Java\javafiles\HelloWorld.java + java.exe : trình thông dịch các chương trình java. VD: C:\> cd Java\javafiles C:\Java\javafiles>C:\Java\J2SDK\bin\java.exe HelloWorld Rõ ràng là chẳng ai muốn mỗi lần chạy java lại phải gõ đầy đủ đường đẫn đến thư mục chứa file chạy java. Vì vậy, nên cập nhật cái đường dẫn này vào PATH. Để đưa đường dẫn ( giả sử lấy đường dẫn "C:\Java\J2SDK\bin" như IPv6 dùng ) vào PATH ta chỉ cần khai báo nó trong file "Autoexec.bat" theo mẫu : SET PATH=C:\Java\J2SDK\bin Có cách làm điều này : Cách 1 : vào Run -> gõ "sysedit" -> Enter -> chọn cửa sổ "C:\Autoexec.bat" -> nhập đường dẫn vào theo mẫu trên Cách 2 : Mở Windows Explorer -> vào ổ C: -> cho hiện tất cả các file ẩn và các file hệ thống ( bằng cách vào Folder Option -> View tab ) , khi đó sẽ nhìn thấy file Autoexec.bat hiện lên trong ổ C:-> chỉ việc mở ra (bằng cách nhấp phải chuột -> edit ) mà nhập đường dẫn vào thôi. Cách 3 : Vào Control Panel -> System -> chọn tab Advance -> Environment Variables -> trong ô phía dưới tìm dòng bắt đầu bởi Path -> Edit -> trong ô Variable Value, đừng xoá, hãy thêm vào cuối dòng đó đường dẫn của ta với dấu ";" ở trước, cụ thể : " ;C:\Java\J2SDK\bin " Normally, TextPad will automatically add commands to compile and run Java applications and applets in the Tools menu in textpad. Otherwise: Add "Compile Java" and "Run Java Application" commands in your TextPad Here we talk about how to add these commands manually: 1. Choose Configure menu and click "Preferences..." command
2. Click "Tools" in left column, click "Add" in right column and choose "Program..." command
3. In "Select a File" dialog, find "javac.exe" program which you have installed with Java SDK software on your computer, and click "Open"
4. You will see a "javac" in the middle column, click it and rename it to "Compile Java".
5. Click "Apply", and expand "Tools" option in left column, you will see "Compile Java" option is there. 6. Click "Compile Java" option, and check the configuration. Make sure that "Parameters:" is $File and "Initial folder:" is $FileDir. Select Capture output and Sound alert when completed. Ignore other options/parameters. Click "Apply" if you make any changes.
7. Click "Tools" in left column again, click "Add" in right column and choose "Program..." command.
8. In "Select a File" dialog, find "java.exe" program which you have installed with Java SDK software on your computer, and click "Open"
9. You will see a "java" in the middle column, click it and rename it to "Run Java Application".
10. Click "Apply", and expand "Tools" option in left column, you will see "Run Java Application" option is there. 11. Click "Run Java Application" option, and check the configuration. Make sure that "Parameters:" is $BaseName and "Initial folder:" is $FileDir. Unselect all options.
12. Click "Apply" if you make any changes. Click "OK" to exit configuration. Then you will see two commands have been added to your Tools menu in TextPad.
13. Now "Compile Java" and "Run Java Application" have been added in your TextPad.

Không có nhận xét nào: