Presentation is loading. Please wait.

Presentation is loading. Please wait.

EE2E1. JAVA Programming Introduction Dr. Mike Spann

Similar presentations


Presentation on theme: "EE2E1. JAVA Programming Introduction Dr. Mike Spann"— Presentation transcript:

1 EE2E1. JAVA Programming Introduction Dr. Mike Spann m.spann@bham.ac.uk

2 Contents Java is just another programming language (eg. C & C++). So why bother to learn Java? Java is just another programming language (eg. C & C++). So why bother to learn Java?

3 Java is …… Portable Portable Object oriented Object oriented Robust Robust Multi-threaded Multi-threaded Graphical Graphical Connected Connected Extensive Extensive

4 Java applications and applets Applications – standalone Java programs Applications – standalone Java programs Applets – Java programs that run inside web browsers Applets – Java programs that run inside web browsers

5 ‘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) public static void main(String[] args) { System.out.println("Hello World!"); System.out.println("Hello World!"); }}

6

7 ‘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()); }

8 ‘Hello World’ html file

9 Run the ‘Hello World’ applet http://www.eee.bham.ac.uk/spannm/Java %20Stuff/HelloWorldApplet/HelloWorld Applet.html http://www.eee.bham.ac.uk/spannm/Java %20Stuff/HelloWorldApplet/HelloWorld Applet.html http://www.eee.bham.ac.uk/spannm/Java %20Stuff/HelloWorldApplet/HelloWorld Applet.html http://www.eee.bham.ac.uk/spannm/Java %20Stuff/HelloWorldApplet/HelloWorld Applet.html

10 Portable Java Java is ‘program once – run anywhere’ Java is ‘program once – run anywhere’ A Java program is compiled to bytecodes A Java program is compiled to bytecodes Bytecodes interpreted by the Java Virtual Machine Bytecodes interpreted by the Java Virtual Machine

11 Object Oriented Java Object oriented programming is concerned with objects and their : State State Behavior Behavior

12 Example Example  A bank account transfer() withdraw() balance account number State Behaviour

13 class BankAccount { public void transfer(int amount); public void withdraw(int amount); private: int balance; int accountNumber; }

14 Robust Java Java is easier than C or C++! Java is easier than C or C++! Java has better memory management 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 You don’t need pointers for accessing arrays or strings in Java No chance of dangling pointers or memory leaks in Java No chance of dangling pointers or memory leaks in Java

15 Multi-threaded Java A thread is a sequence of executing statements in a program 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) 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 – multi- threading is easy in Java! Java supports multi-threading as an intrinsic part of the language – multi- threading is easy in Java!

16 A single-threaded program A multi-threaded program

17 Example – A sort demo Multi-threaded Sorting Applet Multi-threaded Sorting Applet Multi-threaded Sorting Applet Multi-threaded Sorting Applet

18 Graphical Java Abstract widget toolkit (AWT) + User interface library Swing Abstract widget toolkit (AWT) + User interface library Swing Swing is a collection of user interface components (buttons, menus, dialogue boxes etc) Swing is a collection of user interface components (buttons, menus, dialogue boxes etc) AWT does the event handling AWT does the event handling

19 Example 1. A tic-tac-toe applet http://www.eee.bham.ac.uk/spannm/Java %20Stuff/TicTacToeApplet/example1.htm l http://www.eee.bham.ac.uk/spannm/Java %20Stuff/TicTacToeApplet/example1.htm l http://www.eee.bham.ac.uk/spannm/Java %20Stuff/TicTacToeApplet/example1.htm l http://www.eee.bham.ac.uk/spannm/Java %20Stuff/TicTacToeApplet/example1.htm l

20 Example 2. Full swing set demo http://www.eee.bham.ac.uk/spannm/Java %20Stuff/SwingSetApplet/SwingSetApp let.html http://www.eee.bham.ac.uk/spannm/Java %20Stuff/SwingSetApplet/SwingSetApp let.html http://www.eee.bham.ac.uk/spannm/Java %20Stuff/SwingSetApplet/SwingSetApp let.html http://www.eee.bham.ac.uk/spannm/Java %20Stuff/SwingSetApplet/SwingSetApp let.html

21 Connected Java Networking is easy in Java! Networking is easy in Java! Java has classes and methods for network programming. Java has classes and methods for network programming. A Java program can easily access a web- site through a URL connection A Java program can easily access a web- site through a URL connection Java programs can be be written which implement both client and server side processing Java programs can be be written which implement both client and server side processing

