• Tidak ada hasil yang ditemukan

java => .class => JVM execution

N/A
N/A
Protected

Academic year: 2024

Membagikan "java => .class => JVM execution"

Copied!
30
0
0

Teks penuh

(1)

6001104-3 Structured Programming

L. Rafika Maaroufi

(2)

Chapter1: Introduction to

Programming languages & OOP

(3)

Outline

Programming Languages

Java Programming Language

Classes & Objects: Defining, Creating, and Using.

(4)

Programming languages

(5)

Introduction to programming languages

A programming language is a set of rules, symbols and special words used to write statements in order to

develop sets of instructions (software computer) for computers to execute. 

Some programming languages directly understandable by computers and others requiring intermediate translation steps

These may be divided into three general types:

1. Machine languages

(6)

Examples of Programming Languages

(7)

High-Level Languages

High-level languages represent a giant leap towards easier programming.

The syntax of HL languages is similar to English.

Historically, we divide HL languages into two groups:

1. Procedural languages

2. Object-Oriented languages (OOP)

(8)

Procedural Programming

Early high-level languages are typically called procedural languages.

Procedural languages are characterized by sequential sets of linear commands. The focus of such languages is on structure.

Examples of computer procedural languages are BASIC, FORTRAN, Pascal and C.

(9)

Procedural Programming

In procedural (functions-based) programming,

programming relies on procedures (functions) which

contain a series of computational steps to be carried out.

Code is executed from the top of the file to the bottom.

(10)

Object-Oriented Programming (OOP)

Most object-oriented languages are high-level languages.

The focus of OOP languages is not on structure, but on modeling data.

Programmers code using “blueprints” of data models called classes.

Examples of OOP languages : C++, Visual Basic.NET and Java.

(11)

Object-Oriented Programming (OOP)

The OOP paradigm is currently the most popular way of analysing, designing, and developing application

systems, especially large ones.

OOP program is a collection of interacting objects.

That’s mean objects play a central role.

Each object consists of attributes and behavior.

(12)

Java Programming Language

(13)

What is Java ?

It is a high-level programming language

It was originally developed by Sun Microsystems in1995, and now owned by Oracle Corporation.

Java is the preferred language for meeting many organizations’ enterprise programming needs.

Java has also become the language of choice for

implementing Internet-based applications and software for

(14)

Reasons to Learn Java

Java is an OOP Language

Java is easy to learn and it is FREE No Pointers

Great collection of Open Source libraries Excellent documentation support

(15)

Reasons to Learn Java

Java is everywhere: Desktop, web applications, and mobile applications.

Java support Platform Independent Compiling Multithreading

(16)

Programming Language Compiler

A compiler is a software that:

1. Checks the correctness of the source code according to the language rules.

Syntax errors are raised if some rules were violated.

2. Translates the source code into a machine code if no errors were found.

(17)

Platform dependent Compiling

Because different operating

systems (Windows, Macs, Unix), require different machine code, you must compile most programs separately for each platform

(18)

Platform dependent Compiling

The Java compiler (javac) produces bytecode (a “.class” file) not machine code from the source code (the “.java” file).

Java Virtual Machine (JVM): A hypothetical computer developed to make Java programs machine independent ( i.e run on many different types of computer platforms).

Bytecode is the machine language for the JVM

.java => .class => JVM execution

(19)

Java Platform Independent Compiling

The Java Virtual Machine (JVM) Components:

1. The Class Loader

stores bytecodes in memory 2. Bytecode Verifier

ensures bytecodes do not violate security requirements

(20)

Java Platform Independent Compiling

Java programs normally go through five phases : 1. Edit

2. Compile 3. Load 4. Verify 5. Execute.

(21)

Phases in Java Programs

(22)

Classes & Objects: Defining,

Creating, and Using

(23)

Classes

A class is a description of a kind of object (known as blue print).

When we write a program in Java, we define classes, which in turn are used to create objects of the same type.

Classes are, therefore, the main building blocks of Java

programs, as everything (objects, attributes and operations) is contained in classes.

(24)

Classes and Objects

Every object is an instance of a class

Class

(25)

Class Declaration

To declare a new class, we use the keyword class, followed by a non-reserved identifier that names it. A pair of

matching open and close brace characters { and } follow and delimit the class's body.

(26)

Class Declaration

Every .java file has one or more classes. Only one of the

classes can be a public class. Keyword public means that the class is available to everybody.

That public class must have the same name as the .java file, and contains the method main in it.

Execution always begins with method main java applications.

(27)

Creating an object

You can create any number of objects from one class.

To create a object of a class, you have to:

Declare an object identifier (object name/reference) of a particular class.

Construct the object using the "new" operator.

(28)

Declaring Object References

To declare an object, we need an object reference variable.

ClassName objectReferenceName;

The above statement creates a variable

“objectReferenceName” which can reference a ClassName object. It does NOT create an object.

Variable names begin with a lowercase letter, and

subsequent words in the name begin with a capital letter.

(29)

Instantiating Objects

To create an object, we use the new keyword along with a constructor for the class of the object we wish to

create.

To refer to the object, we “point” an object reference variable to the new object.

objectReferenceName = new ClassName();

The declaration and instantiation can be combined as follows:

(30)

Example

Referensi

Dokumen terkait

Since the computer cannot understand assembly language, however, a program called assembler is used to convert assembly language programs into machine code...

Programming Structures in Java, Objects and Classes, Inheritance, Interfaces and Inner Classes, Graphics Programming, Event Handling, User Inter- face Components with Swing,

You may find it somewhat puzzling that an interactive shell has not been introduced earlier in the Java platform as many programming languages, such as Python, Ruby, and a number

The Java Platform, Standard Edition (SE), includes the Java Runtime Environment (JRE) and its encompassing Java Development Kit (JDK; see Chapter 10 ), the Java

Object Oriented Concepts, Introduction to Objects and Object Oriented Programming, Encapsulation, Polymorphism, Overloading, Inheritance, Abstract Classes, Accessifier public/

Java Core APIs Java Core APIs ƒ java.lang • Core Java programming language classes • Object class: superclass of all Java classes • Class class: each loaded class has a Class