ppt - School of Computing

advertisement
Welcome to CISC121
• Prof. (Alan) McLeod – mcleod@cs.queensu.ca
• Web site at:
http://www.cs.queensu.ca/home/cisc121
• All lecture notes and examples will be posted.
Winter 2006
CISC121 - Prof. McLeod
1
WWWW
• Who: (got that already)
• Where: NIC232 (Here!)
• When: 9:30am Tuesday, 8:30am Thursday, and
10:30am Fridays.
• Purpose of course (Why!):
– Provide a basis for upper-year computer courses built
on first year and high school programming courses.
Winter 2006
CISC121 - Prof. McLeod
2
Labs
• TA’s: Chanchal Roy and Chris McAloney
• Section A: Tutorial 2:30, JEF102, Lab 3:30 to
5:30pm JEF157, Mondays
• Section B: Tutorial 8:30, JEF110, Lab 9:30 to
11:30am JEF157, Wednesdays
• Note – tutorial hour before lab!
• Labs start next week!
• There is a self-guided lab exercise posted.
Winter 2006
CISC121 - Prof. McLeod
3
Assignments
•
•
•
•
Five or six of them, probably.
Submit *.java files to WebCT.
Grades and comments returned to WebCT.
No group submission – one assignment per
student.
• Collaboration – share ideas, not code!
Winter 2006
CISC121 - Prof. McLeod
4
Textbook
• “Big Java” by Cay
Horstman, 2nd edition.
• First edition used last year,
but it does not have any
coverage of Java 5.0.
Winter 2006
CISC121 - Prof. McLeod
5
Textbook, Cont.
• “Do I gotta buy the book?”
NO
• “Should I buy the book?”
MAYBE!
Winter 2006
CISC121 - Prof. McLeod
6
Two Possibilities
• Plan A:
– You are pretty confident in your Java programming
skills, and you figure you can get extra material from
the internet, if needed.
– Do really well on the assignments!
– You don’t need to buy the book and you won’t pay too
much attention to the course until around midterm time,
when we get into the more “conceptual” material.
• Plan B:
– Not so confident!
– Buy the book, attend lectures, do the lab exercises and
assignments yourself. Get help from your TA. Work!
– Relax a bit after the midterm.
Winter 2006
CISC121 - Prof. McLeod
7
Course Content (What!)
• This is not a “Java Course”!
• But, we need a language to demonstrate and
practice the concepts to be discussed.
• Java is the language of choice.
– A modern, platform-independent, Object-Oriented
language.
– We could have used many other languages equally
well: C#, C++, VB, Delphi, Pascal, Turing, etc.
Winter 2006
CISC121 - Prof. McLeod
8
Course Content, Cont.
• First, a review of the Java language, then:
Practical Topics
Theory Topics
Algorithm Topics
Coding Style
Analysis of
Complexity
Data Structures
Documentation
Numerical Storage
& Computation
Recursion
Testing &
Debugging
Sorting
Assertions &
Invariants
Searching
Winter 2006
CISC121 - Prof. McLeod
9
Course Content, Cont.
Practical Topics
Theory Topics
Algorithm Topics
Coding Style
Analysis of
Complexity
Data Structures
Documentation
Numerical
Storage &
Computation
Recursion
Testing &
Debugging
Sorting
Assertions &
Invariants
Searching
• These topics are not Language-Dependant!
Winter 2006
CISC121 - Prof. McLeod
10
Course Content, Cont.
• There is no single optimum way to navigate these
topics.
• From example programs in class:
– See examples (I hope!) of good coding style.
– See examples of testing & debugging (I’m sure!).
– Measure time of execution to verify complexity
analyses.
– Test the effect of finite memory used to store numbers.
– Code and demonstrate the data structures and
algorithms discussed.
Winter 2006
CISC121 - Prof. McLeod
11
Course Content, Cont.
• Assignments will:
– At first, be used to practice fundamental Java language
concepts.
– Later, to explore concepts introduced in lecture.
– And then to apply some of the algorithms learned to
practical situations.
Winter 2006
CISC121 - Prof. McLeod
12
Course Content, Cont.
• To add to the excitement!…
– Lectures will be shared with many examples
and class problems.
– Your questions are very important!! They will
really help to make the lectures more
interesting!
– Other kinds of class participation?…
Winter 2006
CISC121 - Prof. McLeod
13
How to Pass
• Evaluation:
– 25% Assignments (5% each?)
– 25% Midterm
– 50% Final Exam
Winter 2006
CISC121 - Prof. McLeod
14
How to Pass – Cont.
• Do all the assignments and all practice questions
yourself. Do not look at solutions until you have
tried them.
• Ask if you have questions:
– Ask me – during lecture, by E-mail, after lectures or in
the WebCT forum.
– Ask TA’s in lab, by E-mail.
• Read lecture notes.
• Get the textbook if you need more help.
• Many other resources are listed on the web site.
Winter 2006
CISC121 - Prof. McLeod
15
Warning!
• Most of the contents of a first year programming
course like APSC142 or CISC101 will be
crammed into the first three weeks.
• If you do not have any programming background
nor a strong aptitude for coding, you might have
problems keeping up!
• If you need more time with basic Java, pick up a
first year-level textbook and/or see if you can
spend more time with the TA’s.
Winter 2006
CISC121 - Prof. McLeod
16
Today
• Demo’s of environments:
– One time only use of JDK - just to show you what is
going on “under the hood”.
– BlueJ
– eclipse
• Note that you can use whatever development tool
you wish. We officially only support eclipse. For
assignments hand in your *.java files only.
Winter 2006
CISC121 - Prof. McLeod
17
A Simple Java Program
public class HelloProg
{
public static void main (String [] args)
{
System.out.println ("Hello there!");
} // end main method
} // end HelloProg class
• The “//” denotes an in-line comment. Everything else on
the line is ignored by the compiler.
Winter 2006
CISC121 - Prof. McLeod
18
A Simple Java Program – Cont.
• The compiler ignores any “white space” in your
source code – returns, line feeds, tabs, extra
spaces and comments.
• Here’s our little program without white space
(imagine this all on one line):
public class HelloProg{public static void main(String[]
args){System.out.println("Hello there!");}}
• This does still run, but it is hard to read…
Winter 2006
CISC121 - Prof. McLeod
19
Running a Java Program
• What happens when a program is run?
• Remember that Java code is platform
independent.
• Compilation of Java source code (HelloProg.java)
is done by a compiler (javac.exe) that creates a
“byte code” file (HelloProg.class) that is still
platform independent.
• This byte code file cannot be viewed or edited and
is very compact.
Winter 2006
CISC121 - Prof. McLeod
20
Running a Java Program – Cont.
• Each platform capable of running Java programs
has its own “JVM” or Java Virtual Machine – also
called a “byte code interpreter”.
• This program (java.exe on a Wintel machine) runs
the byte code file to perform on a specific
platform.
Winter 2006
CISC121 - Prof. McLeod
21
Running an Applet
• Helps to explain why Java programs run this way:
• An Applet is a small byte code file that is linked to
a web page.
• Compact is important in order to minimize
download times.
• The JVM is part of the browser, and browsers are
platform specific, but the applet is not.
• In the case of an applet, the JVM built into the
browser runs the applet.
Winter 2006
CISC121 - Prof. McLeod
22
A Simple Java Program – Cont.
• Back to our little program:
public class HelloProg
{
public static void main (String [] args)
{
System.out.println ("Hello there!");
} // end main method
} // end HelloProg class
Winter 2006
CISC121 - Prof. McLeod
23
A Simple Java Program – Cont.
• A Class is an “Object” in Java. All Objects in Java
are Classes…
• A Class is a container – it holds attributes (data)
and methods (code that does something).
• Our class is called “HelloProg”. Our class must
be defined in a file called “HelloProg.java”.
• The code “public class HelloProg” is used
to declare the class.
• The contents of the class are contained in a set of
curly brackets: “{ }”.
Winter 2006
CISC121 - Prof. McLeod
24
A Simple Java Program – Cont.
• Our little class does not contain any attributes
(data) and only has one method called “main”.
• The main method is declared using the code:
public static void main (String [] args)
• As before the code is contained within: “{ }”.
Winter 2006
CISC121 - Prof. McLeod
25
The main Method
• For the JVM to run a program, it must know where
to start.
• By design, the starting point is always the
execution of the main method.
• The JVM expects the main method to be
declared exactly as shown – the only thing you
can change is the name of the String array, called
“args” in this little program.
Winter 2006
CISC121 - Prof. McLeod
26
A Simple Java Program – Cont.
• Our main method contains only one line of code:
System.out.println ("Hello there!");
• It prints out “Hello there!” to the screen (or
“console”). We’ll talk more about I/O
(“Input/Output”) later.
• Note the “;” at the end of the line of code. Since
the Java compiler ignores white space, it must
use these characters to determine when a line
finishes.
Winter 2006
CISC121 - Prof. McLeod
27
Download