Download Java Presentation

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
EE2E1. JAVA Programming
Introduction
Dr. Mike Spann
[email protected]
Contents

Java is just another programming language
(eg. C & C++). So why bother to learn
Java?
Java is ……







Portable
Object oriented
Robust
Multi-threaded
Graphical
Connected
Extensive
Java applications and applets

Applications – standalone Java programs

Applets – Java programs that run inside
web browsers
‘Hello world’ application
/** * The HelloWorldApp class implements an
application that simply displays "Hello
World!" to the standard output. */
public class HelloWorldApp
{
public static void main(String[] args)
{
System.out.println("Hello World!");
}
}
‘Hello world’ applet
class HelloWorldPanel extends JPanel
{ public void paintComponent(Graphics g)
{ super.paintComponent(g);
Font f=new Font(“SansSerif”,Font.BOLD,36);
g.setFont(f);
g.drawString("Hello World!", 50, 120);
}
}
public class HelloWorldApplet extends JApplet
{ public void init()
{ Container contentPane = getContentPane();
contentPane.add(new HelloWorldPanel());
}
}
‘Hello World’ html file
<APPLET CODE = “HelloWorldApplet.class"
WIDTH = 300 HEIGHT = 300 >
</APPLET>
Run the ‘Hello World’ applet

http://www.eee.bham.ac.uk/spannm/Java
%20Stuff/HelloWorldApplet/HelloWorld
Applet.html
Portable Java



Java is ‘program once – run anywhere’
A Java program is compiled to bytecodes
Bytecodes interpreted by the Java Virtual
Machine
Object Oriented Java
Object oriented programming is concerned
with objects and their :
State
 Behavior


Example
 A bank account
State
balance
account number
transfer()
Behaviour
withdraw()
class BankAccount
{
public void transfer(int amount);
public void withdraw(int amount);
private:
int balance;
int accountNumber;
}
Robust Java
Java is easier than C or C++!
 Java has better memory management
than C or C++
 You don’t need pointers for accessing
arrays or strings in Java
 No chance of dangling pointers or
memory leaks in Java

Multi-threaded Java
A thread is a sequence of executing
statements in a program
 A multi-threaded program comprises a
number of threads which run in parallel
(but only one thread is being executed at
one time)
 Java supports multi-threading as an
intrinsic part of the language – multithreading is easy in Java!

A single-threaded
program
A multi-threaded
program
Example – A sort demo

Multi-threaded Sorting Applet
Graphical Java
Abstract widget toolkit (AWT) + User
interface library Swing
 Swing is a collection of user interface
components (buttons, menus, dialogue
boxes etc)
 AWT does the event handling

Example 1. A tic-tac-toe applet

http://www.eee.bham.ac.uk/spannm/Java
%20Stuff/TicTacToeApplet/example1.htm
l
Example 2. Full swing set demo

http://www.eee.bham.ac.uk/spannm/Java
%20Stuff/SwingSetApplet/SwingSetApp
let.html
Connected Java
Networking is easy in Java!
 Java has classes and methods for network
programming.
 A Java program can easily access a website through a URL connection
 Java programs can be be written which
implement both client and server side
processing

Example – simple web browser

http://www.eee.bham.ac.uk/spannm/Java
%20Stuff/BookMarkApplet/BookMark.h
tml
So what is Java?
Java consists of 2 things :

The Java Virtual Machine (Java VM)

The Java Application Programming
Interface (Java API)
Java VM runs the Java bytecode on the
different hardware platforms
 Java API is a large collection of readymade software components
 You can add additional API’s to this
layer
 Graphics, numerical, image processing
etc
 The Java API is grouped into libraries of
related classes and interfaces; these
libraries are known as packages.

My Java program
Java API
Java VM
Hardware
Other API’s
Java API
java
lang
Math
awt
Graphics
sqrt()
exp()
Button
Math
String
Color
Thread
io
File
InputStream
OutputStream
Java API documentation can be
found online at :

http://docs.oracle.com/javase/7/docs/api/
Extensive Java – Java technology

Java has additional API’s covering a wide
range of software technologies
 Java2D – 2D graphics
 Java3D – 3D graphics
 Java Advanced Imaging (JAI) – image
processing
Java Speech API – speech processing
 Java Media Framework API – multi-media
application
 JavaBeans – re-useable user interface
components
 Java Servlets – extending web server
functionality
 Java Message Service (JMS) – allowing
programs to exchange messages
 Java Telephony API – computer telephony


Java TV API – interactive digital TV

JavaMail API – email applications

JDBC – Java database API
Examples


Java2D API
 http://www.cs.kent.ac.uk/people/staff/pgk/te
aching/java/lab-guides/gettingstarted/demo/jfc/Java2D/Java2D.html
Java 3D API
 http://www.mol3d.com/
Java resources





Sun’s Java home page
 http://java.sun.com/
Java online tutorial
 http://java.sun.com/docs/books/tutorial/
Comparing C++and Java
 http://www.compapp.dcu.ie/~renaat/projects/cvjava.ht
ml
Textbook
 Core Java 2. Volume 1-Fundamentals
 C.S.Horstmann, G. Cornell
 Amazon Link
My web page

http://www.eee.bham.ac.uk/spannm/Courses/ee2e.h
tm
OK, so why should I learn Java?

Main reason, Java is object oriented

What is OOP good for?
 Modelling asynchronously interacting objects
• GUIs
• Event simulation
• Ray tracing visualisation
• CAD simulation
• Real-time control/embedded systems
• Robotics
• Image/Video processing
• Client/Server systems
• etc
OK, so why should I learn Java?






Java is free to download and is easy to learn
Java has powerful (and free!) development tools
e.g. Eclipse , Netbeans
Excellent documentation support – Javadocs
Great community support
Rich collection of open source libraries
Can develop Android apps in Java – supported by
Eclipse and Netbeans
 Android is a good platform for mobile apps
because of ease of release, wide range of
devices and its an open platform
So what about this course?

EE2E1 (MS)
 Introduction to Java programming
 Basic ideas about objects and classes
 We will also look at more advanced features
of Java
• Graphics
• Files and streams
• Multi-threading
• Networks

EE2E2 (DP)
 Object Oriented Software Design
Assessment
EE2E1 and EE2E2 are assessed jointly
(making up the EE2E module)
 EE2E1 is assessed through a classtest and
programming exercises and a major
programming assignment
 15% through a 1 hour class test
 2 x 22.5% through 2 programming
exercises
 40% through a major programming
assignment carried out in semester 2

Related documents