0% found this document useful (0 votes)
20 views42 pages

1 - Java Basics

This document provides information about the 3103 Advanced Programming with Java course. It includes the course details such as the instructor's contact information, recommended textbooks, learning outcomes, course schedule and outline, and grading criteria. The course will cover object-oriented programming principles in Java, Java APIs, GUI programming, database programming, networking, and multithreading. It is scheduled over 14 weeks and will include a midterm exam, projects, and a final exam.

Uploaded by

kareem mahmoud
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
20 views42 pages

1 - Java Basics

This document provides information about the 3103 Advanced Programming with Java course. It includes the course details such as the instructor's contact information, recommended textbooks, learning outcomes, course schedule and outline, and grading criteria. The course will cover object-oriented programming principles in Java, Java APIs, GUI programming, database programming, networking, and multithreading. It is scheduled over 14 weeks and will include a midterm exam, projects, and a final exam.

Uploaded by

kareem mahmoud
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 42

3103: Advanced Programming with Java

Dr. : Mohamed Mostafa


E-mail : dr.mohamed.mustafa@sha.edu.eg

Book Title: Introduction to Java


Programming, 10th Edition

Publisher: Pearson Education, Inc., 2015

Author: Daniel Liang


Useful references
 Mr.Ratan , “core java” , 2013.

 James Keogh & Mario Giannini,


“oop_demystified”, McGraw-Hill, 2004

 Faith Kim, “A Piece of Java_ Introduction


to Programming”
LEARNING OUTCOMES
On completion of this course we will be able to:
1. Identify the importance of Java .
2. Identify the additional features of Java compared to C++ .
3. Identify the difference between Compiler and Interpreter.
4. Identify the difference between applet and application .
5. Apply Object Oriented Principles of Encapsulations, Data abstraction,
Inheritance, Polymorphism.
6. Program using java API (Application Programming Interface).
7. Program using Exception Handling, Event Handling , Files and Threads .
8. Program (GUI, Graphics, DBMS, IO, and Network) applications
COURSE SCHEDULE & OUTLINE
Week LECTURE TOPIC
1 OOP Concepts
2 Java Basic & Introduction to Java
3,4 Language Components
5,6 Objects, Classes and Methods
7 Exception Handling
8 Midterm Exam
9 GUI Basics and Graphics
10 Event Handling
11 Database Programming
12 Network Programming
13 Multithreading
14 Java IO
Grading Criterion

Activity Grade
Midterm Exam 10%
Projects, Assignments &
Student participations 10%

Final Exam 80%


Java Basics
Java Basics

What is Java ?
 Developed by Sun Microsystems (now acquired by ORACLE
in 2010).
 A general-purpose object-oriented language. Can be used to
develop all kinds of software so it is called as programming
suite
 Based on C/C++ (Due to the similarities with C++ it is called
“Internet version of C++”)
 Designed for easy Web/Internet applications
 Widespread acceptance
 Write Once Run Anywhere (WORA).
Java Basics

Java Editions
 Java 2 Standard Edition (J2SE)
 By using j2se the standalone applications
“two-tier applications”.
 Standalone applications (notepad, WordPad, paint, …..etc )
are developed :
 Applicable for the only one desktop hence it is called desktop
applications or window based applications.
 No needs for internet connections.
 It is a local application it doesn’t need any other external
application support.
 Can be launched by using the command line.
Java Basics

Java Editions
 Java 2 Standard Edition (J2SE)
 Two-tier application (Client server application)
1. It is client-server architecture.
2. Easy to maintain and modification.
3. Exist in one or two computers
4. Direct communication.
5. Run faster
 Example: communication between:
1. The desktop application to
database server.
2. The browser to web server.
3. The FTP client to FTP server.
Java Basics

Java Editions
 Java 2 Enterprise Edition (J2EE)
 For business applications, web services, mission-critical
systems (multi-tier applications).
 By using j2ee we are able to develop the web based
applications (Gmail, banks, hotels, …).
 Web-applications:-
 java applications which needs client and server concept.

 must have the internet connections to access the application.

 The application which is present in the internet is called the


