StudyHub+ 1. StudyHub: AP Java. Semester One Final Review

Similar documents
CSCI 2010 Principles of Computer Science. Data and Expressions 08/09/2013 CSCI

CS313D: ADVANCED PROGRAMMING LANGUAGE

AP Computer Science A

Datatypes, Variables, and Operations

Data and Expressions. Outline. Data and Expressions 12/18/2010. Let's explore some other fundamental programming concepts. Chapter 2 focuses on:

DATA TYPES AND EXPRESSIONS

CSc 10200! Introduction to Computing. Lecture 2-3 Edgardo Molina Fall 2013 City College of New York

Full file at

Review: Exam 1. Your First C++ Program. Declaration Statements. Tells the compiler. Examples of declaration statements

CS 106 Introduction to Computer Science I

Introduction to Computer Science and Object-Oriented Programming

Data types Expressions Variables Assignment. COMP1400 Week 2

A variable is a name for a location in memory A variable must be declared

Chapter 2 Using Data. Instructor s Manual Table of Contents. At a Glance. Overview. Objectives. Teaching Tips. Quick Quizzes. Class Discussion Topics

Program Elements -- Introduction

COMP Primitive and Class Types. Yi Hong May 14, 2015

BEGINNING PROBLEM-SOLVING CONCEPTS FOR THE COMPUTER. Chapter 2

Java Basic Programming Constructs

Introduction to Computer Science Unit 2. Notes

Object-Oriented Programming

Ex: If you use a program to record sales, you will want to remember data:

Programming Projects: 2.1, 2.3, 2.4, 2.7, 2.8, 2.13

Chapter 2: Using Data

CIS133J. Working with Numbers in Java

Interpreted vs Compiled. Java Compile. Classes, Objects, and Methods. Hello World 10/6/2016. Python Interpreted. Java Compiled

Lecture 2 Tao Wang 1

Key Concept: all programs can be broken down to a combination of one of the six instructions Assignment Statements can create variables to represent

BASIC COMPUTATION. public static void main(string [] args) Fundamentals of Computer Science I

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal

Solving Equations with Inverse Operations

LESSON 2 VARIABLES, OPERATORS, EXPRESSIONS, AND USER INPUT

Outline. Data and Operations. Data Types. Integral Types

Course Outline. Introduction to java

Lecture 6. Assignments. Java Scanner. User Input 1/29/18. Reading: 2.12, 2.13, 3.1, 3.2, 3.3, 3.4

