Slides 0 - Introduction
Slides 0 - Introduction
OBJECT ORIENTED
PROGRAMMING I
Slides 0: Introduction
n 2
So?
Humans -- natural language Machines -- binary language
q Large vocabulary q Small vocabulary
q Complex syntax q Simple syntax
q Semantic ambiguity q No semantic ambiguity
Programming language
q Ex: ???
q Vocabulary: restricted
q Syntax: small and restricted
q Semantic: no ambiguity (almost)
n 3
Origins of the Java Language
q Created by Sun Microsystems (1991)
n 4
Compilers
q A compiler:
– is a software tool which translates source code into
another language
q Java is different…
n 5
Java Translation
q Java compiler:
• Java source code --> bytecode
• A machine language for a fictitious computer called the Java
Virtual Machine
q Java interpreter:
• Executes the Java Virtual Machine (JVM)
• Java bytecode --> into machine language and executes it
• Translating byte-code into machine code is relatively easy
compared to the initial compilation step
q So the Java compiler is not tied to any particular machine
q Once compiled to byte-code, a Java program can be used on any
computer, making it very portable
n 6
Java Translation
Java source
Code
MyProg.java
n 7
Some definitions
q Algorithm:
• A step-by-step process for solving a problem
• Expressed in natural language
q Pseudocode:
• An algorithm expressed in a more formal language
• Code-like, but does not necessarily follow a specific
syntax
q Program:
• An algorithm expressed in a programming language
• Follows a specific syntax
n 8
Problem Solving
n 9
Java Program Structure
q A java program:
• is made up of one or more classes (collection of
actions)
• a class contains one or more methods (action)
• a method contains program
statements/instructions
n 10
Java Program Structure
// comments about the class
public class MyProgram class header
{
class body
} MyProgram.java
n 11
Java Program Structure
// comments about the class
public class MyProgram
{
}
MyProgram.java
n 12
A small Java program
//********************************************************
// Author: L. Kosseim
//
// Demonstrates the basic structure of a Java application.
//********************************************************
public class Hello
{
//--------------------------------------------------------
// Prints a message on the screen
//--------------------------------------------------------
public static void main (String[] args)
{
System.out.println ("Hello World!!!");
}
}
Hello.java
extension of java programs
Java is case sensitive!
q Syntax rules
define how we can put together symbols, reserved
words, and identifiers to make a valid program
q Semantics
define what a statement means
n 14
3 types of errors
q Compile-time (syntax) errors
• The compiler will find syntax errors and other basic
problems
q Run-time errors
• A problem can occur during program execution
n 15
3 types of errors …
q Logical (semantic) errors… aka a bug
• A mistake in the algorithm
• Compiler cannot catch them
• A program may run, but produce
incorrect results
Ex: ??
A) Syntax error
B) Run-time error
C) Logic error
D) All of the above
n 17
Basic Program Development
Edit and
save program
Compilation
errors Run-time &
logical
Compile program errors
n 18
Development Environments
q Basic compiler & interpreter
• Sun Java Development Kit (JDK) -- download from Sun
n 19
Development Environments
q IDE (Integrated Development Environment)
• Eclipse
• JCreator
• Borland JBuilder
• Microsoft Visual J++
• … see course Web site to download them
n 20