Download whyjava

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

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

Document related concepts
no text concepts found
Transcript
Why use Java?
Chris Loftus
[email protected]
CS25510: Why use Java?
1
It’s easy to knock the top dog
• Maturity
• Lots of support
documentation
• Huge standard
libraries (3777
classes in Java 6)
• Big community
• Etc
• But is it a supertanker, and does
that matter?
CS25510: Why use Java?
2
CS25510: Why use Java?
3
My general view
• Don’t be dogmatic; use the right language
for the right job...
• Don’t slavishly follow the latest trends
– Dynamically typed script languages are also not
that “silver bullet”
• Sometimes there are several equally valid
choices...
CS25510: Why use Java?
4
Promises of Java: WORA
• An aim of Java in 96 was ability to program small
devices, e.g. set-top boxes...
• Write Once Run Anywhere is important
– There are JVMs for all computer platforms
– Symbian OS 47% of smart mobile phones (2008),
includes Java ME...
– Amazon Kindle, Blu-ray Disc, EA Mobile,
etc...(http://www.java.com/en/java_in_action)
– Large usage on server-side: e.g. eBay uses Java,
Infosys Technologies, parts of Amazon (Jboss,
servlets), parts of Google, Twitter (Scala on top of
JVM for backend),...
CS25510: Why use Java?
5
Promises of Java: WORA: Issues
• GUIs: Swing pure Java components give
WORA, but performance issues and
pluggable OS-specific LAFs not accurate...
• Initially Java 1.1 Green Threads, now native
used...
• Performance issues: cross platform means
use of interpreters and/or JIT
compilers...(more on this later)
• Not the only WORA kid on the block: those
script languages and Mono .NET IL...
6
Promises of Java: Network/Web
programming
• From the start: sockets, applets, HTTP
support, RMI (97), servlets (97), CORBA
support (98), JSP (99), JMS (2001), etc
• Web service support:
– JAX-WS etc for W3C SOAP/WSDL style...
– JAX-RS for REST style...
• Web programming support:
– Struts, JSF (with Ajax), Java EE 5, Spring,
Google Web Toolkit, JavaFX ...
7
Promises of Java: Network/Web
programming: Issues
• All programming platforms now support
networking
– However, Java maturity in this area
• Some platforms (e.g. Ruby-on-Rails) support web
development more succinctly...
• JavaFX is commonly believed to be too late as
compared with Adobe Flex/AIR and Silverlight...
• EJB and J2EE bloat-ware, the steep learning
curve, and the influence of affluence...
8
Promises of Java: Security
• Networking requires security:
–
–
–
–
Java sandbox for applets...
Java Security Model...
Java Cryptography Architecture/Extension...
Java Authorization and Authentication
Service...
– Support for web service security (e.g. messagelevel encryption, in-progress as part of JAXWS)
• More comprehensive support than most
platforms...
CS25510: Why use Java?
9
Promises of Java: Type-safe
• Strong typing that is statically checked (at compile time)
long v1 = 10.2;
Object e = new Employee();
Employee e1 = e;
•
•
•
•
•
Strong typing that is dynamically checked...
Array index bounds checking...
No pointer arithmetic...
Consistent handling of floating point types...
Garbage collection rather than dealloc (memory
management issue)...
• Removes a class of runtime faults but performance and
flexibility issues...
10
Criticisms: Performance
• Java’s had this poor performance tag for
some time, is it still justified?
• The HelloWorld comparison of Java and C
is a little misleading:
– A large JVM must be loaded and initialised...
– For short-lived programs this might be an
issue...
• What do the benchmarks show us?...
CS25510: Why use Java?
11
See “The Computer Language Benchmarks Game”
http://shootout.alioth.debian.org/
12
CS25510: Why use Java?
13
CS25510: Why use Java?
14
Why performance worse than
C/C++?
• Load-time bytecode verification, array
bounds checking, floating point simulation,
garbage collection…
• Loading the large JVM
– Big start-up hit…
– Big memory footprint…
• Initially bytecode interpretation, JIT (1998),
and then HotSpot (2000)
– Adaptive compiler: initially interpreted but
hotspots are compiled to native…
15
Criticisms: Java is simply not fun
• Lack of:
– Default parameter values, operator overloading,
closures, pure object orientation, string cases in
switch statements, meta-programming support,
convention over configuration...
• And:
– Boiler-plate code, checked exceptions...
CS25510: Why use Java?
16
HelloWorld in Java and Groovy
public class HelloJava {
public static void main(String [] args){
if (args.length > 0)
System.out.format("Hello %s", args[0]);
else
System.out.print("Hello");
}
}
if (args)
println "Hello ${args[0]}"
else
println "Hello"
CS25510: Why use Java?
17
Java is a super-tanker but I don’t
think it matters
• Criticised by many developers as not including
features discussed earlier, and slow to add new
features...
• But many big projects want API stability, large
mature reusable code libraries, proven technology,
type safety, good security, and sufficient
performance...
– eBay replaced C++ with Java in 2002, citing Java’s good
engineering support for their 1500+ developers
– However Amazon use C++ for compute intensive work
• And if you want to use those fun languages and
have many of Java’s benefits why not use Scala,
Groovy or Jruby?
18