0% found this document useful (0 votes)
5 views20 pages

Slides 0 - Introduction

The document introduces Object-Oriented Programming I (COMP 248) and discusses the differences between human and machine languages, emphasizing the need for programming. It covers the origins of Java, its compilation process, and the structure of Java programs, including definitions of algorithms, pseudocode, and the steps in problem-solving. Additionally, it outlines types of errors in programming and the development environments available for Java programming.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views20 pages

Slides 0 - Introduction

The document introduces Object-Oriented Programming I (COMP 248) and discusses the differences between human and machine languages, emphasizing the need for programming. It covers the origins of Java, its compilation process, and the structure of Java programs, including definitions of algorithms, pseudocode, and the steps in problem-solving. Additionally, it outlines types of errors in programming and the development environments available for Java programming.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 20

COMP 248:

OBJECT ORIENTED
PROGRAMMING I

Slides 0: Introduction

The content on these slides was originally provided by


Dr. Nora Houari.
Why do programming?
q Humans communicate in a natural language
– Large vocabulary (10 000s words)
– Complex syntax
– Semantic ambiguity
■ The chair’s leg is broken.
■ The man saw the boy with the telescope.

q Machines communicate in binary code / machine


language
– Small alphabet (2 characters… 1, 0)
– Simple syntax
– No semantic ambiguity

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 Compiler + Interpreter


(COMP 248 + COMP 249)

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)

q Originally designed for programming home


appliances
q Introduced in 1995 and its popularity has grown
quickly since

q Is an object-oriented programming (OOP)


language

n 4
Compilers
q A compiler:
– is a software tool which translates source code into
another language

q Usually (ex. C, C++)


– The compiler translates directly into machine language
– But each type of CPU uses a different machine
language
– … so same executable file will not work on different
platforms
– … need to re-compile the original source code on
different platforms

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

Java Compiler Machine


javac MyProg.java Code

Java Bytecode Java Interpreter


MyProg.class java MyProg

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

q The purpose of writing a program is to solve


a problem

q The general steps in problem solving are:


1. Understand the problem
2. Design a solution (find an algorithm)
3. Implement the solution (write the program)
4. Test the program and fix any problems

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

q A Java program always contains a method called main

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
{

// comments about the method


public static void main (String[] args)
{
method header
method body
}

}
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!

You will type and run this program in tutorial 1


n 13
Syntax and Semantics

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

q A program that is syntactically correct is not


necessarily logically (semantically) correct.

n 14
3 types of errors
q Compile-time (syntax) errors
• The compiler will find syntax errors and other basic
problems

• An executable version of the program is not created


Ex: ??

q Run-time errors
• A problem can occur during program execution

• Causes the program to terminate abnormally


Ex: ??

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: ??

• The process of eliminating bugs is called debugging


• (who found the first bug?)

Grace Hopper (1906-1992)


American Computer Scientist
& US Navy Admiral n 16
Detecting errors ….

The hardest kind of error to detect in a computer program


is a:

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

Execute program and


evaluate results

n 18
Development Environments
q Basic compiler & interpreter
• Sun Java Development Kit (JDK) -- download from Sun

• Compiler: javac Hello.java


The result is a byte-code program called: Hello.class

• Interpreter: java Hello

n 19
Development Environments
q IDE (Integrated Development Environment)
• Eclipse
• JCreator
• Borland JBuilder
• Microsoft Visual J++
• … see course Web site to download them

q In tutorial 1, you will edit, compile and run Hello.java

n 20

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy