csen 202 – introduction to computer programming - lecture

105
Overview Today’s lecture Background Java A first program CSEN 202 – Introduction to Computer Programming Lecture 1: Introduction and overview Prof. Dr. Slim Abdennadher Dr. Rimon Elias [email protected], [email protected] German University Cairo, Faculty of Media Engineering and Technology Abdennadher GUC–MET CSEN 202

Upload: others

Post on 11-Nov-2021

38 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: CSEN 202 – Introduction to Computer Programming - Lecture

Overview Today’s lecture Background Java A first program

CSEN 202 – Introduction to ComputerProgramming

Lecture 1:Introduction and overview

Prof. Dr. Slim AbdennadherDr. Rimon Elias

[email protected],[email protected]

German University Cairo, Faculty of Media Engineering and Technology

Abdennadher GUC–MET

CSEN 202

Page 2: CSEN 202 – Introduction to Computer Programming - Lecture

Overview Today’s lecture Background Java A first program

About this class

Structure of this class

Lectures.

Tuesday 5th slotWednesday 2nd slotThursday 2nd and 3rd slotProf.Dr. Slim AbdennadherSaturday 4th slotMonday 3rd slotDr. Rimon Elias

Exercises and Homework.Practical assignmentsIndividual work with feedback and advice from yourteaching assistant

Labs.Supervised lab assignmentsIndividual work during the labs

Abdennadher GUC–MET

CSEN 202

Page 3: CSEN 202 – Introduction to Computer Programming - Lecture

Overview Today’s lecture Background Java A first program

About this class

Structure of this classLectures.

Tuesday 5th slotWednesday 2nd slotThursday 2nd and 3rd slotProf.Dr. Slim AbdennadherSaturday 4th slotMonday 3rd slotDr. Rimon Elias

Exercises and Homework.Practical assignmentsIndividual work with feedback and advice from yourteaching assistant

Labs.Supervised lab assignmentsIndividual work during the labs

Abdennadher GUC–MET

CSEN 202

Page 4: CSEN 202 – Introduction to Computer Programming - Lecture

Overview Today’s lecture Background Java A first program

About this class

Structure of this classLectures.

Tuesday 5th slotWednesday 2nd slotThursday 2nd and 3rd slotProf.Dr. Slim Abdennadher

Saturday 4th slotMonday 3rd slotDr. Rimon Elias

Exercises and Homework.Practical assignmentsIndividual work with feedback and advice from yourteaching assistant

Labs.Supervised lab assignmentsIndividual work during the labs

Abdennadher GUC–MET

CSEN 202

Page 5: CSEN 202 – Introduction to Computer Programming - Lecture

Overview Today’s lecture Background Java A first program

About this class

Structure of this classLectures.

Tuesday 5th slotWednesday 2nd slotThursday 2nd and 3rd slotProf.Dr. Slim AbdennadherSaturday 4th slotMonday 3rd slotDr. Rimon Elias

Exercises and Homework.Practical assignmentsIndividual work with feedback and advice from yourteaching assistant

Labs.Supervised lab assignmentsIndividual work during the labs

Abdennadher GUC–MET

CSEN 202

Page 6: CSEN 202 – Introduction to Computer Programming - Lecture

Overview Today’s lecture Background Java A first program

About this class

Structure of this classLectures.

Tuesday 5th slotWednesday 2nd slotThursday 2nd and 3rd slotProf.Dr. Slim AbdennadherSaturday 4th slotMonday 3rd slotDr. Rimon Elias

Exercises and Homework.Practical assignmentsIndividual work with feedback and advice from yourteaching assistant

Labs.Supervised lab assignmentsIndividual work during the labs

Abdennadher GUC–MET

CSEN 202

Page 7: CSEN 202 – Introduction to Computer Programming - Lecture

Overview Today’s lecture Background Java A first program

About this class

Structure of this classLectures.

Tuesday 5th slotWednesday 2nd slotThursday 2nd and 3rd slotProf.Dr. Slim AbdennadherSaturday 4th slotMonday 3rd slotDr. Rimon Elias

Exercises and Homework.Practical assignmentsIndividual work with feedback and advice from yourteaching assistant

Labs.Supervised lab assignmentsIndividual work during the labs

Abdennadher GUC–MET

CSEN 202

Page 8: CSEN 202 – Introduction to Computer Programming - Lecture

Overview Today’s lecture Background Java A first program

About this class

Grading

Tentative weights of the assessments:

Final exam 40%Mid-term exam 25%Quizzes 25%Lab Assignments 10%

Abdennadher GUC–MET

CSEN 202

Page 9: CSEN 202 – Introduction to Computer Programming - Lecture

Overview Today’s lecture Background Java A first program

About this class

Grading

Tentative weights of the assessments:Final exam 40%

Mid-term exam 25%Quizzes 25%Lab Assignments 10%

Abdennadher GUC–MET

CSEN 202

Page 10: CSEN 202 – Introduction to Computer Programming - Lecture

Overview Today’s lecture Background Java A first program

About this class

Grading

Tentative weights of the assessments:Final exam 40%Mid-term exam 25%

Quizzes 25%Lab Assignments 10%

Abdennadher GUC–MET

CSEN 202

Page 11: CSEN 202 – Introduction to Computer Programming - Lecture

Overview Today’s lecture Background Java A first program

About this class

Grading

Tentative weights of the assessments:Final exam 40%Mid-term exam 25%Quizzes 25%

Lab Assignments 10%

Abdennadher GUC–MET

CSEN 202

Page 12: CSEN 202 – Introduction to Computer Programming - Lecture

Overview Today’s lecture Background Java A first program

About this class

Grading

Tentative weights of the assessments:Final exam 40%Mid-term exam 25%Quizzes 25%Lab Assignments 10%

Abdennadher GUC–MET

CSEN 202

Page 13: CSEN 202 – Introduction to Computer Programming - Lecture

Overview Today’s lecture Background Java A first program

About this class

Survival guide

How to succeed in this course:

Hang in!Attend lectures, tutorials, and labs, take notesParticipate in the discussions, be activeSolve the assignments, understand the model solutionsprovided

