Download presentation
Presentation is loading. Please wait.
1
Introduction to Java IEEM241 Routing and Fleet Management Feb 3, 2005
2
Agenda Installing and set PATH environment variables First Cup of Java –HelloWorldApp.java Java basics File I/O Reference
3
Installing Java In IS Lab –WinXP: all are installed with the J2SE Software Development Kit (JDK) –Win98: Check C:\ drive, whether there is a folder named something like j2sdk?????, i.e. c:\j2sdk1.4.2_06 If not, double click the installation file on D:\ drive. The filename is something like j2sdk-1_4_2_06- windows-i586-p.exe.
4
Installing Java (cont’d) For your own PC –Download http://java.sun.com/j2se/1.4.2/download.html Download J2SE SDK(JDK) In UST, http://143.89.21.185/ieem241/j2sdk- 1_4_2_04-windows-i586-p.exehttp://143.89.21.185/ieem241/j2sdk- 1_4_2_04-windows-i586-p.exe
5
Update the PATH environment variable For Windows 2000/XP: –Start Settings Control Panel double-click System ->Advanced tab Environment Variables –Look for "Path" in the User Variables and System Variables. –Add c:\j2sdk1.4.2_ \bin; at the end of PATH –Click "Set", "OK" or "Apply –Run new Command Prompt window to take effect
6
Update the PATH environment variable (cont’d) For Windows 98: –In IS Lab Open a command window Type set PATH=%PATH%; c:\j2sdk1.4.2_ \bin; Notice: DO NOT close this window –For your own PC Edit autoexec.bat in C: Add c:\j2sdk1.4.2_ \bin after PATH = Save the file and reboot the system (In IS Lab we cannot do this. All files on C:\ will be recovered after rebooting.)
7
First Cup of Java: create source file –Use notepad or other java developer software, type in the following code Save as HelloWorldApp.java in a directory Notice 1: File name should be the same as the class name Notice 2: Case Sensitive, HelloWorldApp helloworldapp
8
First Cup of Java: Compile the source File Start a command window –For WinXP/2000, start a new command prompt window –For Win98, use the same window that you set the PATH environment variable, or open a new one and reset the PATH Change to the directory which you save the.java file (e.g cd c:\java) Type javac HelloWorldApp.java Type dir, you can see a file called “ HelloWorldApp.class ” was created
9
First Cup of Java: Running it! –In the same directory, enter at the prompt: java HelloWorldApp –Now you should see:
10
First Cup of Java: Errors –Bad command or file name(in Win98) –'javac' is not recognized as an internal or external command, operable program or batch file. (in WinXP) –Exception in thread “main” java.lang.NoClassDefFoundError –Check if you have typed a wrong file name –Check the PATH environment variable –Check whether the file is in the current directory
11
Java Basics: comments –Comment Type Document comments /** */ /* text */ and //
12
Java Basics: Class Each.java file should contain a class with the same name as the file name.
13
Java Basics: main The main method –Meaningful when public class if there are more than 1 class in this file –Should be verbatim in this form
14
Read & Write File Notice 1: “import” is like “#include” in C++ Notice 2: DO NOT forget the try-catch clause Read & write a file line by line package
15
Read & Write File Can only read/write files character by character
16
In Class Exercises Bubble Sorting Generating a simple report Generating a calendar All source files can be downloaded from http://143.89.21.185/ieem241/t1/ http://143.89.21.185/ieem241/t1/ If your PC does not have UltraEdit-32 installed, please download from http://143.89.21.185/ieem241/uedit32/
17
Reference –The Java Tutorial http://java.sun.com/docs/books/tutorial/inform ation/download.html –Bruce Eckel, Thinking in Java, 3 rd Edition http://www.mindview.net/Books/TIJ http://www.mindview.net/Books/TIJ –Java course website http://developer.java.sun.com/developer/onlineTraining
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.