22 Example – simple web browser http://www.eee.bham.ac.uk/spannm/Java %20Stuff/BookMarkApplet/BookMark.h tml http://www.eee.bham.ac.uk/spannm/Java %20Stuff/BookMarkApplet/BookMark.h tml http://www.eee.bham.ac.uk/spannm/Java %20Stuff/BookMarkApplet/BookMark.h tml http://www.eee.bham.ac.uk/spannm/Java %20Stuff/BookMarkApplet/BookMark.h tml

23 So what is Java? Java consists of 2 things : The Java Virtual Machine (Java VM) The Java Virtual Machine (Java VM) The Java Application Programming Interface (Java API) The Java Application Programming Interface (Java API)

24 Java VM runs the Java bytecode on the different hardware platforms Java VM runs the Java bytecode on the different hardware platforms Java API is a large collection of ready- made software components Java API is a large collection of ready- made 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. The Java API is grouped into libraries of related classes and interfaces; these libraries are known as packages.

25 My Java program Java API Java VM HardwareOther API’s

26 Java API java langawtio Math String Thread Graphics MathButton Color File InputStream OutputStream sqrt() exp()

27 Java API documentation can be found online at : http://docs.oracle.com/javase/7/docs/api/ http://docs.oracle.com/javase/7/docs/api/ http://docs.oracle.com/javase/7/docs/api/

28 Extensive Java – Java technology Java has additional API’s covering a wide range of software technologies Java has additional API’s covering a wide range of software technologies  Java2D – 2D graphics  Java3D – 3D graphics  Java Advanced Imaging (JAI) – image processing

29  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

30  Java TV API – interactive digital TV  JavaMail API – email applications  JDBC – Java database API

31 Examples Java2D API Java2D API  http://www.cs.kent.ac.uk/people/staff/pgk/te aching/java/lab-guides/getting- started/demo/jfc/Java2D/Java2D.html http://www.cs.kent.ac.uk/people/staff/pgk/te aching/java/lab-guides/getting- started/demo/jfc/Java2D/Java2D.html http://www.cs.kent.ac.uk/people/staff/pgk/te aching/java/lab-guides/getting- started/demo/jfc/Java2D/Java2D.html Java 3D API Java 3D API  http://www.mol3d.com/ http://www.mol3d.com/

32 Java resources Sun’s Java home page Sun’s Java home page  http://java.sun.com/ http://java.sun.com/ Java online tutorial Java online tutorial  http://java.sun.com/docs/books/tutorial/ http://java.sun.com/docs/books/tutorial/ Comparing C++and Java Comparing C++and Java  http://www.compapp.dcu.ie/~renaat/projects/cvjava.ht ml http://www.compapp.dcu.ie/~renaat/projects/cvjava.ht ml http://www.compapp.dcu.ie/~renaat/projects/cvjava.ht ml Textbook Textbook  Core Java 2. Volume 1-Fundamentals Core Java 2 Core Java 2  C.S.Horstmann, G. Cornell  Amazon Link Amazon Link Amazon Link My web page My web page  http://www.eee.bham.ac.u k/spannm/Courses/ee2e.h tm http://www.eee.bham.ac.u k/spannm/Courses/ee2e.h tm http://www.eee.bham.ac.u k/spannm/Courses/ee2e.h tm

33 OK, so why should I learn Java? Main reason, Java is object oriented 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

34 OK, so why should I learn Java? Java is free to download and is easy to learn Java is free to download and is easy to learn Java has powerful (and free!) development tools e.g. Eclipse, Netbeans Java has powerful (and free!) development tools e.g. Eclipse, Netbeans Excellent documentation support – Javadocs Excellent documentation support – Javadocs Great community support Great community support Rich collection of open source libraries Rich collection of open source libraries Can develop Android apps in Java – supported by Eclipse and Netbeans Can develop Android apps in Java – supported by Eclipse and Netbeans  Android is a good platform for mobile apps because of  Android is a good platform for mobile apps because of ease of release, wide range of devices and its an open platform

35 So what about this course? EE2E1 (MS) EE2E1 (MS)  Introduction to Java programming  Basic ideas about objects and classes  We will also look at more advanced features of Java GraphicsGraphics Files and streamsFiles and streams Multi-threadingMulti-threading NetworksNetworks EE2E2 (DP) EE2E2 (DP)  Object Oriented Software Design

36 Assessment EE2E1 and EE2E2 are assessed jointly (making up the EE2E module) 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 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

37


Download ppt "EE2E1. JAVA Programming Introduction Dr. Mike Spann"

Similar presentations


Ads by Google