1 / 37

EE2E1. JAVA Programming Introduction

EE2E1. JAVA Programming Introduction. Dr. Mike Spann m.spann@bham.ac.uk. Contents. Java is just another programming language ( eg . C & C++). So why bother to learn Java?. Portable Object oriented Robust Multi-threaded Graphical Connected Extensive. Java is …….

algernon
Download Presentation

EE2E1. JAVA Programming Introduction

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. EE2E1. JAVA ProgrammingIntroduction 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?

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

  4. Java applications and applets • Applications – standalone Java programs • 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) { System.out.println("Hello World!"); } }

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

  7. ‘Hello World’ html file <APPLET CODE = “HelloWorldApplet.class" WIDTH = 300 HEIGHT = 300 > </APPLET>

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

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

  10. Object Oriented Java Object oriented programming is concerned with objects and their : • State • Behavior

  11. balance State account number transfer() Behaviour withdraw() • Example • A bank account

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

  13. 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

  14. 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 – multi-threading is easy in Java!

  15. A single-threaded program A multi-threaded program

  16. Example – A sort demo • http://www.cs.ubc.ca/~harrison/Java/sorting-demo.html

  17. 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

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

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

  20. Connected Java • Networking is easy in Java! • Java has classes and methods for network programming. • 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

  21. Example – simple web browser • http://www.eee.bham.ac.uk/spannm/Java%20Stuff/BookMarkApplet/BookMark.html

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

  23. Java VM runs the Java bytecode on the different hardware platforms • 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.

  24. My Java program Java API Java VM Hardware Other API’s

  25. Java API java lang awt io Math Graphics File sqrt() exp() Math Button InputStream String Color OutputStream Thread

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

  27. 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

  28. 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

  29. Java TV API – interactive digital TV • JavaMail API – email applications • JDBC – Java database API

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

  31. 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.html • 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.htm

  32. 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

  33. 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

  34. 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

  35. 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

More Related