Download presentation
Presentation is loading. Please wait.
Published byFelicity Strickland Modified over 9 years ago
2
Chapter 5: Preparing Java Programs 1 Chapter 5 Preparing Java Programs
3
Chapter 5Program development2 EDIT Understanding the problem Writing an algorithm Converting to code COMPILE RUN errors Result Verifying the algorithm
4
Chapter 5Program development3 EDIT COMPILE RUN errors Result Source code pico prog.java javac prog.java java prog
5
Chapter 5High-level languages4 qMachine language: computer’s native language. Add two numbers: 00100111 1010 0101 qAssembly language: uses mnemonics. Add two numbers: ADD R1 R2 An assembly code needs to be translated to machine code.
6
Chapter 5High-level languages5 qHigh-level programming languages: bridging the gap between machine language and natural languages. qExamples: COBOL, Fortran, Algol, C Add two numbers (in C): Z = A + B; qCompilation: translation to machine code.
7
Chapter 5A Java program6 qA 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 " + n*n); }
8
Chapter 5Compilation in Java7 qUse the javac command to compile: javac prog.java qProduces the object file with extension.class (eg: prog.class) qTo run object file, use the java command: java prog
9
Chapter 5Errors8 qCompilation errors: occur during compilation. uReason: syntax errors. uEasy to rectify. qRun-time errors: occur during execution. uReasons: logic errors, data errors, computation errors. uHarder to rectify.
10
Chapter 5Homework9
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.