110 likes | 240 Views
Java. Java. James Cain. What about Java?. Its history Its data types and tools for manipulating data How it handles exceptions and events Swing – Java’s GUI Why it’s so dang popular Its less common uses. History of Java. Invented by James Gosling; designed in 1990 by Sun Microsystems
E N D
Java Java James Cain
What about Java? • Its history • Its data types and tools for manipulating data • How it handles exceptions and events • Swing – Java’s GUI • Why it’s so dang popular • Its less common uses
History of Java • Invented by James Gosling; designed in 1990 by Sun Microsystems • Originally named “Oak” • Named after the beverage Duke, the Java mascot
The Data and its Manipulation For every integer from 1 to max, increasing... • Java supports 8 primitive data types: byte, short, int, long, float, double, boolean, and char • Implicit type conversion is used automatically • Type conversions are stricter than in C++ • Compound statements are easy to understand for(int i = 1; i <= max; i++) { ... } while(count < 20) { ... } if(AM) { ... } else if(PM) { ... } else { ... } While count is less than 20... If AM is true... Otherwise, if PM is true... Otherwise...
Abstract Data public interface Function{double valueAt(double x);} public class F1 implements Function { ... } import java.awt.Graphics; • Java 5.0 supports generic types • Classes can be declared abstract • Interfaces encapsulate a basic idea for a class • Packages contain many class/interface definitions Must include valueAt method
Exception Handling • Java includes predefined exceptions that are implicitly raised • All exception classes are descendants of Throwable Throwable Error Exception RuntimeException IOException
The Swing of Things • Swing is a collection of classes and interfaces that include GUI components (widgets) • Text fields, radio buttons, checkboxes, drop-down menus, etc. • And, of course, images The function x2 + 2x
Event Handling with Swing • Widgets “know” when something happens by using event listeners • Each listener is registered to a widget and a specific event public class Listener implements ItemListener { if(itemStateChanged( Checkbox1)) { ... } } What happens when Checkbox1 is clicked
Java’s Popularity • Reliability – Trusted in many different areas • Portability – The Java Virtual Machine (JVM) brings the language to computers everywhere • Power – Java is flexible yet firm
Other Uses for Java • Java applets – Gives new abilities to an XHTML document • Java Database Connectivity™ (JDBC) – Used to connect to a database and modify its data • Multithreading – Class with a method named run can execute in parallel
Oh, and My Sources • Java: How to Program, 8th Edition – Paul and Harvey Deitel • http://docs.oracle.com/javase/tutorial/java/nutsandbolts/index.html> • Concepts of Programming Languages, 10th Edition – Robert W. Sebesta