CPSC150

Spring 2011 Dr. Lynn Lambert Take roll

• CS150 roll CPSC150 Overview

• Syllabus • Use Textbook, ask questions • All information and assignments will be posted on Blackboard • All grades posted on Blackboard • For anything you don’t see on Blackboard/ Scholar, send me email Log onto Scholar Content of Course

1. Mechanics of – Writing a Java program – If statements – Loops 2. Program design and abstraction – Methods – Parameters, Return Values – Testing 3. Object Oriented design – Objects and object interaction – Exceptions, Inheritance Success in this Class

• Collaborative • Come prepared to work in class • Take notes; If I write something, write it down. If you can, write what I say. • pay attention; ask questions • Do NOT use the machines when you should not be • Do NOT text. It will hurt your grades (and is rude). Do not IM. Do not surf. Success in this Class

• 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 quizzes/exams. Make sure you are doing your own work before you take quizzes and exams Success in the Department

• Join ACM, IEEE • 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

• Download Java SDK • http://www.java.com/en/download/index.jsp • Download Jedit – JEdit is editor – lots of others (e.g., ) – free and available for Mac, Windows, UNIX – Download jedit for your home machines for development: http://www.jedit.org • Put javac and java in your path – For windows XP: find java path (e.g., c:\program files\java \jdk1.6_11\bin) – control panel/advanced/environment variables/system variables/ path edit – Add ‘;’ then above path at end – Reboot machine Next Steps

• Running Java Code • Reading Java Code • Writing Java Code Java program (Source Code)

Compiler

Java Byte Code Program (Object Code)

JVM runs program

Output of program Java ByteCode (created from Java source code)

Java Virtual Machine PC, , Mac, Unix and Computer

Similar to Figure 1.11b from textbook Reading a Java program Listing 1.1, page 11 // 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

• Log in with login from last semester. Or pcse_user • 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. Type cmd in box

3. Type javac Welcome.java – need ‘c’ and ‘.java’ 3. Run program

1. If errors, fix them using the Jedit editor. 2. If no errors, you will see a prompt No Mess age if things are good 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).