Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
42 views

Programming Basics

The document summarizes a programming basics course offered at the University of Kufa. The course covers introductory Java programming topics like Java history, syntax, flow control, strings and arrays. It will be assessed through three exams and other assignments. The primary textbooks are Java How to Program and Java for Absolute Beginners. Key Java concepts taught include variables, data types, operators, comments and escape characters.

Uploaded by

Hasanen Alyasiri
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views

Programming Basics

The document summarizes a programming basics course offered at the University of Kufa. The course covers introductory Java programming topics like Java history, syntax, flow control, strings and arrays. It will be assessed through three exams and other assignments. The primary textbooks are Java How to Program and Java for Absolute Beginners. Key Java concepts taught include variables, data types, operators, comments and escape characters.

Uploaded by

Hasanen Alyasiri
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 24

University of Kufa

Collage of Computer Science and


Mathematics

Programming Basics (101)


The Course Structure
n Introduction to Programming.
n Java History.
n Java Program Execution and Syntax.
n Controlling the Flow.
n Strings and Arrays.
Assessment
n Three exams:
1. The first exam (15 marks)
2. The second exam (20 marks)
3. The practical exam (10 marks)
n Quizzes, assignment and homework (5 marks)
Textbooks
n Java How to Program (9th
Edition) by Paul and Harvey
Deitel.

n Java for Absolute Beginners


by Iuliana Cosmina.
Introduction
n Program is a set of instructions that tell a
computer how to perform a specific task.

n Programming can be done using a variety of


computer languages for example python,
java, C/C++, PHP, JavaScript, etc.
Programming Languages
Hundreds of languages are in use today. These
may be divided into three general types:

1. Machine languages
2. Assembly languages
3. High-level languages
Algorithm
Is a sequence of precise instructions that
leads to a solution. These instructions are
expressed in English and must be complete
and unambiguous.
Flowchart
A flowchart is a diagram that uses graphic
symbols to depict the nature and flow of the
steps in a process.
Basic Flowchart Symbols
……………. Start/ Stop

……………. Processing operation

……………. Input/ Output

……………. Decision

……………. Connection

……………. Data flowing


Java History
Java programming language was developed by an company
called Sun Microsystems. In 1996, Java 1.0 was released for
Linux, Solaris, Mac and Windows. James Gosling, a
Canadian computer scientist who is recognized as the
“father” of the Java programming language. Oracle acquired
Sun Microsystems in 2010. Java provided developers with
some advantages: security, automatic memory
management, simplicity, support for multithreaded
execution and portability.
First Program in Java
Compile and Execute a Program
n Compiler is a program that translating a high-level language
program into a machine language.

n The Java compiler translates Java source code into bytecodes


that represent the tasks to be executed.

n Java Virtual Machine (JVM) is an abstract computing


machine that enables a computer to run a Java program. It is
a platform-independent execution environment that converts
Java code into machine language and executes it.
Debug
A mistake in a program is usually called bugs and the process
of eliminating and correcting them is called debugging. There
are a few different kinds of errors that can occur in a program,
and it is useful to distinguish between them in order to correct
more quickly.

1. Compile errors (syntax)


2. Logic errors (semantic)
3. Run-time errors
Identifier
n An identifier is the name you give to a class, variable, method
and so forth in a java program.
n It is a series of characters consisting of letters, digits,
underscores (_) and dollar signs ($) that does not begin with a
digit and does not contain spaces. Some valid identifiers are
Welcome1, $value, _value, m_inputField1.
n By convention, class names begin with a capital letter and
capitalize the first letter of each word they include (e.g.,
SampleClassName).
n Do not use special characters such as +, -, *, etc. or reserve
words such as int, float, main, long, char, etc.
Variable
n A variable is a location in the computer’s memory where
a value can be stored for use later in a program.
n Every variable must be declared before using it.
n Variables have unique names.
n You can initialize the variable when it declare.
n The type of the variable determines the size of variable
that stored in computer memory.
n Syntax:
variable_datatype variable_name = variable_value;
Java Data Types
n Data types in Java are divided into two categories:
primitive types and reference types (non-primitive).
n The primitive types are: boolean, byte, char, short, int,
long, float and double. All other types are reference types,
so classes, which specify the types of objects, are reference
types.
n Primitive type instance variables are initialized by default.
Variables of types byte, char, short, int, long, float and
double are initialized to 0. Variables of type boolean are
initialized to false.
Primitive Types
Primitive type Memory
Minimum Maximum
(Keyword) Requirement
boolean — — —
char 16 bits Unicode 0 Unicode 216- 1
byte 8 bits -128 +127
short 16 bits -215 +215-1
int 32 bits -231 +231-1
long 64 bits -263 +263-1
float 32 bits IEEE754 IEEE754
double 64 bits IEEE754 IEEE754
Case sensitive
n Java is case sensitive.

n Example:
rate RATE Rate
Java Operators
1. Arithmetic Operators: (+, -, *, /, %)
2. Unary Operators: (++, --)
3. Assignment Operators:
(=, +=, -=, *=, /=, %=)
4. Relational Operators:
(<, <=, >, >=, ==, !=)
5. Logical operators: (&&, ||, !)
Operator Precedence
Highest
Operators Description precedence
++, -- Increment, Decrement, Parentheses
! Not
*, /, % Multiplication, Division, Remainder (mod)
+, - Addition , Subtraction
<, <=, >, Less than, Less than or equal , Greater than,
>=, ==, != Greater than or equal , Equal , Not equal
&& And
|| Or
=, +=, -=, Assign, Add and assign, Sub and assign, Multiple
*=, /=, %= and assign, Division and assign ,Mod and assign Lowest
precedence
Java Comments
n Java comments refer to pieces of explanatory text that are not
part of the code executed and are ignored by the compiler.
n Comments are very important in programming languages
because they make programs understandable to anyone reading
the code.
n One-line comment:
Average = (x+ y)/ 2; // Calculate the average of two numbers
n Multiline comment:
/* Putting an asterisk at the beginning of each line of a
multiline comment allow people looking at the code to
determine with a quick look what a comment and what is a
code. */
Java Escape Characters
Escape Sequence Description

\n Create a new line.

\t Create a tab.

\r Return to the start of the line.

\\ Backslash. Used to print a backslash character.

Double quote. Used to print a double-quote


\" character.

You might also like