Master the infrastructure!Learn how to operate the software (editor, IDE)Understand the interaction (input/output, error messages)Contribute within the teamInstall relevant software on your own computer/laptop

Remember that this is an introduction to computerprogramming

Abdennadher GUC–MET

CSEN 202

Page 14: CSEN 202 – Introduction to Computer Programming - Lecture

Overview Today’s lecture Background Java A first program

About this class

Survival guide

How to succeed in this course:Hang in!

Attend lectures, tutorials, and labs, take notesParticipate in the discussions, be activeSolve the assignments, understand the model solutionsprovided

Master the infrastructure!Learn how to operate the software (editor, IDE)Understand the interaction (input/output, error messages)Contribute within the teamInstall relevant software on your own computer/laptop

Remember that this is an introduction to computerprogramming

Abdennadher GUC–MET

CSEN 202

Page 15: CSEN 202 – Introduction to Computer Programming - Lecture

Overview Today’s lecture Background Java A first program

About this class

Survival guide

How to succeed in this course:Hang in!

Attend lectures, tutorials, and labs, take notesParticipate in the discussions, be activeSolve the assignments, understand the model solutionsprovided

Master the infrastructure!Learn how to operate the software (editor, IDE)Understand the interaction (input/output, error messages)Contribute within the teamInstall relevant software on your own computer/laptop

Remember that this is an introduction to computerprogramming

Abdennadher GUC–MET

CSEN 202

Page 16: CSEN 202 – Introduction to Computer Programming - Lecture

Overview Today’s lecture Background Java A first program

About this class

Survival guide

How to succeed in this course:Do not fall behind!

Regularly check the course website for announcements,updates, material, resources

http://met.guc.edu.eghttp://cms.guc.edu.eg

Ask your TA (during the tutorial / office hours), professor(lecture)

Abdennadher GUC–MET

CSEN 202

Page 17: CSEN 202 – Introduction to Computer Programming - Lecture

Overview Today’s lecture Background Java A first program

What you will learn (and why)

Motivation

Why should you take CSEN 202?

Improve your problem solving skills (clarity, precision, logic,etc.)To use computers for problem solvingAcquire new skills that will allow you to create useful andcustomized computer-based applicationsIt is in the curriculumAcquire a useful vocabulary that will impress others ingeeky conversations

Abdennadher GUC–MET

CSEN 202

Page 18: CSEN 202 – Introduction to Computer Programming - Lecture

Overview Today’s lecture Background Java A first program

What you will learn (and why)

Motivation

Why should you take CSEN 202?Improve your problem solving skills (clarity, precision, logic,etc.)

To use computers for problem solvingAcquire new skills that will allow you to create useful andcustomized computer-based applicationsIt is in the curriculumAcquire a useful vocabulary that will impress others ingeeky conversations

Abdennadher GUC–MET

CSEN 202

Page 19: CSEN 202 – Introduction to Computer Programming - Lecture

Overview Today’s lecture Background Java A first program

What you will learn (and why)

Motivation

Why should you take CSEN 202?Improve your problem solving skills (clarity, precision, logic,etc.)To use computers for problem solving

Acquire new skills that will allow you to create useful andcustomized computer-based applicationsIt is in the curriculumAcquire a useful vocabulary that will impress others ingeeky conversations

Abdennadher GUC–MET

CSEN 202

Page 20: CSEN 202 – Introduction to Computer Programming - Lecture

Overview Today’s lecture Background Java A first program

What you will learn (and why)

Motivation

Why should you take CSEN 202?Improve your problem solving skills (clarity, precision, logic,etc.)To use computers for problem solvingAcquire new skills that will allow you to create useful andcustomized computer-based applications

It is in the curriculumAcquire a useful vocabulary that will impress others ingeeky conversations

Abdennadher GUC–MET

CSEN 202

Page 21: CSEN 202 – Introduction to Computer Programming - Lecture

Overview Today’s lecture Background Java A first program

What you will learn (and why)

Motivation

Why should you take CSEN 202?Improve your problem solving skills (clarity, precision, logic,etc.)To use computers for problem solvingAcquire new skills that will allow you to create useful andcustomized computer-based applicationsIt is in the curriculum

Acquire a useful vocabulary that will impress others ingeeky conversations

Abdennadher GUC–MET

CSEN 202

Page 22: CSEN 202 – Introduction to Computer Programming - Lecture

Overview Today’s lecture Background Java A first program

What you will learn (and why)

Motivation

Why should you take CSEN 202?Improve your problem solving skills (clarity, precision, logic,etc.)To use computers for problem solvingAcquire new skills that will allow you to create useful andcustomized computer-based applicationsIt is in the curriculumAcquire a useful vocabulary that will impress others ingeeky conversations

Abdennadher GUC–MET

CSEN 202

Page 23: CSEN 202 – Introduction to Computer Programming - Lecture

Overview Today’s lecture Background Java A first program

What you will learn (and why)

Course outline

Introduction to JavaFundamental Data TypesDecisionsIterationMethodsRecursionClasses and ObjectsArrays

Abdennadher GUC–MET

CSEN 202

Page 24: CSEN 202 – Introduction to Computer Programming - Lecture

Overview Today’s lecture Background Java A first program

Outline

Today’s topics and objectives

BackgroundProblem solvingProgramming languages

JavaIntroduction and historyFeatures and constructs

A first programGetting started with JavaSome aspects of Java

Abdennadher GUC–MET

CSEN 202

Page 25: CSEN 202 – Introduction to Computer Programming - Lecture

Overview Today’s lecture Background Java A first program

Outline

Today’s topics and objectives

BackgroundProblem solvingProgramming languages

JavaIntroduction and historyFeatures and constructs

A first programGetting started with JavaSome aspects of Java

Abdennadher GUC–MET

CSEN 202

Page 26: CSEN 202 – Introduction to Computer Programming - Lecture

Overview Today’s lecture Background Java A first program

Outline

Today’s topics and objectives

BackgroundProblem solvingProgramming languages

JavaIntroduction and historyFeatures and constructs

A first programGetting started with JavaSome aspects of Java

Abdennadher GUC–MET

CSEN 202

