Presentation is loading. Please wait.

Presentation is loading. Please wait.

Introduction to JAVA Vijayan Sugumaran School of Business Administration Oakland University Rochester, MI 48309.

Similar presentations

Presentation on theme: "Introduction to JAVA Vijayan Sugumaran School of Business Administration Oakland University Rochester, MI 48309."— Presentation transcript:

1 Introduction to JAVA Vijayan Sugumaran School of Business Administration Oakland University Rochester, MI 48309

2 Introduction to JAVA n Ancestor to JAVA - Oak –small, robust, architecture independent, Object- Oriented, language to control interactive TV. –didn’t go anywhere –refocused for Internet, Java was born. n JAVA is both compiled and interpreted language. JAVA Source Code Compiled JAVA byte-code UNIX PC MAC

3 Java Introduction (contd.) n JAVA byte-code (or J-code) is executed by JAVA run- time interpreter (JAVA compliant Virtual Machine) n The interpreter can be run as a separate application or embedded in another software such as a browser. n The fundamental unit of JAVA code is the “class.” n Since JAVA interpreter runs compiled byte-code, JAVA is relatively a fast interpreted language. n The run-time system can compile byte-code to native machine code on the fly to optimize performance. This is called “Just in time.” (one sticky problem is the array- bounds checking)

4 Java and Javascript n Don’t confuse JAVA with Javascript –Javascript is an object-based scripting language developed by Netscape –Lets you create active user interface and capture and validate user inputs –Client-side replacement for cgi-script, client side computing instead of server side –Java is full-featured programming language –Javascript can interact with Java applets

5 Java Characteristics n Unlike C++, Java doesn’t allow programmer defined operator overloading n Java doesn’t have a preprocessor, so it doesn’t have macros, #define statements, or conditional source compilation n Java provides a well-defined package structure for organizing class files n Supports only single inheritance class hierarchy, but allows multiple inheritance of Interfaces n -Interface of a class--like an abstract class in C++ which specifies the behavior of an object without defining its implementation

6 Java Characteristics (contd.) n Statistically typed –data types etched in stone for the compiler (C, C++) n Dynamically typed –type checking performed during execution (lisp or smalltalk) n Early binding –binding method calls to definitions at compile time (C, C++) n Late binding –locating definitions of methods dynamically at run time n Java is statistically typed and late-binding language n Java carries all data-type and method-signature information with it from its source code to its compiled byte-code form

7 Java Characteristics (contd.) n Base class in Java can evolve with out affecting derived classes as long as it maintains a valid form of its original structure. (in C++, if the base class changes, the derived classes should be recompiled) n Java handles garbage collection n Java uses “references” instead of pointers. Can’t do pointer arithmetic with references. A references is a strongly typed handle for an object. All objects are accessed through references n Security manager controls access to system resources like the file system, network parts, windowing environment, etc.

8 JAVA Security System Resources Security Manager Class Loader Verifier Untrusted Source JAVA Binary

9 Safety Implementation n Verifier guarantees the integrity of incoming classes n Verifier: –reads byte-code & makes sure it behaves properly –it is a type of theorem prover - steps through the byte-code and determines the behavior n Class Loader handles loading classes from the network and protects basic system classes n Class Loaders and security managers are implemented by applications that load applets such as browser and applet viewer

10 More about Class Loader n Class Loader: –Java adds second layer of security with class loader –It brings in Java binary classes that contain byte- code into the interpreter –Classes loaded remain associated with class loader –If a class references another class, the request is served by its original class loader –Classes loaded from one location can be restricted to interact with only those classed loaded from that same location

11 Security Manager n Security Manager : –Application level security decisions –Security manager is consulted every time the application tries to access system resources –The security manager can be simple or complex as the application warrants –The integrity of the security manager is based on the protection afforded by the lower levels of the Java security model

12 Java Applets n Applets: –Small embeddable application –A Java applet is a compiled Java program, consisting of classes just like any other Java program –Applets are autonomous programs confined within the walls of the browser or applet viewer. Can interact with user and communicate with the host over the network

13 Error Handling n The protection of references is one of the most fundamental aspects of Java Security n Java code has to play by the rules--it can’t peek into places it shouldn’t n Error Handling: –Exceptions allow separation of error-handling code from normal code –Exception carries with it an object that contains information about the situation that caused its exception

14 Multi Threading n Thread –flow of control within a program –threads run in the same address space –share instance variables, but not local variables n Multi Threading: –Threads provide efficient multi processing and distribution of tasks –Threads need to be synchronized--only one synchronized method within the object may run at a given time

15 Java Packages n Scalability: –Package--structure that groups classes into functional units –Within a package, a class is publicly visible or protected from outside access –Package promote reuse & scalability –Package names constructed in a hierarchical way using dot-separated naming convention »e.g. Java.awt.event

16 Sample Java Program //Create a file called public class Welcome { public static void main(String[] args) { System.out.println(“Hello World, Welcome to Java!!”); } Compiling and Executing javac (creates Welcome.class - java bytecode) java Welcome (JVM executes the byte code)

17 Sample Applet //create a file called public class HelloWeb extends java.applet.Applet { public void paint( java.awt.Graphics gc) { gc.drawString (“Hello World, Welcome to Java”, 125, 95); }  Compile the java source file (using JDK): javac  Create an html file that embeds the applet using the tag  Load the html page into a java supported browser

18 Sample HTML Document  Save it as HelloWeb.html  Open HelloWeb.html using the browser

Download ppt "Introduction to JAVA Vijayan Sugumaran School of Business Administration Oakland University Rochester, MI 48309."

Similar presentations

Ads by Google