Download Java Development JCreator How to run JCreator?

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
Java Development Process
Developing Java Programs with
• Step 1: Editing the Program
• Step 2: Compiling the Program
JCreator:
• Step 3: Running the Program
Editing, Compiling and Running
1
2
JCreator
Java Development
• Several programs that perform different tasks used
to edit, compile and run
– Java Development Kit (JDK) – available free from
http://java.sun.com/
• Integrated Development Environments (IDE)
–
–
–
–
Borland’s JBuilder
Metrowerk’s CodeWarrior
Nottingham’s CourseMarker
JCreator
• Editor with ability of colour coding.
• Automated Indention
• Code Folding
• Debugger Interface.
• More and more facilities.
4
Example: Colour Coding
Correct Code
5
• Easy to use.
• Word Completion
3
Incorrect Code
• Powerful IDE (Integrated Development
Environment) for Java.
How to run JCreator?
• Click on ‘Start’ Menu
• Choose ‘Program’
• Find ‘JCreator’
• Click on ‘JCreator’
OR
• double click on ‘JCreator’ shortcut
6
1
How to create a file?
Step 1: Editing the Program
• Creating a file
• Saving your file (java program)
• Java file names
7
• Start writing your program.
• Save your program by pressing Ctrl+S
OR selecting ‘Save’ from ‘File’ Menu.
•
•
•
•
•
Choose ‘New’ from ‘File’ Menu OR press Ctrl+N.
Click on ‘Files’ tab on ‘New’ box.
Select ‘Java File’.
Enter your file name (e.g. test).
Select the location that you want to place your program (e.g.
h:\MyProgram).
• Select ok.
8
Some important issues:
• Java file names are case sensitive.
• Java programs should have .java extensions.
you don’t have to worry about that as JCreator does that
automatically for you.
9
10
Step 2 : Compile the program
When you compile…
• Select ‘Compile File’ from ‘Build’ Menu.
OR use the shortcut.
11
• The Java Compiler translates your program
into Java bytecode, which is interpreted by
the Java Virtual Machine (JVM).
• Successful compilation will create a
bytecode .class file
12
2
After the compilation process…
• You may have no errors:
– Your program is ready to be executed. So go to step 3.
• You may have some errors:
– Go back to your program and try correct it using the
information that the JCreator compiler gives you.
– Then compile again.
– If there are no errors, go to step 3 for running your
program.
Example: Compilation Error
class test
{
public static void main(String argv [])
{
// prints "Hello World"
system.out.println("Hello World");
}
}
9.
system.out.println("Hello World");
^----^
*** Semantic Error: No field named "system" was found in type "test".
13
14
Example: Compilation Error
class test
{
public static void main(String argv [])
{
// prints "Hello World"
System.out.println("Hello World")
}
}
9.
System.out.println("Hello World")
Example: Compilation Error
class test
{
public static void main(String argv []
{
// prints "Hello World"
System.out.println("Hello World");
}
}
6.
public static void main(String argv []
^-------------------------------^
*** Syntax: ";" inserted to complete BlockStatementsopt
^
*** Syntax: ) expected after this token
15
Example: Compilation Error
class test
{
public static void main(String argv [])
{
/ prints "Hello World"
System.out.println("Hello World");
}
}
8.
16
Example: Compilation Error
class test
{
public static void main(String argv [])
{
// prints "Hello World"
System.out.println("Hello World");
}
5. { . . .
/ prints "Hello World"
10.
^--------------------^
*** Syntax: Unexpected symbols ignored
}
-------->
*** Syntax: "}" inserted to complete ClassBody
17
18
3
Step 3: Run your Program
Example: Run Time Error
At this stage, the JVM interprets your program, which has been loaded
into memory.
To to run your program:
• Select ‘Execute File’ from ‘Build’ Menu
OR
• Click on shortcut from toolbar.
19
20
If you want to …
• Save your program with different name:
Select ‘Save As’ from ‘File’ menu and enter your desired file name and the
location you need to put it.
• Open an existing file:
Select ‘open’ from ‘File’ menu (or press Ctrl + O) and find your file from the
right directory.
• Copy selected lines of code somewhere else:
Highlight the code with the help of mouse or Shift + Arrow key.
Press Ctrl + C or choose ‘copy’ from ‘Edit’ Menu.
Go to the destination line.
Press Ctrl + V or select ‘paste’ from ‘Edit’ Menu.
• Move selected lines of code somewhere else:
Highlight the code with the help of mouse or Shift + Arrow key.
• Print your file:
Select ‘print’ from ‘File’ menu (or press Ctrl + P).
Press Ctrl + X or choose ‘cut’ from ‘Edit’ Menu.
Go to the destination line.
Press Ctrl + V or select ‘paste’ from ‘Edit’ Menu.
21
22
• Undo
Press Ctrl + Z or select ‘undo’ from ‘Edit’ menu.
• Find a word(s) in file:
Press Ctrl + F or select ‘find’ from ‘Search’ menu.
Enter the word(s) you want to find.
adjust the options in Find box to your desire.
click on ‘find next’.
Common Syntax Errors
• Leaving out symbols such as:
• ;
• }
• )
• Ignore symbol ‘+’ between two literal
strings in print statement
For more shortcut look at ‘advanced’ from ‘Edit’ Menu.
For more information on JCreator look at
http://www.jcreator.com/
23
• System.out.println("Hello" "World");
24
4
Common Semantic Errors
• Failing to define a variable before it is used.
• Use of non-static variables inside a static
method.
• Type mismatch.
• Using a variable that has not been initialised
• Declaring an identifier more than once.
25
5