0% found this document useful (0 votes)
11 views51 pages

CS1211 Computer Programming (1) : Introduction To High-Level Programming Languages

The document outlines the course structure for CS1211, focusing on high-level programming languages, specifically Java. It includes grading criteria, course objectives, learning outcomes, and a detailed syllabus covering fundamental programming concepts. Additionally, it discusses hardware and software components, memory types, and the process of compiling and running Java programs.

Uploaded by

loainabil1010
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)
11 views51 pages

CS1211 Computer Programming (1) : Introduction To High-Level Programming Languages

The document outlines the course structure for CS1211, focusing on high-level programming languages, specifically Java. It includes grading criteria, course objectives, learning outcomes, and a detailed syllabus covering fundamental programming concepts. Additionally, it discusses hardware and software components, memory types, and the process of compiling and running Java programs.

Uploaded by

loainabil1010
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/ 51

CS1211

Computer Programming (1)


Chapter 01
Introduction to high-level programming languages

UMM ALQURA UNIVERSITY

Dr. Hatim Alsuwat 1


Course Information

• Grading:

– Midterm Exam: 20%


– Assignments and Quizzes : 15%
– Lab exercise and Projects : 15%
– Theoretical and Practical Final Exam : 50%

• Total score that can be achieved: 100

2
Course Information

• Meeting time and place:


– Office: Department of Computer Science

– Office hours: Please email me if you have any question.


– Email: [email protected]

Dr. Mohammad almojamed 3


Course Information: Feedback

• Please give feedback positive or negative as


early as you can via email.

Dr. Mohammad almojamed 4


Lectures Reference
W. Savitch, JAVA: an introduction to problem solving and programming, global
edition. Philadelphia, PA: Pearson Education, 2018.

5
Course Description

This course introduces the basic concepts of computer


programming to students with some problem-solving skills to
solve complex problems. Students will be using a high-level
programming language, to learn the fundamentals of computer
programming skills including how to write, compile, and run
programs using relevant tools for program development. Topics
include variables and data types, methods, console input/output,
control structures, coding styles, and the mechanics of running,
testing, and debugging.

6
Course Main Objective

To equip students with the fundamental knowledge required to


develop a procedural program using a high-level programming
language.

7
Course Learning Outcomes

Knowledge and Understanding :


• Recognize high-level programming language.
• Recognize basic control and repetition structures.

Skills:
• Design basic objects.
• Analyze programming problems and implement programs that
realize the required logic.
• Use the command line and relevant IDEs for writing,
formatting, compiling, running, and debugging code.

8
Course Syllabus
• Introduction to high-level programming languages (general
background, programming errors, coding styles, and how to edit,
compile, and run programs in relevant IDE)
• Variables, data types, assignment statements, constants, data type
conversions, arithmetic expressions, and the String type
• Input/output
• Control statements and Boolean expressions
• Loops and repetition structures
• Methods and using parameters

9
Chapter 1: Introduction to high-level programming
languages

• General background.
• Programming errors.
• Coding styles.
• How to edit, compile, and run programs in relevant
IDE.

10
Hardware and Software
• Computer systems consist of hardware and
software.
– Hardware includes the tangible parts of computer
systems.
– Software includes programs - sets of instructions for
the computer to follow.
• Familiarity with hardware basics helps us
understand software.
Hardware and Memory
• Most modern computers have similar
components including
– Input devices (keyboard, mouse, etc.)
– Output devices (display screen, printer, etc.)
– A processor
– Two kinds of memory (main memory and auxiliary
memory).
The Processor
• Also called the CPU (central processing unit) or
the chip (e.g. Pentium processor)
• The processor processes a program’s
instructions.
• It can process only very simple instructions.
• The power of computing comes from speed and
program intricacy.
Memory
• Memory holds
– programs
– data for the computer to process
– the results of intermediate processing.
• Two kinds of memory
– main memory
– auxiliary memory
Main memory
• Working memory used to store
– The current program
– The data the program is using
– The results of intermediate calculations
• Usually measured in megabytes (e.g. 8
gigabytes of RAM)
– RAM is short for random access memory
– A byte is a quantity of memory
Auxiliary Memory
• Also called secondary memory
• Disk drives, CDs, DVDs, flash drives, etc.
• More or less permanent (nonvolatile)
• Usually measured in gigabytes (e.g. 50 gigabyte
hard drive)
Bits, Bytes, and Addresses
• A bit is a digit with a value of either 0 or 1.
• A byte consists of 8 bits.
• Each byte in main memory resides at a
numbered location called its address.
Main Memory
• Figure 1.1
Storing Data
• Data of all kinds (numbers, letters, strings of
characters, audio, video, even programs) are
encoded and stored using 1s and 0s.
• When more than a single byte is needed,
several adjacent bytes are used.
– The address of the first byte is the address of the unit
of bytes.
Files
• Large groups of bytes in auxiliary memory are
called files.
• Files have names.
• Files are organized into groups called directories
or folders.
• Java programs are stored in files.
• Programs files are copied from auxiliary memory
to main memory in order to be run.
0s and 1s
• Machines with only 2 stable states are easy to
make, but programming using only 0s and 1s is
difficult.
• Fortunately, the conversion of numbers, letters,
strings of characters, audio, video, and
programs is done automatically.
Programs
• A program is a set of instructions for a computer
to follow.
• We use programs almost daily (email, word
processors, video games, bank ATMs, etc.).
• Following the instructions is called running or
executing the program.
Input and Output
• Normally, a computer receives two kinds of
input:
– The program
– The data needed by the program.
• The output is the result(s) produced by following
the instructions in the program.
Running a Program
• Figure 1.2

