Review by Mr. Maasz, Summary of Chapter 2: Starting Out with Java.

Slides:



Advertisements
Similar presentations
L2:CSC © Dr. Basheer M. Nasef Lecture #2 By Dr. Basheer M. Nasef.
Advertisements

Introduction to Computing Concepts Note Set 7. Overview Variables Data Types Basic Arithmetic Expressions ▫ Arithmetic.
Types, Variables and Operators Computer Engineering Department Java Course Asst. Prof. Dr. Ahmet Sayar Kocaeli University - Fall 2013.
Class 7.
Java Syntax Part I Comments Identifiers Primitive Data Types Assignment.
©2004 Brooks/Cole Chapter 2 Variables, Values and Operations.
Introduction to Primitives. Overview Today we will discuss: –The eight primitive types, especially int and double –Declaring the types of variables –Operations.
CMT Programming Software Applications
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
Hello, world! Dissect HelloWorld.java Compile it Run it.
1 Chapter Two Using Data. 2 Objectives Learn about variable types and how to declare variables Learn how to display variable values Learn about the integral.
Objectives You should be able to describe: Data Types
Introduction to Programming Prof. Rommel Anthony Palomino Department of Computer Science and Information Technology Spring 2011.
VARIABLES AND TYPES CITS1001. Types in Java the eight primitive types the unlimited number of object types Values and References The Golden Rule Scope.
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 Basic Elements of Java. Chapter Objectives Become familiar with the basic components of a Java program, including methods, special symbols,
Introduction to Programming David Goldschmidt, Ph.D. Computer Science The College of Saint Rose Java Fundamentals (Comments, Variables, etc.)
Introduction to Programming David Goldschmidt, Ph.D. Computer Science The College of Saint Rose Java Fundamentals (Variables, Arithmetic, etc.)
Java Simple Types CSIS 3701: Advanced Object Oriented Programming.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 2 Basic Elements of Java.
Using Data Within a Program Chapter 2.  Classes  Methods  Statements  Modifiers  Identifiers.
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 2: Variables & Data Types.
College Board A.P. Computer Science A Topics Program Design - Read and understand a problem's description, purpose, and goals. Procedural Constructs.
Java Programming, Second Edition Chapter Two Using Data Within a Program.
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
CSI 3125, Preliminaries, page 1 Data Type, Variables.
1 Chapter 2: Java Fundamentals cont’d Spring Lory Al Moakar.
Java Programming: From Problem Analysis to Program Design, Second Edition 1 Lecture 1 Objectives  Become familiar with the basic components of a Java.
Java Basics. Tokens: 1.Keywords int test12 = 10, i; int TEst12 = 20; Int keyword is used to declare integer variables All Key words are lower case java.
Chapter 4: Variables, Constants, and Arithmetic Operators Introduction to Programming with C++ Fourth Edition.
CS0007: Introduction to Computer Programming Primitive Data Types and Arithmetic Operations.
CSE 110: Programming Language I Matin Saad Abdullah UB 1222.
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.
Chapter 2 Variables and Constants. Objectives Explain the different integer variable types used in C++. Declare, name, and initialize variables. Use character.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-1 Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
Topic 2 Elementary Programming
Chapter 2 Variables.
Elementary Programming
BASIC ELEMENTS OF A COMPUTER PROGRAM
Building Java Programs
Chapter 4 – Fundamental Data Types
Type Conversion, Constants, and the String Object
Java Programming: From Problem Analysis to Program Design, 4e
Chapter 2.
IDENTIFIERS CSC 111.
Computers & Programming Languages
مساق: خوارزميات ومبادئ البرمجة الفصل الدراسي الثاني 2016/2015
Chapter 2: Basic Elements of Java
Building Java Programs
Chapter 2 Variables.
Chapter 2: Java Fundamentals
Chapter 2: Java Fundamentals
Building Java Programs
Chapter 2: Introduction to C++.
Building Java Programs
Building Java Programs
Building Java Programs
Building Java Programs
Building Java Programs
Building Java Programs
Introduction to Primitives
Introduction to Primitives
Building Java Programs
Primitive Types and Expressions
Chapter 2 Variables.
Building Java Programs
Building Java Programs
Variables and Constants
Presentation transcript:

