Title: CS 1322
1CS 1322
- Introduction to
- Object Oriented Programming
- Lecture 01
2Agenda
- Brief Introduction
- Course Mechanics
- Warning Danger Will Robinson
- Textbook
- Some Java Basics
3Brief Introduction (12pm)
- Instructor Bill Leahy
- bleahy_at_cc.gatech.edu
- Web pages
- www.cc.gatech.edu/classes/AY2001/cs1322
- Office College of Computing Room 121
- Office Hours Tues/Thur 200-330 p.m. and by
appointment email me! (bleahy_at_cc.gatech.edu)
4Course Mechanics
5Contact Elements 1200 - 145 P.M.
- Lecture
- 2/week Howey-Physics
- Lecture Hall L3 1200 - 145 P.M.
6Contact Elements
Recitation Normally 1 per week 605 - 755
p.m. Tuesday See your personal Oscar schedule for
details as to which room. Starts next week!!!
This week only Help Session Thursday Library
Cluster 605 - 755 p.m. Verify on .announce
7Contact Elements
Lab 1/week approx. (will be 3 per week early) On
your own. Unlike CS1 (i.e., linked to course
content) Turn in via WebWork (help on web page
soon)
8Your Lifelines
- Your TA
- Is your friend
- Will have office hours
- First point of contact for problems
- Lecturer Office Hours
- TBA or by appointment
- Help Sessions
- To be announced
- Use them to your advantage
9Evaluation
- Quizzes
- 4 / semester
- Given during recitation
- Labs
- Programs
- Design Docs
10Evaluation
- Final
- Oscar is tentative
- Official time/date will be announced
- Comprehensive
- Some coding
- Some theory/general knowledge
- Grading
- TA by hand
- Autograding
11Grade
- 25 Programs
- 5 Designs
- 33 Tests (quizzes)
- 2 Buzzback!! (can even get extra credit)
- 15 Labs
- 20 Written final
- Extra Credit maximum 5 (Details on web page)
12BuzzBack
- http//survey.opaion.com
- Due approximately weekly
- Buzzbacks total 2 of grade!
- Completing all buzzbacks 1 extra credit
- Special Dead Week Buzzback is worth 1 extra
credit completion - Watch .announce for more info
13Academic Honesty
- It is expected that (unless specific instructions
to the contrary are given) all student
submissions will be individual efforts. - All required coursework that is submitted for
evaluation in this academic course becomes the
property of the Georgia Institute of Technology,
and is subject to review for evidence of academic
misconduct. If such evidence is discovered,
then the offending students will be referred to
the Dean of Students for investigation.
14Academic Misconduct
- Section XVIII.C. of the Student Rules and
Regulations defines academic misconduct as "any
act that does or could improperly distort student
grades or other student records." - Among the list of items that are cited in this
section are the following
15Academic Misconduct
- 1. Possessing, using or exchanging improperly
acquired written or verbal information in the
preparation of an essay, laboratory report,
examination, or other assignment included in the
academic course. - 3. Submission of material that is wholly or
substantially identical to that created or
published by another person or persons, without
adequate credit notations indicating the
authorship (plagiarism).
16This also includes...
- Any attempt to circumvent autograders by
producing the correct output for an assignment by
using incorrect methods and techniques.
17Academic Honesty
- In layman's terms, this means that if any student
receives or provides any information that would
enable himself/herself or any other person to
complete an assignment or examination that is not
wholly the work of the person submitting that
assignment or examination, then that student is
in violation of the academic honor code of
Georgia Tech. This includes copying published
material from any source, whether written or
electronic.
18Academic Honesty
- Any such incidents will be dealt with
accordingly, and penalties for conviction can be
severe - up to and including notice of academic
misconduct on a transcript, failure in the
academic course, required community service,
expulsion from the College of Computing,
expulsion from Georgia Tech.
19Questions?
20Why CS 1322?
- Was CS 1312, was CS 1302, was CS 1502
- University System of the State of Georgia Course
Numbering System - Large number of students received transfer credit
for cs1501/cs1301/cs1311 - Results
Most transfer students who skip cs1311 fail or
drop cs1322
If you skipped cs1311, used excessive word, or
forgot things, you will find 1322 difficult.
21NOTE
- CS 1321 is not a Scheme programming course
- CS 1321 is an Introduction to Programming and
Computing - Similarly
- CS 1322 is not a Java programming course
- CS 1322 is about Object Oriented Programming and
Data Structures
22Tip 1
Dont wait until the last minute to get help
23Tip 2
Hey, Ill still pass if I can get enough partial
credit.
Bad things happen while learning a new skill.
You will probably crash and burn on some
programs. Start early give yourself time for
mistakes.
24Tip 3
Dont be too ambitious with your course load.
You CANNOT slack off in this class, even for a
few days.
25Tip 4
Watch out for the big picture. Dont forget
this is a programming course, not a Java
course. Its dangerous to hide from the
programming part of the course. You may be
crushed on the final.
26Bottom Line
- If youre not adequately prepared for this
course - Option 1 Get prepared
- Option 2 Drop Now...Do us both a favor!
- Will have take home quiz to test your knowledge
of the prerequisites.
27Textbooks
- Recommended Data Structures Problem Solving
Using Java - Mark Allen Weiss
- Hardcover or CD-ROM Edition!!!
28Additional Resources
- Download Bruce Eckels Book, Thinking in Java.
- 1,000 pages.
- Quite good.
- Might just help.
- Surf to
- http//www.mindview.net
- http//www.mindview.net/TIJ2/index.html
Possibly the worst web design ever seen keep
looking for the link!
29Additional Resources
Sun also has a free 1,000 page book on
Java. You should download or bookmark
this resource.
http//www.javasoft.com/docs/books/tutorial/index.
html
30Additional Resources The API for Java
We asked students a while ago what we could do to
improve the course. Many said
Why didnt you tell us about the API on the
first day?
The API is the Application Programmers
Interface, a useful document describing many of
Javas builtin features. For now, it might look
mysterious later it will be very useful.
31Where to get this API thing
http//www.javasoft.com/docs/
32 NEW PACKAGING
2.
The Basics (Just the FAQs, Maam)
33Object Oriented Programming
- Abstraction
- Abstract data types
- Encapsulation
- Data
- Behavior
- Classes as templates
- Define object characteristics
- Used to produce instances (1 or more)
34Clever Segue
- To study Object Oriented Programming we will use
the Java language - There are a number of different OO Languages
- C
- Smalltalk
- Eiffel
- Java and OO are not synonymous
35Introduction to Java
- What Java is
- A tool for programming well
- Portable across any hardware platform that has a
JVM interpreter - Relatively easy to learn if you have a good
foundation - An object-oriented language
- What Java is not
- The Ultimate Programming Language
- HTML or another web-content language
- Only useful for web applets
- Just Another Vacuous Acronym
36Introduction to Java (contd)
- Strengths of Java
- A real language, in demand in industry
- Portability
- Comparatively easy to learn
- Difficult to destroy a machine with it -)
- Advanced built-in GUI/Graphics features
- Weaknesses of Java
- Slow interpreted and OO
- GUI/Graphics via Least Common Denominator
approach (due to platform independence) - Awkward/annoying syntax obscures some concepts
and principles
37Javas Popularity
- Keys to Javas Popularity
- An OO language thats relatively simple.
- Virtual Machine approach, allowing
transportability to various different kinds of
computers (operating systems). - Presence of JVM as part of Web browsers,
encouraging movement of Java programs over the
Web.
38What is Java?
"A simple, object-oriented, distributed,
interpreted, robust, secure, architecture
neutral, portable, high-performance,
multithreaded, and dynamic language -- Sun
Sounds like marketing lets take a closer look .
. .
39 object oriented
- Java is an object oriented (or OO) language.
- It is possible (but seldom desirable) to write
non-object oriented Java code (so-called hybrid
OO). - In an OO language, classes are used to
encapsulate data (state) and behavior.
- Instances of a class are then used to manipulate
data and drive the program. - Classes are arranged in an hierarchy, or package
structure.
40 object oriented,
Example A Stack is a class found in the
package java.util. We create an instance of the
class Stack using the keyword new thus import
java.util. Stack c new Stack() c.push(3)
java.util.Stack x new Stack()
This differs from procedural (e.g., C, Pascal)
and functional languages (e.g., Lisp) where other
data structures would be used to model the Stack.
More on classes in later slides . . .
41 distributed,
Java is also a distributed language. It was
built with networking in mind Fully supports
IPv4, with structures to support IPv6--protocols
used on the internet. Includes support for
Applets small programs embedded in HTML
documents. See java.net package
RMI/CORBA
42 interpreted,
Java is an interpreted language, meaning that
each instruction is translated into machine code
at the time of execution, not during
compilation. This allows for platform
neutrality WORA, or write once run
anywhere. This also allows one to rewrite
and change a program while it is
running. Penalty speed
43 robust,
Java is simple--no pointers/stack concerns (for
the most part) In-bound checking at runtime of
array pointers--no memory corruption and cryptic
error messages. Exception handling
try/catch /finally series allows for simplified
error recovery Strongly typed language many
errors caught during compilation.
44 secure,
Bytecode verification on loading (not just
compilation). Applet code runs in 'sandbox',
with significant restrictions Security is
enforced by the SecurityManager class
Work-arounds for applet security restrictions
include digitally signing code, and Servlets
45Structure of Java Programs
- Applications (normal computer programs)
- Create one or more Java source files
- Compile each source file into a class file
- Thus an application will consist of a bunch of
these class files. Not a single executable i.e.
.exe - Send one class file to the Java system
- It must have a method (module) called main
- public static void main(String argv)
- ( Get used to weird looking
stuff! ) - The main method controls program flow (but the OO
orientation means that it starts a process that
features decentralized control).
46Sample Application (in a file called
HelloWorld.java)
- public class HelloWorld
-
- public static void main(String argv)
-
- System.out.println(Hello World!)
-
47Java File Names
Source code files must have the ".java"
extension. The file name should match the class
name. This naming convention is enforced by most
reasonable compilers. Thus, an improperly named
java file, saved as "myTest.java"
class test ... Compiled bytecode has the
".class" extension.
Incorrect
48Java File Names
Source code files must have the ".java"
extension. The file name should match the class
name. This naming convention is enforced by most
reasonable compilers. Thus, a properly named
java file, saved as "Test.java"
class Test ... Compiled bytecode has the
".class" extension.
49Big Picture Time
HelloWorld.java
HelloWorld.class
0xCAFEBABE ...
javac
public class HelloWorld public static void
main(String argv) System.out.println
(Hello World!)
java HelloWorld
javac HelloWorld.java
50Java File Structure
Java Files 1. Consist of the optional package
statement, 2. followed by any necessary
import statements 3. followed by the class
name, 4. followed by any inheritance and
interface declarations. 5. Note if the file
defines more than one class or interface, only
one can be declared public, and the source file
name must match the public class name.
For cs1322, you will only follow points 2 - 4
51An Average Java File
Thus package edu.gatech.cc.dagon.gsams-java
import java.util. import edu.gatech.cc.dagon.gs
ams-java.hashtable. import netscape.javascript.J
SObject import netscape.javascript.JSException
public class SplayTree implements TreeType,
TreeConstants ... //
SplayTree Note the globally unique package
name. Without a package specification, the
code becomes part of an unnamed default package
in the current directory.
For CS1322, youll need only work with class
names, a few import statements, and some
inheritance
52Vocabulary
- Structured Programming
- A programming paradigm in which the actions (or
verbs, or procedures) are emphasized. - OO Programming
- A programming paradigm in which the actors (or
nouns, or objects) and their interaction is
emphasized. - Byte Compiler
- A compiler which translates human-readable source
code into bytecode (transportable to various
virtual machines) instead of object code written
for a specific kind of machine.
53Vocabulary (contd)
- Byte Interpreter
- An interpreter which translates byte code into
object code for a particular kind of machine and
executes them on that machine. - Bytecode
- An instruction for a virtual machine.
- Java Virtual Machine (JVM)
- The virtual machine (software) for which all Java
programs are compiled. A byte code interpreter
is required to translate from the JVM byte code
instructions into to instructions for a given
actual machine.
54Java Portability
Demo.java
javac Demo.java
Demo.class
java Demo
55Built-in Data Types
- Pseudocode (4 atomic data types String)
- Num (number)
- Char (character)
- Boolean
- Ptr (pointer)
- String
- Java (6 important primitives String)
- int (integer)
- long (long integer, 2x bits)
- float (real number)
- double (real number, 2x bits)
- char (character, use single quotes b)
- boolean
- String (Java is case sensitive, so capitalize
first letter here String, not string use double
quotes a string)
Note A String is NOT a primitive
56Built-in Data Types
- Scheme
- Typical typeless Lisp-like language
- Java (6 important primitives String)
- int (integer)
- long (long integer, 2x bits)
- float (real number)
- double (real number, 2x bits)
- char (character, use single quotes b)
- boolean
- String (Java is case sensitive, so capitalize
first letter here String, not string use double
quotes a string)
Note A String is NOT a primitive
57List of Data Types
Primitive Type Default Value boolean
false char
'\u0000' (null) byte (byte) 0 short
(short) 0 int
0 long
0L float 0f double
0d void
N/A
Note At times, the Java Language Specification
refers to void as a primitive, though other parts
(e.g., s. 14.7) say void is not a primitive as
in C/C. One cannot cast to a void type in Java.
58Variable Declarations
- CS1501/CS1311
- ltidentifiergt isoftype ltdata typegt
- Java
- ltdatatypegt ltidentifiergt
- or (optional initialization at declaration)
- ltdata typegt ltidentifiergt ltinit valuegt
59Examples
- int counter
- int numStudents 583
- float gpa
- double batAvg .406
- char gender
- char gender f
- boolean isSafe
- boolean isEmpty true
- String personName
- String streetName North Avenue
60Questions?
61Assignment
- Java allows multiple assignment.
- int iStart, iEnd
- int iWidth 100, iHeight 45, iLength 12
- This tends to complicate javadoc comments,
however - /
- Declare cylinders diameter and height
- /
- int iDiameter 50, iHeight 34
Javadoc comment gets repeated twice in
output, once above each listed variable!
62Examples
- Note that whole integers appearing in your source
code are taken to be ints. So, you might wish
to flag them when assigning to non-ints - float fMaxGrade 100f // now holds 100.0
- double dTemp 583d // holds double precision
583 - float fTemp 5.5 // ERROR!
- // Java thinks 5.5
is a double - Upper and lower case letters can be used for
float (F or f), double (D or d), and long
(l or L, but we should prefer L) - float fMaxGrade 100F // now holds 100.0
- long x 583l // holds 583, but looks
like 5,381 - long y 583L // Ah, much better!
63Primitive Casting
- Conversion of primitives is accomplished by (1)
assignment with implicit casting or (2) explicit
casting - int iTotal 100
- float fTemp iTotal // fTemp now
holds 100.0 - When changing type results in a loss of
precision, an explicit cast is needed. This is
done by placing the new type in parens - float fTotal 100f
- int iTemp fTotal // ERROR!
- int iStart (int) fTotal
- We will see much, much more casting with
objects (later) . . .
64Casting Test Your Knowledge
- Given
- int iStart 10
- float fTemp 5.5
- fTemp fTemp (float)iStart
- What does iStart now hold?
Trick question
Remember Everythings a number at some level
65Operators
- Assignment
- Arithmetic , -, , /, (mod), and others
- int iNumLect 2
- int iNumStudents 583
- int iStudentsPerLect
- iStudentsPerLect iNumStudents / iNumLect
- // gives 291 due to integer division
- int iNumQualPoints 30
- int iNumCreditHours 8
- float fGPA
- fGPA iNumQualPoints / iNumCreditHours
- // gives 3.0 due to integer division
- iVar iVar fVar // gives compile-time error
66Test Your Knowledge
SOLUTION VARIETY PACK
- Heres the problem
- int iVar 10
- float fVar 23.26f
- // gives compile-time error
- iVar iVar fVar
- Which solution works best?
3
230
4
1
232
232
2
Lesson write code thats easily understood.
Same Compile Error
67Shorthand Operators
- iCounter iCounter 1 //OR iCounter
- iCounter iCounter - 1 //OR iCounter--
- iCounter iCounter 2 //OR iCounter2
- iCounter iCounter 5 //OR iCounter5Last
two examples its op then equals (e.g.,
2), not equals then op (e.g., isnt 2) - We will see examples with recursion where the
shorthand operator potentially causes a problem.
68Documentation Comments
- Three ways to do it
- // Double slashes comment out everything until
the end of the line - / This syntax comments out everything between
the / and the /. - (There are no nested comments as in C. /
- /
- This is syntax for Javadoc comments (similar
to second style - of commenting, but allows for HTML formatting
features. - /
- For CS1322, use Javadoc comments
69Some Comments on Comments
1. C-style comments with / / no nesting 2.
C style comments beginning // 3. A unique
"doc comment" starting with / .../ Fun with
comments // / // /
/////////////////// / /
Lesson Comments should be helpful dont worry
about compiler tricks with syntax.
70Commenting Factoids
- Watch for comments that open, but never close
- int x, y /
- Here, we declare the
- the point coordinates.
- // int z /
Lesson Java encourages clear code through the
type of operators and comments it allows!
A syntax highlighting editor is your friend!
71Javadoc
/ ltPREgt Get the name. Returns the
name at a specified array location. lt/PREgt
_at_param i the index of the array to be
retrieved. _at_return strName the name _at_see
EmployeesisEmployed() called to verify
employment / public String getName (int
i) if (myEmpl.isEmployed()) return
myArrayi else return "Nada" //
getName(int)
72Javadoc (Contd)
- You may include HTML tags (but avoid structuring
tags, like ltH1gt, etc.) - Javadoc comments should immediately precede the
declaration of the class, field or method. The
first sentence should be a summary. Use the
special javadoc tags--_at_. When '_at_' tags are used,
the parsing continues until the doc compiler
encounters the next '_at_' tag.
_at_see ltclass namegt _at_see ltfull-class namegt
_at_seeltfull-class namemethod.namegt _at_v
ersion
_at_author _at_param _at_return
_at_exception
_at_deprecated // jdk 1.1
_at_since
// jdk 1.1 _at_serial // jdk 1.2
73Design/Documentation
- Java comes with an excellent documentation tool
called Javadoc - Usage of the Javadoc system requires following
several steps - First special Javadoc block comments are added to
source files. - Javadoc block comments start with / and end
with / thus they function like regular comments - Each class, field and method should be commented
with a Javadoc comment just before the actual
item.
74Javadoc
- The comment should start with a short descriptive
phrase followed by a period . - Then a longer description of the purpose of the
item may be added. - HTML may be embedded
- Special tags can be used such as
- _at_author
- _at_revision
- _at_parameter
- _at_return
75Javadoc
- Once commenting is complete the Javadoc program
is run from the OS prompt. - If for example a group of class files for a given
project are located in the same directory then
Javadoc may be run by typing - javadoc .java
- When the program runs it will report any problems
and will produce a series of HTML files
documenting all classes, methods and fields. - A Javadoc template is on the next slide followed
by a sample
76Javadoc Template
- / Descriptive phrase. Longer statement of
purpose. - _at_param p1 A description of this parameter
- _at_param p2 A description of this parameter
- _at_ return A description of the return value
- /
- public int someMethod(double p1, String p2)
- return 0
-
77Results
78Constants
- CS1
- ltCONST_IDgt is ltconstant valuegt
- MIN_PASSING is 60
- PI is 3.14159
- Java
- public final static lttypegt ltIDergt ltvaluegt
- public final static int iMIN_PASSING 60
- public final static float fPI (float) 3.14159
- Details on why this syntax to come soon...
79Printing to Screen
- CS1
- print (ltargumentsgt)
- (display ltargumentgt)
- Java
- System.out.println(ltargumentgt)
- System.out.println( ) // prints blank line
- System.out.println(5) // prints 5
- System.out.println(Hello World) // prints
Hello World - println vs. print in Java
- println includes carriage return at end, next
print or println on new line - print causes next print or println to begin at
next location on same line
80Printing (contd)
- When starting Java, there are at least three
streams created for you - System.in // for getting input
- System.out // for output
- System.err // for bad news output
- These are InputStream and PrintStream objects
- Note For Win95/NT System.out is "almost"
identical to System.err they both display to the
screen (the one exception is when using DOS
redirect, gt, where System.out is redirected,
while System.err is still put to the screen.)
81Printing (contd)
System.out.println ("This line is printed
out") System.err.println ("This is the error
stream's output") These are both instances of
the PrintStream class. There are other methods
you might find useful in these classes
System.out.flush() System.out.write(int)
Dont use in 1322 (needed for autograder)
82Summary
- Java Basics Summary
- Java Programs
- JVM, applications applets
- Entry point is main() or init()
- Java Primitives and Operators
- Primitive data types vs. CS1 types
- Operators straightforward except for and
- Your new best friend
- System.out.println( )
83Questions
84(No Transcript)