• Sometimes the computer and the program


are considered to be one unit.
– Programmers typically find this view to be more
convenient.
The Operating System
• The operating system is a supervisory program
that oversees the operation of the computer.
• The operating system retrieves and starts
program for you.
• Well-known operating systems including:
Microsoft Windows, Apple’s Mac OS, Linux, and
UNIX.
Programming Languages
• High-level languages are relatively easy to use
– Java, C#, C++, Visual Basic, Python, Ruby.
• Unfortunately, computer hardware does not
understand high-level languages.
– Therefore, a high-level language program must be
translated into a low-level language.
Compilers
• A compiler translates a program from a high-
level language to a low-level language the
computer can run.
• You compile a program by running the compiler
on the high-level-language version of the
program called the source program.
• Compilers produce machine- or assembly-
language programs called object programs.
Compilers
• Most high-level languages need a different
compiler for each type of computer and for each
operating system.
• Most compilers are very large programs that are
expensive to produce.
Java Byte-Code
• The Java compiler does not translate a Java
program into assembly language or machine
language for a particular computer.
• Instead, it translates a Java program into byte-
code.
– Byte-code is the machine language for a hypothetical
computer (or interpreter) called the Java Virtual
Machine.
Java Byte-Code

• A byte-code program is easy to translate into machine


language for any particular computer.
• A program called an interpreter translates each byte-
code instruction, executing the resulting machine-
language instructions on the particular computer before
translating the next byte-code instruction.
• Most Java programs today are executed using a Just-In-
Time or JIT compiler in which byte-code is compiled as
needed and stored for later reuse without needing to be
re-compiled.
Compiling, Interpreting, Running

• Use the compiler to translate the Java program


into byte-code (done using the javac command).
• Use the Java virtual machine for your computer
to translate each byte-code instruction into
machine language and to run the resulting
machine-language instructions (done using the
java command).
Portability
• After compiling a Java program into byte-code,
that byte-code can be used on any computer
with a byte-code interpreter and without a need
to recompile.
• Byte-code can be sent over the Internet and
used anywhere in the world.
• This makes Java suitable for Internet
applications.
Class Loader
• A Java program typically consists of several
pieces called classes.
• Each class may have a separate author and
each is compiled (translated into byte-code)
separately.
• A class loader (called a linker in other
programming languages) automatically connects
the classes together.
Compiling and Running a Program
• Figure 1.3
A Sip of Java: Outline

• History of the Java Language


• Applications and Applets
• A First Java Application Program
• Writing, Compiling, and Running a Java
Program
History of Java
• In 1991, James Gosling and Sun Microsystems
began designing a language for home
appliances (toasters, TVs, etc.).
– Challenging, because home appliances are controlled
by many different chips (processors)
– Programs were translated first into an intermediate
language common to all appliance processors.
History of Java
– Then the intermediate language was translated into
the machine language for a particular appliance’s
processor.
– Appliance manufacturers weren’t impressed.

• In 1994, Gosling realized that his language


would be ideal for a Web browser that could run
programs over the Internet.
– Sun produced the browser known today as HotJava.
Applications and Applets
• Two kinds of java programs: applications and
applets
• Applications
– Regular programs
– Meant to be run on your computer
• Applets
– Little applications
– Meant to be sent to another location on the internet
and run there
– Deprecated by Oracle and not supported by many
web browsers today in favor of HTML5 and
JavaScript
A First Java Application
A First Java Application

Sample
screen
output
Some Terminology
• The person who writes a program is called the
programmer.
• The person who interacts with the program is
called the user.
• A package is a library of classes that have been
defined already.
– import java.util.Scanner;
Some Terminology
• The item(s) inside parentheses are called
argument(s) and provide the information needed
by methods.
• A variable is something that can store data.
• An instruction to the computer is called a
statement; it ends with a semicolon.
• The grammar rules for a programming language
are called the syntax of the language.
Printing to the Screen

System.out.println (“Whatever you want to print”);

• System.out is an object for sending output to the


screen.
• println is a method to print whatever is in
parentheses to the screen.
Printing to the Screen

• The object performs an action when you invoke


or call one of its methods
objectName.methodName(argumentsTheMethodNeeds);
Compiling a Java Program or Class

• A Java program consists of one or more classes,


which must be compiled before running the
program.
• You need not compile classes that accompany
Java (e.g. System and Scanner).
• Each class should be in a separate file.
• The name of the file should be the same as the
name of the class.
Compiling and Running
• Use an IDE (integrated development
environment) which combines a text editor with
commands for compiling and running Java
programs.
• When a Java program is compiled, the byte-
code version of the program has the same
name, but the ending is changed from .java to
.class.
Compiling and Running
• A Java program can involve any number of
classes.
• The class to run will contain the words

public static void main(String[] args)


Errors

• An error in a program is called a bug.


• Eliminating errors is called debugging.
• Three kinds or errors
– Syntax errors
– Runtime errors
– Logic errors
Syntax Errors
• Grammatical mistakes in a program
– The grammatical rules for writing a program are very
strict
• The compiler catches syntax errors and prints an
error message.
• Example: using a period where a program
expects a comma
Runtime Errors
• Errors that are detected when your program is
running, but not during compilation
• When the computer detects an error, it
terminates the program and prints an error
message.
• Example: attempting to divide by 0
Logic Errors

• Errors that are not detected during compilation


or while running, but which cause the program
to produce incorrect results
• Example: an attempt to calculate a Fahrenheit
temperature from a Celsius temperature by
multiplying by 9/5 and adding 23 instead of 32

You might also like