COMP Review of Chapter 1 & 2

Slides:



Advertisements
Similar presentations
Introduction to Computing Concepts Note Set 7. Overview Variables Data Types Basic Arithmetic Expressions ▫ Arithmetic.
Advertisements

 2005 Pearson Education, Inc. All rights reserved Introduction.
1 Chapter 2 Introduction to Java Applications Introduction Java application programming Display ____________________ Obtain information from the.
03 Data types1June Data types CE : Fundamental Programming Techniques.
CMT Programming Software Applications
Constants Variables change, constants don't final = ; final double PI = ; … area = radius * radius * PI; see Liang, p. 32 for full code.
Lecture 4 Types & Expressions COMP1681 / SE15 Introduction to Programming.
COMP 110 Primitive Types, Strings, and Console I/O Tabitha Peck M.S. January 23, 2008 MWF 3-3:50 pm Philips
COMP 110 Errors, Strings, and Review Tabitha Peck M.S. January 28, 2008 MWF 3-3:50 pm Philips
Fundamental data types Horstmann Chapter 4. Constants Variables change, constants don't final = ; final double PI = ; … areaOfCircle = radius *
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;
COMP Computer Basics Yi Hong May 13, 2015.
COMP Classes Yi Hong May 22, Announcement  Lab 2 & 3 due today.
Introduction to Java Appendix A. Appendix A: Introduction to Java2 Chapter Objectives To understand the essentials of object-oriented programming in Java.
Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. All rights reserved. 1 Chapter 2 Elementary Programming.
1 Course Lectures Available on line:
COMP 110 Computer Basics Luv Kohli August 25, 2008 MWF 2-2:50 pm Sitterson
COMP 110 Spring Announcements Computers in class on Friday: Lab Office Hours: Monday 12-2 New students see me after class Administrative Changes.
Chapter 2: Basic Elements of Java J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, Second Edition.
CS_OOP Lecture #2: Computer Hardware/Software; Variables, C# Data Types, and IO.
Java means Coffee Java Coffee Beans The name “JAVA” was taken from a cup of coffee.
Outline Character Strings Variables and Assignment Primitive Data Types Expressions Data Conversion Interactive Programs Graphics Applets Drawing Shapes.
Chapter 2 Elementary Programming
COMP String and Console I/O Yi Hong May 18, 2015.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 2 Basic Elements of Java.
A First Look at Java Chapter 2 1/29 & 2/2 Imagine! Java: Programming Concepts in Context by Frank M. Carrano, (c) Pearson Education - Prentice Hall, 2010.
Using Data Within a Program Chapter 2.  Classes  Methods  Statements  Modifiers  Identifiers.
College Board A.P. Computer Science A Topics Program Design - Read and understand a problem's description, purpose, and goals. Procedural Constructs -
COMP Primitive and Class Types Yi Hong May 14, 2015.
Component 4: Introduction to Information and Computer Science Unit 5: Overview of Programming Languages, Including Basic Programming Concepts Lecture 3.
Variables and Constants Objectives F To understand Identifiers, Variables, and Constants.
Variables and Types Java Part 3. Class Fields  Aka member variable, field variable, instance variable, class variable.  These are the descriptors of.
1.2 Primitive Data Types and Variables
Chapter One Lesson Three DATA TYPES ©
Java – Variables and Constants By: Dan Lunney. Declaring Variables All variables must be declared before they can be used A declaration takes the form:
Catie Welsh January 31,  Project 1 Due Wednesday  Lab 1 Grades are posted 2.
Java Programming: From Problem Analysis to Program Design, Second Edition 1 Lecture 1 Objectives  Become familiar with the basic components of a Java.
Chapter 2: Basic Elements of Java J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, Second Edition.
Chapter 2: Data and Expressions. Variable Declaration In Java when you declare a variable, you must also declare the type of information it will hold.
1 Lecture # 2. * Introducing Programming with an Example * Identifiers, Variables, and Constants * Primitive Data Types * Byte, short, int, long, float,
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.
Review by Mr. Maasz, Summary of Chapter 2: Starting Out with Java.
Topic 2 Elementary Programming
Chapter 2 Variables.
Chapter 2 Basic Computation
Crash course in the Java Programming Language
Elementary Programming
Chapter 2 Elementary Programming
Console Output, Variables, Literals, and Introduction to Type
Yanal Alahmad Java Workshop Yanal Alahmad
Multiple variables can be created in one declaration
CISC124 Labs start this week in JEFF 155: Meet your TA.
Type Conversion, Constants, and the String Object
Java Programming: From Problem Analysis to Program Design, 4e
Chapter 2.
IDENTIFIERS CSC 111.
Type Conversion, Constants, and the String Object
CSS 161 Fundamentals of Computing Introduction to Computers & Java
مساق: خوارزميات ومبادئ البرمجة الفصل الدراسي الثاني 2016/2015
Chapter 2 Edited by JJ Shepherd
Chapter 2: Basic Elements of Java
Chapter 2 Variables.
Fundamentals 2.
Chapter 2: Java Fundamentals
CS2011 Introduction to Programming I Elementary Programming
Primitive Types and Expressions
Chapter 2 Variables.
Chapter 2: Java Fundamentals cont’d
Presentation transcript:

