Download Object Oriented Programming Languages

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
Object Oriented Programming Languages:
A Quick and Caffeinated Overview
Presented by Chris Start
CS 331 - 4/23/08
1
Background




Who made it? : James Gosling
Working for? : Sun Microsystems since 1984
When? : in June 1991
Originally called: Oak, Green, then Java
(from list of random words)

Why? (originally):





needed a safe, reliable language for consumer
electronics (toasters, TVs, microwave ovens)
C was not object oriented, which was necessary
C++ was too large/complex and unreliable
Products never marketed
In 1993 w/explosion of WWW and graphical
browsers, Java was found useful for Web

Applets embedded into HTML code
CS 331 - 4/23/08
2
Different Versions for Different Applications


Java 1 was a single version for
everyone
Java 2 : J2EE, J2ME, J2SE, built for
different types of platforms



Java EE: Enterprise Edition for large
“enterprise” applications
Java ME: Mobile Edition was very
stripped down for mobile applications
Java SE: Standard Edition for most
users
CS 331 - 4/23/08
3
History Timeline


JDK 1.0 (January 23, 1996)
JDK 1.1 (February 19, 1997)


inner classes added to the language (nested
classes, classes completely defined within the
body of another class)
JavaBeans



J2SE 1.2 (December 8, 1998)



reusable software components - manipulated
visually in a builder tool
group objects to be moved together
Swing graphical API integrated into core classes
Sun's JVM included w/JIT compiler
J2SE 1.3 (May 8, 2000)
CS 331 - 4/23/08
4
More History…

J2SE 1.4 (February 6, 2002)



first release of the Java platform developed
under the Java Community Process
 assert keyword
 Java Web Start included (Java Web Start was
first released in March, 2001 for J2SE 1.3)
J2SE 5.0 (September 30, 2004)
Java SE 6 (December 11, 2006)


Updates 2 & 3 released during 2007
Updates 4 & 5 released in 2008
 Dramatic performance improvements for the
core platform
CS 331 - 4/23/08
5
Not Historical… Yet

Java SE 7


early planning and development stages
started up in August 2006; to be tentatively
released in January 2009
 JVM support for dynamic languages, following
the prototyping work currently done on the
Multi Language Virtual Machine
 new library for parallel computing on Multicore processors
CS 331 - 4/23/08
6
Syntax:


Mostly derived from C++, but is
exclusively object-oriented
(unlike C++ which is structured,
generic, and OOP)
Almost everything is an object
and all code is inside a class

Numbers, Boolean values,
characters are not objects for
performance reasons
CS 331 - 4/23/08
7
Java Characteristics…


Predefined container classes
(ArrayList) can only contain objects
Primitive type (int) must be placed
in a wrapper class

Pre Java 5.0


Post Java 5.0


myArray.add(new Integer(10));
myArray.add(10);
boxing (post Java5)implicitly converts
primitive types to objects when put in
object context
CS 331 - 4/23/08
8
Hello, World example:
1.
Code is saved as
HelloWorldApp.java
2.
Javac compiler
converts to bytecode
producing
HelloWorldApp.class
3.
HelloWorldApp.class
is launched and run
Used JDK6 Update 6
CS 331 - 4/23/08
9
Philosophy
5 Primary goals:





use object-oriented programming
methodology
platform independence
contain built-in support for computer
networks
designed to execute code from remote
sources securely
easy and safe to use
CS 331 - 4/23/08
10
Platform Independence

able to write code, compile it once, and run on any
platform/system
How?
Virtual Machines and the JIT compiler


Java compilers convert Java Language to
bytecode (simplified Virtual Machine instructions)
Virtual Machine, written in native code for host
hardware, interprets bytecode for execution
CS 331 - 4/23/08
11
JIT: Just In Time Compiler
Vs.
Static Compilation

The Java bytecode is
interpreted/converted
to native machine code
by the JIT compiler.


