CS 2430 Day 1
Agenda Load NetBeans Introduction Syllabus Review some array operations
Contact information Name: Scott Summers Web: Phone: Office: Ulrich 214 Office hours: See “schedule” on my webpage
About me Starting fifth semester at UW—Platteville Education: –BS: UW-Green Bay, 2004 –MS: Iowa State University, 2007 –PhD: Iowa State University, 2010 Studied theory of computation ISU: home of the first (non-programmable) electronic digital computing device Atanasoff-Berry Computer (ABC)
Course homepage
Course work 3 exams (60 points each) 180 Final exam quizzes (drop lowest quiz) 50 Programs and labs 170 ___________________________________ TOTAL 500
Grading scale Course Grade Points Percentage Grade Points A % 4.0 A % 3.7 B % 3.3 B % 3.0 B % 2.7 C % 2.3 C % 2.0 C % 1.7 D % 1.3 D % 1.0 F below
Syllabus Read the rest of the syllabus on your own time!
Any questions?
CS 243 versus CS 143 CS 143: C++ HiC CS 243: Java NetBeans All methods, including “main()”, are contained inside of classes
Java and NetBeans How to create a new project? (Lab 1) Uncheck “Set As Main Project” Uncheck “Create Main Class” The filename is case sensitive Mind the location!
Transition from C++ to Java If you know C++ syntax, then you will find Java syntax familiar You already know how to do a lot of stuff in Java such as –Declare variables –Write loops –Process (but not declare) arrays –Call methods
Primitive data types TypeSize (bits)Default value char 16‘\u0000’ int, short, long 32, 16, 640, 0, 0L float, double 32, 640.0f, 0.0d boolean ??? false byte 80
Some syntax int value, total = 0, rem, quot; value = 5; if (value > 0) total += value; else { rem = value % 5; quot = value / 5; } // Declaration statement // Assignment statement // Conditional statement // Braces needed for statement // block Is this Java or C++ code? It’s both!
A while loop in C++ int count = 0, total = 0; while (count < 100) { ++count; // performs the increment before doing // anything else (highest precedence), same // as "count++" in this case total += count; }
A while loop in Java int count = 0, total = 0; while (count < 100) { ++count; // performs the increment before doing // anything else (highest precedence), same // as "count++" in this case total += count; } No difference! Same with “for” loops—Java and C++ have same syntax
Input and output C++ cin >> value; cout << "The value: " << value; cout << "The value: " << value << endl; Java // We will discuss input later in the course! System.out.print("The value: " + value); System.out.println("The value: " + value);
Any questions?
Go to:
Review array operations Do you remember how to do these? Declare an array Add to the end Delete and maintain relative order Delete and do not maintain relative order Linear search Mean (average) Sort (discussed later in the course!)
Array organization C++ int intArray[50]; // Array of size 50 // Indexed from 0 to 49 Java // Array is a class in Java int [] intArray; // int[] intArray; // int intArray[]; // To get an array object, use // the new keyword (literally!) intArray = new int[50]; intArray∙ ∙ ∙
Array declaration final int MAX_SIZE = 10; // same as const from C++ int xVal, size = 0; int intArray[]; intArray = new int[MAX_SIZE]; // could use a non-constant variable // intArray: array of integers // MAX_SIZE: the maximum number of values of intArray // size : the actual number of values of intArray int len = intArray.length; // no ()'s // returns the length of the array, // NOT the number of elements in the // array