Lecture 1 Introduction to Java Language.pptx

amirbukhari 104 views 22 slides Sep 09, 2025
Slide 1
Slide 1 of 22
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22

About This Presentation

Java 1, Basics , What is a programming language?
Why Java in this course?
Short history of Java
How Java runs
Byte-Code and the Java Virtual Machine
Computer language levels (high vs. low vs. machine)
Java programs: classes & objects
How Java Programs Are Organized
Compiling and run...


Slide Content

CS 120 - Programming I Lecture 1: Introduction Jubail Industrial College Computer Science & Engineering Department

What is a programming language? Why Java in this course? Short history of Java How Java runs Byte-Code and the Java Virtual Machine Computer language levels (high vs. low vs. machine) Java programs: classes & objects How Java Programs Are Organized Compiling and running a program Outline 2

Introduction • A programming language is the language used to write programs • A programming language employs a set of rules that dictate how the words and  symbols can be put together to form valid program statements • A programming language has a syntax and semantics • There are several types of languages (functional, Object-Oriented(OOP), etc.) • In this course we focus on Java programming language. 3 3

Java Language   • 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++. 4

?Why Java Language Java is one of the most popular language in the world ! Reference: Spectrum’s 2024 Ranking https://spectrum.ieee.org/top-programming-languages-2024 5 4

Why Java Language ? Simple Get started quickly Concise Write less code Object-oriented Better quality code Portable Architecture neutral (write once run anywhere) Secure More appropriate for Internet 6 Java Language Features

Computer Language Levels High-level language :  A language that people can read, write, and  understand A program written in a high-level language must be translated into a language that can be understood by a computer before it can be run Machine language:   A language that a computer can understand Low-level language :  Machine language or any language similar to machine language 7

Byte-Code and the Java Virtual Machine The compilers for most programming languages translate high-level programs directly into the machine language for a particular computer Since different computers have different machine languages, a different compiler is needed for each one In contrast, the Java compiler translates Java programs into byte-code, a machine language for a fictitious computer called the Java Virtual Machine  (JVM) Once compiled to byte-code, a Java program can be used on any computer, making it very portable 8

Byte-Code and the Java Virtual Machine Interpreter :  The program that translates a program written in Java byte-code into the machine language for a particular computer when a Java program is executed The interpreter translates and immediately executes each byte-code instruction, one after another Translating byte-code into machine code is relatively easy compared to the initial compilation step  9

Classes and Objects 10 Java is an  object-oriented programming (OOP)  language A class is the basic building block of Java programs. A class encapsulates:    a) data (attributes) and    b) operations on this data (methods)        and permits to create objects as its instances.

Classes and Objects 11

Main Method The main method must be present in every Java application:       1)   public static void main(String[] args ) where:          a)   public means that the method can be called by any object           b)   static means that the method is shared by all instances           c)   void means that the method does not return any value      2) When the interpreter executes an application, it starts by calling its           main method which in turn invokes other methods in this or other classes.      3) The main method accepts a single argument – a string array,           which holds all command-line parameters. 12

How Java Programs Are Organized •   A Java program resides in one or more files. •  The file name of a Java program has extension .java . •  One of the classes of a Java program is called the driver class. •   The name of the driver class must be the same as the name of its Java file . (Java is case sensitive. So EX1 is different from ex1.) •  The driver class must contain a method called main. The execution of Java program starts from the main method of the driver class. 13

Syntax and Semantics Syntax: The arrangement of words and punctuations that are legal in a language, the grammar rules of a language Semantics: The meaning of things written while following the syntax rules of a language 14

Simple Java Program 15 A Class to display a simple message:

Java Program Explained 16

Java Program Explained 17

Java Program Explained 18

Java Program Explained 19

Java Program Explained 20

• Type in your program • Save the program Store all your files in one directory for now Give the program the same name as the class • Compile the program this produces a . class file Translates the program into something the computer can understand and execute (Java bytecode) • Run the program • Observe the result and adjust the program if necessary 21 Compiling and running a program

The end 22