11
James Cain Java Java

James Cain Java. What about Java? Its history Its data types and tools for manipulating data How it handles exceptions and events Swing – Java’s GUI Why

Embed Size (px)

Citation preview

Page 1: James Cain Java. What about Java? Its history Its data types and tools for manipulating data How it handles exceptions and events Swing – Java’s GUI Why

James Cain

Java Java

Page 2: James Cain Java. What about Java? Its history Its data types and tools for manipulating data How it handles exceptions and events Swing – Java’s GUI Why

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

Page 3: James Cain Java. What about Java? Its history Its data types and tools for manipulating data How it handles exceptions and events Swing – Java’s GUI Why

History of Java

• Invented by James Gosling; designed in 1990 by Sun Microsystems

• Originally named “Oak”• Named after the

beverage

Duke, the Java mascot

Page 4: James Cain Java. What about Java? Its history Its data types and tools for manipulating data How it handles exceptions and events Swing – Java’s GUI Why

The Data and its Manipulation

• 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{ ... }

For every integer from 1 to max, increasing...

While count is less than 20...

If AM is true...

Otherwise, if PM is true...

Otherwise...

Page 5: James Cain Java. What about Java? Its history Its data types and tools for manipulating data How it handles exceptions and events Swing – Java’s GUI Why

public interface Function{ double valueAt(double x);}

public class F1 implements Function{...}

import java.awt.Graphics;

Abstract Data

• 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

Page 6: James Cain Java. What about Java? Its history Its data types and tools for manipulating data How it handles exceptions and events Swing – Java’s GUI Why

Exception Handling

• Java includes predefined exceptions that are implicitly raised

• All exception classes are descendants of Throwable

Throwable

Error Exception

RuntimeException IOException

Page 7: James Cain Java. What about Java? Its history Its data types and tools for manipulating data How it handles exceptions and events Swing – Java’s GUI Why

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

Page 8: James Cain Java. What about Java? Its history Its data types and tools for manipulating data How it handles exceptions and events Swing – Java’s GUI Why

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

Page 9: James Cain Java. What about Java? Its history Its data types and tools for manipulating data How it handles exceptions and events Swing – Java’s GUI Why

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

Page 10: James Cain Java. What about Java? Its history Its data types and tools for manipulating data How it handles exceptions and events Swing – Java’s GUI Why

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

Page 11: James Cain Java. What about Java? Its history Its data types and tools for manipulating data How it handles exceptions and events Swing – Java’s GUI Why

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