Download presentation
Presentation is loading. Please wait.
1
Lecture 1: Introduction to JAVA
CS 212 : Programming 1 java Lecture 1: Introduction to JAVA
2
Outline What is a computer . What is a computer program
What is programming language JAVA
3
What Is a computer? Element of computer:
-Executes statements (computations/logical decisions) Element of computer: Hardware :Physical devices of computer system Software: Programs that run on computers Hardware Software Computer
4
Computer Organization
Six logical units of computer system Input unit (Mouse, keyboard) Output unit (Printer, monitor, audio speakers) Memory unit (Retains input and processed information) Central processing unit (CPU) which consists of: Control unit (controls the other components & Guarantees instruction are executed in sequence ) Arithmetic and logic unit (ALU) (Performs arithmetic and logical operations) Secondary storage unit (Hard drives, floppy drives)
5
What is a computer program?
For a computer to be able to perform specific tasks, it must be given instructions to do the task. A Computer Program is The set of instructions that tells the computer to perform specific tasks Each instruction tells the computer to do something ( an action, a calculation, a comparison ) Introduction to OOP Dr. S. GANNOUNI & Dr. A. TOUIR
6
Program Execution A program tells the CPU how to manipulate and/or move information Programming is about processing information Take some input, manipulate it in some way, and produce a particular output Program Manipulation Inputs Outputs ICS102: Intro To Comp
7
Programming languages
A program is expressed in a computer language. Languages differ in Size ( complexity) Readability Writability Level : closeness to instructions for CPU
8
Machine Language
9
Assembly Language
10
High- level languages
11
Java It was first released in 1995.
Java is a programming language originally developed by James Gosling at Sun Microsystems It was first released in 1995. The language derives much of its syntax from C and C++. But has a simpler object model and fewer low-level facilities than C and C++. ICS102: Intro To Comp
12
Why Coding in high –level Programming Languages
We write computer programs (i.e. a set of instructions) in programming languages such as C, C++, and Java. We use these programming languages because they are easily understood by humans But then how does the computer understand the instructions that we write?
13
Compiling Computer Programs
Computers do not understand programs written in programming languages such as C++ and Java Programs must first be converted into machine code that the computer can run A Software that translates a programming language statements into machine code is called a compiler Machine code Program Source code Machine Code Translating Compiling
14
Programming Language Compiler
A compiler is a software that: Checks the correctness of the source code according to the language rules. Syntax errors are raised if some rules were violated. Translates the source code into a machine code if no errors were found.
15
Platform dependent Compiling
Because different platforms, or hardware architectures along with the operating systems (Windows, Macs, Unix), require different machine code, you must compile most programs separately for each platform.
16
Compiling Java Programs
The Java compiler produces bytecode (a “.class” file) not machine code from the source code (the “.java” file). Bytecode is converted into machine code using a Java Interpreter Source Code Bytecode
17
Platform Independent Java Programs Compiling
You can run bytecode on an computer that has a Java Interpreter installed “Hello.java” “Hello.class”
18
Multipurpose Java Compiling
19
Running The Program The Java Virtual Machine Components
The Class Loader stores bytecodes in memory Bytecode Verifier ensures bytecodes do not violate security requirements Bytecode Interpreter translates bytecodes into machine language Class Loader Running Bytecode Verifier Bytecode The Bytecode (the “.class” file) Interpreter JVM Operating System JVM is platform specific. The interpreter translates the bytecodes into specific machine commands. Hardware
20
Testing and Debugging the Program
Be sure that the output of the program conforms with the input. There are two types of errors: Logical Errors: The program run but provides wrong output. Runtime errors: The program stop running suddenly when asking the OS executing a non accepted statement (divide by zero, etc). Debugging Find, Understand and correct the error
21
Phase 1 Editor Phase 2 Compiler Phase 3 Class Loader Bytecode Verifier
Primary Memory . Disk Editor Compiler Class Loader Program is created in an editor and stored on disk in a file ending with .java. Compiler creates bytecodes and stores them on disk in a file ending with .class. Class loader reads .class files containing bytecodes from disk and puts those bytecodes in memory. Phase 1 Phase 2 Phase 3 Bytecode Verifier Bytecode verifier confirms that all bytecodes are valid and do not violate Java’s security restrictions. Phase 4 Interpreter Interpreter reads bytecodes and translates them into a language that the computer can understand, possibly storing data values as the program executes. Phase 5
22
Some Characteristics of Java
Object-Oriented Combines data and behavior into one unit objects Provides Data abstraction and encapsulation Decompose program into objects. Programs are collections of interacting and cooperating objects. Platform-independent Portable Architecture neutral ”Write-once, run-anywhere” Secure The bytecode verifier of the JVM : checks untrusted bytecode controls the permissions for high level actions.
23
Classical model : Java model :
Similar presentations
© 2024 SlidePlayer.com Inc.
All rights reserved.