COMP 110-001 Review of Chapter 1 & 2 Yi Hong May 18, 2015

Today Review of Chapter 1 & 2 Review programs in lectures & labs

Michele Weigle - COMP 14 - Spr 04 Hardware vs. Software Hardware - physical machine CPU, Memory Software - programs that give instructions to the computer Windows XP, Games, Eclipse 3

Measuring Data 1 bit (binary digit): 0 or 1 1 byte: 8 bits 00000000 ~ 11111111 2^8 = 256 possible states An example of a byte 0 1 0 1 0 0 1 0 As decimal number: 82 = 2^1 + 2^4 + 2^6

Measuring Data 4 bytes: 4 * 8 = 32 bits Size of int type in Java 2^32 possible states Size of int type in Java If we use 4 bytes to represent an integer, what is the range? Unsigned: 0 ~ 2^32-1 ( starts from 0 ) Signed: -2^31 ~ 2^31-1

Primitive Types Examples (For a full list, check p. 52) Type Size Remarks int 4 bytes 3443, -1024 Integer only Smaller range +, - , * , / , % double 8 bytes -0.4, 3.2, 3.343*10^100 Much larger range Limited precision boolean 1 bit true, false And or negation && || ! char 2 bytes ‘a’, ‘0’, ‘-’, ‘%’ Single quotes

Variables Container of Data Declaration of Variable: Data can be of Class type or Primitive type Declaration of Variable: type variable_name; type variable_name = initial_value; e.g.: int i = 1; boolean passedTest = true; Polygon triangle = new Polygon(); int age; double length; char letter; main memory

Using Variables Specify the type only once at declaration In assignment operation, the right side is evaluated first. The value is then stored into the left side E.g.: Swap values of two integer variables int a = 10; int b = 5; Method 1: Method 2: int c = a; a = a + b; a = b; b = a – b; b = c; a = a – b;

Michele Weigle - COMP 14 - Spr 04 Defined constants public static final Type Variable = Constant; Named in ALL_CAPS public class DefinedConstant { public static final double PI = 3.14159; public static void main(String[] args){ … } } 9

Compatibility and Type Casting Variable of “Bigger” type can hold values of “Smaller” type int a = 5; double b = a; One can cast one type into another type (at the risk of losing information) double a = 10.0 / 3.0; // a = 3.333333333… int b = (int)a; // b = 3

Object Oriented Programming (OOP) Object: Attributes + Methods Class: the blueprint of objects of the same type Person name, contact Superclass Student student ID, program, year Teacher employee ID, department, rank Subclass Class Objects S1 name=“Alan”, contact=“919-…..”, program = biostat, year = 1st S2 name=“Anna”, contact=“919-…..”, program = CS, year = 1st T1 name=“Yi”, contact=“919-…..”, dept = CS, rank = no rank T2 name=“Marc”, contact=“919-…..”, program = biostat, rank = assoc prof

Java is an OOP language Encapsulation Polymorphism Inheritance “Information hiding”: putting things in a capsule Polymorphism “Many forms”: the same instruction to mean the same thing in different contexts Inheritance Organizing classes, so properties only have to be defined once

OOP in Practice Import class if necessary Create object E.g.: import java.util.*; Create object Class_Type variable_name = new ClassType(…); E.g.: Scanner keyboard = new Scanner(System.in); Polygon treeTop = new Polygon(); Access object members (attribute or method) int inputNumber = keyboard.nextInt(); treeTop.setColor(Color.green);

String A Class Type Objects of String class can be defined as: String myString = “UNC is Great!”; Each String object consists of A sequence of characters (char) A set of methods that can process the sequence of characters String Indices: U N C i s G r e a t ! 1 2 3 4 5 6 7 8 9 10 11 12

String Concatenation by “+” Mixed operations “My name is ” + “Yi”  “My name is Yi” Mixed operations “The sum is ” + 5 + 6  “The sum is 56” “The sum is ” + (5+6)  “The sum is 11” More methods, see Java API for reference length(), subString(), charAt(), toLowerCase() …

Console I/O Two built-in Java objects Console input: use Scanner class System.in System.out Console input: use Scanner class Scanner keyboard = new Scanner(System.in); int inputNumber = keyboard.nextInt(); String name = keyboard.next(); Console output System.out.print(…); System.out.println(…);

Review Programs in Previous Lectures & Labs

SecondProgram.java in Lecture 2

TypeCasting.java in Lecture 4

VendingMachine.java in Lab1

StringsAndChars.java in Lecture 5

TestStringMethods.java in Lecture 5

Next Class Flow of control: Branching Reading assignments: Chapter 3.1-3.3