Survey
* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project
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
• 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 every integer from 1
to max, increasing...
for(int i = 1; i <= max; i++)
{ ... }
While count is less than 20...
while(count < 20)
{ ... }
If AM is true...
if(AM)
{ ... }
Otherwise, if PM is true...
else if(PM)
{ ... }
Otherwise...
else
{ ... }
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
public interface Function
{
double valueAt(double x);
}
public class F1 implements
Function
{
...
Must include valueAt method
}
import java.awt.Graphics;
Exception Handling
Throwable
Error
Exception
RuntimeException
• Java includes
predefined exceptions
that are implicitly raised
• All exception classes are
descendants of
Throwable
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/n
utsandbolts/index.html>
• Concepts of Programming Languages, 10th
Edition – Robert W. Sebesta