Week 2: Console I/O and Operators Arithmetic Operators. Integer Division. Arithmetic Operators. Gaddis: Chapter 3 (2.14,3.1-6,3.9-10,5.

TOPIC 2 INTRODUCTION TO JAVA AND DR JAVA

The Warhol Language Reference Manual

M e t h o d s a n d P a r a m e t e r s

Chapter 3 Syntax, Errors, and Debugging. Fundamentals of Java

Lecture 6. Assignments. Summary - Variables. Summary Program Parts 1/29/18. Reading: 3.1, 3.2, 3.3, 3.4

Computational Expression

Chapter. Let's explore some other fundamental programming concepts

Basic operators, Arithmetic, Relational, Bitwise, Logical, Assignment, Conditional operators. JAVA Standard Edition

Review Chapters 1 to 4. Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013

cis20.1 design and implementation of software applications I fall 2007 lecture # I.2 topics: introduction to java, part 1

Chapter 2: Data and Expressions

Introduction to Java Chapters 1 and 2 The Java Language Section 1.1 Data & Expressions Sections

Basics of Java Programming

Values, Variables, Types & Arithmetic Expressions. Agenda

ECE 122 Engineering Problem Solving with Java

Program Fundamentals

Programming and Data Structures

Creating a C++ Program

3. Simple Types, Variables, and Constants

Visual C# Instructor s Manual Table of Contents

Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal

REVIEW. The C++ Programming Language. CS 151 Review #2

Important Java terminology

Chapter 1 Introduction to Java

ENGR 101 Engineering Design Workshop

Peer Instruction 1. Elementary Programming

Prof. Navrati Saxena TA: Rochak Sachan

1 Epic Test Review 2 Epic Test Review 3 Epic Test Review 4. Epic Test Review 5 Epic Test Review 6 Epic Test Review 7 Epic Test Review 8

Data and Variables. Data Types Expressions. String Concatenation Variables Declaration Assignment Shorthand operators. Operators Precedence

Variables, Constants, and Data Types

Building Java Programs

Define a method vs. calling a method. Chapter Goals. Contents 1/21/13

Basics of Java Programming variables, assignment, and input

Fundamentals of Programming CS-110. Lecture 2

Chapter 2: Using Data

CS1004: Intro to CS in Java, Spring 2005

CS 112 Introduction to Programming

Admin. CS 112 Introduction to Programming. Recap: Java Static Methods. Recap: Decomposition Example. Recap: Static Method Example

CS5000: Foundations of Programming. Mingon Kang, PhD Computer Science, Kennesaw State University

Chapter 2: Introduction to C++

Language Reference Manual

Lecture 3 Tao Wang 1

Declaration and Memory

Chapter 2: Special Characters. Parts of a C++ Program. Introduction to C++ Displays output on the computer screen

Building Java Programs

Chapter 2. Outline. Simple C++ Programs

C++ PROGRAMMING. For Industrial And Electrical Engineering Instructor: Ruba A. Salamh

Lecture 2. COMP1406/1006 (the Java course) Fall M. Jason Hinek Carleton University

Simple Java Reference

CS 302: Introduction to Programming

An Introduction to Processing

Objectives. Chapter 2: Basic Elements of C++ Introduction. Objectives (cont d.) A C++ Program (cont d.) A C++ Program

Chapter 2: Data and Expressions

Fundamentals of Programming

Chapter 2: Basic Elements of C++

Chapter 2: Basic Elements of C++ Objectives. Objectives (cont d.) A C++ Program. Introduction

Chapter 2 Using Data. Instructor s Manual Table of Contents. At a Glance. A Guide to this Instructor s Manual:

Introduction to Computer Science Unit 2. Notes

HUDSONVILLE HIGH SCHOOL COURSE FRAMEWORK

5/3/2006. Today! HelloWorld in BlueJ. HelloWorld in BlueJ, Cont. HelloWorld in BlueJ, Cont. HelloWorld in BlueJ, Cont. HelloWorld in BlueJ, Cont.

I Internal Examination Sept Class: - BCA I Subject: - Principles of Programming Lang. (BCA 104) MM: 40 Set: A Time: 1 ½ Hrs.

AP CS Unit 3: Control Structures Notes

Basic data types. Building blocks of computation

Data Types and the while Statement

RTL Reference 1. JVM. 2. Lexical Conventions

Transcription:

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 in the alphabet. A character can be converted into a number value using the ASCII chart Int: A numeric data type for integers. Boolean: A data type that only uses true or false. Double: A numeric data type for numbers with decimals. Byte: A numeric data type in Java. Float: A numeric data type in Java Short: A numeric data type in Java Long: A numeric data type in Java. If you are wondering why there are so many different numeric data types, it is because of saving memory and different storage location. Using an int instead of a long would save several bytes of memory. Floating point numbers and integer numbers are stored differently in a computer. These data types serve as a basic foundation for coding in and data manipulation in Java. Each data type has one purpose, or one specific type or kind of value. Each variable must be assigned a data type. Basic Operations: Addition (+) The basic function to add variables together would be x + y. x += y x = x + y Subtraction (-) The basic function to subtract variables together would be x - y. x -= y x = x - y Multiplication (*) The basic function to multiply variables together would be x * y. x *= y x = x * y Division (/) The basic function to divide variables together would be x / y. x /= y x = x / y Modulus (%) The remainder of dividing two numbers. The basic function to modulus variables together would be x % y.

StudyHub+ 3 The operations occur from left to right. Anything in Parentheses is calculated first. Multiplication, Division, and Modulus are calculated next from left to right. Subtraction and Addition are then calculated from left to right. Example: 3 / 14 % 7 / (1.0 * 2) + 10 / 6 We begin with calculating all the operations in parentheses. 3 / 14 % 7 / 2.0 + 10 / 6 We then look at the equation from left to right and calculate the multiplications, divisions, and modulus first. 3 / 14 is calculated first 0. Then the answer from 3 / 14 is then modulus by 7 7. The answer from the previous bullet point is then divided by 2.0 to form a decimal 3.5. After looking at the operations on the left, we continue on and find another divide operator for 10 / 6 1. 3.5 + 1 Then, we add the two numbers together. 4.5 When dividing, if one of the numbers or both of the numbers is a decimal, then divide it with decimals as an answer. Examples: 3.0 / 2 = 1.5 3.0 / 2.0 = 1.5 3 / 2.0 = 1.5 Strings in Expressions: Anything after a String acts like a String. Examples: 4 + 1 + 9 +. + (-3 + 10) + 11/3 The first step is to solve for the parentheses. 4 + 1 + 9 +. + 7 + 11/3 Then, add the operations before the String. 14 +. + 7 + 11/3 The operations after a String act like a String. Therefore, the addition signs are concatenating the numbers together. Concatenating Chicken + Nuggets results in Chicken Nuggets.

StudyHub+ 4 Thus, the final result is 14.73 (11/3 is 3). Basic Functions from Different Classes: String Class:.toUpperCase(): Converts the whole String to Uppercase letters..tolowercase(): Converts the whole String to Lowercase letters..charat((integer Value)): Determines the character at a specific index / location. The position of a String starts at 0 and ends at one less than the length of the String. String x = ChickeN ; char y = x.charat(0); char z = x.charat(x.length() - 1); System.out.println(y); System.out.println(z); The result is: C N.compareTo((String)) Compares two strings lexicographically Subtracts the first character of the String inside the method by the first character of the String before the method is called. If the first character is the same, the java virtual machine continues to run, one character after the next The characters are converted into ASCII values String chicken = apple ; String apple = chicken ; System.out.println(chicken.compareTo(apple)); The result is -2 because the first character of chicken, a, which turns into 97, is subtracted by the first character of apple, c, which turns into 99, System.out.println( apple.compareto( chicken ); The result is -2..contains((String)) Checks whether a String is located inside another String. Returns true or false. String chicken = Hello my name is Bob ;

StudyHub+ 5 if(chicken.contains( Bob )) System.out.println( So, your name is not Do? ); else System.out.println( Hello, Bob ); The result is So, your name is not Do? because the string chicken does contain the string Bob..equals((String)) Checks whether the string is equal to another String. Returns true or false. String chicken = butter ; String butter = butter ; if(chicken.equals(butter)) System.out.println( Hello ); else System.out.println( No Hello ); The result is Hello because the String chicken does equal the String butter..length() Used to find the length of a String. String joseph = choi ; System.out.println(joseph.length()); The result is 4 because there are four letters in the string joseph.substring() Used to isolate a specific part of a string Begins at index 0 and ends at one less than the number you want String jeffrey = says hi ; System.out.println(jeffrey.substring(0, 6); The result is says h because it begins at the first character, index 0, and keeps going until it reaches index 5, which is h int class: All you really need to know for the finals is Integer.parseInt() Used to convert a string into an integer String number = 5 ; int therealnumber = Integer.parseInt(number); System.out.println(therealnumber + 5);

StudyHub+ 6 The result is 10 because the string variable number is converted into an integer value and stored in the variable therealnumber Math Class: This class includes all the basic math operations e.g. square root, cube root, absolute value Math.abs() This method takes the absolute value of a number double num = 2.867449; double pi = 3.14159265; System.out.println(Math.abs(num - pi)); The result is 0.27414365 because it takes the absolute value of the subtraction Math.max(x,y) Takes the maximum of two integers. Math.min(x,y) Takes the minimum of two integers. Math.pow((value), (raised to this number)) Takes a value and raises it to the power of a certain number Loop Control Variable: Used in order to regulate the number of times the body of a loop is executed, and when to exit the series of instructions. Loops: They keywords while and for both indicate the start of a loop. The body of the loop will be continued for as long as the loop conditions remain true. To prime a loop statement means to set up code (such as methods) before the loop is executed, in order for each test to make logical sense. Example: If the test in the loop is while the user s response is yes, then the loop would have to be primed by getting a response from the user (or creating one) before the loop initializes. The priming statement is typically proceeding the while() method. While Loop: Repeats the body of the loop while a Boolean expression is true. Programmers tend to use the while loop when they do not know how many times the loops will execute. Do While Loop: Very similar to a While loop The Do While loop always executes at least one time because it reads the statements before testing whether the condition is true.

StudyHub+ 7 int count = 5; do { count++; }while(count > 6) This example will run one time because the Do happens first and then the While is tested. For Loop: Contains a header with three possible parts. Declaration / Initialization, Condition, and Change. Before the loop starts, the Declaration / Initialization is executed. Then, it repeats the body of the loop while the Condition remains true. The code in the Change portion is executed each time at the end of the body of the loop. Programmers tend to use the For loop when they know the number of times the loops will execute. Importing Easy Reader: Easy Reader allows the user to read numbers, characters, words, and Strings from the console and from the text file. The following code permits the user to open the standard input screen for reading keyboard inputs. EasyReader console = new EasyReader(); console is the name of the input stream, which the user decides. Examples for Reading Data: EasyReader read = new EasyReader(); int input = read.readint(); String word = read.readline(); char reference = read.readchar(); De Morgan s Law: De Morgan s Law show how to handle the negation of a complex conditional Example:!(x < 3 && y > 2) The result is (x >= 3 y <= 2) because the opposite of! is the absence of it, the opposite of < is >=, the opposite of && is, and the opposite of > is <=.