Page 27: CSEN 202 – Introduction to Computer Programming - Lecture

Overview Today’s lecture Background Java A first program

Outline

Today’s topics and objectives

BackgroundProblem solvingProgramming languages

JavaIntroduction and historyFeatures and constructs

A first programGetting started with JavaSome aspects of Java

Abdennadher GUC–MET

CSEN 202

Page 28: CSEN 202 – Introduction to Computer Programming - Lecture

Overview Today’s lecture Background Java A first program

Problem solving

So what is problem solving?

The purpose of writing a program is to solve a problem

The general steps of problem solving areUnderstand the problemDissect the problem into manageable piecesDesign a solutionConsider alternatives and refine itImplement the solutionTest the solution and fix any problems that exist

Abdennadher GUC–MET

CSEN 202

Page 29: CSEN 202 – Introduction to Computer Programming - Lecture

Overview Today’s lecture Background Java A first program

Problem solving

So what is problem solving?

The purpose of writing a program is to solve a problem

The general steps of problem solving are

Understand the problemDissect the problem into manageable piecesDesign a solutionConsider alternatives and refine itImplement the solutionTest the solution and fix any problems that exist

Abdennadher GUC–MET

CSEN 202

Page 30: CSEN 202 – Introduction to Computer Programming - Lecture

Overview Today’s lecture Background Java A first program

Problem solving

So what is problem solving?

The purpose of writing a program is to solve a problem

The general steps of problem solving areUnderstand the problem

Dissect the problem into manageable piecesDesign a solutionConsider alternatives and refine itImplement the solutionTest the solution and fix any problems that exist

Abdennadher GUC–MET

CSEN 202

Page 31: CSEN 202 – Introduction to Computer Programming - Lecture

Overview Today’s lecture Background Java A first program

Problem solving

So what is problem solving?

The purpose of writing a program is to solve a problem

The general steps of problem solving areUnderstand the problemDissect the problem into manageable pieces

Design a solutionConsider alternatives and refine itImplement the solutionTest the solution and fix any problems that exist

Abdennadher GUC–MET

CSEN 202

Page 32: CSEN 202 – Introduction to Computer Programming - Lecture

Overview Today’s lecture Background Java A first program

Problem solving

So what is problem solving?

The purpose of writing a program is to solve a problem

The general steps of problem solving areUnderstand the problemDissect the problem into manageable piecesDesign a solution

Consider alternatives and refine itImplement the solutionTest the solution and fix any problems that exist

Abdennadher GUC–MET

CSEN 202

Page 33: CSEN 202 – Introduction to Computer Programming - Lecture

Overview Today’s lecture Background Java A first program

Problem solving

So what is problem solving?

The purpose of writing a program is to solve a problem

The general steps of problem solving areUnderstand the problemDissect the problem into manageable piecesDesign a solutionConsider alternatives and refine it

Implement the solutionTest the solution and fix any problems that exist

Abdennadher GUC–MET

CSEN 202

Page 34: CSEN 202 – Introduction to Computer Programming - Lecture

Overview Today’s lecture Background Java A first program

Problem solving

So what is problem solving?

The purpose of writing a program is to solve a problem

The general steps of problem solving areUnderstand the problemDissect the problem into manageable piecesDesign a solutionConsider alternatives and refine itImplement the solution

Test the solution and fix any problems that exist

Abdennadher GUC–MET

CSEN 202

Page 35: CSEN 202 – Introduction to Computer Programming - Lecture

Overview Today’s lecture Background Java A first program

Problem solving

So what is problem solving?

The purpose of writing a program is to solve a problem

The general steps of problem solving areUnderstand the problemDissect the problem into manageable piecesDesign a solutionConsider alternatives and refine itImplement the solutionTest the solution and fix any problems that exist

Abdennadher GUC–MET

CSEN 202

Page 36: CSEN 202 – Introduction to Computer Programming - Lecture

Overview Today’s lecture Background Java A first program

Problem solving

“Divide and conquer”

Many software projects fail because the developer did notreally understand the problem to be solved

We must avoid assumptions and clarify ambiguitiesAs problems grow larger, we need to organize thedevelopment of a solution in manageable pieces:

“Divide and conquer”This technique is fundamental to software development.We will see how Java supports this approach.

Abdennadher GUC–MET

CSEN 202

Page 37: CSEN 202 – Introduction to Computer Programming - Lecture

Overview Today’s lecture Background Java A first program

Problem solving

“Divide and conquer”

Many software projects fail because the developer did notreally understand the problem to be solvedWe must avoid assumptions and clarify ambiguities

As problems grow larger, we need to organize thedevelopment of a solution in manageable pieces:

“Divide and conquer”This technique is fundamental to software development.We will see how Java supports this approach.

Abdennadher GUC–MET

CSEN 202

Page 38: CSEN 202 – Introduction to Computer Programming - Lecture

Overview Today’s lecture Background Java A first program

Problem solving

“Divide and conquer”

Many software projects fail because the developer did notreally understand the problem to be solvedWe must avoid assumptions and clarify ambiguitiesAs problems grow larger, we need to organize thedevelopment of a solution in manageable pieces:

“Divide and conquer”

This technique is fundamental to software development.We will see how Java supports this approach.

Abdennadher GUC–MET

CSEN 202

Page 39: CSEN 202 – Introduction to Computer Programming - Lecture

Overview Today’s lecture Background Java A first program

Problem solving

“Divide and conquer”

Many software projects fail because the developer did notreally understand the problem to be solvedWe must avoid assumptions and clarify ambiguitiesAs problems grow larger, we need to organize thedevelopment of a solution in manageable pieces:

“Divide and conquer”This technique is fundamental to software development.We will see how Java supports this approach.

Abdennadher GUC–MET

CSEN 202

Page 40: CSEN 202 – Introduction to Computer Programming - Lecture

Overview Today’s lecture Background Java A first program

Programming languages

Problem solving using a programming language

A programming language specifies the words and symbolsthat we can use to write a program.

A programming language employs a set of rules thatdictate how the words and symbols can be put together toform valid program statements.Examples of Programming Languages:

FortranCobolCC++, C#PascalPrologJAVA