web application.
Java Basics

Java Editions
 Java 2 Enterprise Edition (J2EE)

Three-tier architecture
Java Basics

Java Editions
 Java 2 Enterprise Edition (J2EE)
Host Server Network Windows
Tier #2 (myshop.com Browser
Tier #1

Network n-tier architecture

Tier #3 Tier #4
VISA Bank
Application Network Application
Java Basics

Java Editions
 Java 2 Micro Edition (J2ME)

 Very small Java environment for smart cards, pages,


phones, and set-top boxes.

 Subset of the standard Java libraries aimed at limited


size and processing power.

 By using j2me we are able to develop the applications that


applications only run on mobile devices.
Java Basics

Characteristics of Java
Java is a high-level programming language that can be characterized by
all of the following advantages:

Simple, Dynamic
High
Small and
performance
Familiar

Multithreaded
Portable
Features
of java
OOP
Robust

Language of
Secure internet Java API’s
Java Basics

Characteristics of Java
 Simple, Small and Familiar

Java is designed to be easy for the professional programmer


to learn and use :

 Similar to C/C++ in syntax but eliminates several complexities

 No operator overloading

 No direct pointer manipulation or pointer arithmetic

 No malloc() and free(). It handles memory automatically with


the help of garbage collector.
Java Basics

Characteristics of Java
 Portable (Platform independence)
 If a program yields the same result on every machine, then
that program is called portable.
 Java programs are portable. This is the result on java’s
independent nature
Java Basics

Characteristics of Java
 Portable (Platform independence)
 Java compiler generate byte-codes, not native machine code.
 The compiled byte-codes are platform-independent.
 Java byte-codes are translated on the fly to machine readable instructions
in runtime .
Source code Machine code Machine code

Compiler Interpreter

 All computation in the JVM centers on the stack. Because the JVM has no registers
for storing values, everything must be pushed onto the stack before it can be used in a
calculation.
 Byte-code instructions therefore operate primarily on the stack.
 The JVM was designed as a stack-based machine rather than a register-based machine
Java Basics

Characteristics of Java
 Portable (Platform independence)

 Same application (Byte


code) runs on all
platforms “Write-
Once Run-Anywhere”.

 Changes in system
resources will not
force any change in the
program.
Java Basics

Characteristics of Java
 Secure

 Programs are confined to the Java execution environment


and can not access other parts of the computer

 Security threats like eavesdropping, Tampering and virus


can be eliminated or minimized by using java on internet

 Designed with the intention of being secure


 It verify all memory access
 Ensure that no viruses are communicated with an applet.
Java Basics

Characteristics of Java
 Robust
 Robust means Strong.
 Java programs are strong and they don’t crash easily like
C and C++.
 Memory allocation made by JVM not by the program.
 Garbage collection de allocate the memory. [Java (and
JVM in particular) uses automatic garbage collection]
 No pointer arithmetic or manual memory management.
Java Basics

Characteristics of Java
 High Performance
 Java performance is slower than C, because it handles
more complicated task than C language.

 Incorporation of multithreading enhance the overall


execution speed.

 Can sometimes be even faster than compiled C code.

 As it dose not include the library files as like C into the


byteCode file, its linking & working is faster.
Java Basics

Characteristics of Java
 Language of Internet Programming
 Java Applets:
 Java Applets are small java programmes created to be transmitted over internet
and downloaded by the uses on their machine.
 An applet is designed to be embedded in a Web page, and run by a browser.
 Applets run in a sandbox with numerous restrictions; for example, they can’t read
files and then use the network.
 Java compatible web browser can download java applets without fear of viral
infection and malicious agent.
<HTML>
<HEAD>
</HEAD>
<BODY>
<div >
<APPLET CODE = "Main.class" WIDTH = "800" HEIGHT = "500"></APPLET>
</div>
</BODY> import java.applet.*;
</HTML> import java.awt.*;
public class Main extends Applet {
public void paint(Graphics g) {
g.drawString("Welcome in Java Applet.",40,20);
}}
Java Basics