Review by Mr. Maasz, Summary of Chapter 2: Starting Out with Java

 Variables are names (often called “identifiers”) for memory locations.  Just as there are many different types of “information” in math or English, there are many types of data in computer memory  Primitive data types are called this because they cannot be used to create “objects”  Data types: Since numbers come in several flavors like whole numbers, fractional numbers, positive or negative, even very larger or very small numbers  Numeric data types are:  int for whole numbers (integers)  Real numbers (float or double)  Scientific notation numberes Java OOP Programming 2

Two data types related to text: 1. String – literally a “list” of characters, but with methods that contribute to manipulating each String, for example: toUpper( ) toLower( ) 2. char - holds only one character at a time 3. Unicode: a code or numeric representation that uses numbers to represent numbers, symbols, and letters. Includes over 65K characters for other languages, even Greek and mathematics symbols. Data TypeSize (mem- bytes) Range byte1 byteInteger from to 127 short2 bytesIntegers in the range from - 32,768 to 32,767 int4 bytesReally small to really large nos. long8 bytesHUGE numbers float4 bytes-3.4E-38 to 3.4E38 double8 bytes-1.7E-308 to 1.7E308 Java OOP Programming 3

 Integer types hold “whole” numbers  Basic declaration has syntax: int ;  Declaration and Initialization looks like: int age = 15; // age is 15 Read as “age gets the value of 15” Java OOP Programming 4 Data TypeSize (mem- bytes) Range byte1 byteInteger from -128 to 127 short2 bytesIntegers in the range from - 32,768 to 32,767 int4 bytesReally small to really large nos. long8 bytesHUGE numbers

OUTPUT : We have made a journey of 105 miles. It took us 120 minutes. Our account balance is $-20 About days ago Columbus stood on this spot. // This program has variables of several of the integer types. public class IntegerVariables { public static void main(String[] args) { int checking; // Declare an int variable named checking. byte miles; // Declare a byte variable named miles. short minutes; // Declare a short variable named minutes. long days; // Declare a long variable named days. checking = -20; miles = 105; minutes = 120; days = ; System.out.print("We have made a journey of " + miles); System.out.println(" miles."); System.out.println("It took us " + minutes + " minutes."); System.out.println("Our account balance is $" + checking); System.out.print("About " + days + " days ago Columbus "); System.out.println("stood on this spot."); } Java OOP Programming 5

OUTPUT : We have made a journey of 105 miles. It took us 120 minutes. Our account balance is $-20 About days ago Columbus stood on this spot. // This program has variables of several of the integer types. public class IntegerVariables { public static void main(String[] args) { int checking; // Declare an int variable named checking. byte miles; // Declare a byte variable named miles. short minutes; // Declare a short variable named minutes. long days; // Declare a long variable named days. checking = -20; miles = 105; minutes = 120; days = ; System.out.print("We have made a journey of " + miles); System.out.println(" miles."); System.out.println("It took us " + minutes + " minutes."); System.out.println("Our account balance is $" + checking); System.out.print("About " + days + " days ago Columbus "); System.out.println("stood on this spot."); } Java OOP Programming 6 Single line comment Class header: public – can be access by other projects/classes Class – name of the container, keyword IntegerVariables – programmer created class name Left brace, begin class definition Header for main method, static defined page 55

