Download presentation
Presentation is loading. Please wait.
Published byBennett Phillip Dawson Modified over 8 years ago
1
EIE375 BlueJ: Getting Started Dr Lawrence Cheung
2
EIE 375 BlueJ: Getting Started Hong Kong Polytechnic University 2 Login Login your computer in CF105, CF105a. Username: student id. (e.g., 01234567D) Password: your email password After login, you will find there exists a network drive for your storage, i.e., Drive H. You should have a flash drive to save all your programs.
3
EIE 375 BlueJ: Getting Started Hong Kong Polytechnic University 3 BlueJ BlueJ is a Java programming development environment. This software package that can help you to develop and test program codes.
4
EIE 375 BlueJ: Getting Started Hong Kong Polytechnic University 4 Installation Prerequisites: You must have J2SE v1.4 (JDK 1.4) or later installed on your system. You can download it from Sun’s web site at http://java.sun.com http://java.sun.com Download both “JRE” (Java Runtime Environment) and “SDK” (Software Development Kit) Downloading JRE only is not sufficient.
5
EIE 375 BlueJ: Getting Started Hong Kong Polytechnic University 5 Installation The distribution file for Windows systems is called bluejsetup-xxx.exe, where xxx is a version number. Example: bluejsetup-200.exe represents version 2.0.0. You can download it from the BlueJ web site at http://www.bluej.org http://www.bluej.org
6
EIE 375 BlueJ: Getting Started Hong Kong Polytechnic University 6 Getting Started Create a new project (a group of Java programs) Select “New Project...” from the Project menu. Click OK, and the new project is created and opened.
7
EIE 375 BlueJ: Getting Started Hong Kong Polytechnic University 7 Getting Started Create a new class Select “New Class...” from the menu. A dialog will appear to let you enter a name for the new class
8
EIE 375 BlueJ: Getting Started Hong Kong Polytechnic University 8 Getting Started Edit a class Right click the icon of the class and select “Open Editor”. Or you simply double-click the icon.
9
EIE 375 BlueJ: Getting Started Hong Kong Polytechnic University 9 Getting Started Compile a project Select “Compile” from the menu. This function will always try to compile all un-compiled classes. If errors are detected, each class with one or more errors is opened and the first error is displayed.
10
EIE 375 BlueJ: Getting Started Hong Kong Polytechnic University 10 Getting Started Compile a class Right click the icon of the class and select “Compile”.
11
EIE 375 BlueJ: Getting Started Hong Kong Polytechnic University 11 Getting Started Create an object from a class Right click the class and select a constructor for the class. An object creation dialog will appear. This dialog may look like this:
12
EIE 375 BlueJ: Getting Started Hong Kong Polytechnic University 12 Getting Started In the name field, you have to enter a name for the object (or instance) to be created. If the constructor has parameters, the dialog will also include fields to enter the parameters.
13
EIE 375 BlueJ: Getting Started Hong Kong Polytechnic University 13 Getting Started Once the object is created, it will appear on the object bench. The object icon shows its name and class. For example:
14
EIE 375 BlueJ: Getting Started Hong Kong Polytechnic University 14 Getting Started Call a method To call any method, you must first create an object first. Then you can right click the object. A pop-up menu will list all methods of the object. When a method is selected, it will execute and the result (if any) will be displayed in a separate window.
15
EIE 375 BlueJ: Getting Started Hong Kong Polytechnic University 15 Getting Started Call the main method Right click the class icon and select “void main(String[] args)”
16
EIE 375 BlueJ: Getting Started Hong Kong Polytechnic University 16 Program Execution without BlueJ You can run your java programs in Windows command prompt. Open a Windows command prompt. Move to the working directory. Run by typing java.
17
EIE 375 BlueJ: Getting Started Hong Kong Polytechnic University 17 Debugging Set a breakpoint Open a class and select “Set/Clear Breakpoint” from the Tools menu. Or click in the tag bar and then click in that area will set a breakpoint at the selected position.
18
EIE 375 BlueJ: Getting Started Hong Kong Polytechnic University 18 Debugging Once execution reaches the breakpoint, the machine will be interrupted, the source code currently executed will be shown and the debugger window will be opened automatically.
19
EIE 375 BlueJ: Getting Started Hong Kong Polytechnic University 19 Debugging You can then use the “Step” or “Step Into” button to step through your code. The current position in the code will be indicated by an arrow in the tag bar. Note: Step will execute the whole method and stop again at the next instruction after the method. Step Into will go into the method and stop at the first instruction within the method.
20
EIE 375 BlueJ: Getting Started Hong Kong Polytechnic University 20 First Java Program: “Hello World” Step 1: Create a new project then create a new class named “HelloWorld”. Step 2: Open a class then type in the following text: public class HelloWorld { private String name; public HelloWorld(String fullName) { name = fullName; }
21
EIE 375 BlueJ: Getting Started Hong Kong Polytechnic University 21 First Java Program: “Hello World” public String getName() { return name; } public void print() { System.out.println(name); } public static void main(String[] args) { System.out.println("Hello, World!"); }
22
EIE 375 BlueJ: Getting Started Hong Kong Polytechnic University 22 First Java Program: “Hello World” Step 3: Compile the program. If you compiled your program successfully, you should have.class file under your project directory. Step 4: Execute the program.
23
EIE 375 BlueJ: Getting Started Hong Kong Polytechnic University 23 Reminder Each time when you start to work on a new tutorial exercise, assignment or mini- project, you should Create a new project and, Create a new.java file.
24
End
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.