Characteristics of Java
 Language of Internet Programming

 Java Program Applications


Applications are programmes that run on a stand-alone
computer and similar to programmes written in any other
language

 Java Servlet
A servlet is designed to be run by a web server
Java Basics

Characteristics of Java
 Dynamic
 Capable of dynamically linking a new class libraries,
methods and objects, with the OOPS pillar ‘Modularity’.

 Java can use efficient functions available in C/C++. Means


it can connect the source code of C,C++ with its source
code.

 Installing new version of library files, automatically


updates all programs as the library is linked and not
included.
Java Basics

Characteristics of Java
 Dynamic
Java Basics

Characteristics of Java
 Multithreaded OS Review: Batch / Uni-programming
 The earlier days the computer’s memory is occupied only one
program after completion of one program it is possible to
execute another program
 Whenever one program execution is completed then only
second program execution will be started . This execution we
are having lot of disadvantages:
 Most of the times memory will be wasted
 CPU utilization will be reduced because only program allow
executing at a time.
 To overcome above problems a new programming style
introduced is called “multiprogramming “
Java Basics

Characteristics of Java
 Multithreaded OS Review: Multiprogramming
 There are one or more programs loaded in main memory which are ready
to execute
 Since there is one processor , there can be no true simultaneous
execution of different programs. Instead, the operating system
executes part of one program, then part of another, and so on. To the
user it appears that all programs are executing at the same time.
 Is a simple form of parallel processing in which several programs are run
at the same time on a single processor .
 Multiprogramming mainly focuses on the number of programs.
 Advantages of Multiprogramming:
 CPU utilization will be increased.
 Execution speed will be increased and response time will be
decreased.
 CPU resources are not wasted.
Java Basics

Characteristics of Java
 Multithreaded OS Review: Multiprocessing
 Multiprocessing refers to the hardware (i.e., the CPU units) rather than
the software (i.e., running processes)

 Several variations on the basic scheme exist, e.g., multiple cores on one
CPU multiple CPU in one Computer or multiple Computers in one system.

 A system can be both multiprogrammed by having multiple programs running


at the same time and multiprocessing by having more than one physical
processor.
Java Basics

Characteristics of Java
 Multithreaded OS Review: Multitasking
 in an operating system, is allowing a user to perform more than one
computer task (such as the operation of an application program) at a
time.

 The operating system is able to keep track of where you are in these
tasks and go from one to the other without losing information.

 Almost all of the today’s operating system are multitasking. When you
open your web browser and then open word at the same time , you are
causing the operating system to do multitasking.
Java Basics

Characteristics of Java
 Multithreaded
 Multithreading, the management of multiple execution paths
through the computer or of multiple users sharing the same copy
of a program.
 Executing more than one thread a time is called multithreading.
 Thread is nothing but separate path of sequential execution.
 The thread is light weight process because whenever we are
creating thread it is not occupying the separate memory it uses
the same memory. Whenever the memory is shared means it is
not consuming more memory.
 Whenever different parts of the program executed
simultaneously that each and every part is called thread.
Java Basics

Characteristics of Java
 Multithreaded
 Handles multiple tasks simultaneously.
 Java runtime system contains tools to support
multiprocessing synchronization and construct smoothly
running interactive systems.
 Java supports Threading to modulate the task and is
capable of handling it.
 The main important application areas of the
multithreading are :
 Developing video games
 Implementing multimedia graphics.
 Developing animations
Java Basics

Characteristics of Java
 Object Oriented Language
Fundamentally based on OOP
 Classes and Objects

 Efficient re-use of packages such that the programmer


only cares about the interface and not the
implementation.

 The object model in java is simple and easy to extend.


Java Basics

Characteristics of Java
 The Java API’s
 Contains hundreds of classes and methods grouped into
several functional packages.
 Also known as a “library”.
 Contains predefined java code that we can use to develop
java programs
 Faster and easier development process.
 No need to write everything from scratch.
Java Basics

