Presentation is loading. Please wait.

Presentation is loading. Please wait.

Prepared By E.Musa Alyaman1 Chapter 2 The Java Overview.

Similar presentations

Presentation on theme: "Prepared By E.Musa Alyaman1 Chapter 2 The Java Overview."— Presentation transcript:

1 Prepared By E.Musa Alyaman1 Chapter 2 The Java Overview

2 Prepared By E.Musa Alyaman2 Chapter 2 Outline What is Java? The Java Programming Language The Java Platform –The Java Virtual Machine –Java Runtime Environment The Java API Applications of Java Network Programming –Network clients –Games –Software agents –Web Applications –Distributed Systems Java Language Issues 1. Exception Handling in Java 2. What are Exceptions 3. Types of Exceptions 4. Handling exceptions 5. Causes of exceptions Chapter 2 Highlights

3 Prepared By E.Musa Alyaman3 What is Java? The name Java is applied to a variety of technologies created by Sun Microsystems There are three main components of Java: 1.The Java Programming Language – a programming language used to write software for the Java platform 2.The Java platform – a range of runtime environments that supports execution of software written in Java 3.The Java API – a rich, fully featured class library that provides graphical user interface, data storage, data processing, I/O and networking support

4 Prepared By E.Musa Alyaman4 The Java Programming Language Properties of the Java language Object orientation Simplicity Automatic garbage collection Portability Multi-threaded programming Security Internet awareness

5 Prepared By E.Musa Alyaman5 The Java Platform Third-generation language The source code instructions written in Java must be compiled to a form that the computer is capable to understand Most languages would be compiled to machine native code, hence running on a specific CPU architecture. Problem with distribution of the program

6 Prepared By E.Musa Alyaman6 The Java Platform The Java platform takes a different approach. Instead of creating machine code for particular pieces of hardware, Java source code is compiled to run on a single CPU Java machine code or bytecode is executed by a special software that mimics a CPU chip capable of understanding bytecode The software is called Java Virtual Machine (JVM)

7 Prepared By E.Musa Alyaman7 The Java Virtual Machine An emulation of hardware device Write Once, Run Anywhere (WORA) JVM allows Java to be portable across different type of OS Flexibility vs performance issues However, advancement of CPU performance “covers” Java weakness

8 Prepared By E.Musa Alyaman8 Java Runtime Environment JVM is not a software application that can itself be run Usually, the JVM is hosted within a Java runtime environment (JRE) JRE will also include the core classes from the Java API and other supporting files. J2SE, J2EE, J2ME

9 Prepared By E.Musa Alyaman9 The Java API The API provides a rich suite of classes and components that allows Java to do real work, such as: Reading from and writing to files on the local hard drive Creating graphical user interfaces with menus, buttons, text fields and drop-down lists Drawing pictures from graphical primitives such as lines, circles, squares and ellipses Assessing network resources such as Web sites or network servers Storing data in data structures such as linked lists and arrays Manipulating and processing data such as text and numbers Retrieving information from databases or modifying records

10 Prepared By E.Musa Alyaman10 Java Networking Considerations “Ideal” language for network programming However, Java does not provide low-level access to Internet Protocols Java imposes severe security restrictions on Java applets

11 Prepared By E.Musa Alyaman11 Network clients A common use for Java is to create network clients such as: Mail readers Remote file transfer application Browser

12 Prepared By E.Musa Alyaman12 Games One major application of network communication is the multiplayer games that run over a LAN or online games which run over the Internet

13 Prepared By E.Musa Alyaman13 Software agents A software that acts on the behalf of one or more users, to perform specific commands and tasks or to fulfill a set of goals Examples: –An agent to sort through email message –An agent that searches for information on the Web –An agent that monitors a source of information for changes relating to the interest of a user

14 Prepared By E.Musa Alyaman14 Web Applications One of the most important areas for Java network programming Applets Server-side Java

15 Prepared By E.Musa Alyaman15 Distributed Systems Used to solve very complex and large problems Resources may be distributed across an organization Remote Method Invocation (RMI) and Common Object Request Broker Architecture (CORBA) make this possible

16 Prepared By E.Musa Alyaman16 Java Language Issues In network programming using Java, there are some issues that we need to be aware of 1. Exception Handling in Java 2. What are Exceptions 3. Types of Exceptions 4. Handling exceptions 5. Causes of exceptions

17 Prepared By E.Musa Alyaman17 Exception Handling in Java A mechanism for dealing with errors that occur in software at runtime. For example, while attempting to read from a file, an application may be unable to proceed because the file is missing (occur at runtime).

18 Prepared By E.Musa Alyaman18 What are Exceptions Unusual conditions that occur at runtime and are represented as objects Track information about errors condition, making it possible to diagnose the cause of the problem or at least to provide clues as to why it occurred. “throw” the exception and pass it to the calling method. The calling method may choose to handle the error condition and “catch” the exception or it may throw the exception to its calling method. Method will generate the exception that indicates the type of exception will be thrown. At some point in the code, the exceptions need to be caught and dealt with accordingly

19 Prepared By E.Musa Alyaman19 Types of Exceptions The types of exception vary depending on the classes that are being used Compilation Error examples: AWTError – serious error occurs in the Abstract Windowing Toolkit NoClassDefFoundError – thrown when the JVM is unable to locate the class definition file (.class) for a class OutOfMemoryError – occurs when JVM can no longer allocate memory to objects

20 Prepared By E.Musa Alyaman20 Types of Exceptions Runtime error examples: –NoSuchElementException – thrown when an attempt is made to access the next element of an enumeration but all elements have been exhausted –NullPointerException – thrown when an attempt to reference an object has been made but the reference was null –SecurityException – thrown by the current security manager when an attempt to access a resource, object or method has been made but not permitted

21 Prepared By E.Musa Alyaman21 Handling Exceptions Java provides three statements for handling exceptions: 1. try 2. catch 3. finally

22 Prepared By E.Musa Alyaman22 try statement –The try statement indicates a block of code that can generate exception //code outside of try block should not throw an exception try { // do something that could generate an exception… } //handle exception…

23 Prepared By E.Musa Alyaman23 catch statement The catch statement is used to catch exceptions thrown within a try block of code. //try block can generate exceptions try { //generate an exception } catch (SocketException se) { System.err.println(“Socket error reading from host: “ + se); System.exit(2); } catch (Exception e) { System.err.println(“Error:” + e); System.exit(1); }

24 Prepared By E.Musa Alyaman24 finally statement The finally statement is a generic catchall for cleaning up after a try block. //try block can generate exceptions try { //generate an exception } catch (SomeException some) { //handle some exception } finally { //clean up after try block, regardless of any //exceptions that are thrown }

25 Prepared By E.Musa Alyaman25 Causes of exceptions In networking, the most common cause of exceptions is related to the state of the network connection: –Loss of connection due to congestion –Server/host behind firewall that block external requests Other may be due to security measures imposed by the browser or by Java security policy or security manager.

26 Prepared By E.Musa Alyaman26 Development Tools Java SDK version 6 (the latest) IDE –NetBeans –Eclipse –JCreator –TextPad

27 Prepared By E.Musa Alyaman27 Chapter Highlights You have learned –The history of Java, design goals and properties of the Java language –About compiled bytecode, the Java Virtual Machine and Java Runtime Environment –The core Java API and some Java extensions –Some issue and consideration related to Java –Example of applications –Exception handling –Development tools

Download ppt "Prepared By E.Musa Alyaman1 Chapter 2 The Java Overview."

Similar presentations

Ads by Google