Abdennadher GUC–MET

CSEN 202

Page 41: CSEN 202 – Introduction to Computer Programming - Lecture

Overview Today’s lecture Background Java A first program

Programming languages

Problem solving using a programming language

A programming language specifies the words and symbolsthat we can use to write a program.A programming language employs a set of rules thatdictate how the words and symbols can be put together toform valid program statements.

Examples of Programming Languages:FortranCobolCC++, C#PascalPrologJAVA

Abdennadher GUC–MET

CSEN 202

Page 42: CSEN 202 – Introduction to Computer Programming - Lecture

Overview Today’s lecture Background Java A first program

Programming languages

Problem solving using a programming language

A programming language specifies the words and symbolsthat we can use to write a program.A programming language employs a set of rules thatdictate how the words and symbols can be put together toform valid program statements.Examples of Programming Languages:

FortranCobolCC++, C#PascalPrologJAVA

Abdennadher GUC–MET

CSEN 202

Page 43: CSEN 202 – Introduction to Computer Programming - Lecture

Overview Today’s lecture Background Java A first program

Programming languages

Levels of programming languages

There are four programming languages levels:

Fourth-generation language — Higher order programminglanguage that introduces complex abstractions andconceptsHigh-level language — Programming language withconvenient programming constructs (Somewhat platformindependent, compiler-specific)Assembly language — Somewhat human-readablemnemonics that encode machine language(hardware-platform specific)Machine language — A byte-stream that can directly beprocessed by computing hardware (hardware-platformspecific)

Abdennadher GUC–MET

CSEN 202

Page 44: CSEN 202 – Introduction to Computer Programming - Lecture

Overview Today’s lecture Background Java A first program

Programming languages

Levels of programming languages

There are four programming languages levels:

Fourth-generation language — Higher order programminglanguage that introduces complex abstractions andconceptsHigh-level language — Programming language withconvenient programming constructs (Somewhat platformindependent, compiler-specific)Assembly language — Somewhat human-readablemnemonics that encode machine language(hardware-platform specific)

Machine language — A byte-stream that can directly beprocessed by computing hardware (hardware-platformspecific)

Abdennadher GUC–MET

CSEN 202

Page 45: CSEN 202 – Introduction to Computer Programming - Lecture

Overview Today’s lecture Background Java A first program

Programming languages

Levels of programming languages

There are four programming languages levels:

Fourth-generation language — Higher order programminglanguage that introduces complex abstractions andconceptsHigh-level language — Programming language withconvenient programming constructs (Somewhat platformindependent, compiler-specific)

Assembly language — Somewhat human-readablemnemonics that encode machine language(hardware-platform specific)Machine language — A byte-stream that can directly beprocessed by computing hardware (hardware-platformspecific)

Abdennadher GUC–MET

CSEN 202

Page 46: CSEN 202 – Introduction to Computer Programming - Lecture

Overview Today’s lecture Background Java A first program

Programming languages

Levels of programming languages

There are four programming languages levels:

Fourth-generation language — Higher order programminglanguage that introduces complex abstractions andconcepts

High-level language — Programming language withconvenient programming constructs (Somewhat platformindependent, compiler-specific)Assembly language — Somewhat human-readablemnemonics that encode machine language(hardware-platform specific)Machine language — A byte-stream that can directly beprocessed by computing hardware (hardware-platformspecific)

Abdennadher GUC–MET

CSEN 202

Page 47: CSEN 202 – Introduction to Computer Programming - Lecture

Overview Today’s lecture Background Java A first program

Programming languages

Levels of programming languages

There are four programming languages levels:Fourth-generation language — Higher order programminglanguage that introduces complex abstractions andconceptsHigh-level language — Programming language withconvenient programming constructs (Somewhat platformindependent, compiler-specific)Assembly language — Somewhat human-readablemnemonics that encode machine language(hardware-platform specific)Machine language — A byte-stream that can directly beprocessed by computing hardware (hardware-platformspecific)

Abdennadher GUC–MET

CSEN 202

Page 48: CSEN 202 – Introduction to Computer Programming - Lecture

Overview Today’s lecture Background Java A first program

Programming languages

The normal compilation procedure

Translating/compiling a program (simplified)

Platform−

specific

libraries

Assembly

Code

Binary

(Machine

Code)

Source Code

Compiling

Execute

Abdennadher GUC–MET

CSEN 202

Page 49: CSEN 202 – Introduction to Computer Programming - Lecture

Overview Today’s lecture Background Java A first program

Introduction and history

What isJava?

Abdennadher GUC–MET

CSEN 202

Page 50: CSEN 202 – Introduction to Computer Programming - Lecture

Overview Today’s lecture Background Java A first program

Introduction and history

What is Java?

It’s an island of Indonesia

They grow a lot of coffee there.

Abdennadher GUC–MET

CSEN 202

Page 51: CSEN 202 – Introduction to Computer Programming - Lecture

Overview Today’s lecture Background Java A first program

Introduction and history

What is Java?

It’s an island of Indonesia

They grow a lot of coffee there.

Abdennadher GUC–MET

CSEN 202

Page 52: CSEN 202 – Introduction to Computer Programming - Lecture

Overview Today’s lecture Background Java A first program

Introduction and history

What is Java?

It is the US-American slang term for coffee

Programmers run on coffee.

Abdennadher GUC–MET

CSEN 202

Page 53: CSEN 202 – Introduction to Computer Programming - Lecture

Overview Today’s lecture Background Java A first program

Introduction and history

What is Java?

It is the US-American slang term for coffee

Programmers run on coffee.

Abdennadher GUC–MET

CSEN 202

Page 54: CSEN 202 – Introduction to Computer Programming - Lecture

Overview Today’s lecture Background Java A first program

Introduction and history

What is Java?

It is the name of a programming language, becauseprogrammers love coffee.

Seriously.

Abdennadher GUC–MET

CSEN 202

Page 55: CSEN 202 – Introduction to Computer Programming - Lecture

Overview Today’s lecture Background Java A first program

Introduction and history

What is Java?

It is the name of a programming language, becauseprogrammers love coffee.

Seriously.

