CS5015 Object-oriented Software Development Lecture: Overview of Java Platform A. O Riordan, 2010 Most recent revision, 2014 updated for Java 8
Java Programming Language Java is an object-oriented programming language based on C and object-oriented languages such as C++ and Smalltalk Developed by Sun Microsystems (now Oracle) in 1990s Java language is core component of the Java platform Portability was a key goal Java Virtual Machine Other goals: simple, object-oriented, and familiar; robust and secure; architecture-neutral and portable; high performance; and interpreted, threaded, and dynamic. See White Paper: The Java Language Environment, 1996 2
JCP, JRE, SDK Specifications of the Java language, the Java Virtual Machine (JVM) and the Java API are community-maintained through the Java Community Process (JCP) Java's core code is available under a free open-source license The Java Runtime Environment (JRE) is the software required to run any application deployed on the Java platform end-users commonly use a JRE in software packages and plugins The Java Development Kit (JDK) is a superset of the JRE which includes development tools such as the Java compiler, debugger, etc. 3
Java: Early Developments 1991. Oak programming language developed under James Gosling at Sun as part of a project codenamed Green for applications like PDAs and set-top boxes; prototype PDA device with graphical interface agent called Duke 1994. Re-targeting of the platform for the World Wide Web as a prototype, Patrick Naughton wrote a small web browser WebRunner later renamed HotJava Oak was renamed Java 1995. Announcement at 1995's SunWorld conference that Netscape would be including support for it in their Navigator browser 1996. JavaSoft group formed by Sun Microsystems to develop technology 100% Pure Java initiative launched supported by Sun, IBM, Oracle, and others to guarantee Java compatibility using test suites to test compatibility 4
Initial release 1996. Initial release, JDK 1.0 Language features: C/C++ style syntax, strong typing, fixed-size primitive types, C-style operators and imperative statements, Strings, arrays, automatic memory management, classes, abstract classes, inheritance, interfaces, packages, class variables/methods, synchronization primitives for threading Supports Web applets; Libraries for graphics and GUIs Simpler than C++ No Preprocessor No Structures/Unions No Pointers No Enumerated types (introduced in Java 5) No Functions No Multiple Inheritance No Operator Overloading No Generic types (introduced in Java 5) 5
JDK 1.1 and Java 2 1997. JDK 1.1 released adds inner classes to core language; adds libraries for JDBC and RMI for database access and remote method call 1998. Version 1.2 (Playground) released this and subsequent 1.* releases branded Java 2; Swing graphical user interface API integrated into the core classes; JVM has a JIT compiler for the first time; Collections framework added. 2000. J2SE 1.3 (Kestrel) released bundling of the HotSpot JVM; new libraries include Java Platform Debugger Architecture (JPDA) and Java Naming and Directory Interface (JNDI); 6
J2SE 1.4 2002. J2SE 1.4 (Merlin) released Language change: assert keyword for assertions Library changes: exception chaining: when re-throwing a caught exception, wrap original inside a new exception; regular expressions support; logging API; integrated XML parser (JAXP); integrated security and cryptography extensions; non-blocking new I/O API (NIO); image I/O API; Web Start (and JNLP). 7
Java 5 2004. Major new release JDK 5 (Java 5) codename Tiger Introduces major features to core language: generics compile-time type-safe collections e.g. ArrayList<String> als = new ArrayList<String>(); annotations for metadata including @Deprecated, @Override and @SuppressWarnings autoboxing/unboxing automatic type conversions between primitive types and wrappers enumerations type-safe ordered list of values; enum keyword 8
Java 5 continued new enhanced for syntax; for (Customer c : customerlist) varargs variable length argument lists void drawtext(string... lines) static imports allows members (fields and methods) to be used without specifying class import static java.lang.math.*; allows System.out.println("A circumference of " + (PI * 5) + "cm") changes to memory model in multi-threading 9
Java 5 continued II Non-core changes include: For VM: Monitoring and management API for the Java VM class data sharing reduce application start-up time and footprint Libraries: Collections framework updated for core language changes concurrency utilities e.g. thread pools, task scheduling Scanner class Formatter class interpreter for printf-style format strings significant enhancements for security internationalization enhancements and, after seven years, ajframe.add() is now equivalent to ajframe.getcontentpane().add()! 10
Java 6 2006. Java SE 6 released no changes to core language; Sun replaced the name J2SE with Java SE; JVM improvements. Changes to libraries: scripting language support; GUI improvements; Java Compiler API; 2006/2007. Sun releases Java as open source software under the terms of the GNU General Public License (GPL) 2008. Java SE 6 Update 10 HotSpot VM 11 including Java Deployment Toolkit, getting the right version of Java for a user s system 11
Java 7 2010. Oracle acquires Sun Microsystems 2011. Java SE 7 major new release language changes some of Project Coin; parts deferred to Java 8 Strings in switch, catching multiple exception types; try-with-resources; change in varargs semantics; diamond operator <> for generic type creation; binary integer literals; New file I/O library (NIO.2) JVM support for dynamic languages 12
Java 8 18 March 2014. Java 8 Language additions: support for lambda expressions (closures) and method references to allow functional programming Streams API parallel processing of large data sets Profiles of the Java SE JavaFX (for rich client applications) is now part of the Java SE Nashorn, a new lightweight, high-performance implementation of JavaScript, integrated into the JDK major security enhancements new Date and Time API and more...see What s new! and Full list of features 13
Future: Java 9 2016?. Possible features better native code integration; modularization of the JDK; tight integration of JavaFX; automatic parallelization; multi-language interoperability; cloud support. 14
Java Virtual Machine Java Virtual Machine (JVM) executes Java bytecode executes.class or.jar files JIT (just in time) compiling, instead of interpreting, is used in most JVMs today has a stack-based architecture; stack-based architecture is a model of computation in which the computer's memory takes form of one or more stacks, data structures based on the principle of Last In First Out (LIFO) each particular host operating system needs its own implementation of the JVM dynamically loads, links and initializes classes and interfaces verifies all bytecode before it is executed branching, access, memory protection, type-safety dynamically loads, links and initializes classes and interfaces heap is the memory used by the JVM security restrictions: remote code runs in a sandbox 15
HotSpot Oracle officially licenses the Java SE platform for Linux, Mac OS X, and Solaris but many JVM implementations Oracle s HotSpot JVM (1999-present) contains class loader, bytecode verifier, interpreter, client and server runtime JIT compilers, garbage collectors, a set of supporting runtime libraries; available under a GNU General Public License; uses adaptive optimization Other JVMs: JRocket (Oracle); J9 (IBM) used in IBM WebSphere; IKVM.NET for Microsoft systems 16
JVM Languages Programming languages that execute on JVM aside of Java itself Includes: JRuby Java implementation of Ruby; Groovy high-level scripting language; Scala multi-paradigm programming language; Jython implementation of Python; and many others. 17
Java Platforms There are four platforms targeting different application environments and segmenting many of its APIs so that they belong to one of the platforms Java Card allows small Java-based applications to be run securely on small memory footprint devices such as smart cards; Java ME (Micro Edition) targeting environments with limited resources - limited storage, display, and power capacities mobile phones, PDAs, set-top boxes; profiles Mobile Information Device Profile (MIDP) for mobiles used in Symbian Java SE (Standard Edition) targeting workstation environments; Java EE (Enterprise Edition) targeting large distributed enterprise environments. 18
Libraries, APIs and Packages Java has large set of dynamically loadable libraries that applications call at runtime Java Standard Edition or Java SE is a collection of Java Application Programming Interfaces (APIs) useful to any Java platform programs The classes in the Java APIs are organized into separate groups called packages each package contains a set of related interfaces, classes and exceptions APIs and packages don t coincide an API may be spread across multiple packages 19
Base Libraries lang and util packages basic classes used to most applications Math java.lang.math package Collections Framework structures for represents a group of objects Concurrency Utilities Logging I/O (input/output) java.io and java.nio packages Object Serialization Networking Security Internationalization JavaBeans Component API XML (JAXP) and others 20
Other Java Libraries Integration libraries, to communicate with external systems: Java Database Connectivity (JDBC) for database access; Java Naming and Directory Interface (JNDI) for lookup and discovery; RMI and CORBA for distributed application development; scripting for the Java Platform User Interface libraries, which include: Abstract Windowing Toolkit (AWT) and Swing Java 2D; Sound APIs for audio capture, processing, and playback; Accessibility API Optional APIs downloaded separately Java 3D; Java Speech API; Java OpenGL 21
Java EE Java Enterprise Edition (Java EE) is Java platform for large enterprise applications Facilitates the development of modular, fault-tolerant, scalable, distributed, multi-tier, Web-based Java applications Contains APIs for e-mail, messaging, Web services and Web applications, transaction processing, and persistence Implementations include: Oracle s GlassFish and Weblogic; Red Hat s JBoss; IBM s WebSphere 22
Java and the Web Applets Java was designed from the very beginning (1994) so that it can operate on the Web used to provide interactive features to Webpages; a client running a browser with a Java plug-in (essentially JRE) can run bytecode that is transported over the net (using HTTP); the Java programs, called Applets, are referenced in HTTP Web pages by means of <APPLET> tag; can also be run with JDK s appletviewer; run in sandbox constrained environment with no access to system resources such as files any I/O has to be done by the browser or a helper app or the server; for authentication applets can use code signing signed classes 23
Java Web Start Java Web Start (JWS) and Java Network Launching Protocol (JNLP) API enables Java applications can be run over a network; started directly from the Internet using a Web browser but does not run in the browser; browser-independent architecture for deployment; more robust than applets; sandbox in which they run need not have as many restrictions as applets; can be used e.g. for auto-download of software; JNLP describes how to launch WebStart; classes in the javax.jnlp package; applications delivered as a set of JAR files; demos here: http://www.oracle.com/technetwork/java/javase/demosnojavascript-137100.html 24
Server-side Java: Servlets Servlets and the related Java technology JavaServer Pages use high-level request-response model of networking these technologies are often deployed to create Web applications Java Servlets allows addition of dynamic content to a Web server Servlet is a Java class which conforms to the Java Servlet API contained in the Java package hierarchy javax.servlet JavaServer Pages (JSP) allows dynamic generation of HTML, XML or other types of documents in response to a Web client request Apache Tomcat is implementation of Servlets and JSP developed by the Apache Software Foundation (www.apache.org ) often used with the popular Apache Web server 25
Android Google's Android mobile operating system uses Java programming language and the core libraries but has its own set of APIs for mobile app development Uses a different virtual machine Dalvik instead of JVM Android is based on a Linux kernel Runs apps which are available from Android Market and elsewhere Android software development kit (SDK) has various tools and a handset emulator officially supported IDE is Eclipse using the Android Development Tools (ADT) Plugin 26
Java Issues Security problems JavaFX will it be sidelined by HTML5? Not fully object-oriented primitive types are not objects but has wrappers for built-in types and autoboxing Lack of some programming language features (being addressed in Java 7/8) Some initiatives have failed Network computers based on Java JavaStation; Java chips picojava microprocessor; Lack of standardization e.g. C++ and C are ISO standards, Java is not 27