Activities Fair Tuesday night!
7:00 to 9:00 pm in Cheel arena
CS labs: ITL, COSI & VR Lab
Clarkson Student ACM
IDEA Club: ACM SIGGRAPH
Objectives of this course
Administrivia
Overview of Java
A Brief History of Java
Introduction to Java technology
Getting started: Compiling & running your first Java program
Students will learn advanced programming concepts and modern programming techniques. These will include object-oriented design and design patterns, graphical user interface design, event models, exception handling, multithreading, network programming, the client/server paradigm, servlets/JSP web apps, mobile apps for Android.
Students will learn the Java programming language and core APIs, the Java Virtual Machine (JVM), and JavaFX
course webpage:
http://www.clarkson.edu/~jets/cs242/fa13
contact info:
office: SC375 (or Applied CS labs, SC334-336)
phone: 268-2377,
email: [email protected]
Required: Effective Java Second Edition, Joshua Bloch, Prentice Hall PTR, ISBN-13 978-0-321-35668-0, 2008 (also available on Safari Books Online).
Recommended: Head-First Java, 2nd Edition, Kathy Sierra & Bert Bates, O’Reilly, ISBN 978-0-596-00920-5, 2005
Required: Java Tutorials (online)
JavaFX: Developing Rich Internet Applications, by Jim Clarke, Jim Connors & Eric Bruno,
Addison-Wesley, 2009,
ISBN 0-13-701287-X
ISBN-13 978-0-13-701287-X
35% 2 Midterm Exams
(tentatively 10/16 & 11/28)
40% Final Exam
25% Programming Projects &
Homework
http://www.clarkson.edu/~jets/cs242/fa13/onlineresources.html
Compiling, running & debugging
Java tutorials & documentation
Java source
UML, design patterns, etc.
Sun Microsystems - 1991
James Gosling - Oak
Pat Naughton (Clarkson alum, CS) – X11
Mike Sheridan
Bill Joy
… and others
Coding Problems: Java Solution:
pointers references (“safe” pointers)
memory leaks garbage collection
error handling exception handling
complexity reusable code in APIs
platform dependent portable code
… plus
security, networking, multithreading,
web programming, mobile apps, and so on
Windows Linux
programming language object-oriented, architecture independent, distributed,
multithreaded syntax similar to C/C++ concepts similar to Smalltalk
collection of APIs (Application Programming Interface)
java.lang automatically imported into Java programs
java.util useful utility classes (e.g. Date)
java.io Input/Output classes
java.awt windowing classes
javafx JavaFX platform for GUI development
java.net networking classes
standard extension APIs for enterprise, security, etc.
// From TIJ by Bruce Eckel
import java.util.*;
public class HelloDate {
public static void main(String[ ] args) {
System.out.println("Hello, it's: ");
System.out.println(new Date());
}
}
source file:
HelloDate.java
All code must be inside a named class &
the filename must match the classname
exactly (case-sensitive)
// From TIJ by Bruce Eckel
There are 3 kinds of
comments in Java
1. //
2. /* … */
3. /** … */
Implementation comments: tells a
programmer reading your code
about your implementation
Documentation comments: used
by javadoc to generate a webpage
for users of your classes
// From TIJ by Bruce Eckel
import java.util.*;
public class HelloDate {
public static void main(String[] args) {
System.out.println("Hello, it's: ");
System.out.println(new Date());
}
}
Similar to #include in
C/C++;
but only loads a class
dynamically, if needed
at runtime
Never import the java.lang API –
it is always automatically imported
// From TIJ by Bruce Eckel
import java.util.*;
public class HelloDate {
Defines a new class. The source file must be the
exact same name followed by extension .java
A file can contain more than one class definition,
but only one can be public.
// From TIJ by Bruce Eckel
import java.util.*;
public class HelloDate {
public static void main(String[] args) {
public – the main method is publicly visible
The main program must have this exact header:
static – allows the main program to be called
without creating an object (details to follow)
void – no value is returned
String[ ] – array of Strings allows info to be given
to the main program ( String args[ ] is also OK )
// From TIJ by Bruce Eckel
import java.util.*;
public class HelloDate {
public static void main(String[] args) {
System.out.println("Hello, it's: ");
Prints a string to the standard output stream
System is a java class
out is an instance of an OutputStream;
defaults to the console
// From TIJ by Bruce Eckel
import java.util.*;
public class HelloDate {
public static void main(String[] args) {
System.out.println("Hello, it's: ");
System.out.println(new Date());
Also prints a string to standard output, in this
case the current date and time (must interact
with the operating system to get this info)
creates a new object of the Date class (from
java.util package); this is converted to a string
This new object is created on-the-fly; since it is
no longer needed after this line, it is subject to
garbage collection
// From TIJ by Bruce Eckel
import java.util.*;
public class HelloDate {
public static void main(String[ ] args) {
System.out.println(
"Hello, it's: " + new Date() );
}
}
println only can have 1 string argument,
so can concatenate strings with +
source file:
HelloDate.java
Step 1: compile into bytecodes
javac HelloDate.java
Step 2: run
java HelloDate
Step 1: compile into bytecodes
javac HelloDate.java
java compiler – creates
HelloDate.class file
(machine independent
bytecodes)
must include the
.java extension
Step 2: run
java HelloDate
• loads the classes from HelloDate.class, from
java.lang, and java.util.Date
• verifies the bytecodes
• runs the main program
run HelloDate on laptop using TextPad
show javadoc generated documentation
Visit www.oracle.com, download & install Java JDK 7u25 plus documentation
Download and install editor/IDE of your choice (Eclipse, NetBeans, Ant, TextPad, Jedit, whatever…)
Visit java.sun.com tutorials & read “Your first cup of Java” and “Getting Started”
Read Chapter 1 of Effective Java
Complete this before Friday.