Abdennadher GUC–MET

CSEN 202

Page 56: CSEN 202 – Introduction to Computer Programming - Lecture

Overview Today’s lecture Background Java A first program

Introduction and history

Origin of Java

Began in 1991 with Green Team at Sun Microsystems inMenlo Park, CA

Initial title was OAK (Object Application Kernel)The initial goal was the development of a programminglanguage for embedded devices (e. g., toaster, coffeemachine, VHS recoder, . . . )Java created in 1992 by James Gosling, Patrick Naughton,and Mike Sheridan.Digital TV applications failed to generate businessFocus turned to the InternetNew goal was a general purpose language with anemphasis on portability and interpretation

Abdennadher GUC–MET

CSEN 202

Page 57: CSEN 202 – Introduction to Computer Programming - Lecture

Overview Today’s lecture Background Java A first program

Introduction and history

Origin of Java

Began in 1991 with Green Team at Sun Microsystems inMenlo Park, CAInitial title was OAK (Object Application Kernel)

The initial goal was the development of a programminglanguage for embedded devices (e. g., toaster, coffeemachine, VHS recoder, . . . )Java created in 1992 by James Gosling, Patrick Naughton,and Mike Sheridan.Digital TV applications failed to generate businessFocus turned to the InternetNew goal was a general purpose language with anemphasis on portability and interpretation

Abdennadher GUC–MET

CSEN 202

Page 58: CSEN 202 – Introduction to Computer Programming - Lecture

Overview Today’s lecture Background Java A first program

Introduction and history

Origin of Java

Began in 1991 with Green Team at Sun Microsystems inMenlo Park, CAInitial title was OAK (Object Application Kernel)The initial goal was the development of a programminglanguage for embedded devices (e. g., toaster, coffeemachine, VHS recoder, . . . )

Java created in 1992 by James Gosling, Patrick Naughton,and Mike Sheridan.Digital TV applications failed to generate businessFocus turned to the InternetNew goal was a general purpose language with anemphasis on portability and interpretation

Abdennadher GUC–MET

CSEN 202

Page 59: CSEN 202 – Introduction to Computer Programming - Lecture

Overview Today’s lecture Background Java A first program

Introduction and history

Origin of Java

Began in 1991 with Green Team at Sun Microsystems inMenlo Park, CAInitial title was OAK (Object Application Kernel)The initial goal was the development of a programminglanguage for embedded devices (e. g., toaster, coffeemachine, VHS recoder, . . . )Java created in 1992 by James Gosling, Patrick Naughton,and Mike Sheridan.

Digital TV applications failed to generate businessFocus turned to the InternetNew goal was a general purpose language with anemphasis on portability and interpretation

Abdennadher GUC–MET

CSEN 202

Page 60: CSEN 202 – Introduction to Computer Programming - Lecture

Overview Today’s lecture Background Java A first program

Introduction and history

Origin of Java

Began in 1991 with Green Team at Sun Microsystems inMenlo Park, CAInitial title was OAK (Object Application Kernel)The initial goal was the development of a programminglanguage for embedded devices (e. g., toaster, coffeemachine, VHS recoder, . . . )Java created in 1992 by James Gosling, Patrick Naughton,and Mike Sheridan.Digital TV applications failed to generate business

Focus turned to the InternetNew goal was a general purpose language with anemphasis on portability and interpretation

Abdennadher GUC–MET

CSEN 202

Page 61: CSEN 202 – Introduction to Computer Programming - Lecture

Overview Today’s lecture Background Java A first program

Introduction and history

Origin of Java

Began in 1991 with Green Team at Sun Microsystems inMenlo Park, CAInitial title was OAK (Object Application Kernel)The initial goal was the development of a programminglanguage for embedded devices (e. g., toaster, coffeemachine, VHS recoder, . . . )Java created in 1992 by James Gosling, Patrick Naughton,and Mike Sheridan.Digital TV applications failed to generate businessFocus turned to the Internet

New goal was a general purpose language with anemphasis on portability and interpretation

Abdennadher GUC–MET

CSEN 202

Page 62: CSEN 202 – Introduction to Computer Programming - Lecture

Overview Today’s lecture Background Java A first program

Introduction and history

Origin of Java

Began in 1991 with Green Team at Sun Microsystems inMenlo Park, CAInitial title was OAK (Object Application Kernel)The initial goal was the development of a programminglanguage for embedded devices (e. g., toaster, coffeemachine, VHS recoder, . . . )Java created in 1992 by James Gosling, Patrick Naughton,and Mike Sheridan.Digital TV applications failed to generate businessFocus turned to the InternetNew goal was a general purpose language with anemphasis on portability and interpretation

Abdennadher GUC–MET

CSEN 202

Page 63: CSEN 202 – Introduction to Computer Programming - Lecture

Overview Today’s lecture Background Java A first program

Introduction and history

History of Java

Java was released in 1995C functionalityObject Oriented (OO) capabilitiesOther nice features (e. g., garbage collection)

Advantages:Simple for an OO languageSecure and reliablePlatform independent: will work on any processor that hasa Java interpreter—Java Virtual MachineExtensive libraries (esp. graphics & WWW)

Disadvantages:Slower than C (more overhead)Limits user ability

Abdennadher GUC–MET

CSEN 202

Page 64: CSEN 202 – Introduction to Computer Programming - Lecture

Overview Today’s lecture Background Java A first program

Introduction and history

History of Java

Java was released in 1995C functionalityObject Oriented (OO) capabilitiesOther nice features (e. g., garbage collection)

Advantages:Simple for an OO languageSecure and reliablePlatform independent: will work on any processor that hasa Java interpreter—Java Virtual MachineExtensive libraries (esp. graphics & WWW)

Disadvantages:Slower than C (more overhead)Limits user ability

Abdennadher GUC–MET

CSEN 202

Page 65: CSEN 202 – Introduction to Computer Programming - Lecture

Overview Today’s lecture Background Java A first program

Introduction and history

History of Java

Java was released in 1995C functionalityObject Oriented (OO) capabilitiesOther nice features (e. g., garbage collection)

