Title: Editing Java programs with the BlueJ IDE
1Editing Java programs with the BlueJ IDE
2Working environments to develop ( write)
programs
- There are 2 ways to develop (write) computer
programs
- Using an editor (e.g. gedit) and a compiler (such
as javac) separately. - You have seen this method in the last webnote ---
http//192.168.1.3/cheung/teaching/web/170/Syllab
us/02/BlueJ/java.html - 2. Using an editor and a compiler in an
integrated manner
3Working environments to develop ( write)
programs (cont.)
- In the second way, you will need to install a
special application called an Integrated
Development Environment (IDE)
4Java IDEs
- There are a number of Integrated Development
Environment IDE) available for Java - Java IDEs
- Eclipse -- Eclipse is highly extensible and
customizable, but hard to learn (freely
available) - NetBeans -- created by Sun MircoSystem (original
designer of the Java programming language)
(freely available) - JBuilder -- top commercial Java IDE very
costly... - BlueJ -- easy to learn (freely available)
5Java IDEs (cont.)
- In this webnote, you will learn to edit Java
programs with BlueJ - In the next webnote, you will learn how to
- You will learn how to program in the Java
programming language later in this course
- compile the Java program with BlueJ
- run the (compiled) Java program with BlueJ
6Java IDEs (cont.)
- BlueJ is freely available and it can be obtained
from this website http//www.bluej.org/
7Preparation
- Before you can use BlueJ, you must
- Login to a computer in the MathCS lab
- Open a terminal window
- Change the current (working) directory to your
cs170 directory This directory is used to store
CS 170 labs and homework.
8Information about this BlueJ tutorial
- The tutorial is described from the perspective of
the user cheung - (Because it was developed by Professor Cheung)
- The directory used to hold the project is
/home/cheung/cs170 - For clarity, I have delete all files and folders
from my cs170 directory.
9Information about this BlueJ tutorial (cont.)
- We will write a simple Java program and store the
program in a project directory called "TestProj".
- The "TestProj" will be contained inside the
/home/cheung/cs170 directory. - In other words, the absolute path of the project
directory is
- /home/cheung/cs170/TestProj
10Information about this BlueJ tutorial (cont.)
- Here is the Simple Java program that you will
enter into BlueJ - You don't need to understand this program right
now it will be explained later in the course.
public class Hello public static void
main(String args) System.out.println("Hel
lo Class") System.out.println("How is
everyone doing so far ?")
11Topics covered in this (short) tutorial
- Things you need to learn to get started with
BlueJ
- Run the BlueJ application
- Create a new project in BlueJ
- Create a new program file
- Insert text into the file
- Delete text from the file
- Goto a certain line in the file
- Search for a pattern in the file
- Search and replace for a pattern with another
pattern in the file - Undo a change
- Save your work
- Quit without saving (because you made a mess)...
12Starting the BlueJ IDE application
- Enter the following command in a terminal window
- This will run BlueJ as a detached process
UNIX promptgtgt bluej
13Starting the BlueJ IDE application (cont.)
- You will first see an announcement window
14Starting the BlueJ IDE application (cont.)
- When it's ready, you will see the main window
15Create a new project
- BlueJ requires that each project be stored in a
different directory -
- When you create a new project, BlueJ will also
create a new directory for you.
16Create a new project (cont.)
- How to create a new project
- Left click on the Project tab
- Then left click on the New Project tab
-
17Create a new project (cont.)
18Create a new project (cont.)
- Enter the name of the new project directory
(/home/cheung/cs170/TestProj) and click on the
Create button
19Create a new project (cont.)
- When BlueJ has successful created an new
project, it will show the following window
20Create a new program file
- Suppose we want to create a file that contains
the following Java program (given above)
public class Hello public static void
main(String args) System.out.println("Hel
lo Class") System.out.println("How is
everyone doing so far ?")
21Create a new program file (cont.)
- Notice that the program is called class Hello
- This will be important in the creation procedure.
22Create a new program file (cont.)
- How to create a Java program file
- Left click on the New Class button
23Create a new program file (cont.)
24Create a new program file (cont.)
- Type in the name of the "class" (which is Hello)
and click OK - A new window will pop up
25Create a new program file (cont.)
- Final result
- You can see the new file Hello in the TestProj
area.
26Create a new program file (cont.)
- To see that BlueJ has created a file, we list the
content of the TestProj directory from a terminal
window - The icon named Hello in BlueJ represents the
program file Hello.java inside the TestProj
directory.
27Open a program file for editing
- If you want to edit a program file, do the
following
- Right click on the file icon
- Then left click on the Open Editor button
28Open a program file for editing
- If you want to edit a program file, do the
following
29Open a program file for editing
- The new window contains the content of the file
Hello.java -
- (To verify, use "cat Hello.java" in a terminal
window) -
- BlueJ has already inserted a few things in the
file Hello.java to help you start writing a Java
program
30Deleting text from a file
- How to delete text from a file
- Highlight the text in BlueJ that you want to
delete
31Deleting text from a file (cont.)
- Press the backspace key You can also press the
delete key or control-X - Result
32Inserting text into a file
- Use the scroll bar on the right to find the
location in the file where you want to insert
text. - Left click at the insert location
- Then type in the new text.
- Example
33Insert text by copy and paste
- You can insert text from another window into the
document in BlueJ by using the copy and paste
facility
- Highlight any text in a window (e.g., from a
webpage) The highlighted text is automatically
copied in UNIX - (On a Windows-based PC, you need to type
control-C to copy) - Now click in the BlueJ window at the position
where you want to insert the highlighted text - Type control-V (for paste)
34Replacing some text
- Delete the text
- Insert new text
35Undo a change
- When you make a edit mistake, you can undo the
last change with the undo-command
36Undo a change (cont.)
- You can undo earlier changes by pressing
control-Z multiple time - The maximum number of changes can be undo is 25
37Undo an undo
- Suppose you have undone a change that was in fact
correct - You can undo an undo operation using
- control-Y (this is called a Redo operation) Â Â Â
38Goto a certain line in the file
- A feature that is very useful when you write
computer programs is - That is because compilers (an application that
translates a program written in a high level
language into machine code) always report an
error along with the location (as a line number)
in the file.
- Goto a certain line in a file
39Goto a certain line in the file (cont.)
- How to go to line number n in a file
- Left click on the Tools tab
- Then left click on the Go to Line tab
40Goto a certain line in the file (cont.)
Example After this, a window will pop up
and you can enter the desired line number
41Goto a certain line in the file (cont.)
- The keyboard shortcut for the Go to Line function
is control-L
42Search for a text pattern
- Finding the next occurrence of a pattern in a
file
- Left click on the Find tab The lower portion of
the BlueJ window will change to the Find menu - Example
43Search for a text pattern (cont.)
- Enter the search text pattern and click Next
- The text highlighted in yellow is the next
matching pattern - All other matching patterned are highlighted in
blue
44Search for a text pattern (cont.)
- Left click on the Next button to find the
subsequent matching pattern - Search forward
- Left click on the Prev button to search forward
45Search and Replace
- Finding the next occurrence of a text pattern in
a file and replace it with some other pattern
- Left click on the Replace tab
- The lower portion of the BlueJ window will change
to the Replace menu
46Search and Replace (cont.)
Example
47Search and Replace (cont.)
2. Enter the replacement pattern in the Replace
field
48Search and Replace (cont.)
- Click on the Once button to replace the current
occurrence (in yellow)
49Search and Replace (cont.)
You can replace the next occurrence by clicking
on Once another time. Click on All to replace
every occurrence
50Search and Replace (cont.)
- If you do not want to replace the current
occurrence and want to continue the Search and
Replace operation, then do the following - Click on the text immediately after the current
occurrence - Click Next (to find the next occurrence)
- Continue with replace if desire
51Search and Replace (cont.)
52Search and Replace (cont.)
- Click on the text immediately after the current
occurrence
53Search and Replace (cont.)
- Click Next
- Continue with the Replace operation if so
desired.
54Saving the changes
- You do not need to save your work.
- When you quit (close) the BlueJ window, it saves
your works automatically
55Saving the changes (cont.)
- Save your work explicitly
- You can choose to save your work explicit by
clicking of Class and then Save
56Quit without saving your work...
- You do not have this option in BlueJ
57Exit BlueJ
- Before you exit BlueJ, I would recommend that you
save all your changes explicitly -
- You have learned saving your work above !!!
58Exit BlueJ (cont.)
- To exit BlueJ, click Project in the BlueJ's main
window - and select Quit