Copywrite 2003 Walter Savitch These slides are for the exclusive use of students in CSE 11 at UCSD,...

Post on 21-Dec-2015

214 views 0 download

Transcript of Copywrite 2003 Walter Savitch These slides are for the exclusive use of students in CSE 11 at UCSD,...

Copywrite 2003 Walter Savitch

These slides are for the exclusive use of students in CSE 11 at UCSD,

Winter quarter 2003.They may not be copied or used for

any other purpose without the written permission of Walter Savitch.

CSE 11

Walter Savitch

3620 APM

• CSE 11 = CSE 8A + CSE 8B

• You do not need to know any Java to take this course, BUT

• If you have not programmed before in some language, you should not take this course.

• You do Chapters 1-3 of Savitch text on your own. It should be close to a “a review.”

Text Book

• Savitch, “Java: An Introduction to Computer Science and Programming,” Second Edition.

• Some UNIX book of your choice. (A suggestion is on the handout.)

• Get Handout and READ IT!

• You must have a computer account for this course. (It starts cs11w__)

• All Home Work graded in interviews.

• All interview in SUNPAL lab APM 3414.

• Teams; HW 1 work alone. All other HW can work in teams of 2.

Home Work Deadlines

• Two deadlines: turnin deadline, interview deadline.

• If you miss the turnin deadline, you get zero for the assignment.

• If you miss the interview deadline by one or two days, you pay a penalty.

• If you miss the interview deadline by more than two days, you get zero.

No Work Accepted Late for Any Reason

• Except as already noted for interviews.

• Read the handout.

Home Work 1

• Is on the handout.• If you do not pass HW 1 by the deadlines,

you must drop the course. No exceptions.• If you take an interview before the turnin

deadline, you do not need to turn in the assignment.

• Instructions for turning in assignments will be given in a later lecture.

Home Work 1 Deadlines Correction

• Turnin deadline Friday January 17.• Interview deadline Tuesday January 21.• There is a mistake in the deadlines on the

handout.• Home work 2 deadlines will be immediately

after HW 1 deadline. The HW2 turnin deadline may be BEFORE the HW1 interview deadline.

Proctor Hours

• In public directory

• On website

• APPROXIMATELY: M-Th 9AM-10PMF 10Am-6PMSa noon-6pm

Quizzes

• Surprise quizzes at end of some lectures.

• Do not ask “Will there be a quiz today?”

• Cannot makeup a missed quiz for any reason.

Read the Handout

• Cheating policy.

• Meaning of turnin deadlines.

• Grading policy.

• No late work policy.

Home Computer

• You do not need a home computer.

• If you work on a home computer, you must somehow move your files to the SUNPAL lab for turnin and interviews.

• Java for your home computer is free on Sun website. See Savitch book preface. Get version 1.4 or higher. (1.2 is good enough.)

UNIX

• We will use the UNIX operating system in the SUNPAL laboratory for all interviews.

• Your programs must be on the SUNPAL machine and must compile and run there.

• You need to know enough UNIX to manipulate files, edit files, compile and run your programs.

• No UNIX on any quiz or exam. Only test of UNIX is that you can do the interviews in the SUNPAL lab.

Editor

• You can use any editor you wish in the SUNPAL lab, so long as the proctor can give you an interview.

UNIX commands

• Learn command line commands.

• More details in discussion section.

UNIX Commands

• cp file1 file2

• cp file1 directory

• mv file1 file2

• rm file

Wildcards

• cp * directory

• cp *.java directory

Directories

• Often called folders• mkdir directoryName• cd subdirectoryName• cd ..• cd ~• Learn about absolute and relative path names.

Java

• General purpose programming language.

• Includes GUI (Graphical User Interface) libraries.

• Includes lots of other libraries.

• Has Internet stuff, but we will use little of it directly.

Java, What’s Unique?

• Byte Code Compile a Java program, such as MyProg.java, to byte code, MyProg.class.

• Interpret byte code using Java Virtual Machine.

• All but the Java Virtual Machine is portable. Same Java program and same byte code runs on any computer.

Java, What’s Unique?

• Lots of libraries.

• Threads: multiple processes (not covered in this class.)

• Applets (Covered but no big deal)

Object Oriented ProgrammingOOP

• The accepted way to program now. To you, “programming” and “object oriented programming” mean the same thing.

• Explained in detail after you know more, but more or less everything you are learning is OOP.

• Java is an OOP language. So is C++. C is not. If the language has classes it is an OOP language.

Chapters 1-3

• Expressions, similar to most all other languages. int n = 5*(count + 7); //Assignment

• Flow of control. Same as C++; similar to other languages.

Java Types

• Primitive types: int, double, boolean, char, others.

• Class types, String and others including all the things that you define in Java.

boolean

• Is a full fledged type in Java.

• Values are not and do not convert to integers. Values are true and false. true is not 1, false is not 0.

Spelling Conventions

• Class names start with an uppercase, for example, String.

• Variable (and most other things) start with a lowercase, for example, theTime, rate, myStuff, yourStuff.

• Constants (literals) all uppercse, for example, NUMBER_OF_PEOPLE

Spelling Conventions

• Do not abbreviate use myFirstScore not myFrSc use timeLimit not tmLim nor tmLimit

Console Output

int number = 7;

System.out.println(number + “ things”);

Screen output:

7 things

Console Input

System.out.println(“Enter an integer:”);

int number = SavitchIn.readLineInt();

Sets the value of number to the integer types in at the keyboard.

The integer must be on a line by iteslf.

SavitchIn.readLineInt()

• SavitchIn is a class.

• readLineInt is a method.

• () indicates no arguments.

• Returns a value of type int, namely the integer entered at keyboard.

• Good error messages if user screws up.

SavitchIn

• A class written in Java.• Is not a standard Java library class.• The file SavitchIn.java (or SavitchIn.class)

must be in the same directory as your program.

• File SavitchIn.java is with programs on machine in SUNPAL and is on CD in the Savitch text.

SavitchIn

• readLineInt()

• readLineDouble()

• readLineNonWhiteChar()

• readLine()

readLineNonWhiteChar()

• Different from other methods• Reads the first nonwhite char on a line and

discards the rest of the line.• The char need not be the only thing on the

line.• If line is

yesit reads the ‘y’

• Next time start Chapter 4

• Get a course account before you leave today.

public class FirstProgram{ public static void main(String[] args) { System.out.println("Hello out there."); char answerLetter; answerLetter = SavitchIn.readLineNonwhiteChar(); if (answerLetter == 'y') System.out.println("Nice weather."); System.out.println("Good-bye."); }}

public class NameOfProgram

{

public static void main(String[] args)

{

Your Code Goes Here.

}

}