Advantages:Simple for an OO languageSecure and reliablePlatform independent: will work on any processor that hasa Java interpreter—Java Virtual MachineExtensive libraries (esp. graphics & WWW)

Disadvantages:Slower than C (more overhead)Limits user ability

Abdennadher GUC–MET

CSEN 202

Page 66: CSEN 202 – Introduction to Computer Programming - Lecture

Overview Today’s lecture Background Java A first program

Introduction and history

History of Java

Java was released in 1995C functionalityObject Oriented (OO) capabilitiesOther nice features (e. g., garbage collection)

Advantages:Simple for an OO languageSecure and reliablePlatform independent: will work on any processor that hasa Java interpreter—Java Virtual MachineExtensive libraries (esp. graphics & WWW)

Disadvantages:Slower than C (more overhead)Limits user ability

Abdennadher GUC–MET

CSEN 202

Page 67: CSEN 202 – Introduction to Computer Programming - Lecture

Overview Today’s lecture Background Java A first program

Getting started

Hello world

The first Java program

public class Hello {public static void main (String[] args) {

// display a greeting in the console windowSystem.out.println ("Hello, World!");

}}

This code defines a class named Hello.The definition must be in a file Hello.java.The method main is the code that runs when you executethe program

Abdennadher GUC–MET

CSEN 202

Page 68: CSEN 202 – Introduction to Computer Programming - Lecture

Overview Today’s lecture Background Java A first program

Getting started

Hello world

The first Java program

public class Hello {public static void main (String[] args) {

// display a greeting in the console windowSystem.out.println ("Hello, World!");

}}

This code defines a class named Hello.

The definition must be in a file Hello.java.The method main is the code that runs when you executethe program

Abdennadher GUC–MET

CSEN 202

Page 69: CSEN 202 – Introduction to Computer Programming - Lecture

Overview Today’s lecture Background Java A first program

Getting started

Hello world

The first Java program

public class Hello {public static void main (String[] args) {

// display a greeting in the console windowSystem.out.println ("Hello, World!");

}}

This code defines a class named Hello.The definition must be in a file Hello.java.

The method main is the code that runs when you executethe program

Abdennadher GUC–MET

CSEN 202

Page 70: CSEN 202 – Introduction to Computer Programming - Lecture

Overview Today’s lecture Background Java A first program

Getting started

Hello world

The first Java program

public class Hello {public static void main (String[] args) {

// display a greeting in the console windowSystem.out.println ("Hello, World!");

}}

This code defines a class named Hello.The definition must be in a file Hello.java.

The method main is the code that runs when you executethe program

Abdennadher GUC–MET

CSEN 202

Page 71: CSEN 202 – Introduction to Computer Programming - Lecture

Overview Today’s lecture Background Java A first program

Getting started

Hello world

The first Java program

public class Hello {public static void main (String[] args) {

// display a greeting in the console windowSystem.out.println ("Hello, World!");

}}

This code defines a class named Hello.The definition must be in a file Hello.java.The method main is the code that runs when you executethe program

Abdennadher GUC–MET

CSEN 202

Page 72: CSEN 202 – Introduction to Computer Programming - Lecture

Overview Today’s lecture Background Java A first program

Getting started

Building and executing Java code

Source file name must end in “.java”

Source file name must match the name of the public classA Java Development Kit (JDK) must be installed to compileand run the programsCompiling to produce .class file

$ javac Hello.java

Running in the JVM environment$ java Hello

Notice the lack of .class extension

Abdennadher GUC–MET

CSEN 202

Page 73: CSEN 202 – Introduction to Computer Programming - Lecture

Overview Today’s lecture Background Java A first program

Getting started

Building and executing Java code

Source file name must end in “.java”Source file name must match the name of the public class

A Java Development Kit (JDK) must be installed to compileand run the programsCompiling to produce .class file

$ javac Hello.java

Running in the JVM environment$ java Hello

Notice the lack of .class extension

Abdennadher GUC–MET

CSEN 202

Page 74: CSEN 202 – Introduction to Computer Programming - Lecture

Overview Today’s lecture Background Java A first program

Getting started

Building and executing Java code

Source file name must end in “.java”Source file name must match the name of the public classA Java Development Kit (JDK) must be installed to compileand run the programs

Compiling to produce .class file$ javac Hello.java

Running in the JVM environment$ java Hello

Notice the lack of .class extension

Abdennadher GUC–MET

CSEN 202

Page 75: CSEN 202 – Introduction to Computer Programming - Lecture

Overview Today’s lecture Background Java A first program

Getting started

Building and executing Java code

Source file name must end in “.java”Source file name must match the name of the public classA Java Development Kit (JDK) must be installed to compileand run the programsCompiling to produce .class file

$ javac Hello.java

Running in the JVM environment$ java Hello

Notice the lack of .class extension

Abdennadher GUC–MET

CSEN 202

Page 76: CSEN 202 – Introduction to Computer Programming - Lecture

Overview Today’s lecture Background Java A first program

Getting started

Building and executing Java code

Source file name must end in “.java”Source file name must match the name of the public classA Java Development Kit (JDK) must be installed to compileand run the programsCompiling to produce .class file

$ javac Hello.java

Running in the JVM environment$ java Hello

Notice the lack of .class extension

Abdennadher GUC–MET

CSEN 202

Page 77: CSEN 202 – Introduction to Computer Programming - Lecture

Overview Today’s lecture Background Java A first program

Getting started

Building and executing Java code

Source file name must end in “.java”Source file name must match the name of the public classA Java Development Kit (JDK) must be installed to compileand run the programsCompiling to produce .class file

$ javac Hello.java

Running in the JVM environment$ java Hello

Notice the lack of .class extension

Abdennadher GUC–MET

CSEN 202

Page 78: CSEN 202 – Introduction to Computer Programming - Lecture

Overview Today’s lecture Background Java A first program

Getting started

The Java compilation and execution

Note:

The Java compiler does not produce machine code.The Java compiler produces byte code for the Java VirtualMachine (JVM).The JVM for a platform reads byte code and executes it onthat platform at run time.

Abdennadher GUC–MET

CSEN 202

Page 79: CSEN 202 – Introduction to Computer Programming - Lecture

