Computational Expression

Similar documents
Computational Expression

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

Computational Expression

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

Programming with Java

Full file at

ECE 122 Engineering Problem Solving with Java

Data Conversion & Scanner Class

Chapter. Let's explore some other fundamental programming concepts

Chapter 2: Data and Expressions

Datatypes, Variables, and Operations

Java How to Program, 10/e. Copyright by Pearson Education, Inc. All Rights Reserved.

PROGRAMMING FUNDAMENTALS

Constants. Why Use Constants? main Method Arguments. CS256 Computer Science I Kevin Sahr, PhD. Lecture 25: Miscellaneous

Sir Muhammad Naveed. Arslan Ahmed Shaad ( ) Muhammad Bilal ( )

Full file at

Lesson 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 11053, Fundamentals of Programming By: S. Sabraz Nawaz Senior Lecturer in MIT Department of MIT FMC, SEUSL

Chapter 2 Elementary Programming

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

Chapter 02: Using Data

Exam 1 Prep. Dr. Demetrios Glinos University of Central Florida. COP3330 Object Oriented Programming

4. If the following Java statements are executed, what will be displayed?

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

Chapter 2: Using Data

An Introduction to Processing

Gaddis: Starting Out with Java: From Control Structures through Objects, 6/e

Introduction to Programming Using Java (98-388)

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

INDEX. A SIMPLE JAVA PROGRAM Class Declaration The Main Line. The Line Contains Three Keywords The Output Line

Chapter 2: Data and Expressions

Starting Out with Java: From Control Structures through Data Structures 3e (Gaddis and Muganda) Chapter 2 Java Fundamentals

Introduction to Bioinformatics

Input. Scanner keyboard = new Scanner(System.in); String name;

Fundamentals of Programming Data Types & Methods

boolean, char, class, const, double, else, final, float, for, if, import, int, long, new, public, return, static, throws, void, while

COMP 202 Java in one week

Java Identifiers, Data Types & Variables

Assoc. Prof. Dr. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved.

Full file at

12/22/11. Java How to Program, 9/e. Help you get started with Eclipse and NetBeans integrated development environments.

3. Java - Language Constructs I

Basics of Java Programming

2: Basics of Java Programming

Hello 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

Data types Expressions Variables Assignment. COMP1400 Week 2

Computational Expression

Chapter 2 ELEMENTARY PROGRAMMING

Basic Computation. Chapter 2

ing execution. That way, new results can be computed each time the Class The Scanner

Using Java Classes Fall 2018 Margaret Reid-Miller

Java Notes. 10th ICSE. Saravanan Ganesh

Fall 2017 CISC124 9/16/2017

AP Computer Science Unit 1. Programs

Important Java terminology

Chapter 2. Elementary Programming

ARG! Language Reference Manual

We now start exploring some key elements of the Java programming language and ways of performing I/O

c) And last but not least, there are javadoc comments. See Weiss.

Data Types, Variables and Arrays. OOC 4 th Sem, B Div Prof. Mouna M. Naravani

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

Lecture Set 2: Starting Java

Lecture Set 2: Starting Java

Peer Instruction 1. Elementary Programming

AP Computer Science A

Entry Point of Execution: the main Method. Elementary Programming. Learning Outcomes. Development Process

Chapter 2 Primitive Data Types and Operations. Objectives

Chapter 2: Using Data

Values and Variables 1 / 30

Getting started with Java

Java Foundations: Introduction to Program Design & Data Structures, 4e John Lewis, Peter DePasquale, Joseph Chase Test Bank: Chapter 2

Introduction to Java & Fundamental Data Types

VENTURE. Section 1. Lexical Elements. 1.1 Identifiers. 1.2 Keywords. 1.3 Literals

Chapter 2: Basic Elements of Java

Chapter 2 Elementary Programming. Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. All rights reserved.

Program Fundamentals

Lecture Notes. System.out.println( Circle radius: + radius + area: + area); radius radius area area value

Basic Computation. Chapter 2

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

Array. Prepared By - Rifat Shahriyar

I. Variables and Data Type week 3

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

