Title: Administrative Issues
1Administrative Issues
2General Info
- Lab based class
- Accessible to all majors
- Als lectures on Mondays will focus on theory
- We will cover java and lab related material on
Wednesdays.
3Grading
- Pass-Fail Class
- No Exams
- 9 labs (first 8 are 10 points and the 9th is 20
points) - Due Thursday mornings at 230 AM
- Posted Monday (9 days before it is due)
- Must make a valid attempt at all labs.
- Must have a 65 or greater
- Extensions are at the TAs discretion
4How To Pass
- Try to complete each lab, if you cant do
something explain what you were trying to do and
what went wrong. - More effort More reward
- Give yourself time to work on the labs and get
help - Work with other people
- Bother TAs
5Section and Lab Hours
- We will be assigning you to TAs (sections) for
grading purposes. (Assignments will be posted
soon) - We will have TAs in the lab in the evening on
Monday, Tuesday, and Wednesday
6Collaboration
- You are encouraged to work together
- Must submit your OWN solution
- If you are looking at your friends code they
should be explaining it to you - Do not write any code you dont understand
7The Java Programming Language
8Brewing Java (Step 1 Compiling)
Java Compiler
Hello.class
9Brewing Java (Step 2 Running)
Applet (Webpage)
Java Virtual Machine
Hello.class
Application (Window)
10Language Characteristics
- Imperative (sequential instructions modify the
environment) - Object Oriented
- Data Centric Programming
- Naturally maps to real world
- C/C like syntax
- Platform independent
- Large Standardized API
11What is an Object?
- In real life
- Toaster
- White Board
- Marker
- Eraser
- Bicycle
- Each of these things have a state and behavior
- State The attributes of the object at a given
time - Behavior Operations on the state of the object
and other objects
12Objects can Work Together
- A whiteboard, marker, and eraser work together
13An Object in Java
- Objects in Java also maintain state and behavior
- State is maintained through internal variables
- Behavior changes/accesses the state through
methods - Can represent things in real life or other
constructs (linked lists, stacks, trees, etc.) - Objects can certainly call methods on other
objects
14A Java Class
- A Text Document
- A description of an objects
- define objects state and behavior
- Used by the Virtual Machine to create instances
of the object. - Analogy
- Class ? The Expo design for their markers
(casing, ink cartridge, cap). - The Virtual Machine ? The machine at the Expo
plant that puts all the pieces together to
construct black, blue, red markers. - Instance ? An Expo marker
15The Three parts of a Java Class
- Data Members
- Describe the state inkRemaining
- Constructors
- Called to create an instance of the object
- Methods
- Used to manipulate the state of the object
- Comments
- Used to describe to yourself what you want the
code to do - Comments
- Used to describe to the grader what you want the
code to do - Explain where and when your code is broken
- Comments
- Used to get a good grade
16ExpoMarker.java
public class ExpoMarker
private int inkRemaining // in mL private String
color // I like blue private boolean toxic //
Ok to sniff?
public ExpoMarker(int inkRemaining, String color,
boolean toxic) this.inkRemaining
inkRemaining this.color color
this.toxic toxic
public void setColor(String color) this.color
color public int getInkRemaining() return
inkRemaining public void write(Board b, String
s) b.draw(s, color) // Draw the text
with color inkRemaining-- // Remove some
ink
public static void main(String args) Board
board new Board() ExpoMarker pen new
ExpoMarker(10, blue, true) pen.write(board,
Hello World) System.out.println(Done)
17ExpoMarker.java
public class ExpoMarker
private int inkRemaining // in mL private String
color // I like blue private boolean toxic //
Ok to sniff?
public ExpoMarker(int inkRemaining, String color,
boolean toxic) this.inkRemaining
inkRemaining this.color color
this.toxic toxic
public void setColor(String color) this.color
color public int getInkRemaining() return
inkRemaining public void write(Board b, String
s) b.draw(s, color) // Draw the text
with color inkRemaining-- // Remove some
ink
public static void main(String args) Board
board new Board() ExpoMarker pen new
ExpoMarker(10, blue, true) pen.write(board,
Hello World) System.out.println(Done)
18ExpoMarker.java
public class ExpoMarker
private int inkRemaining // in mL private String
color // I like blue private boolean toxic //
Ok to sniff?
public ExpoMarker(int inkRemaining, String color,
boolean toxic) this.inkRemaining
inkRemaining this.color color
this.toxic toxic
public void setColor(String color) this.color
color public int getInkRemaining() return
inkRemaining public void write(Board b, String
s) b.draw(s, color) // Draw the text
with color inkRemaining-- // Remove some
ink
public static void main(String args) Board
board new Board() ExpoMarker pen new
ExpoMarker(10, blue, true) pen.write(board,
Hello World) System.out.println(Done)
19ExpoMarker.java
public class ExpoMarker
private int inkRemaining // in mL private String
color // I like blue private boolean toxic //
Ok to sniff?
public ExpoMarker(int inkRemaining, String color,
boolean toxic) this.inkRemaining
inkRemaining this.color color
this.toxic toxic
public void setColor(String color) this.color
color public int getInkRemaining() return
inkRemaining public void write(Board b, String
s) b.draw(s, color) // Draw the text
with color inkRemaining-- // Remove some
ink
public static void main(String args) Board
board new Board() ExpoMarker pen new
ExpoMarker(10, blue, true) pen.write(board,
Hello World) System.out.println(Done)
20Comments
- // This is a comment
- / This is a comment /
- / This is a special comment that can be read by
the JavaDoc application /
21Primitive Data Types
- Integer Numbers
- byte (8) ? short (16) ? int (32) ? long (64)
- Example int simpleNumber 3
- Decimal Numbers
- float (32) ? double (64)
- Example double pi 3.14159265358
- Character
- char (16)
- Example char myGrade F
- boolean true or false
- Example boolean isPassing false
22Strings
- Each string is an object, not a primitive data
type. - Example
- Some Text
- String myName Joseph Gonzalez
- String yourName new String(bob)
- int length myName.length()
- String concat myName is 21
23Private vs. Public
- Private data members and methods can only be
accessed from within the object they are defined. - Public data members and methods can be accessed
by other objects.
24Constructors
- public ltClass Namegt(ltargsgt) // Code
25Methods
- public void ltNamegt(ltargsgt) // Code
- public ltreturn typegt ltNamegt (ltargsgt) //
Code return ltvariable of the return typegt
26Math
- int x 3 5 2 // x 6
- int y x / 2 // y 3
- x // Same as x x 1
- x y // Same as x x y
- x Math.sqrt(4) // x 2
27This
- The this keyword references the object in which
it is contained - For example return this
- return the current instance
28Casting
- int x 7
- int y x / 2 // y 3
- float f x / 2 // f 3.0
- f (float) x / 2 // f 3.5
29Naming Conventions
- Separate words
- indicated by capitalizing the first letter of the
new word if its a class or variable for
(thisIsVeryLongVariableName) - Separated by an underscore _ for constants
- Class names begin with a capital letter
- MyClass
- ExpoMarker
- Variable names begin with a lowercase letter
- String foo bar?
- double inkRemaining 7.5
- Constants are all caps
- public static final int NUMBER_OF_STUDENTS 50
30Indenting
- Each indent logically separates inner levels of
code - Normally an indent is about 4 spaces long
class FooBar . . . public void sayHi()
System.out.println(Hi)
4 spaces
31Indenting, continued
- Starting braces can go on the same line or the
next line - Ending braces usually go on a line of its own
- It is also acceptable to put everything on one
line for short methods.
public void foo() ...
public void bar() ...
public int getNum() return num
32Other Conventions
- Line length
- Try to keep number of characters in a line under
80. - Slightly over ( lt 10) may be ok
- Use common sense-if it is difficult for you to
read, it is probably difficult for us to read. - Use these conventions as a guideline, but above
all, be consistent with your code.
33Online Resources
- Sun Java Tutorial
- http//java.sun.com/docs/books/tutorial/java/index
.html - Java API
- http//java.sun.com/j2se/1.4.2/docs/api/
34References
- What is an Object? http//java.sun.com/docs/books
/tutorial/java/concepts/object.html