Overview Today’s lecture Background Java A first program

Getting started

The Java compilation and execution

Note:The Java compiler does not produce machine code.

The Java compiler produces byte code for the Java VirtualMachine (JVM).The JVM for a platform reads byte code and executes it onthat platform at run time.

Abdennadher GUC–MET

CSEN 202

Page 80: CSEN 202 – Introduction to Computer Programming - Lecture

Overview Today’s lecture Background Java A first program

Getting started

The Java compilation and execution

Note:The Java compiler does not produce machine code.The Java compiler produces byte code for the Java VirtualMachine (JVM).

The JVM for a platform reads byte code and executes it onthat platform at run time.

Abdennadher GUC–MET

CSEN 202

Page 81: CSEN 202 – Introduction to Computer Programming - Lecture

Overview Today’s lecture Background Java A first program

Getting started

The Java compilation and execution

Note:The Java compiler does not produce machine code.The Java compiler produces byte code for the Java VirtualMachine (JVM).The JVM for a platform reads byte code and executes it onthat platform at run time.

Abdennadher GUC–MET

CSEN 202

Page 82: CSEN 202 – Introduction to Computer Programming - Lecture

Overview Today’s lecture Background Java A first program

Getting started

The Java compilation and execution

Translating/compiling a Java program (simplified)

Class

files

Library

files

Source Code

Compiling

Virtual machine

Execute

Abdennadher GUC–MET

CSEN 202

Page 83: CSEN 202 – Introduction to Computer Programming - Lecture

Overview Today’s lecture Background Java A first program

Getting started

Concepts that we will handle later

public class Hello {public static void main (String[] args) {

// display a greeting in the console windowSystem.out.println ("Hello, World!");

}}

public class ClassName: public denotes that theclass is usable by the “public”.public static void main(String[] args):defines a method called main.The parameter String[] args contains the commandline arguments

Abdennadher GUC–MET

CSEN 202

Page 84: CSEN 202 – Introduction to Computer Programming - Lecture

Overview Today’s lecture Background Java A first program

Getting started

Concepts that we will handle later

public class Hello {public static void main (String[] args) {

// display a greeting in the console windowSystem.out.println ("Hello, World!");

}}

public class ClassName: public denotes that theclass is usable by the “public”.

public static void main(String[] args):defines a method called main.The parameter String[] args contains the commandline arguments

Abdennadher GUC–MET

CSEN 202

Page 85: CSEN 202 – Introduction to Computer Programming - Lecture

Overview Today’s lecture Background Java A first program

Getting started

Concepts that we will handle later

public class Hello {public static void main (String[] args) {

// display a greeting in the console windowSystem.out.println ("Hello, World!");

}}

public class ClassName: public denotes that theclass is usable by the “public”.public static void main(String[] args):defines a method called main.

The parameter String[] args contains the commandline arguments

Abdennadher GUC–MET

CSEN 202

Page 86: CSEN 202 – Introduction to Computer Programming - Lecture

Overview Today’s lecture Background Java A first program

Getting started

Concepts that we will handle later

public class Hello {public static void main (String[] args) {

// display a greeting in the console windowSystem.out.println ("Hello, World!");

}}

public class ClassName: public denotes that theclass is usable by the “public”.public static void main(String[] args):defines a method called main.The parameter String[] args contains the commandline arguments

Abdennadher GUC–MET

CSEN 202

Page 87: CSEN 202 – Introduction to Computer Programming - Lecture

Overview Today’s lecture Background Java A first program

Getting started

Concepts that we will handle later

public class Hello {public static void main (String[] args) {

// display a greeting in the console windowSystem.out.println ("Hello, World!");

}}

The keyword static means that main does not inspector change objects of the Hello class.The terminal window is represented in Java by an objectcalled out.The System class contains useful objects and methods toaccess system resources.

Abdennadher GUC–MET

CSEN 202

Page 88: CSEN 202 – Introduction to Computer Programming - Lecture

Overview Today’s lecture Background Java A first program

Getting started

Concepts that we will handle later

public class Hello {public static void main (String[] args) {

// display a greeting in the console windowSystem.out.println ("Hello, World!");

}}

The keyword static means that main does not inspector change objects of the Hello class.

The terminal window is represented in Java by an objectcalled out.The System class contains useful objects and methods toaccess system resources.

Abdennadher GUC–MET

CSEN 202

Page 89: CSEN 202 – Introduction to Computer Programming - Lecture

Overview Today’s lecture Background Java A first program

Getting started

Concepts that we will handle later

public class Hello {public static void main (String[] args) {

// display a greeting in the console windowSystem.out.println ("Hello, World!");

}}

The keyword static means that main does not inspector change objects of the Hello class.The terminal window is represented in Java by an objectcalled out.

The System class contains useful objects and methods toaccess system resources.

Abdennadher GUC–MET

CSEN 202

Page 90: CSEN 202 – Introduction to Computer Programming - Lecture

Overview Today’s lecture Background Java A first program

Getting started

Concepts that we will handle later

public class Hello {public static void main (String[] args) {

// display a greeting in the console windowSystem.out.println ("Hello, World!");

}}

The keyword static means that main does not inspector change objects of the Hello class.The terminal window is represented in Java by an objectcalled out.The System class contains useful objects and methods toaccess system resources.

Abdennadher GUC–MET

CSEN 202

Page 91: CSEN 202 – Introduction to Computer Programming - Lecture

Overview Today’s lecture Background Java A first program

Getting started

Concepts that we will handle later

public class Hello {public static void main (String[] args) {

// display a greeting in the console windowSystem.out.println ("Hello, World!");

}}

To use the out object in the System class, we must referto it as System.out.The println method will print a line of text.

Abdennadher GUC–MET

CSEN 202

Page 92: CSEN 202 – Introduction to Computer Programming - Lecture

Overview Today’s lecture Background Java A first program

Getting started

Concepts that we will handle later

public class Hello {public static void main (String[] args) {

// display a greeting in the console windowSystem.out.println ("Hello, World!");

}}

To use the out object in the System class, we must referto it as System.out.

The println method will print a line of text.

Abdennadher GUC–MET

