0% found this document useful (0 votes)
20 views

Week2-L1-Introduction To Programming

This document discusses programming languages and paradigms and introduces the Java programming language. It defines programming as a process of telling computers how to solve problems through instructions in a language they can understand. It describes how high-level programming languages make programming more understandable for humans compared to machine language. It also discusses procedural and object-oriented programming paradigms and provides examples in both styles. Finally, it gives an overview of how to compile and run a simple Java program and introduces some key concepts like the Java Virtual Machine and Java Runtime Environment.

Uploaded by

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

Week2-L1-Introduction To Programming

This document discusses programming languages and paradigms and introduces the Java programming language. It defines programming as a process of telling computers how to solve problems through instructions in a language they can understand. It describes how high-level programming languages make programming more understandable for humans compared to machine language. It also discusses procedural and object-oriented programming paradigms and provides examples in both styles. Finally, it gives an overview of how to compile and run a simple Java program and introduces some key concepts like the Java Virtual Machine and Java Runtime Environment.

Uploaded by

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

By

Dr. Yasser Abdelhamid


 Programming languages
 Programming paradigms
 Introducing Java language
1. Java: The Complete Reference, Seventh
Ed., By H. Schildt, McGraw-Hill, 2006.
2. Course notes and slides.
3. http://www.w3schools.com
4. http://javatpoint.com
5. http://www.tutorialspoint.com
 Programming : Is a technological process
for telling a computer which tasks to
perform in order to solve problems.
 Programmers create instructions (code)
for a computer to follow in a language
computers can understand.
 Computers only understand their language (
Machine language ).
 It is hard for human beings (Programmers) to
read/write machine language.
 Programmers need to write program
instructions in an understandable language
(English-like language).
 With the help of a translator, we can translate
these programs into machine language.
 Instead
of writing machine language
code, we write the program in the form of
symbols, then translate it into machine
code.
 Programminglanguages that are
understandable by human beings
(programmers) are called high-level
programming languages.
 Programming tools to translate programs
written in high-level language into
machine executable code.
 Imperative programming
 Structured programming
 Procedural programming
 Functional programming
 Declarative programming
 Object Oriented Programming
 Procedural programming is a paradigm or
style of programming that consists of data
and modules/procedures that operate on
the data.
 The two are treated as separate entities.
 In the object-oriented programming (OOP)
paradigm, however, a program is built
from objects, which encapsulate data and
methods (functions).
 Pascal, Basic, Fortran are examples of
procedural languages.
result = []
i=0
start:
numPeople = length(people)
if i >= numPeople goto finished
p = people[i]
nameLength = length(p.name)
if nameLength <= 5 goto nextOne
upperName = toUpper(p.name)
addToList(result, upperName)
nextOne:
i=i+1
goto start
finished:
return sort(result)
program myProgram;
var
a, b, c, min: integer;
procedure findMin(x, y, z: integer; var m: integer);
(* Finds the minimum of the 3 values *)

begin
if x < y then
m:= x
else
m:= y;

if z < m then
m:= z;
end; { end of procedure findMin }

begin
writeln(' Enter three numbers: ');
readln( a, b, c);
findMin(a, b, c, min); (* Procedure call *)

writeln(' Minimum: ', min);


end.
 object-orientedprogramming is about
creating objects that contain both data
and methods.
 Anything is an object.
 An object can be described by its state
and its behavior.
 A state is an attribute (data member).
 A behavior is a method / (function).
 Methods operate on the internal state of
an object and the
 object-to-object communication is done
via messages (a method call).
 A dog has states like color, name,
breed,…
 A dog has behaviors like wagging the tail,
barking, eating.
 An object is an instance of a Class.
 A Class is a template/blueprint that describes the
behavior/state of the objects related to it.
 When the individual objects are created, they inherit all
the variables and methods from their class.
public class Dog {
String breed;
int age;
String color;

void barking() {
}

void hungry() {
}

void sleeping() {
}
}
class Simple{
public static void main(String args[]){
System.out.println("Hello EELU");
}
}

To compile: javac Simple.java


To execute: java Simple
To compile: javac Simple.java
To execute: java Simple
 When we compile the java file, we get a
.class (not an .exe).
 This file contains java byte code which is
interpreted by JVM.
 The machine language of the JVM.
 Java Virtual Machine:
It is responsible for
loading, verifying
and executing the
code.
 JVM is platform
dependent because
it is responsible for
converting the
bytecodes into the
native machine
language for a
specific
computer/machine.
 Java Runtime Environment.
 It contains the JVM, the library files and the
other supporting files.
 To run a java program, the JRE must be
installed in the system.
 JRE=JVM+ some packages.
 Java Development Kit: It provides the
tools that we need to develop java
programs and JRE.
 These tools contain javac.exe, java.exe
etc.
 When we launch a java application, it will
open the JRE and load the class and then,
in turn, it will execute the main method.
 JDK=JRE+ Development tools.

JDK JRE JVM

Dev.
Libs.
Tools
 Can
we save a Java source file by another
name than the class name?

 Yes, if the class is not public.


 Canyou have multiple classes in a java
source file?

 Yes.
 Install JDK
 Install IDE (NetBeans, VS Code)
 Setup environment variables (PATH,…)

 Having any problems, please contact TA.

You might also like