Motivations. Chapter 2: Elementary Programming 8/24/18. Introducing Programming with an Example. Trace a Program Execution. Trace a Program Execution

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

Computational Expression

Basic Programming Elements

Computer Programming, I. Laboratory Manual. Experiment #4. Mathematical Functions & Characters

CEN 414 Java Programming

Università degli Studi di Bologna Facoltà di Ingegneria. Principles, Models, and Applications for Distributed Systems M

data_type variable_name = value; Here value is optional because in java, you can declare the variable first and then later assign the value to it.

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

Lexical Considerations

Object oriented programming. Instructor: Masoud Asghari Web page: Ch: 3

Software Practice 1 Basic Grammar

12/22/11. Java How to Program, 9/e. public must be stored in a file that has the same name as the class and ends with the.java file-name extension.

Elementary Programming. CSE 114, Computer Science 1 Stony Brook University

1 Lexical Considerations

Object-Oriented Programming

AP Computer Science A Unit 2. Exercises

Chapter 2 Working with Data Types and Operators

Transcription:

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 for a memory s location where a data value is stored. Janyl Jumadinova Computational Expression 28-30 January, 2019 2 / 17

Variables Variable is a name for a memory s location where a data value is stored. Variable Declaration allows the compiler to reserve space in the main memory that is large enough for the specified type int count; Janyl Jumadinova Computational Expression 28-30 January, 2019 2 / 17

Variables Variable is a name for a memory s location where a data value is stored. Variable Declaration allows the compiler to reserve space in the main memory that is large enough for the specified type int count; Variable Assignment assigns a value to the variable count = 0; Janyl Jumadinova Computational Expression 28-30 January, 2019 2 / 17

Variables Variable is a name for a memory s location where a data value is stored. Variable Declaration allows the compiler to reserve space in the main memory that is large enough for the specified type int count; Variable Assignment assigns a value to the variable count = 0; Must give a value to the variable before using it in the main method. Janyl Jumadinova Computational Expression 28-30 January, 2019 2 / 17

Java Identifiers reserved keywords (class, public, static, void) Java classes, methods, variables: words we chose or make up when writing a program System, println, main, args Janyl Jumadinova Computational Expression 28-30 January, 2019 3 / 17

Java Identifiers reserved keywords (class, public, static, void) Java classes, methods, variables: words we chose or make up when writing a program System, println, main, args Identifier a letter followed by zero or more letters (including $ and ) and digits Janyl Jumadinova Computational Expression 28-30 January, 2019 3 / 17

Identifiers - An identifier may be any descriptive sequence of uppercase and lowercase letters, numbers, or the underscore and dollar-sign characters. Janyl Jumadinova Computational Expression 28-30 January, 2019 4 / 17

Identifiers - An identifier may be any descriptive sequence of uppercase and lowercase letters, numbers, or the underscore and dollar-sign characters. - Ex: Average, count, num1, $test, this is fine Janyl Jumadinova Computational Expression 28-30 January, 2019 4 / 17

Identifiers - An identifier may be any descriptive sequence of uppercase and lowercase letters, numbers, or the underscore and dollar-sign characters. - Ex: Average, count, num1, $test, this is fine Janyl Jumadinova Computational Expression 28-30 January, 2019 4 / 17

Identifiers Identifiers must start with a letter, a currency character ($), or a connecting character such as the underscore ( ). Janyl Jumadinova Computational Expression 28-30 January, 2019 5 / 17

Identifiers Identifiers must start with a letter, a currency character ($), or a connecting character such as the underscore ( ). Identifiers cannot start with a number. Janyl Jumadinova Computational Expression 28-30 January, 2019 5 / 17

Identifiers Identifiers must start with a letter, a currency character ($), or a connecting character such as the underscore ( ). Identifiers cannot start with a number. After the first character, identifiers can contain any combination of letters, currency characters, connecting characters, or numbers. Janyl Jumadinova Computational Expression 28-30 January, 2019 5 / 17

Identifiers Identifiers must start with a letter, a currency character ($), or a connecting character such as the underscore ( ). Identifiers cannot start with a number. After the first character, identifiers can contain any combination of letters, currency characters, connecting characters, or numbers. There is no limit to the number of characters an identifier can contain. Janyl Jumadinova Computational Expression 28-30 January, 2019 5 / 17

