Lecture01-Object Oriented Concepts
Lecture01-Object Oriented Concepts
Programming
(OOP)
1
Java Language Features
• Simple
• Object Oriented
• Robust
• Multithreaded
• Architecture Neutral
• Interpreted and high performance
• Distributed
• Dynamic
• Secure
2
Java Language Features
3
Java Language Features
4
Java Language Features
5
JAVA IS ARCHITECTURE
NEUTRAL(Platform
Independent)
• Before a computer program can be run , it has to be translated
into machine language that the computer processor understands.
• In programming language such as Pascal , C or C++ this
translation is done by a compiler and the resulting machine
language version of the program is called executable image or
binary code . But different processor have different machine
languages.
• Binary code in essence is a pattern of 1’s and 0’s understandable
by the underlying hardware architecture. Of the computer on which
the program is intended to run.
• Like the source code byte codes are independent of the computer
system. Any computer can use the same byte code file.
6
JAVA IS ARCHITECTURE
NEUTRAL(Platform
Independent)
7
JAVA IS ARCHITECTURE
NEUTRAL(Platform
Independent)
• To over come this problem. java provide both the compiler and
a software system called JVM(java virtual machine) for each
computer system.
• The java compiler javac translate Java source code into an
intermediate level language called Byte code.
• Like the source code byte codes are independent of the
computer system. Any computer can use the same byte code
file.
• That is no matter whether a java program is compiled under
sun Solaris, or windows NT or MacOs or any other operating
system for which a java compiler is available the resultant
Byte code turns out to be same, and hence can be run on any
computer that support a JVM.
8
JAVA IS ARCHITECTURE
NEUTRAL(Platform
Independent)
• Instead of a java program running directly under control of
the operating system .like traditional compiled program
do. the JVM itself runs under direct control of the
operating system and the java program run under control
of the JVM.
• JVM in essence serves as a ‘translator’ turning byte code’
language’ into the machine code language that a particular
computer can understand.
• When one computer wants to run a java program written on
another computer it downloads that program ‘s byte code
file and delivers it to its own JVM. The JVM then translate the
byte codes into System’s machine language and runs the
results.
9
JAVA IS ARCHITECTURE
NEUTRAL(Platform
Independent)
10
JAVA IS ARCHITECTURE
NEUTRAL(Platform
Independent)
11
JAVA PLATFORM
12
Sample Java Program
• Here is an example Java program. It is about as small a program as is
possible. Some of its details will be explained later.
• class Hello
• { public static void main ( String[] args )
• {
• System.out.println("Hello World!");
• }}
• This program will be created as a text file using a text editor such as
the "Notepad" editor (details on how to do this will come later.) The
important thing for now is to note that it is a file that is saved on the
hard disk. The file should be named Hello. java. This file is called a
source program.
• Since the file contains characters (stored as bytes) it can not be
directly executed (run) by the computer system. As a file containing
text, all that can be done with it is to print it, display it on the monitor,
or alter it with a text editor.
13
Bytecodes:
14
Bytecodes:
15
Java Virtual Machine
16
Java Virtual Machine
• The "Java interpreter" in the picture is an executable program
that is running on the computer system. Each type of computer
system has its own Java interpreter that can run on that system.
The "Actual processor" is the actual, hardware, processor chip of
that computer system.
• Any computer system can execute all Java byte code programs
if it has a Java interpreter. The Java interpreter has to be
specifically written for the specific processor type of the
computer system, but once that is done, the computer system
can become a Java virtual machine. That is, it looks like a
computer with a Java processor chip and can run Java byte
codes.
17
Java Virtual Machine
18
RUNNING A JAVA
APPLICATION
• Java source code is always stored with .java extension.
• Compile the program using the following command
• Javac Hello.java
• Javac is the name of the java compiler.
19
Java Program Execution
20
Java Program Execution
21
JAVA AND WORLD WIDE
WEB
• Platform dependency of java makes it an ideal language for
deployment over the world wide web.
• APPLETS are designed for this exact purpose.
• An applet is a ‘mini java’ program . typically with a graphical
user interface front- ends that can be embedded in HTML page.
• An Applet is written in java and compile just like any other
java program.
• A reference to the applet is embedded in an HTML page using
an applet tag.
22
JAVA AND WORLD WIDE
• example WEB
• <HTML>
• <HEAD>
• <TITLE>
• MY HOME PAGE
• </TITLE>
• </HEAD>
• <BODY>
• </BODY>
• </HTML>
23
JAVA AND WORLD WIDE
WEB
• when you get an html page with contain applet. It perform the
following steps
• Your browser downloads the HTML for that page from the
appropriate web server to your local machine, and interprets
HTML ,in this case it detects an applet tags.
• An applet can only execute under the control of either a Java-
enabled browser as sun Microsoft’s hot java browser, or more
recent version of Netscape communicator and Microsoft’s
internet Explorer..
• If your browser is applet aware then the browser next downloads
the byte code version of the applet to your computer.
24
JAVA AND WORLD WIDE
WEB
• The byte code is verified to ensue that
• the version of java used to write applet matches he version of java
that your browser understands( browsers sometimes lag behind in
terms of which version of java they support.)
• that the applet can be trusted : that is that no malicious
instructions are present which could do damage to your computer.
25
JAVA AND WORLD WIDE
WEB
26
Java API
What is Java API?
27
Java Program Types
Types of Java programs:
1) applications – standalone (desktop) Java programs, executed from the
command line, only need the Java Virtual Machine to run
2) applets – Java program that runs within a Java-enabled browser,
invoked through a “applet” reference on a web page, dynamically
downloaded to the client computer
3) servlets – Java program running on the web server, capable of
responding to HTTP requests made through the network
4) etc.
28
Java Platform Features
1) essentials - objects, strings, threads, numbers, input/output, data
structures, system properties, date and time, and others.
2) networking:
1) Universal Resource Locator (URL)
2) Transmission Control Protocol (TCP)
3) User Datagram Protocol (UDP) sockets
4) Internet Protocol (IP) addresses
3) internationalization - programs that can be localized for users worldwide,
automatically adapting to specific locales and appropriate languages.
29
Java Platform Features
4) security – low-level and high-level security, including electronic
signatures, public and private key management, access control, and
certificates
5) software components – JavaBeans can plug into an existing component
architecture
6) object serialization - lightweight persistence and communication, in
particular using Remote Method Invocation (RMI)
7) Java Database Connectivity (JDBC) - provides uniform access to a
wide range of relational databases
30
Java Technologies
Different technologies depending on the target applications:
31
Java Technologies SDK
33
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.
34
35
Indentation
// Authors: J. P. Cohoon and J. W. Davidson
// Purpose: display a quotation in a console window
Method main() is part of
public class DisplayForecast { DisplayForecast
Whitespace
public class DisplayForecast {
38
Let’s Run The Program
• For that any IDE (Integrated Development Environment) that
supports java can be used
• Most prominent one are Net Beans , Eclipse, JCreater ,
Jdeveloper , BlueJ and many more . Some are freeware and some
are proprietary
• Online IDE are also available e.g
https://www.jdoodle.com/online-java-compiler/
39
Common Language Elements
• There are some concepts that are common to virtually all
programming languages.
• Common concepts:
• Key words like class, int
• Operators like +, -
• Punctuation like ;, {}
• Programmer-defined identifiers like name
• Strict syntactic rules like ‘S’ capital is System.out.print()
• Control Statements like if , while
• Assignment Statement like a=1
40
Programming Overview
41
The Programming Process
1. Clearly define what the program is to do.
42
The Programming Process
5. Enter the code and compile it.
44
SIR SYED UNIVERSITY OF ENGINEERING AND TECHNOLOGY 45