AP Computer Science A
|
|
- Irma Floyd
- 5 years ago
- Views:
Transcription
1 AP Computer Science A 1st Quarter Notes Table of Contents - section links Click on the date or topic below to jump to that section Date : 9/8/2017 Aim : Java Basics Objects and Classes Data types: Primitive and Reference Variables Key words / Reserved words Naming Conventions Comments Assignment and Operands Date: 9/11/2017 Aim: Method Declarations Date: 9/14/2017 Aim: Calling Methods Date : 10/2/2017 Aim : Loops ( for ) & Decisions ( if ) for statement: if-then-else statement: Modulo operator (%): Relational Operators: Increment and Decrement: Error Types: Syntax and Logical Date : 10/12/2017 Aim : String Operations String Operations: Escape Sequences: Date: 10/17/2017 Aim: Math & Numbers (lesson 4) Multiple declarations The assignment operator Fundamental arithmetic operations PEMDAS Increment & Decrement Compound Operators Integer Division Truncation Date: 10/19/2017 Aim: Numbers: Mixed Data Types, Casting, and Constants (lesson 5) Mixed data types Casting Constants
2 Date: 10/25/2017 Aim: Boolean Operators (lesson 8) & Keyboard Input (lesson 7) Boolean Operators: Keyboard Input: String equality: Date: 10/30/2017 Aim: Switch & While (lessons 10 & 12) if versus switch Another if versus switch for versus while while versus do-while Compound Control Expressions More fun stuff Math.random( ); return; if (word.equalsignorecase( hello ))... char letter = word.charat(1); // returns e int offset = word.indexof( e ); // returns 1 int offset = word.tolowerc ase().indexof( h ); // returns 0 (zero) More java string methods:
3 Date : 9/8/2017 Aim : Java Basics Why Java? Java is platform independent - it runs on any computer with a Java interpreter. Almost every browser includes a Java interpreter; therefore almost every computer can interpret Java code. MyProgram.java MyProgram.class My Program (Source code) (Java byte code) (Runs) Objects and Classes All code is written inside Classes We can create a penguin class Classes create Objects We can create penguins named Blackbeard, Bruce, Einstein, Gandhi, and Lindsey. These are all unique objects of the same class. Objects have Properties and Behaviors Properties define what the object has : hat, coat, beard, glasses, shoes, age, etc. Behaviors define what the object does : talk, write, ski, work, etc. Data types: Primitive and Reference Eight primitive data types exist as part of the Java language (we ll use the boldface data types): boolean - true or false byte - integer, 8 bits of storage char - single Unicode character short - integer, 16 bits int - integer, 32 bits long - integer, 64 bits float - decimal, 32 bits double - decimal, 64 bits Reference data types are user-defined classes created using primitive data types Many are available from the Java API library for general use Examples: String Scanner Random Math
4 Variables A Variable is a space in memory that stores a data value of a particular data type. Variables are used to store information which the program needs to do its job. Data types may be defined as a primitive type ( int ), or as an object type ( String ). Examples: boolean hat = false; String job = Scientist ; // double quotes char gender = f ; // single quotes Penguin huey = new Penguin( ); Key words / Reserved words These are words that mean something in Java, and they cannot be used to name anything else. Examples: boolean case class public for do Naming Conventions Naming conventions are not important to Java; they are important to programmers. Class names begin with Uppercase letters Method names begin with lowercase letters Variable names begin with lowercase letters All names MUST be descriptive and can be a combination of two or more words: the words are joined, but the start of each new word is uppercase (ie- typeofcar ) Java is CASE SENSITIVE ( cat!= Cat ) Comments Three types of comments: Single line: // comment, explanation, etc. Multiple line: /* * comment, etc */ JavaDoc (for Documentation Generator): /** hat the type of hat */
5 Assignment and Operands Variables are assigned values using a SINGLE equal sign. char myinitial = W ; String thisschool = CMHS ; double addhalf +=.5; // same as addhalf = addhalf +.5; The right side is evaluated first, and the resulting value is stored in the variable. Operands: + - * / % (addition, subtraction, multiplication, division, modulo) Date : 9/11/2017 Aim : Method Declarations The method declaration requires modifier (public or private) return type name a pair of parentheses ( ) a body between braces { } public int addtwonumbers (int a, int b) { return a + b; } Date : 9/14/2017 Aim : Calling Methods p1.getname(); vs. getname();
6 Date : 10/2/2017 Aim : Loops ( for ) & Decisions ( if ) for loop: Repeats the statement(s) while a given condition is true. if statement: executes a section of code only if a test evaluates to true. else statement: a secondary path when an "if" clause evaluates to false for statement: // initialize the loop control variable for (initialization; BooleanExpression; update) { // Statements } // i is the loop control variable for (int i=0; i < 3; i++) { System.out.println(i); } Program Trace i i < 3 result 0 true 0 1 true 1 2 true 2 3 false if-then-else statement: if (condition) { // statements else if (condition) { // statements else if (condition) { // statements else { // statements if (grade==100) { letter = A+ else if (grade>=90) { letter = A ; else if (grade>=80) { letter = B ; else { // grade < 80 letter = C ; Modulo operator (%): Returns the remainder of two numbers: 1 R 2 12 % 10 = 2 10 ) Often used to determine if a number is odd or even (if the number % 2 is 0 it s even) Relational Operators: < > <= >= ==!= Note: Equality contains TWO equal signs Not is always represented with an exclamation point
7 Increment and Decrement: Increment: add 1 long way: i = i + 1; abbreviated: ++i; i++; Decrement: subtract 1 long way: i = i - 1; abbreviated: --i; i--; Error Types: Syntax and Logical Syntax errors: Program won t compile due to errors with spelling, punctuation, etc. Logical errors: Program compiles but doesn t do what you want it to? Which one is harder to debug? Date : 10/12/2017 Aim : String Operations String Operations: Concatenation : Put one string at the end of another String x = hello + there ; Length : returns the # of characters in a string int c = s1.length( ); touppercase : s2 = s1.touppercase(); tolowercase : s3 = s1.tolowercase(); Substring: Extract a subset of a String: beginning at the OFFSET specified String s1 = Good Morning! ; // G o o d M o r n i n g // String sub1 = s1.substring(3); // sub1 contains d Morning! beginning at the offset (inclusive), ending at the offset (exclusive) String sub2 = s1.substring(3,7); // 3,4,5,6 // sub2 contains d Mo Escape Sequences: Allows inclusion of special characters in a String String str = Say \ Hi\ to him. ; // str will contain: Say Hi to him. Sequence Inserts a \t tab \n new line \" double quote \\ backslash
8 Date : 10/17/2017 Aim : Math & Numbers (lesson 4) Multiple declarations It s possible to declare and / or initialize multiple variables in one statement: double x = 31.2, m, p = ; int i, j = 2, k; note: declare vs. initialize The assignment operator Equal Sign = Fundamental arithmetic operations Addition + Subtraction - Multiplication * Division / Modulo % PEMDAS ( ) exponent * / + - Increment & Decrement ++i Increment i, then use it i++ Use i, then increment it --i Decrement i, then use it i -- Use i, then decrement it System.out.println(i++); System.out.println(++i); Compound Operators Compound Operator Example Meaning += x += 3; x = x + 3; -= x -= y - 2; x = x - (y - 2); *= z *= 46; z = z * 46; /= p /= x-z; p = p / (x - z); %= j %= 2 j = j % 2; Integer Division Truncation When dividing two integers, the fractional part is truncated (thrown away): int x = 5; int y = 2; int z = x / y; // the answer is 2
9 Date : 10/19/2017 Aim : Numbers: Mixed Data Types, Casting, and Constants (lesson 5) Mixed data types: Calculations with double and int Casting: Forcing a variable to a new type Constants: A variable s value CANNOT change Mixed data types Calculations with double and int Java does not like to lose data. It will always want to store a result in the most precise data type involved. If it can t it will give an error: double d = 29.78; int i = d; // error, data loss int p = * 6.0; //error int j = 29; double k = j; // ok, no data loss Casting Forcing one data type into another double d = 29.78; int ii = (int) d; // forcing d into an int The casting only applies to the number, variable, or parenthetical expression that immediately follows the cast. double d = (double)5 / 4; // 1.25 double e = (double)(5 / 4); //1.0 Remember that when a calculation has numbers that are different data types the result will be the more precise: int m = 4 / 2 * 1.0; // error Constants Variables whose values will not change final double PI = ; PI = 72.0; // error The word final is used The variable name is all UPPERCASE Can be created for any data type final String NAME = Mercy ; final int SECTIONS = 8;
10 Date : 10/25/2017 Aim : Boolean Operators (lesson 8) & Keyboard Input (lesson 7) Boolean Operators: == equal > greater than!= not equal >= greater / equal < less than && and <= less / equal or! not -- applied to boolean variables -- ex: if (!a == b) Truth tables How && ( and ) and ( or ) work with combinations of a and b: a b (a && b) a b (a b) false false false false false false false true false false true true true false false true false true true true true true true true Keyboard Input: 1 - Import the Java io and utility libraries import java.io.*; import java.util.*; 2 - Declare an object to associate with the keyboard - a Scanner object - and give it a name Scanner kb = new Scanner(System.in); 3 - Use the Scanner methods String input = kb.nextline(); Create an object: Scanner kb = new Scanner(System.in); Methods in the Scanner class String equality: nextint(); nextdouble(); next(); nextline(); // kb.nextint(); // kb.nextdouble(); // kb.next(); // kb.nextline(); When comparing two String objects you CANNOT use the == comparator You must use String s equals method: String fruit_1 = apple ; String fruit_2 = cantaloupe ; if (fruit_1.equals(fruit_2)) System.out.println( same ); if (!fruit_1.equals(fruit_2)) System.out.println( different );
11 Date: 10/30/2017 Aim: Switch & While (lessons 10 & 12) The switch statement is an alternative to the if-then-else decision statement. It is easier to read and write. The while and do-while statements are an alternative to the for loop statement. All 3 are loops but each is used for a different purpose. if versus switch String todo; // more code if (todo.equals( + )) { answer = a + b; else if (todo.equals( - )) { answer = a - b; else if (todo.equals( x )) { answer = a * b; else { // division answer = a / b; String todo; //---- more code switch (todo) { case + : answer = a + b; break; case - : answer = a - b; break; case x : answer = a * b; break; default: answer = a / b; } Another if versus switch if (num <= 3) { answer = low ; } else if (num <=6 ) { answer = middle ; } else answer = top ; switch (num) { case 1: case 2: case 3: answer = low ; break; case 4: case 5: case 6: answer = middle ; break; default: answer = top ;
12 for versus while for (int i=1; i <=10; i++) { System.out.println(i); // versus: Scanner kb = new Scanner (System.in); boolean done = false; String answer; // control expression: i <=10; while (!done) { // control expression:!done System.out.println( Finished? (yes or no) ); answer = kb.nextline(); done = (answer.equals( yes )); while versus do-while while (!done) { // control expression before the loop System.out.println( Finished? (yes or no) ); answer = kb.nextline(); done = (answer.equals( yes )); // versus: do { System.out.println( Finished? (yes or no) ); answer = kb.nextline(); done = (answer.equals( yes )); while (!done); // control expression after Compound Control Expressions int loops = 0; while (!done && loops <= 3 ) { System.out.println( Finished? (yes or no) ); answer = kb.nextline(); done = (answer.equals( yes )); loops++;
13 Math.random( ); More fun stuff Returns a number between 0 (inclusive) and 1 (exclusive) If you want a random number within a range, multiply the result by the high end of the range Math.random( ) * 5; // returns a number between 0 (inclusive) and 5 (exclusive) return; Exits the program String word = Hello ; if (word.equalsignorecase( hello ))... char letter = word.charat(1); // returns e int offset = word.indexof( e ); // returns 1 int offset = word.tolowercase().indexof( h ); // returns 0 (zero) More java string methods:
CSCI 2010 Principles of Computer Science. Data and Expressions 08/09/2013 CSCI
CSCI 2010 Principles of Computer Science Data and Expressions 08/09/2013 CSCI 2010 1 Data Types, Variables and Expressions in Java We look at the primitive data types, strings and expressions that are
More informationData and Expressions. Outline. Data and Expressions 12/18/2010. Let's explore some other fundamental programming concepts. Chapter 2 focuses on:
Data and Expressions Data and Expressions Let's explore some other fundamental programming concepts Chapter 2 focuses on: Character Strings Primitive Data The Declaration And Use Of Variables Expressions
More informationFull file at
Java Programming: From Problem Analysis to Program Design, 3 rd Edition 2-1 Chapter 2 Basic Elements of Java At a Glance Instructor s Manual Table of Contents Overview Objectives s Quick Quizzes Class
More informationChapter 2: Data and Expressions
Chapter 2: Data and Expressions CS 121 Department of Computer Science College of Engineering Boise State University January 15, 2015 Chapter 2: Data and Expressions CS 121 1 / 1 Chapter 2 Part 1: Data
More informationA variable is a name for a location in memory A variable must be declared
Variables A variable is a name for a location in memory A variable must be declared, specifying the variable's name and the type of information that will be held in it data type variable name int total;
More informationChapter 2: Data and Expressions
Chapter 2: Data and Expressions CS 121 Department of Computer Science College of Engineering Boise State University April 21, 2015 Chapter 2: Data and Expressions CS 121 1 / 53 Chapter 2 Part 1: Data Types
More informationECE 122 Engineering Problem Solving with Java
ECE 122 Engineering Problem Solving with Java Lecture 3 Expression Evaluation and Program Interaction Outline Problem: How do I input data and use it in complicated expressions Creating complicated expressions
More informationLecture 6. Assignments. Summary - Variables. Summary Program Parts 1/29/18. Reading: 3.1, 3.2, 3.3, 3.4
Assignments Lecture 6 Complete for Project 1 Reading: 3.1, 3.2, 3.3, 3.4 Summary Program Parts Summary - Variables Class Header (class name matches the file name prefix) Class Body Because this is a program,
More informationCS313D: ADVANCED PROGRAMMING LANGUAGE
CS313D: ADVANCED PROGRAMMING LANGUAGE Computer Science department Lecture 2 : C# Language Basics Lecture Contents 2 The C# language First program Variables and constants Input/output Expressions and casting
More informationData and Variables. Data Types Expressions. String Concatenation Variables Declaration Assignment Shorthand operators. Operators Precedence
Data and Variables Data Types Expressions Operators Precedence String Concatenation Variables Declaration Assignment Shorthand operators Review class All code in a java file is written in a class public
More informationCONTENTS: Compilation Data and Expressions COMP 202. More on Chapter 2
CONTENTS: Compilation Data and Expressions COMP 202 More on Chapter 2 Programming Language Levels There are many programming language levels: machine language assembly language high-level language Java,
More informationUsing Java Classes Fall 2018 Margaret Reid-Miller
Using Java Classes 15-121 Fall 2018 Margaret Reid-Miller Today Strings I/O (using Scanner) Loops, Conditionals, Scope Math Class (random) Fall 2018 15-121 (Reid-Miller) 2 The Math Class The Math class
More informationComputational Expression
Computational Expression Variables, Primitive Data Types, Expressions Janyl Jumadinova 28-30 January, 2019 Janyl Jumadinova Computational Expression 28-30 January, 2019 1 / 17 Variables Variable is a name
More informationChapter. Let's explore some other fundamental programming concepts
Data and Expressions 2 Chapter 5 TH EDITION Lewis & Loftus java Software Solutions Foundations of Program Design 2007 Pearson Addison-Wesley. All rights reserved Data and Expressions Let's explore some
More informationcis20.1 design and implementation of software applications I fall 2007 lecture # I.2 topics: introduction to java, part 1
topics: introduction to java, part 1 cis20.1 design and implementation of software applications I fall 2007 lecture # I.2 cis20.1-fall2007-sklar-leci.2 1 Java. Java is an object-oriented language: it is
More informationLesson 02 Data Types and Statements. MIT 12043, Fundamentals of Programming By: S. Sabraz Nawaz Senior Lecturer in MIT Department of MIT FMC, SEUSL
Lesson 02 Data Types and Statements MIT 12043, Fundamentals of Programming By: S. Sabraz Nawaz Senior Lecturer in MIT Department of MIT FMC, SEUSL Topics Covered Statements Variables Constants Data Types
More informationExpressions and Data Types CSC 121 Spring 2015 Howard Rosenthal
Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal Lesson Goals Understand the basic constructs of a Java Program Understand how to use basic identifiers Understand simple Java data types
More informationTOPIC 2 INTRODUCTION TO JAVA AND DR JAVA
1 TOPIC 2 INTRODUCTION TO JAVA AND DR JAVA Notes adapted from Introduction to Computing and Programming with Java: A Multimedia Approach by M. Guzdial and B. Ericson, and instructor materials prepared
More informationEntry Point of Execution: the main Method. Elementary Programming. Learning Outcomes. Development Process
Entry Point of Execution: the main Method Elementary Programming EECS1021: Object Oriented Programming: from Sensors to Actuators Winter 2019 CHEN-WEI WANG For now, all your programming exercises will
More informationProgramming with Java
Programming with Java Data Types & Input Statement Lecture 04 First stage Software Engineering Dep. Saman M. Omer 2017-2018 Objectives q By the end of this lecture you should be able to : ü Know rules
More informationTester vs. Controller. Elementary Programming. Learning Outcomes. Compile Time vs. Run Time
Tester vs. Controller Elementary Programming EECS1022: Programming for Mobile Computing Winter 2018 CHEN-WEI WANG For effective illustrations, code examples will mostly be written in the form of a tester
More informationElementary Programming
Elementary Programming EECS1022: Programming for Mobile Computing Winter 2018 CHEN-WEI WANG Learning Outcomes Learn ingredients of elementary programming: data types [numbers, characters, strings] literal
More informationChapter 2 Primitive Data Types and Operations. Objectives
Chapter 2 Primitive Data Types and Operations Prerequisites for Part I Basic computer skills such as using Windows, Internet Explorer, and Microsoft Word Chapter 1 Introduction to Computers, Programs,
More informationLecture Notes. System.out.println( Circle radius: + radius + area: + area); radius radius area area value
Lecture Notes 1. Comments a. /* */ b. // 2. Program Structures a. public class ComputeArea { public static void main(string[ ] args) { // input radius // compute area algorithm // output area Actions to
More informationHUDSONVILLE HIGH SCHOOL COURSE FRAMEWORK
HUDSONVILLE HIGH SCHOOL COURSE FRAMEWORK COURSE / SUBJECT Introduction to Programming KEY COURSE OBJECTIVES/ENDURING UNDERSTANDINGS OVERARCHING/ESSENTIAL SKILLS OR QUESTIONS Introduction to Java Java Essentials
More informationLecture Set 2: Starting Java
Lecture Set 2: Starting Java 1. Java Concepts 2. Java Programming Basics 3. User output 4. Variables and types 5. Expressions 6. User input 7. Uninitialized Variables 0 This Course: Intro to Procedural
More informationProgram Fundamentals
Program Fundamentals /* HelloWorld.java * The classic Hello, world! program */ class HelloWorld { public static void main (String[ ] args) { System.out.println( Hello, world! ); } } /* HelloWorld.java
More informationChapter 2: Data and Expressions
Chapter 2: Data and Expressions CS 121 Department of Computer Science College of Engineering Boise State University August 21, 2017 Chapter 2: Data and Expressions CS 121 1 / 51 Chapter 1 Terminology Review
More informationLecture 6. Assignments. Java Scanner. User Input 1/29/18. Reading: 2.12, 2.13, 3.1, 3.2, 3.3, 3.4
Assignments Reading: 2.12, 2.13, 3.1, 3.2, 3.3, 3.4 Lecture 6 Complete for Lab 4, Project 1 Note: Slides 12 19 are summary slides for Chapter 2. They overview much of what we covered but are not complete.
More informationLecture Set 2: Starting Java
Lecture Set 2: Starting Java 1. Java Concepts 2. Java Programming Basics 3. User output 4. Variables and types 5. Expressions 6. User input 7. Uninitialized Variables 0 This Course: Intro to Procedural
More informationLesson 02 Data Types and Statements. MIT 11053, Fundamentals of Programming By: S. Sabraz Nawaz Senior Lecturer in MIT Department of MIT FMC, SEUSL
Lesson 02 Data Types and Statements MIT 11053, Fundamentals of Programming By: S. Sabraz Nawaz Senior Lecturer in MIT Department of MIT FMC, SEUSL Topics Covered Statements Variables Data Types Arithmetic
More informationProgram Elements -- Introduction
Program Elements -- Introduction We can now examine the core elements of programming Chapter 3 focuses on: data types variable declaration and use operators and expressions decisions and loops input and
More informationBASIC COMPUTATION. public static void main(string [] args) Fundamentals of Computer Science I
BASIC COMPUTATION x public static void main(string [] args) Fundamentals of Computer Science I Outline Using Eclipse Data Types Variables Primitive and Class Data Types Expressions Declaration Assignment
More informationReview Chapters 1 to 4. Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013
Review Chapters 1 to 4 Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013 Introduction to Java Chapters 1 and 2 The Java Language Section 1.1 Data & Expressions Sections 2.1 2.5 Instructor:
More informationComputational Expression
Computational Expression Scanner, Increment/Decrement, Conversion Janyl Jumadinova 17 September, 2018 Janyl Jumadinova Computational Expression 17 September, 2018 1 / 11 Review: Scanner The Scanner class
More informationboolean, char, class, const, double, else, final, float, for, if, import, int, long, new, public, return, static, throws, void, while
CSCI 150 Fall 2007 Java Syntax The following notes are meant to be a quick cheat sheet for Java. It is not meant to be a means on its own to learn Java or this course. For that you should look at your
More informationCOMP Primitive and Class Types. Yi Hong May 14, 2015
COMP 110-001 Primitive and Class Types Yi Hong May 14, 2015 Review What are the two major parts of an object? What is the relationship between class and object? Design a simple class for Student How to
More informationVisual C# Instructor s Manual Table of Contents
Visual C# 2005 2-1 Chapter 2 Using Data At a Glance Instructor s Manual Table of Contents Overview Objectives s Quick Quizzes Class Discussion Topics Additional Projects Additional Resources Key Terms
More informationBasic Computation. Chapter 2
Basic Computation Chapter 2 Outline Variables and Expressions The Class String Keyboard and Screen I/O Documentation and Style Variables Variables store data such as numbers and letters. Think of them
More informationData Conversion & Scanner Class
Data Conversion & Scanner Class Quick review of last lecture August 29, 2007 ComS 207: Programming I (in Java) Iowa State University, FALL 2007 Instructor: Alexander Stoytchev Numeric Primitive Data Storing
More informationChapter 2 ELEMENTARY PROGRAMMING
Chapter 2 ELEMENTARY PROGRAMMING Lecture notes for computer programming 1 Faculty of Engineering and Information Technology Prepared by: Iyad Albayouk ١ Objectives To write Java programs to perform simple
More informationExpressions and Data Types CSC 121 Fall 2015 Howard Rosenthal
Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal Lesson Goals Understand the basic constructs of a Java Program Understand how to use basic identifiers Understand simple Java data types and
More informationBasic Computation. Chapter 2
Walter Savitch Frank M. Carrano Basic Computation Chapter 2 Outline Variables and Expressions The Class String Keyboard and Screen I/O Documentation and Style Variables Variables store data such as numbers
More information2: Basics of Java Programming
2: Basics of Java Programming CSC 1051 Algorithms and Data Structures I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website: www.csc.villanova.edu/~map/1051/
More information4 Programming Fundamentals. Introduction to Programming 1 1
4 Programming Fundamentals Introduction to Programming 1 1 Objectives At the end of the lesson, the student should be able to: Identify the basic parts of a Java program Differentiate among Java literals,
More informationIntroduction to Java & Fundamental Data Types
Introduction to Java & Fundamental Data Types LECTURER: ATHENA TOUMBOURI How to Create a New Java Project in Eclipse Eclipse is one of the most popular development environments for Java, as it contains
More informationEntry Point of Execution: the main Method. Elementary Programming. Compile Time vs. Run Time. Learning Outcomes
Entry Point of Execution: the main Method Elementary Programming EECS2030: Advanced Object Oriented Programming Fall 2017 CHEN-WEI WANG For now, all your programming exercises will be defined within the
More informationCS 302: Introduction to Programming
CS 302: Introduction to Programming Lectures 2-3 CS302 Summer 2012 1 Review What is a computer? What is a computer program? Why do we have high-level programming languages? How does a high-level program
More informationChapter 2 Elementary Programming
Chapter 2 Elementary Programming Part I 1 Motivations In the preceding chapter, you learned how to create, compile, and run a Java program. Starting from this chapter, you will learn how to solve practical
More informationEx: If you use a program to record sales, you will want to remember data:
Data Variables Programs need to remember values. Ex: If you use a program to record sales, you will want to remember data: A loaf of bread was sold to Sione Latu on 14/02/19 for T$1.00. Customer Name:
More informationDefine a method vs. calling a method. Chapter Goals. Contents 1/21/13
CHAPTER 2 Define a method vs. calling a method Line 3 defines a method called main Line 5 calls a method called println, which is defined in the Java library You will learn later how to define your own
More informationc) And last but not least, there are javadoc comments. See Weiss.
CSCI 151 Spring 2010 Java Bootcamp The following notes are meant to be a quick refresher on Java. It is not meant to be a means on its own to learn Java. For that you would need a lot more detail (for
More informationAP Computer Science Unit 1. Programs
AP Computer Science Unit 1. Programs Open DrJava. Under the File menu click on New Java Class and the window to the right should appear. Fill in the information as shown and click OK. This code is generated
More informationCS 106 Introduction to Computer Science I
CS 106 Introduction to Computer Science I 05 / 31 / 2017 Instructor: Michael Eckmann Today s Topics Questions / Comments? recap and some more details about variables, and if / else statements do lab work
More informationChapter 4 Fundamental Data Types. Big Java by Cay Horstmann Copyright 2009 by John Wiley & Sons. All rights reserved.
Chapter 4 Fundamental Data Types Chapter Goals To understand integer and floating-point numbers To recognize the limitations of the numeric types To become aware of causes for overflow and roundoff errors
More information2/9/2012. Chapter Four: Fundamental Data Types. Chapter Goals
Chapter Four: Fundamental Data Types Chapter Goals To understand integer and floating-point numbers To recognize the limitations of the numeric types To become aware of causes for overflow and roundoff
More informationChapter 2 Using Data. Instructor s Manual Table of Contents. At a Glance. A Guide to this Instructor s Manual:
Java Programming, Eighth Edition 2-1 Chapter 2 Using Data A Guide to this Instructor s Manual: We have designed this Instructor s Manual to supplement and enhance your teaching experience through classroom
More informationWhat did we talk about last time? Examples switch statements
Week 4 - Friday What did we talk about last time? Examples switch statements History of computers Hardware Software development Basic Java syntax Output with System.out.print() Mechanical Calculation
More informationJava Foundations: Introduction to Program Design & Data Structures, 4e John Lewis, Peter DePasquale, Joseph Chase Test Bank: Chapter 2
Java Foundations Introduction to Program Design and Data Structures 4th Edition Lewis TEST BANK Full download at : https://testbankreal.com/download/java-foundations-introduction-toprogram-design-and-data-structures-4th-edition-lewis-test-bank/
More informationDATA TYPES AND EXPRESSIONS
DATA TYPES AND EXPRESSIONS Outline Variables Naming Conventions Data Types Primitive Data Types Review: int, double New: boolean, char The String Class Type Conversion Expressions Assignment Mathematical
More informationMr. Monroe s Guide to Mastering Java Syntax
Mr. Monroe s Guide to Mastering Java Syntax Getting Started with Java 1. Download and install the official JDK (Java Development Kit). 2. Download an IDE (Integrated Development Environment), like BlueJ.
More informationStudyHub+ 1. StudyHub: AP Java. Semester One Final Review
StudyHub+ 1 StudyHub: AP Java Semester One Final Review StudyHub+ 2 Terminology: Primitive Data Type: Most basic data types in the Java language. The eight primitive data types are: Char: A single character
More informationBasics of Java Programming
Basics of Java Programming Lecture 2 COP 3252 Summer 2017 May 16, 2017 Components of a Java Program statements - A statement is some action or sequence of actions, given as a command in code. A statement
More informationWe now start exploring some key elements of the Java programming language and ways of performing I/O
We now start exploring some key elements of the Java programming language and ways of performing I/O This week we focus on: Introduction to objects The String class String concatenation Creating objects
More informationIntroduction To Java. Chapter 1. Origins of the Java Language. Origins of the Java Language. Objects and Methods. Origins of the Java Language
Chapter 1 Getting Started Introduction To Java Most people are familiar with Java as a language for Internet applications We will study Java as a general purpose programming language The syntax of expressions
More informationHello World. n Variables store information. n You can think of them like boxes. n They hold values. n The value of a variable is its current contents
Variables in a programming language Basic Computation (Savitch, Chapter 2) TOPICS Variables and Data Types Expressions and Operators Integers and Real Numbers Characters and Strings Input and Output Variables
More informationUnit 4: Classes and Objects Notes
Unit 4: Classes and Objects Notes AP CS A Another Data Type. So far, we have used two types of primitive variables: ints and doubles. Another data type is the boolean data type. Variables of type boolean
More informationDeclaration and Memory
Declaration and Memory With the declaration int width; the compiler will set aside a 4-byte (32-bit) block of memory (see right) The compiler has a symbol table, which will have an entry such as Identifier
More information12/22/11. Java How to Program, 9/e. Help you get started with Eclipse and NetBeans integrated development environments.
Java How to Program, 9/e Education, Inc. All Rights Reserved. } Java application programming } Use tools from the JDK to compile and run programs. } Videos at www.deitel.com/books/jhtp9/ Help you get started
More informationChapter 3 Syntax, Errors, and Debugging. Fundamentals of Java
Chapter 3 Syntax, Errors, and Debugging Objectives Construct and use numeric and string literals. Name and use variables and constants. Create arithmetic expressions. Understand the precedence of different
More informationChapter 2 Part 2 Edited by JJ Shepherd, James O Reilly
Basic Computation Chapter 2 Part 2 Edited by JJ Shepherd, James O Reilly Parentheses and Precedence Parentheses can communicate the order in which arithmetic operations are performed examples: (cost +
More informationFull file at
Java Programming, Fifth Edition 2-1 Chapter 2 Using Data within a Program At a Glance Instructor s Manual Table of Contents Overview Objectives Teaching Tips Quick Quizzes Class Discussion Topics Additional
More informationCourse Outline. Introduction to java
Course Outline 1. Introduction to OO programming 2. Language Basics Syntax and Semantics 3. Algorithms, stepwise refinements. 4. Quiz/Assignment ( 5. Repetitions (for loops) 6. Writing simple classes 7.
More informationCS5000: Foundations of Programming. Mingon Kang, PhD Computer Science, Kennesaw State University
CS5000: Foundations of Programming Mingon Kang, PhD Computer Science, Kennesaw State University Overview of Source Code Components Comments Library declaration Classes Functions Variables Comments Can
More informationProfessor: Sana Odeh Lecture 3 Python 3.1 Variables, Primitive Data Types & arithmetic operators
1 Professor: Sana Odeh odeh@courant.nyu.edu Lecture 3 Python 3.1 Variables, Primitive Data Types & arithmetic operators Review What s wrong with this line of code? print( He said Hello ) What s wrong with
More informationInterpreted vs Compiled. Java Compile. Classes, Objects, and Methods. Hello World 10/6/2016. Python Interpreted. Java Compiled
Interpreted vs Compiled Python 1 Java Interpreted Easy to run and test Quicker prototyping Program runs slower Compiled Execution time faster Virtual Machine compiled code portable Java Compile > javac
More informationCOMP 202. Built in Libraries and objects. CONTENTS: Introduction to objects Introduction to some basic Java libraries string
COMP 202 Built in Libraries and objects CONTENTS: Introduction to objects Introduction to some basic Java libraries string COMP 202 Objects and Built in Libraries 1 Classes and Objects An object is an
More informationSection 2: Introduction to Java. Historical note
The only way to learn a new programming language is by writing programs in it. - B. Kernighan & D. Ritchie Section 2: Introduction to Java Objectives: Data Types Characters and Strings Operators and Precedence
More informationHomework Set 1- Fundamentals
1 Homework Set 1- Fundamentals Topics if statements with ints if-else statements with Strings if statements with multiple boolean statements for loops and arrays while loops String ".equals()" method "=="
More informationChapter 2 Using Data. Instructor s Manual Table of Contents. At a Glance. Overview. Objectives. Teaching Tips. Quick Quizzes. Class Discussion Topics
Java Programming, Sixth Edition 2-1 Chapter 2 Using Data At a Glance Instructor s Manual Table of Contents Overview Objectives Teaching Tips Quick Quizzes Class Discussion Topics Additional Projects Additional
More informationCOMP-202 Unit 2: Java Basics. CONTENTS: Using Expressions and Variables Types Strings Methods
COMP-202 Unit 2: Java Basics CONTENTS: Using Expressions and Variables Types Strings Methods Assignment 1 Assignment 1 posted on WebCt and course website. It is due May 18th st at 23:30 Worth 6% Part programming,
More informationCMPT 125: Lecture 3 Data and Expressions
CMPT 125: Lecture 3 Data and Expressions Tamara Smyth, tamaras@cs.sfu.ca School of Computing Science, Simon Fraser University January 3, 2009 1 Character Strings A character string is an object in Java,
More informationJAVA Programming Fundamentals
Chapter 4 JAVA Programming Fundamentals By: Deepak Bhinde PGT Comp.Sc. JAVA character set Character set is a set of valid characters that a language can recognize. It may be any letter, digit or any symbol
More informationCOMP-202: Foundations of Programming. Lecture 2: Variables, and Data Types Sandeep Manjanna, Summer 2015
COMP-202: Foundations of Programming Lecture 2: Variables, and Data Types Sandeep Manjanna, Summer 2015 Announcements Midterm Exams on 4 th of June (12:35 14:35) Room allocation will be announced soon
More informationExam 1 Prep. Dr. Demetrios Glinos University of Central Florida. COP3330 Object Oriented Programming
Exam 1 Prep Dr. Demetrios Glinos University of Central Florida COP3330 Object Oriented Programming Progress Exam 1 is a Timed Webcourses Quiz You can find it from the "Assignments" link on Webcourses choose
More informationZheng-Liang Lu Java Programming 45 / 79
1 class Lecture2 { 2 3 "Elementray Programming" 4 5 } 6 7 / References 8 [1] Ch. 2 in YDL 9 [2] Ch. 2 and 3 in Sharan 10 [3] Ch. 2 in HS 11 / Zheng-Liang Lu Java Programming 45 / 79 Example Given a radius
More informationObject-Oriented Programming
Object-Oriented Programming Java Syntax Program Structure Variables and basic data types. Industry standard naming conventions. Java syntax and coding conventions If Then Else Case statements Looping (for,
More informationFirst Java Program - Output to the Screen
First Java Program - Output to the Screen These notes are written assuming that the reader has never programmed in Java, but has programmed in another language in the past. In any language, one of the
More informationdouble float char In a method: final typename variablename = expression ;
Chapter 4 Fundamental Data Types The Plan For Today Return Chapter 3 Assignment/Exam Corrections Chapter 4 4.4: Arithmetic Operations and Mathematical Functions 4.5: Calling Static Methods 4.6: Strings
More informationBasics of Java Programming variables, assignment, and input
Basics of Java Programming variables, assignment, and input CSC 1051 Algorithms and Data Structures I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website: www.csc.villanova.edu/~map/1051/
More informationChapter 2. C++ Basics. Copyright 2014 Pearson Addison-Wesley. All rights reserved.
Chapter 2 C++ Basics 1 Overview 2.1 Variables and Assignments 2.2 Input and Output 2.3 Data Types and Expressions 2.4 Simple Flow of Control 2.5 Program Style Slide 2-3 2.1 Variables and Assignments 2
More informationMobile Computing Professor Pushpendra Singh Indraprastha Institute of Information Technology Delhi Java Basics Lecture 02
Mobile Computing Professor Pushpendra Singh Indraprastha Institute of Information Technology Delhi Java Basics Lecture 02 Hello, in this lecture we will learn about some fundamentals concepts of java.
More informationPrimitive Data Types: Intro
Primitive Data Types: Intro Primitive data types represent single values and are built into a language Java primitive numeric data types: 1. Integral types (a) byte (b) int (c) short (d) long 2. Real types
More informationDM550 / DM857 Introduction to Programming. Peter Schneider-Kamp
DM550 / DM857 Introduction to Programming Peter Schneider-Kamp petersk@imada.sdu.dk http://imada.sdu.dk/~petersk/dm550/ http://imada.sdu.dk/~petersk/dm857/ OBJECT-ORIENTED PROGRAMMING IN JAVA 2 Programming
More informationLanguage Reference Manual
ALACS Language Reference Manual Manager: Gabriel Lopez (gal2129) Language Guru: Gabriel Kramer-Garcia (glk2110) System Architect: Candace Johnson (crj2121) Tester: Terence Jacobs (tj2316) Table of Contents
More informationCOMP-202 Unit 2: Java Basics. CONTENTS: Printing to the Screen Getting input from the user Types of variables Using Expressions and Variables
COMP-202 Unit 2: Java Basics CONTENTS: Printing to the Screen Getting input from the user Types of variables Using Expressions and Variables Assignment 1 Assignment 1 posted on WebCt and course website.
More informationCIS 110: Introduction to Computer Programming
CIS 110: Introduction to Computer Programming Lecture 3 Express Yourself ( 2.1) 9/16/2011 CIS 110 (11fa) - University of Pennsylvania 1 Outline 1. Data representation and types 2. Expressions 9/16/2011
More informationWeek 6: Review. Java is Case Sensitive
Week 6: Review Java Language Elements: special characters, reserved keywords, variables, operators & expressions, syntax, objects, scoping, Robot world 7 will be used on the midterm. Java is Case Sensitive
More informationJAVA Programming Concepts
JAVA Programming Concepts M. G. Abbas Malik Assistant Professor Faculty of Computing and Information Technology University of Jeddah, Jeddah, KSA mgmalik@uj.edu.sa Programming is the art of Problem Solving
More informationChapter 2. Elementary Programming
Chapter 2 Elementary Programming 1 Objectives To write Java programs to perform simple calculations To obtain input from the console using the Scanner class To use identifiers to name variables, constants,
More information