Introductory Class Notes
Download
Report
Transcript Introductory Class Notes
CPSC150
Fall 2008
Dr. L. Lambert
CPSC150 Overview
• Syllabus
• Use Textbook, ask questions, extra
thorough, I will post sections covered
• All information and assignments posted on
CPSC150 web page:
• For anything you don’t see on the web
page, send me email
• All grades posted on Blackboard
Success in this Class
•
•
•
•
•
•
•
•
Collaborative
Come prepared to work in class
Take notes; pay attention; ask questions
Never procrastinate
Don’t assume you know/can program easily
Come see me/Java expert early and often
Ask questions
Consult with (possibly non-expert) peers, but be
careful. >50% of your grade is exams. Make
sure you are doing your own work before
you take the exam
Success in the Department
•
•
Join ACM, IEEE, SWE
Study with others.
– Right now, find others and exchange:
major, contact information, one thing
about you
• Sign up for department info.
1. open browser, go to www.pcs.cnu.edu
2. click on mailing lists, and students and careers
3. Subscribe using an email address that you read
regularly
Using Java and Jedit
•
•
•
•
We will use Jedit for program development
JEdit is editor – lots of others (e.g., Eclipse)
free and available for Mac, Windows, UNIX
(download Java 1.5 first):
http://java.sun.com/j2se/1.5.0/download.jsp
(Download SDK, NOT JRE)
http://www.java.com/en/download/index.jsp
• Download jedit for your home machines for
development: http://www.jedit.org
Next Steps
• Running Java Code
• Reading Java Code
• Writing Java Code
Java ByteCode
Java Virtual Machine
PC, Linux,
Mac, Unix
Operating
System and
Computer
Figure
1.5 from
textbook
Java program
(Source Code)
Compiler
Java Byte Code Program
(Object Code)
JVM runs program
Output of program
Reading Source Code
A Java program
import package; // if any
// comments and /* … */ and
/** javadoc here */
public class Name
{
// entire program in here. For now, main only
public static void main(String[ ] args)
{
// put code here
}
}
Write, Compile and Test
Listing Figure 1.1, page 15
// This application program prints Welcome to Java!
public class Welcome {
public static void main(String[] args) {
System.out.println("Welcome to Java!");
}
}
// Green part is the same in every program
// Black is the program
Three Steps to A Program
1. Type program (in JEdit)
2. Compile program (using javac)
3. Run program (using java)
1. Type program
•
Open Jedit. Type program. Save.
public class Welcome {
public static void main(String[] args) {
System.out.println("Welcome to Java!");
}
}
•
Save as classname + .java
– File name MUST be class name + .java
(Welcome.java in this case)
2. Compile program
1. Go to Start
2. Choose Run …
3. Type cmd in box
4. Type javac Welcome.java – need ‘c’ and ‘.java’
Run program
1. If errors, fix them
2. If no errors, you will see a prompt
3. Run your program: java (no ‘c’) program (no
.java) at prompt: java Welcome
Parts to a program
• Class name
– must be same as file name
• main function
– required for every Java program
• { }s around class and around main
• ‘;’ at the end of every statement in a
function
• System.out.println for printing
Write a program that prints “My name is …”
(fill in your name).
Save it to your username.