public class IntegerVariables { public static void main(String[] args) { int checking;. Static: (Java Methods: as define on page 55,) “indicates that the method main is not called for any particular object: it belongs to the class as a whole.” A Java app can have only one main. Java OOP Programming 7 Header for main method,

OUTPUT : We have made a journey of 105 miles. It took us 120 minutes. Our account balance is $-20 About days ago Columbus stood on this spot. // This program has variables of several of the integer types. public class IntegerVariables { public static void main(String[] args) { int checking; // Declare an int variable named checking. byte miles; // Declare a byte variable named miles. short minutes; // Declare a short variable named minutes. long days; // Declare a long variable named days. checking = -20; miles = 105; minutes = 120; days = ; System.out.print("We have made a journey of " + miles); System.out.println(" miles."); System.out.println("It took us " + minutes + " minutes."); System.out.println("Our account balance is $" + checking); System.out.print("About " + days + " days ago Columbus "); System.out.println("stood on this spot."); } Java OOP Programming 8 Three process: Input, output, processing, Declaration of variables first Assignment second Output is last Data type: int (whole numbers) Variable name: checking Data type: byte, Variable name: miles Data Type: short, Variable minutes Data Type: long, Variable: days

OUTPUT : We have made a journey of 105 miles. It took us 120 minutes. Our account balance is $-20 About days ago Columbus stood on this spot. // This program has variables of several of the integer types. public class IntegerVariables { public static void main(String[] args) { int checking; // Declare an int variable named checking. byte miles; // Declare a byte variable named miles. short minutes; // Declare a short variable named minutes. long days; // Declare a long variable named days. checking = -20; miles = 105; minutes = 120; days = ; System.out.print("We have made a journey of " + miles); System.out.println(" miles."); System.out.println("It took us " + minutes + " minutes."); System.out.println("Our account balance is $" + checking); System.out.print("About " + days + " days ago Columbus "); System.out.println("stood on this spot."); } Java OOP Programming 9 Three process: Input, output, processing, Declaration of variables first Assignment second Output is last Assignments second; checking “gets value” 20 minutes gets 120 miles “gets” 105 Days “gets” the value of by the assignment op

OUTPUT : We have made a journey of 105 miles. It took us 120 minutes. Our account balance is $-20 About days ago Columbus stood on this spot. // This program has variables of several of the integer types. public class IntegerVariables { public static void main(String[] args) { int checking; // Declare an int variable named checking. byte miles; // Declare a byte variable named miles. short minutes; // Declare a short variable named minutes. long days; // Declare a long variable named days. checking = -20; miles = 105; minutes = 120; days = ; System.out.print("We have made a journey of " + miles); System.out.println(" miles."); System.out.println("It took us " + minutes + " minutes."); System.out.println("Our account balance is $" + checking); System.out.print("About " + days + " days ago Columbus "); System.out.println("stood on this spot."); } Java OOP Programming 10 Three process: Input, output, processing, Declaration of variables first Assignment second Output is last System.out.println( ) Method println displays strings from what is between ( )

 Dollar amounts or precise measurements cannot be expressed as “int”egers  Numbers that allow fractional values are called floating-point numbers  Starting Out With Java, Page  Two floating point data types:  Float – single precision (4 bytes) store floating-pt numbers with 7 digits of accuracy  Double – double precision  Store floating-point with 15 digits of accuracy  Code listing Sale.java Java OOP Programming 11

Code Examples: float number; number = 23.5; // error Correct example: float number; number = 23.5F; // ABOVE IS GOOD  If you use “floating point” literals in your source code,  Java is a “strongly typed” language, will not allow loss of precision  Floating point literals are considered double  Use an “F” capital letter to force (called a cast) conversion. Java OOP Programming 12

 FLOATING POINTS expressed in E notation  Pg 53 Java OOP Programming 13

 boolean data type:  Variables that can only hold the values of either  True  False  Page 54 Java OOP Programming 14

 Used to store character data, one letter, symbol, or numeric character  Character literals are surrounded by single quotation marks.  char myInitials = ‘J’;  Page 55 Java OOP Programming 15

Math.pow(base, power) Math.sqrt(number) Java OOP Programming 16

Lesson 6 Project Java OOP Programming 17

Java OOP Programming 18

 Variables & Data Types  Data types and memory allocations (bytes)  Integer values  Output  Source code example of Integer arithmetic and output  Floating Point Data Types  Math  Pow  Sqrt  Other  Lesson 6: Blue Pelican Java Java OOP Programming 19

Java OOP Programming 20