The difference between C++ & Java?


 Java is multithreaded
 Java has no pointers
 Java has automatic memory management (garbage
collection)
 Java is platform independent
 Java has built-in support for comment documentation
 Java has no operator overloading
 Java doesn’t provide multiple inheritance
 There are no destructors in Java
Java Basics

Java Developing phases


Program is created in an editor and
Phase 1 Editor stored on disk in a file ending with
Disk .java
Compiler creates bytecodes and stores
Phase 2 Compiler Disk them on disk in a file ending with .class

Primary Memory
JVM
Phase 3 Class Loader Class loader reads .class files
containing bytecodes from disk and
puts those bytecodes in memory.
Disk

Primary Memory
JVM
Phase 4 Bytecode Verifier Bytecode verifier confirms that all
bytecodes are valid and do not violate
Java’s security restrictions.

JVM Primary Memory Interpreter reads bytecodes and


Phase 5 Interpreter translates them into a language that
the computer can understand, possibly
storing data values as the program
executes.
Java Basics

Java Environment
 Java Environment called Java Development Kit (JDK) which
includes a large number of development tools and hundreds
of classes and methods. Components of JDK :
 Library of classes and methods is known as the
Application Programming Interface (API).
 Development tools includes :
 Appletviewer (for viewing applets)
 Javac (Compiler)
 Java (Interpreter)
 Javah (for C header files)
 Javadoc (for creating HTML description)
 If we run java application (no development) no need to install
JDK, we need to download and install JRE
Java Basics

Java Environment
 Application Programming Interface (API)
 Java = small core + extensive collection of packages
(API)
 A package consists of some related Java classes:
 Swing: a GUI (graphical user interface) package
 AWT: Application Window Toolkit (more GUI)
 util: utility data structures

 The import statement tells the compiler to make


available classes and methods of another package

 API’s is integrated part of JDK and JRE


Java Basics

Java Integrated Development Environment (IDE)


 The main purpose of the IDE is to :
 Write : source code.
 Compile : machine code.
 Debug : tools to find errors.
 Build : files that can be executed by JVM
 Run : execute our program
 Make Java development efforts easier and more
efficient.
 Popular Java IDE’s : NetBeans, Eclipse, ….
 I recommend TextPad (text editor by Helios Software)
Java Basics

Fundamental Computer Architectures


 The hardware designer must make some decisions on how the
CPU should store data.
 This is the most basic means to differentiate CPU
architectures.
 There are three choices:
1. A stack architecture (JAVA Virtual Machine JVM)
2. An accumulator architecture (MARIE)
3. Load/Store machine (INTEL / Motorola / …)
 In choosing one over the other, the tradeoffs are simplicity
(and cost) of hardware design with execution speed and ease
of use.
MARIE … Machine Architecture that is Really Intuitive and Easy
Java Basics

Fundamental Computer Architectures


1- Stack architecture

 Stack architectures use a stack to execute instructions & the


operands are (implicitly) found on top of the stack
 a stack cannot be accessed randomly, which makes it difficult to
generate efficient code.
 Example : x = 2 * (m + n )
Java Basics

Fundamental Computer Architectures


2- Accumulator architecture
 Has one operand implicitly in the accumulator (such as MARIE), minimize
the internal complexity of the machine and allow for very short
instructions.
 But because the accumulator is only
temporary storage, memory traffic is
very high.
 Example : A = B + C * D * E + F
Programs Comments
LOAD C Load C in AC
MULT D Multiply D in AC (i.e C * D)
MULT E Multiply E in AC (i.e C * D * E)
ADD B Add B in AC (i.e B + C * D * E)
ADD F Add F in AC (i.e B + C * D * E +F)
STORE A Store Result in A
Java Basics

Fundamental Computer Architectures


3- Load/Store machine
 The most widely accepted models
for machine architectures today.
 Use sets of general purpose
registers. These register sets
are faster than memory, easy for
compilers to deal with, and can be
used very effectively and
efficiently.
 Example: A*B - (A+C*B)
mul D,A,B
mul E,C,B
add E,A,E
sub E,D,E

You might also like