Welcome to IIT and cs115!.

Slides:



Advertisements
Similar presentations
 2005 Pearson Education, Inc. All rights reserved Introduction.
Advertisements

1 Chapter 2 Introduction to Java Applications Introduction Java application programming Display ____________________ Obtain information from the.
Bellevue University CIS 205: Introduction to Programming Using C++ Lecture 3: Primitive Data Types.
1 CS 105 Lecture 2 Variables Wed, Jan 19, 2011, 5:07 pm.
Announcements Quiz 1 Next Week. int : Integer Range of Typically -32,768 to 32,767 (machine and compiler dependent) float : Real Number (i.e., integer.
Aalborg Media Lab 21-Jun-15 Software Design Lecture 2 “ Data and Expressions”
If You Missed Last Week Go to Click on Syllabus, review lecture 01 notes, course schedule Contact your TA ( on website) Schedule.
Welcome to IIT and cs105!. CS Secs Jon Hanrath SB Office Hours: –MW 8:00 A.M. – 9:45 A.M. –W 5:00 P.M. – 6:00 P.M
1 Welcome to CS 105 Intro Comp Pgm’g I Welcome to IIT too?
1 CS 105 Lecture 3 Constants & Expressions Wed, Jan 26, 2011, 4:15 pm.
Data types and variables
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie June 27, 2005.
Chapter 2 Data Types, Declarations, and Displays
1 The First Step Learning objectives write Java programs that display text on the screen. distinguish between the eight built-in scalar types of Java;
Objectives You should be able to describe: Data Types
Welcome to IIT and cs115!. CS Secs. 001 Jon Hanrath SB
Welcome to IIT and cs115!.
Welcome to IIT and cs115!.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
CSC 1051 – Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
Constants Numeric Constants Integer Constants Floating Point Constants Character Constants Expressions Arithmetic Operators Assignment Operators Relational.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 2 Basic Elements of Java.
Java Programming: From Problem Analysis to Program Design, 5e Chapter 2 Basic Elements of Java.
 Pearson Education, Inc. All rights reserved Introduction to Java Applications.
1 Chapter 3 Syntax, Errors, and Debugging Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.
© 2004 Pearson Addison-Wesley. All rights reserved ComS 207: Programming I Instructor: Alexander Stoytchev
Welcome to IIT and cs105! 1. CS Sec. 02 Summer 2015 George Koutsogiannakis – office: 214 SB Best way to communicate.
Chapter 3 Syntax, Errors, and Debugging Fundamentals of Java.
A Simple Java Program //This program prints Welcome to Java! public class Welcome { public static void main(String[] args) { public static void main(String[]
Programming in Java (COP 2250) Lecture 4 Chengyong Yang Fall, 2005.
CSC 1051 – Algorithms and Data Structures I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
Programming Fundamentals. Overview of Previous Lecture Phases of C++ Environment Program statement Vs Preprocessor directive Whitespaces Comments.
Announcements Quiz 1 Next Monday. int : Integer Range of Typically –2,147,483,648 to 2,147,483,647 (machine and compiler dependent) float : Real Number.
CHAPTER 2 PROBLEM SOLVING USING C++ 1 C++ Programming PEG200/Saidatul Rahah.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
Variables in C Topics  Naming Variables  Declaring Variables  Using Variables  The Assignment Statement Reading  Sections
CMSC 104, Version 8/061L09VariablesInC.ppt Variables in C Topics Naming Variables Declaring Variables Using Variables The Assignment Statement Reading.
Java Programming: From Problem Analysis to Program Design, Second Edition 1 Lecture 1 Objectives  Become familiar with the basic components of a Java.
Welcome to IIT and cs105!. CS 105 Jon Hanrath – SB112B Office Hours: –TBD
Lecture 3: More Java Basics Michael Hsu CSULA. Recall From Lecture Two  Write a basic program in Java  The process of writing, compiling, and running.
Java Programming: Guided Learning with Early Objects Chapter 1 Basic Elements of Java.
CompSci 230 S Programming Techniques
Chapter 2 Variables.
Topics Designing a Program Input, Processing, and Output
Chapter 3 Syntax, Errors, and Debugging
BASIC ELEMENTS OF A COMPUTER PROGRAM
Building Java Programs
Multiple variables can be created in one declaration
Primitive Data, Variables, Loops (Maybe)
Java Programming: From Problem Analysis to Program Design, 4e
IDENTIFIERS CSC 111.
Introduction to C++ Programming
Chapter 2 Edited by JJ Shepherd
Chapter 2: Basic Elements of Java
Building Java Programs
MSIS 655 Advanced Business Applications Programming
IFS410 Advanced Analysis and Design
Expressions and Assignment
elementary programming
Topics Designing a Program Input, Processing, and Output
Topics Designing a Program Input, Processing, and Output
Fundamental OOP Programming Structures in Java: Comments, Data Types, Variables, Assignments, Operators.
In this class, we will cover:
Primitive Types and Expressions
Unit 3: Variables in Java
Chapter 2 Variables.
An Overview of C.
Variables in C Topics Naming Variables Declaring Variables
Instructor: Alexander Stoytchev
Welcome to cs105 and cs104!.
Presentation transcript:

Welcome to IIT and cs115!

CS 115 - Secs. 001 Jon Hanrath - SB112B hanrath@iit.edu www.cs.iit.edu/~cs115hanrath

Lecture/Lab: TR 1:00 P.M. –4:00 P.M. SB 112E Lectures will be followed by lab time. Lab assignments are due by the end of class on Thursdays each week.

CS 115 – Required Textbook “Java 6 Illuminated: An Active Learning Approach” Second or Third or Fourth Edition, Anderson and Franceschi

CS 115 - Quizzes/Exams & Grading 1 Quiz –5% of Grade 2 Exams: Exam I - Lecture Exam - 15% Exam II - Lecture Exam - 25% Final Exam - 35% Labs - 20% Must Take Final to Pass Course Final Grade: A > 90% B 80-89.99% C 70 –79.99% D 60 – 69.99% E < 60%

CS115 Labs Labs Consist of a Reading Assignment, and Lab Exercises from Website Lab Exercises Comprised of Written Exercises and Programming Exercises Lab Exercises Due by End of Class Thursdays Students Receive Full Credit for Attempting Each Problem Lab Exercises Not Corrected or Handed Back Labs Graded Either 10 (fully completed), 5 (partially completed), or 0 (not completed)

Expectations Attendance in Lectures and Labs Completion of Quizzes and Exams Four to Six Hours per Week on Homework Outside Help If Necessary No Cheating Have fun!!

Rules No Swearing or Other Inconsiderate Behavior Turn Off Cell Phones, iPads, Laptops Questions, Discussion, Ideas Welcome

Excuses If You Will Miss an Exam or Quiz, Make Arrangements **BEFORE** the Exam or Quiz Date Exam, Quiz Dates Already Posted If Emergency: Doctor/Hospital Note Family Problem: Contact Info for Parents

Unacceptable Excuses Slept Late Felt Sick I’m Just a Freshman Roommate Ate My Alarm Clock/Textbook/Underwear Missed Bus Had a Game/Match/Practice Didn’t Know When Exam/Quiz Was If Any of Above Happen, Get to Class As SOON as Possible!!!

CS 115 - Ethics Exams: Labs Should Be Done Independently Closed Book, Closed Notes, Closed Everything Nothing in Ears (mp3 players, cell phones, etc.) Labs Should Be Done Independently

CS 115 – Where to Get Help www.cs.iit.edu/~cs115hanrath Internet: Search for “JAVA tutorial”, or “JAVA help” GET HELP EARLY RATHER THAN LATER!!!

CS 115 – Web Page http://www.cs.iit.edu/~cs115hanrath Click on Syllabus Weekly Assignments Quiz and Exam Dates Lecture Slides Other Course Information

CS115 Labs (Cont) All Labs Assigned from Website Work on Labs on Personal PC, or Campus Computers Save .java File(s) to flash drive, or send to yourself in email and Bring to Lab Section for Discussion and Questions Hand in assignments by end of class Thursday

Course Philosophy Computer Science Side “Real World” Side Problem Solving Logical Thought Programming in JAVA “Real World” Side Human Nature Corporate World Surviving during and after College

Problem Solving CS 115 Develops Logic Skills to Solve Problems by Writing a Program A Program is a Problem Solving Tool Computers Follow Instructions Given to Them Computers Do Not Have “Intuition” Computers Do Not Make Decisions “on Their Own”

Why Use a Program? Computers Perform Tasks Many Times Faster than a Person Computers Are More Consistent than a Person Computers Can Work 24-7

Terminology Source Code: the Original Problem-Solving, Logical Solution Written in a Programming Language (e.g. JAVA, .java file) Interpretation: Converting source code into common language (.class file) Compiling: the Action of Turning the Source Code into a Format the Computer Can Use Linking: the Action of Bringing in Already Written Code (Libraries) for Use in a New Program Executable: the Result of Compiling and Linking a Source Program; the “.exe” file that the Computer Can Run

JAVA Required Elements Every JAVA Program Must Have: public class MyProgram { public static void main( String [ ] args) }

Your First Program { System.out.println(“Hello World!!”); } // Jon Hanrath // CS115 // Section 042 public class MyProgram { public static void main( String [ ] args) System.out.println(“Hello World!!”); System.exit(0); }

Writing a JAVA Program Design Design Team (Experienced) Pseudocode In Practice, 75% of Total Program Time Program Java, C++, etc. Coders (Less Experienced) Test Test Team If Even One Error, Back to Design

What Is Pseudocode? Every Programmer’s Way of Writing Down Steps in Solving a Problem Steps in Creating Pseudocode: Understand the Problem Decide How to Solve the Problem Write the Solution Using a Logical Sequence of Statements Design Issues Apply to almost ANY Vocation

Compiler Converts Source Code into an Object File or Machine Code Each Change to Source File Requires a Recompilation Compiler Detects Syntax Errors Syntax Error: a Non-Proper, Not Allowable, Sequence of Characters or Words Given a Particular Language

Syntax Errors Spelling Errors Examples: Punctuation Errors Examples: Undefined Variable Name Unrecognized Keyword Punctuation Errors Examples: Missing Curly Braces Missing Semicolons Malformed Comments Syntax Errors Are Listed at Bottom of Screen When Compilation Is Complete

Syntax Errors (Cont) Syntax Errors Are Listed at Bottom of Screen When Compilation Is Completed First Error in Program May “Cause” Other Errors to Show Up General Rule: Fix First Error (and Any Obvious Errors); Then Recompile

Logic Errors – “Bugs” Also Called Semantic or Run-Time Errors Program Compiles, but Doesn’t Produce the Expected Results Examples: Program Keeps Running Forever (Infinite Loop) Nothing Happens Program Output Is Incorrect Error Message at Run Time (e.g. Dividing by 0) Errors May Be Intermittent May Be Able to Find Semantic Problems with Debugger

Debugging public class MyProgram { public static void main( String [ ] args) System.out.println(“Program Begins” ); // first 10 lines of program System.out.println(“ Made it to line 10”); // next 10 lines of program System.out.println(“ Made it to line 20” ); //… and so on System.out.println(“ Made it to line 100” ); }

Detecting “Bugs” Running Program Should Be Tested Several Times with Different Inputs Test Plan – Series of tests (e.g., inputs) that have predetermined expected outputs. Running Program Should Be Tested Several Times under All Potential Conditions When Errors Detected: Analysis Needed: Debugging Mechanism

Test Plan What should the Test Plan contain for a program that accepts numerical input from a user, and outputs the square of the input?

JAVA Packages/Libraries Over 2000 Libraries Exist Sometimes Called “Packages” Java.lang Package Automatically Imported Import Statements Above First Class Import Others with import statement import java.util.* //import all classes

Comments Comments: Describe a Program // Comment to end of line /* Comment until first occurrence of star slash */ Difficult to Understate Importance of Good Comments Should Be at Beginning of Program (Overall Summary) Should Be Next to Variable Declaration Briefly Describing Uses of Variable Should Be Anywhere in Program Where Unobvious Coding Is Performed

Program Format Not Recognized by Compiler White Space: Not Recognized by Compiler Indent (e.g. 3 Spaces) for Each New Function, Selection, or Loop public class MyProgram{public static void main( String [ ] args){System.out.println(“Hello World!!”);System.exit(0);}} .vs public class MyProgram { public static void main( String [ ] args) System.out.println(“Hello World!!”); System.exit(0); }

Variables Identifiers Used to Store Values that May Change Every Variable Has a Type : What Kind of Value (e.g., Integer, Floating Point Number, Character) Is Begin Stored Every Variable Has a Value which Is Assigned and Can Be Changed Every Variable Must Be Declared, which Sets Aside Memory for the Storage Location

Declaring a Variable Declaration Normally Comes after a Function Definition Opening Curly Brace: public class MyProgram { public static void main( String [ ] args) int num1; //variable declaration num1 = 10; // variable assignment // variable output below System.out.println(“num1 is:” + num1); } Declaration Includes Type and the Name of the Variable All Variables Must Be Declared before Being Used

Variables and Main Memory int num; num = 10; num = 15; num <garbage> num 10 num 15

Main Memory Storage Location of Data in a Computer Used When a Program Is Running “Wiped Clean” When Computer Rebooted Bit: Represents One Wire of Computer (On or Off, i.e., “1” or “0”) Byte: Basic Unit of Storage (Can Store One Letter of the Alphabet) (8 bits per byte…256 combinations) Kilobyte (KB): 1000 (or 1024) Bytes (Pages of Text) Megabyte (MB): 1,000,000 Bytes (Large Pictures) Gigabyte (GB): 1,000,000,000 Bytes (Music Files, Video Files)

Initialization and Assignment Initialization: Value Given to Variable at Declaration Assignment: Value Given to Variable in Execution Statement

Variable Initialization public class MyProgram { public static void main( String [ ] args) int num1 = 10; //variable initialization System.out.println(“num1 is:” + num1); }

Built-In (or Primitive) Data Types for Variables int: Integer Range of Typically –2,147,483,648 to 2,147,483,647 (machine and compiler dependent) float: Real Number (i.e., integer part, decimal part, and exponent part) Range of Typically (+/-) 10e-45 to 10e38 double: Larger Real Number ((+/-) 10e-324 to 10e308) char: Character

Naming Variables in JAVA: Identifiers Can Use Letters: Remember That JAVA is Case Sensitive (e.g., NumWidgets Is Not the Same as numwidgets) Can Use Digits 0-9, $, and Underscore Cannot Start with a Digit Cannot Contain Spaces or Other Characters Cannot Use JAVA Keywords

Naming Variables (Cont) Should Use a Meaningful, Descriptive Name so that Variable’s Use Is Easily Understood: Examples: counter, second, minute, length, width Be Consistent with Case; Usually Lower Case with Upper Case for Second Part of Variable Name averageRainfall, totalStudentGrades, maxBuildingHeight, minPackageWeight;

Variable Scope Scope: Area of a Program within which a Variable Can Be Referenced Variable Definitions Are Recognized in the Curly Braces in which They Were Defined Variables Declared Outside of Functions Are Recognized from the Point Declaration through the Rest of the Program

Named Constants Constant: An Identifier that Is Initialized to a Value that Cannot Change Usually Declared at Top of Program using Keyword final Standard Naming of Constants Is to Use All Upper Case Letter with or without Underscore between Words All Constants Should Be Initialized Syntax: final int MAXHT = 100;

Advantages of Constants Easier to Understand Easier to Modify Example: Compare using Number 5000 in Program versus Constant MAXHT

Named Constants public class MyProgram { public static void main( String [ ] args) final int MAXHT = 100; ... currentHeight > MAXHT bridgeHeight == MAXHT bridgeHeight + newAddition >= MAXHT ... // used MAXHT 223 times in this program }

Literal Constants (Values) Constants Whose values Are Already Known: Characters (Specified Inside Single Quotes): ‘A’ , ‘a’ , ’5’ , ’ ‘ , ’\n’ (newline) , ’\0’ (NULL Character) Integers: 10, 1345, -34 Float or Double: 2.3, -45.18, 10.6e6 String (Specified Inside Double Quotes): “HELLO” , “What a great deal.” , “5”

Input and Output Also Known as I/O Output : Input (Scanner): System.out.println(“Hello World!!”); Input (Scanner): import java.util.Scanner; Scanner scan = new Scanner(System.in); scan.nextInt(); scan.nextFloat(); scan.nextDouble(); scan.next(); //String to whitespace scan.nextLine(); // String to end of line All JAVA Statements End in Semicolon (;)

Input and Output Example import java.util.Scanner; public class MyProgram { public static void main( String [ ] args) Scanner scan = new Scanner(System.in); int numEntered; System.out.print(“Enter an integer:”); numEntered = scan.nextInt(); System.out.println(“You entered: “ + numEntered); }

Characters and Strings Strings in java.lang package Java.lang imported automatically

JAVA Strings Declaration: String yourName; Assigning a Value to a String: yourName = “A. Goose”; String Constants (Values) Must Be Enclosed in Double Quotes

Input String Example import java.util.Scanner; public class MyProgram { public static void main( String [ ] args) Scanner scan = new Scanner(System.in); String lastname; System.out.print(“Enter last name:”); lastname = scan.next(); System.out.println(“You entered: “ + lastname); }

Expressions Expression: A Sequence of One or More Identifiers and Operators that Evaluates to a Value Operator: A Symbol Expressing a Way to Modify a Value or Values (e.g., + for Addition) Operand: A Value Being Modified by an Operator Example Expressions: 5 currentHeight currentHeight + 10

Arithmetic Expressions Standard Arithmetic Operations Can Be Performed: Addition, Subtraction, Multiplication, Division Standard Arithmetic Operators Can Be Used for These Operations: +, -, *, / Others: % - “Modulo (Mod)” – Remainder after Integer Division Example: int num1 = 9, num2 = 5; num1 / num2 is 1 (NOT 1 point something) num1 % num2 is 4 -- Decrement (Subtract 1) ++ Increment (Add 1) num1++; is the same as num1 = num1 + 1;

Order of Operations Precedence: Level of Importance of Operations Multiplicative Operators Have Higher Precedence than Additive Operators: *, /, % Higher +, - Lower Associativity: Order of Operation for Equal Level Precedence Most Operators Have Left-to-Right Associativity Use Parentheses to Force Differing Precedence of Operations

Precedence/Associativity int num1 = 9, num2 = 6, num3 = 8, num4 = 4; num4 = num1 + num2 * num3; num4 = num1 / num2 * num3;