CSEN 202

Page 93: CSEN 202 – Introduction to Computer Programming - Lecture

Overview Today’s lecture Background Java A first program

Getting started

Concepts that we will handle later

public class Hello {public static void main (String[] args) {

// display a greeting in the console windowSystem.out.println ("Hello, World!");

}}

To use the out object in the System class, we must referto it as System.out.The println method will print a line of text.

Abdennadher GUC–MET

CSEN 202

Page 94: CSEN 202 – Introduction to Computer Programming - Lecture

Overview Today’s lecture Background Java A first program

Some aspects of Java

Identifiers

Names in programs are called identifiers.

IdentifiersAlways start with a letter.Can include, digits, underscore and the dollar sign symbol.Must be different from any Java reserved words (orkeywords).Keywords that we have seen so far include: public,static, class, and void.Are case-sensitive, for example foobar, Foobar, andFOOBAR are all different.

We should try to use descriptive names.

Abdennadher GUC–MET

CSEN 202

Page 95: CSEN 202 – Introduction to Computer Programming - Lecture

Overview Today’s lecture Background Java A first program

Some aspects of Java

Identifiers

Names in programs are called identifiers.Identifiers

Always start with a letter.Can include, digits, underscore and the dollar sign symbol.Must be different from any Java reserved words (orkeywords).Keywords that we have seen so far include: public,static, class, and void.Are case-sensitive, for example foobar, Foobar, andFOOBAR are all different.

We should try to use descriptive names.

Abdennadher GUC–MET

CSEN 202

Page 96: CSEN 202 – Introduction to Computer Programming - Lecture

Overview Today’s lecture Background Java A first program

Some aspects of Java

Identifiers

Names in programs are called identifiers.Identifiers

Always start with a letter.Can include, digits, underscore and the dollar sign symbol.Must be different from any Java reserved words (orkeywords).Keywords that we have seen so far include: public,static, class, and void.Are case-sensitive, for example foobar, Foobar, andFOOBAR are all different.

We should try to use descriptive names.

Abdennadher GUC–MET

CSEN 202

Page 97: CSEN 202 – Introduction to Computer Programming - Lecture

Overview Today’s lecture Background Java A first program

Some aspects of Java

Comments

To make our code understandable, we comment sectionswhose purpose is not immediately obvious.

First kind of comments:

/* This is one kind of commentthat can span several lines. Don’tforget to put the closingcharacters at the end. */

Second kind of comments:

// This is the other type of comment.// It covers the entire line// and requires a new set// of slashes for each new line.

Abdennadher GUC–MET

CSEN 202

Page 98: CSEN 202 – Introduction to Computer Programming - Lecture

Overview Today’s lecture Background Java A first program

Some aspects of Java

Comments

To make our code understandable, we comment sectionswhose purpose is not immediately obvious.

First kind of comments:

/* This is one kind of commentthat can span several lines. Don’tforget to put the closingcharacters at the end. */

Second kind of comments:

// This is the other type of comment.// It covers the entire line// and requires a new set// of slashes for each new line.

Abdennadher GUC–MET

CSEN 202

Page 99: CSEN 202 – Introduction to Computer Programming - Lecture

Overview Today’s lecture Background Java A first program

Some aspects of Java

Comments

To make our code understandable, we comment sectionswhose purpose is not immediately obvious.

First kind of comments:

/* This is one kind of commentthat can span several lines. Don’tforget to put the closingcharacters at the end. */

Second kind of comments:

// This is the other type of comment.// It covers the entire line// and requires a new set// of slashes for each new line.

Abdennadher GUC–MET

CSEN 202

Page 100: CSEN 202 – Introduction to Computer Programming - Lecture

Overview Today’s lecture Background Java A first program

Some aspects of Java

Comments

To make our code understandable, we comment sectionswhose purpose is not immediately obvious.

Third kind of comments:

/** This is a javadoc comment. Italso spans a several lines. */

Abdennadher GUC–MET

CSEN 202

Page 101: CSEN 202 – Introduction to Computer Programming - Lecture

Overview Today’s lecture Background Java A first program

Some aspects of Java

Comments

To make our code understandable, we comment sectionswhose purpose is not immediately obvious.

Third kind of comments:

/** This is a javadoc comment. Italso spans a several lines. */

Abdennadher GUC–MET

CSEN 202

Page 102: CSEN 202 – Introduction to Computer Programming - Lecture

Overview Today’s lecture Background Java A first program

Some aspects of Java

Errors

Syntax errors: Detected by the compilerSystem.ouch.print("Hello");System.out.print("Hello);

Logic errors: Detected hopefully through testingSystem.out.print("Hell");

Runtime errors: Detected by the JVM when it is too lateSystem.out.print(1/0);

Abdennadher GUC–MET

CSEN 202

Page 103: CSEN 202 – Introduction to Computer Programming - Lecture

Overview Today’s lecture Background Java A first program

Some aspects of Java

Errors

Syntax errors: Detected by the compilerSystem.ouch.print("Hello");System.out.print("Hello);

Logic errors: Detected hopefully through testingSystem.out.print("Hell");

Runtime errors: Detected by the JVM when it is too lateSystem.out.print(1/0);

Abdennadher GUC–MET

CSEN 202

Page 104: CSEN 202 – Introduction to Computer Programming - Lecture

Overview Today’s lecture Background Java A first program

Some aspects of Java

Errors

Syntax errors: Detected by the compilerSystem.ouch.print("Hello");System.out.print("Hello);

Logic errors: Detected hopefully through testingSystem.out.print("Hell");

Runtime errors: Detected by the JVM when it is too lateSystem.out.print(1/0);

Abdennadher GUC–MET

CSEN 202

Page 105: CSEN 202 – Introduction to Computer Programming - Lecture

Overview Today’s lecture Background Java A first program

Some aspects of Java

Errors

Syntax errors: Detected by the compilerSystem.ouch.print("Hello");System.out.print("Hello);

Logic errors: Detected hopefully through testingSystem.out.print("Hell");

Runtime errors: Detected by the JVM when it is too lateSystem.out.print(1/0);

Abdennadher GUC–MET

CSEN 202