Java 2 More Java Then Starbucks ;-). Important Terms Primitive Data – Basic, built-in values (characters & numbers) Data Type – Used to talk about values.

Slides:



Advertisements
Similar presentations
STRING AN EXAMPLE OF REFERENCE DATA TYPE. 2 Primitive Data Types  The eight Java primitive data types are:  byte  short  int  long  float  double.
Advertisements

CS0007: Introduction to Computer Programming Console Output, Variables, Literals, and Introduction to Type.
1 Chapter 2 Introduction to Java Applications Introduction Java application programming Display ____________________ Obtain information from the.
Primitive Data Types There are a number of common objects we encounter and are treated specially by almost any programming language These are called basic.
Data Types in Java Data is the information that a program has to work with. Data is of different types. The type of a piece of data tells Java what can.
ECE122 L4: Creating Objects February 8, 2007 ECE 122 Engineering Problem Solving with Java Lecture 4 Creating and Using Objects.
Introduction to Programming with Java, for Beginners Primitive Types Expressions Statements Variables Strings.
©2004 Brooks/Cole Chapter 2 Variables, Values and Operations.
1 Java Basics. 2 Compiling A “compiler” is a program that translates from one language to another Typically from easy-to-read to fast-to-run e.g. from.
CIS 234: Using Data in Java Thanks to Dr. Ralph D. Westfall.
Introduction to Computers and Programming Lecture 7:
COMPSCI 125 Spring 2005 ©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 3: Numeric Data *Variables *Numeric data.
Aalborg Media Lab 21-Jun-15 Software Design Lecture 2 “ Data and Expressions”
Working with the data type: char  2000 Prentice Hall, Inc. All rights reserved. Modified for use with this course. Introduction to Computers and Programming.
ECE122 L3: Expression Evaluation February 6, 2007 ECE 122 Engineering Problem Solving with Java Lecture 3 Expression Evaluation and Program Interaction.
Chapter 3 Numerical Data. Topics Variables Numeric data types Assignment Expressions.
Primitive Types Java supports two kinds of types of values – objects, and – values of primitive data types variables store – either references to objects.
CSci 142 Data and Expressions. 2  Topics  Strings  Primitive data types  Using variables and constants  Expressions and operator precedence  Data.
COMP 14: Primitive Data and Objects May 24, 2000 Nick Vallidis.
String Escape Sequences
Expressions, Data Conversion, and Input
1 Variables, Constants, and Data Types Primitive Data Types Variables, Initialization, and Assignment Constants Characters Strings Reading for this class:
 Value, Variable and Data Type  Type Conversion  Arithmetic Expression Evaluation  Scope of variable.
Java Primitives The Smallest Building Blocks of the Language (corresponds with Chapter 2)
Outline Questions / Review Predefined Objects Variables Primitive Data Arithmetic Expressions Interactive Programs Decision Making Assignments.
1 Do you have a CS account? Primitive types –“ building blocks ” for more complicated types Java is strongly typed –All variables in a Java program must.
1 The String Class Every character string is an object in Java, defined by the String class Every string literal, delimited by double quotation marks,
Outline Character Strings Variables and Assignment Primitive Data Types Expressions Data Conversion Interactive Programs Graphics Applets Drawing Shapes.
JAVA 0. HAFTA Algorithms FOURTH EDITION Robert Sedgewick and Kevin Wayne Princeton University.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Software Solutions Foundations of Program Design Sixth Edition by Lewis.
Mathematical Calculations in Java Mrs. G. Chapman.
1 Programming Java Java Basics. 2 Java Program Java Application Program Application Program written in general programming language Applet Program running.
SE-1010 Dr. Mark L. Hornick 1 Variables & Datatypes.
© 2011 Pearson Education, publishing as Addison-Wesley Chapter 2: Objects and Primitive Data Presentation slides for Java Software Solutions for AP* Computer.
Chapter 3 Syntax, Errors, and Debugging Fundamentals of Java.
Chapter 2 Variables.
Mathematical Calculations in Java Mrs. C. Furman.
1 Lecture 2 b declaration and use of variables b expressions and operator precedence b introduction to objects b class libraries b flow of control b decision-making.
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.
Operators and Expressions. 2 String Concatenation  The plus operator (+) is also used for arithmetic addition  The function that the + operator performs.
Data Tonga Institute of Higher Education. Variables Programs need to remember values.  Example: A program that keeps track of sales needs to remember.
Java 3 More Java Then Java. Libraries & Packages Java standard class library is composed of useful classes that help us to achieve our programming goals.
Road map char data type Reading –Liang 5: Chapter 2: 2.7.4; 2.9; –Liang 6: Chapter 2: 2.7.4; 2.9 –Liang 7: Chapter 2: 2.7.4; 2.9.
ITK 168 – More Variables 10/13/05. Another example of using instance variables and constants  Go through SimpleBot  Modify SimpleBot to “teleport”
© 2007 Pearson Addison-Wesley. All rights reserved2-1 Character Strings A string of characters can be represented as a string literal by putting double.
CS 106 Introduction to Computer Science I 09 / 10 / 2007 Instructor: Michael Eckmann.
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.
© 2004 Pearson Addison-Wesley. All rights reserved September 5, 2007 Packages & Random and Math Classes ComS 207: Programming I (in Java) Iowa State University,
CS0007: Introduction to Computer Programming Primitive Data Types and Arithmetic Operations.
Data and Expressions. Let's explore some other fundamental programming concepts Chapter 2 focuses on: Character Strings Primitive Data The Declaration.
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.
© 2004 Pearson Addison-Wesley. All rights reserved August 27, 2007 Primitive Data Types ComS 207: Programming I (in Java) Iowa State University, FALL 2007.
Chapter 2 Variables.
Java Primer 1: Types, Classes and Operators
Primitive Data Types August 28, 2006 ComS 207: Programming I (in Java)
Object Oriented Programming
Data Conversion & Scanner Class
Multiple variables can be created in one declaration
Type Conversion, Constants, and the String Object
An overview of Java, Data types and variables
Objects and Primitive Data
Creating Objects A variable holds either a primitive value or a reference to an object A class name can be used as a type to declare an object reference.
Java Programming Review 1
Packages & Random and Math Classes
Names of variables, functions, classes
Chapter 2 Variables.
Presentation transcript:

Java 2 More Java Then Starbucks ;-)

Important Terms Primitive Data – Basic, built-in values (characters & numbers) Data Type – Used to talk about values and the things that can be done to them Operators – Used to perform operations on primitive data types. Object Class

Objects An object is an instance of a class. They have properties. They can be acted upon by invoking methods. Encapsulation – “Each object protects & manages its own information”…Your car keeps track of its mileage/fuel gauge and only its mileage/fuel gauge.

What’s a Class? Used to define the data type of an object. If you prefer, think of a class as defining a concept for something. A method is used to define what operations we can perform on an object. Auto Objects Auto Class

Inheritance One class can extend another class (parent/child) Cars & trucks share many common elements so we just inherit the auto class properties & methods and add or modify what is needed to create a truck. Truck Objects Auto Class Truck Class

Escape Characters String literals are defined by placing them between “” quotes. Some characters have special meaning to Java and can’t be used between quotes or are ignored as “white space.” \t = tab \n = newline \” = “ P. 71 in book for more

The + Operator Works on Text and Numbers! Concatenation – Sticking on string onto the end of another. “Hello” + “World” = “Hello World” All operators listed in Appendix D of the Java book! Arithmetic operators are “right to left” associative. See p. 82 in book too.

Variables Named location in memory used to hold a value. Must be declared so memory can be reserved. They type of data to store in the memory space must be defined. May or may not be initialized when reserved. = operator is “Assigned” not “Equals”

Primitives byte – 8 bits short – 16 bits int – 32 bits long – 64 bits float – 32 bits double – 64 bits Ranges on p. 77 in Java book

Conversions Narrowing or Widening Assignment this = that Arithmetic promotion this = a / b Casting this = (int) that

Literals Integer literals are assumed to be of type “int” unless an l or L is appended to it. Floating point literals are assumed to be of type “double” unless an f or F is appended to it. Character literals are defined between single quotes ‘ String literals between double quotes “

Creating Objects Variables hold either primitive data or a reference to an object. Instantiation is the “fancy” term for creating objects with the new operator. String first = new String(“Bob”) “.” operator used to access object methods.

The String Class Strings are objects instantiated from the string class. String objects are “immutable” See string sample code.

Libraries & Packages Java standard class library is composed of useful classes that help us to achieve our programming goals but are not a part of the Java language Java packages are groups of classes that we can call by a single name…the String class is part of the java.lang package. Some packages are listed on p. 94

Importing Classes Java.lang packages are automatically available to every program we write. To access other packages we must use a fully qualified reference to the package or import it. import java.util.*; import cs1.Keyboard;

Basic Conditional Statements if (this > that) { this++; } else { that++; }

Basic Conditional Statements Equality Operators… == equal to !=not equal to greater than >=greater than or equal to