Preparing%20Java%20Programs - PowerPoint PPT Presentation

About This Presentation
Title:

Preparing%20Java%20Programs

Description:

COMPILE. RUN. errors. Result. Verifying the algorithm. Chapter 5. Program development. 3 ... Use the javac command to compile: javac prog.java ... – PowerPoint PPT presentation

Number of Views:34
Avg rating:3.0/5.0
Slides: 10
Provided by: cen7150
Category:

less

Transcript and Presenter's Notes

Title: Preparing%20Java%20Programs


1
Chapter 5
  • Preparing Java Programs

2
Program development
3
Program development
pico prog.java
javac prog.java
java prog
4
High-level languages
  • Machine language computers native language.
  • Add two numbers 00100111 1010 0101
  • Assembly language uses mnemonics.
  • Add two numbers ADD R1 R2
  • An assembly code needs to be translated to
    machine code.

5
High-level languages
  • High-level programming languages bridging the
    gap between machine language and natural
    languages.
  • Examples COBOL, Fortran, Algol, C
  • Add two numbers (in C) Z A B
  • Compilation translation to machine code.

6
A Java program
  • A sample Java program
  • // A Java program to read a number and compute
    and display its square.
  • import java.io.
  • class square
  • public static void main(String arg) throws
    IOException
  • int n
  • BufferedReader stdin new BufferedReader
  • (new InputStreamReader (System.in))
  • System.out.print ("Enter the number to be
    square ")
  • n Integer.parseInt (stdin.readLine())
  • System.out.println ("The square of " n "
    is " nn)

7
Compilation in Java
  • Use the javac command to compile
  • javac prog.java
  • Produces the object file with extension .class
    (eg prog.class)
  • To run object file, use the java command
  • java prog

8
Errors
  • Compilation errors occur during compilation.
  • Reason syntax errors.
  • Easy to rectify.
  • Run-time errors occur during execution.
  • Reasons logic errors, data errors, computation
    errors.
  • Harder to rectify.

9
Homework
  • Try exercises in chapter 5.
Write a Comment
User Comments (0)
About PowerShow.com