Identifiers Identifiers must start with a letter, a currency character ($), or a connecting character such as the underscore ( ). Identifiers cannot start with a number. After the first character, identifiers can contain any combination of letters, currency characters, connecting characters, or numbers. There is no limit to the number of characters an identifier can contain. You can t use a Java keyword as an identifier. Janyl Jumadinova Computational Expression 28-30 January, 2019 5 / 17

Identifiers Identifiers must start with a letter, a currency character ($), or a connecting character such as the underscore ( ). Identifiers cannot start with a number. After the first character, identifiers can contain any combination of letters, currency characters, connecting characters, or numbers. There is no limit to the number of characters an identifier can contain. You can t use a Java keyword as an identifier. Identifiers in Java are case-sensitive; foo and FOO are two different identifiers. Janyl Jumadinova Computational Expression 28-30 January, 2019 5 / 17

Java keywords Janyl Jumadinova Computational Expression 28-30 January, 2019 6 / 17

Literal A constant value in Java is created by using a literal representation of it. 100 ( integer literal ) 98.6 ( float literal ) X ( character literal ) This is a test ( String literal ) Janyl Jumadinova Computational Expression 28-30 January, 2019 7 / 17

Constants Constants hold the same value during their existence. Can use a keyword final before the type and name of the variable: - always contains the same value. final int MAX BUDGET = 1000 Janyl Jumadinova Computational Expression 28-30 January, 2019 8 / 17

Data Types Data stored in memory is a string of bits (0 or 1) Janyl Jumadinova Computational Expression 28-30 January, 2019 9 / 17

Data Types Data stored in memory is a string of bits (0 or 1) How the computer interprets the string of bits depends on the context. In Java, we must make the context explicit by specifying the type of the data. Janyl Jumadinova Computational Expression 28-30 January, 2019 9 / 17

Data Types Java has two categories of data: primitive data (e.g., number, character) object data (programmer created types) There are 8 primitive data types: byte, short, int, long, float, double, char, boolean Primitive data are only single values; they have no special capabilities. Janyl Jumadinova Computational Expression 28-30 January, 2019 10 / 17

Primitive Data Types integers: byte, short, int, long floating point: float, double characters: char booleans: boolean Janyl Jumadinova Computational Expression 28-30 January, 2019 11 / 17

Common Primitive Data Types Type Description Example of Literals int integers (whole numbers) 42, 60634, -8 double real numbers 0.039, -10.2 char single characters a, B, &, 6 boolean logical values true, false Janyl Jumadinova Computational Expression 28-30 January, 2019 12 / 17

Range of Values Type Storage Range of Values int 32 bits -2,147,483,648 to 2,147,483,647 double 64 bits ±10 45 to ±10 38 char 16 bits = 2 bytes 0 to 2 16 or \u0000 to \uffff boolean 1 bit NA Janyl Jumadinova Computational Expression 28-30 January, 2019 13 / 17

Expression Expression is a combination of one or more operators (+,, %,...) and operands (literals, constants, variables,...) Janyl Jumadinova Computational Expression 28-30 January, 2019 14 / 17

Order of Precedence Operators are evaluated in an expression according to the rules of precedence. Janyl Jumadinova Computational Expression 28-30 January, 2019 15 / 17

Order of Precedence Operators are evaluated in an expression according to the rules of precedence. Operators within ( ) are evaluated first. *, /, % evaluated next (L to R). +, - evaluated last (L to R). Janyl Jumadinova Computational Expression 28-30 January, 2019 15 / 17

Scanner The Scanner class in the java.util package is a simple text scanner which can parse primitive types and strings We can use the Scanner class to get the input from the terminal We must create an instance of the Scanner as: Scanner name = new Scanner (System.in); where name is the name you choose for your instance of the Scanner Janyl Jumadinova Computational Expression 28-30 January, 2019 16 / 17

Scanner Methods next() : get the next word (token) as a String nextline() : get a line of input as a String nextint() : get an integer nextdouble() : get a double value Janyl Jumadinova Computational Expression 28-30 January, 2019 17 / 17