Editing Java programs with the BlueJ IDE - PowerPoint PPT Presentation

About This Presentation
Title:

Editing Java programs with the BlueJ IDE

Description:

Editing Java programs with the BlueJ IDE Working environments to develop (= write) programs There are 2 ways to develop (write) computer programs: Working ... – PowerPoint PPT presentation

Number of Views:303
Avg rating:3.0/5.0
Slides: 59
Provided by: Nath96
Category:
Tags: bluej | ide | editing | java | programs

less

Transcript and Presenter's Notes

Title: Editing Java programs with the BlueJ IDE


1
Editing Java programs with the BlueJ IDE
2
Working 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

3
Working environments to develop ( write)
programs (cont.)
  • In the second way, you will need to install a
    special application called an Integrated
    Development Environment (IDE)

4
Java 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)

5
Java 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

6
Java IDEs (cont.)
  • BlueJ is freely available and it can be obtained
    from this website http//www.bluej.org/

7
Preparation
  • 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.

8
Information 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.

9
Information 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

10
Information 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 ?")
11
Topics 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)...

12
Starting the BlueJ IDE application
  • Enter the following command in a terminal window
  • This will run BlueJ as a detached process

UNIX promptgtgt bluej
13
Starting the BlueJ IDE application (cont.)
  • You will first see an announcement window

14
Starting the BlueJ IDE application (cont.)
  • When it's ready, you will see the main window

15
Create 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.

16
Create a new project (cont.)
  • How to create a new project
  • Left click on the Project tab
  • Then left click on the New Project tab

17
Create a new project (cont.)
  • A new window will pop up

18
Create a new project (cont.)
  • Enter the name of the new project directory
    (/home/cheung/cs170/TestProj) and click on the
    Create button

19
Create a new project (cont.)
  • When BlueJ has successful created an new
    project, it will show the following window

20
Create 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 ?")
21
Create a new program file (cont.)
  • Notice that the program is called class Hello
  • This will be important in the creation procedure.

22
Create a new program file (cont.)
  • How to create a Java program file
  • Left click on the New Class button

23
Create a new program file (cont.)
  • A new window will pop up

24
Create a new program file (cont.)
  • Type in the name of the "class" (which is Hello)
    and click OK
  • A new window will pop up

25
Create a new program file (cont.)
  • Final result
  • You can see the new file Hello in the TestProj
    area.

26
Create 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.

27
Open 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

28
Open a program file for editing
  • If you want to edit a program file, do the
    following
  • A new window will pop up

29
Open 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

30
Deleting text from a file
  • How to delete text from a file
  • Highlight the text in BlueJ that you want to
    delete

31
Deleting text from a file (cont.)
  • Press the backspace key You can also press the
    delete key or control-X
  • Result

32
Inserting 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

33
Insert text by copy and paste
  • You can insert text from another window into the
    document in BlueJ by using the copy and paste
    facility
  1. Highlight any text in a window (e.g., from a
    webpage) The highlighted text is automatically
    copied in UNIX
  2. (On a Windows-based PC, you need to type
    control-C to copy)
  3. Now click in the BlueJ window at the position
    where you want to insert the highlighted text
  4. Type control-V (for paste)

34
Replacing some text
  • How to replace text
  • Delete the text
  • Insert new text

35
Undo a change
  • When you make a edit mistake, you can undo the
    last change with the undo-command
  • control-Z    

36
Undo a change (cont.)
  • Undo earlier changes
  • You can undo earlier changes by pressing
    control-Z multiple time
  • The maximum number of changes can be undo is 25

37
Undo 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)    

38
Goto 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

39
Goto a certain line in the file (cont.)
  • How to go to line number n in a file
  1. Left click on the Tools tab
  2. Then left click on the Go to Line tab

40
Goto a certain line in the file (cont.)
Example After this, a window will pop up
and you can enter the desired line number
41
Goto a certain line in the file (cont.)
  • Keyboard shortcut
  • The keyboard shortcut for the Go to Line function
    is control-L

42
Search 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

43
Search 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

44
Search 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

45
Search 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

46
Search and Replace (cont.)
Example
47
Search and Replace (cont.)
2. Enter the replacement pattern in the Replace
field
48
Search and Replace (cont.)
  1. Click on the Once button to replace the current
    occurrence (in yellow)

49
Search and Replace (cont.)
You can replace the next occurrence by clicking
on Once another time. Click on All to replace
every occurrence
50
Search and Replace (cont.)
  • Hint
  • 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

51
Search and Replace (cont.)
  • Example

52
Search and Replace (cont.)
  • Click on the text immediately after the current
    occurrence

53
Search and Replace (cont.)
  • Click Next
  • Continue with the Replace operation if so
    desired.

54
Saving the changes
  • Auto saving
  • You do not need to save your work.
  • When you quit (close) the BlueJ window, it saves
    your works automatically

55
Saving the changes (cont.)
  • Save your work explicitly
  • You can choose to save your work explicit by
    clicking of Class and then Save

56
Quit without saving your work...
  • You do not have this option in BlueJ

57
Exit BlueJ
  • Before you exit BlueJ, I would recommend that you
    save all your changes explicitly
  • You have learned saving your work above !!!

58
Exit BlueJ (cont.)
  • Exiting BlueJ
  • To exit BlueJ, click Project in the BlueJ's main
    window
  • and select Quit
Write a Comment
User Comments (0)
About PowerShow.com