Early versions of JIT ran
slow compared to code
natively compiled to
machine code – got
reputation of running
slowly
Translates the Java
language code
directly into native
machine code




CS 331 - 4/23/08
No bytecode stage
Good performance
compared to
original JIT
Lose portability (not
cross platform
anymore!)
Can be useful to
provide a bytecode
and a faster,
optimized native
version
12
Dynamic Compilation (Sophisticated VM)



VM can optimize and recompile critical parts
of the program
Can be faster than static compilation,
recompiles code based on what is happening
Combination of JIT and dynamic compilation
take advantage of speed without losing
portability
CS 331 - 4/23/08
13
Java’s Memory Management

All Java objects are explicit heap-dynamic


Allocated with new but no deallocation
 Ex.: myArray.add(new Integer(10));
No Pointers!




Everything done by reference
No access to hardware
No access to absolute memory addresses
No function pointers to call functions
dynamically
 Virtual functions with inheritance to get
dynamic binding of member to objects
CS 331 - 4/23/08
14
Automatic Memory Management :
Garbage Collection





Users don’t have to deallocate
Java runtime responsible for deallocation from
heap
Lack of references to an object allows object to
be freed
Memory leaks can still happen if user keeps
references to variables that they no longer
need/use
Will not free resources other than heap memory


Ex.: files, lock on a shared resource…
finalize method similar to C++ destructor

Called when garbage collector is about to free resource
CS 331 - 4/23/08
15
Comparing to C++ : Simplicity

Unlike C++, Java suppresses
several features (such as
operator overloading and
multiple inheritance) for classes



to simplify the language
to "save the programmers from
themselves"
to prevent possible errors and antipattern design
CS 331 - 4/23/08
16
Inheritance


Supports single inheritance
final methods cannot be overridden
in descendant classes


Bindings can be statically bound to
methods of subclass
Abstract class: interface
CS 331 - 4/23/08
17
Abstract class: interface




Partial support for multiple inheritance
No constructors or nonabstract methods
Only method declarations (not definitions) and named
constants
Not inherited, implemented by class


All methods must be implemented if defined by interface
“virtually” takes place of second parent class
public interface Comparable {
public int compareTo(Object b);
}
CS 331 - 4/23/08
18
Dynamic Binding




In C++ a method must be defined as
virtual to allow dynamic binding
In Java, all methods are dynamic unless
defined as final
Allows easier integration and logical flow
in inheritance structure and deployment
Methods defined as static or private use
static binding and disallow overriding
CS 331 - 4/23/08
19
Nested Classes


Hidden from all classes in their package,
except for nesting class
Nonstatic classes nested directly in another
class have implicit pointer to nesting class


Gives access of all nesting class’s methods to
nested class
Static classes do not have pointer, cannot
access members of nesting class

Static nested classes are like C++’s nested classes
CS 331 - 4/23/08
20
History tidbit: Implementations

Microsoft used to ship a version of
Java Virtual Machine (MSJVM)



Had proprietary components which if
used would not run on Sun’s JVM
Sun sued MS for breach of trademark
Since October 2001, Java is not
shipped w/Windows, installed
separately
CS 331 - 4/23/08
21
Conclusions :


Started as a language to program
toasters (microwave ovens, TVs, etc)
Became popular because:




Portable (especially across WWW)
Easy to use (programmer’s like its design)
Free and easy to obtain
Relatively safe to program in (less
reliance on the expertise of the
programmer)
CS 331 - 4/23/08
22
Conclusions Continued…




More consistent to principles of
object-oriented programming than
C++
Lack of functions = does not support
procedural programming
Dynamic binding is the “normal” way
to bind method calls to method
definitions
Uses interfaces as simple form of
support for multiple inheritance
CS 331 - 4/23/08
23
References :




http://java.sun.com/
http://en.wikipedia.org/wiki/
Sebesta, Programming
Languages. 8th Edition.
http://math.hws.edu/javanotes
CS 331 - 4/23/08
24