Names of variables, functions, classes

Slides:



Advertisements
Similar presentations
AP Computer Science Anthony Keen. Computer 101 What happens when you turn a computer on? –BIOS tries to start a system loader –A system loader tries to.
Advertisements

STRING AN EXAMPLE OF REFERENCE DATA TYPE. 2 Primitive Data Types  The eight Java primitive data types are:  byte  short  int  long  float  double.
DATA TYPES, VARIABLES, ARITHMETIC. Variables A variable is a “named container” that holds a value. A name for a spot in the computer’s memory This value.
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.
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.
IntroductionIntroduction  Computer program: an ordered sequence of statements whose objective is to accomplish a task.  Programming: process of planning.
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall Office hours: M-F 11:00-11:
Primitives in Java Java has eight primitive types –boolean –integral types: signed: long, int, short, byte unsigned: char –floating point types: double,
10-Jun-15 Introduction to Primitives. 2 Overview Today we will discuss: The eight primitive types, especially int and double Declaring the types of variables.
Variables Pepper. Variable A variable –box –holds a certain type of value –value inside the box can change Example –A = 2B+1 –Slope = change in y / change.
CIS 234: Using Data in Java Thanks to Dr. Ralph D. Westfall.
Introduction to Computers and Programming Lecture 4: Mathematical Operators New York University.
CMT Programming Software Applications
1 Data types, operations, and expressions Overview l Primitive Data Types l Variable declaration l Arithmetical Operations l Expressions.
1 9/20/06CS150 Introduction to Computer Science 1 Review: Exam 1.
Data types and variables
Fundamental Programming Structures in Java: Comments, Data Types, Variables, Assignments, Operators.
Primitive Types Java supports two kinds of types of values – objects, and – values of primitive data types variables store – either references to objects.
Chapter 2 Data Types, Declarations, and Displays
Hello, world! Dissect HelloWorld.java Compile it Run it.
L EC. 02: D ATA T YPES AND O PERATORS (1/2) Fall Java Programming.
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.
CSCI 1100/1202 January 16, Why do we need variables? To store intermediate results in a long computation. To store a value that is used more than.
 Value, Variable and Data Type  Type Conversion  Arithmetic Expression Evaluation  Scope of variable.
Copyright © 2002 W. A. Tucker1 Chapter 7 Lecture Notes Bill Tucker Austin Community College COSC 1315.
By Nicholas Policelli An Introduction to Java. Basic Program Structure public class ClassName { public static void main(String[] args) { program statements.
Outline Character Strings Variables and Assignment Primitive Data Types Expressions Data Conversion Interactive Programs Graphics Applets Drawing Shapes.
 JAVA Compilation and Interpretation  JAVA Platform Independence  Building First JAVA Program  Escapes Sequences  Display text with printf  Data.
Data & Data Types & Simple Math Operation 1 Data and Data Type Standard I/O Simple Math operation.
Primitive Variables.
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.
An Introduction to Java – Part 1 Dylan Boltz. What is Java?  An object-oriented programming language  Developed and released by Sun in 1995  Designed.
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall
Introduction to Java Lecture Notes 3. Variables l A variable is a name for a location in memory used to hold a value. In Java data declaration is identical.
Assignment An assignment statement changes the value of a variable The assignment operator is the = sign total = 55; Copyright © 2012 Pearson Education,
1 CS 007: Introduction to Computer Programming Ihsan Ayyub Qazi.
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
Primitive Variables.
Java Language Basics By Keywords Keywords of Java are given below – abstract continue for new switch assert *** default goto * package.
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.
Java Nuts and Bolts Variables and Data Types Operators Expressions Control Flow Statements Arrays and Strings.
A data type in a programming language is a set of data with values having predefined characteristics.data The language usually specifies:  the range.
1 Identifiers: Names of variables, functions, classes (all user defined objects), Examples: a b gcd GCD A COSC1373 TAX Tax_Rate Tax Rate if else while.
1 Lecture # 2. * Introducing Programming with an Example * Identifiers, Variables, and Constants * Primitive Data Types * Byte, short, int, long, float,
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.
What will each of the following lines print? System.out.println("number" ); number645 System.out.println("number" + (6 + 4)+ 5); number105 System.out.println(6.
2.0 FUNDAMENTALS OF JAVA PROGRAMMING LANGUAGE
Lecture 2 Data Types Richard Gesick.
Yanal Alahmad Java Workshop Yanal Alahmad
Lecture 2: Data Types, Variables, Operators, and Expressions
2.5 Another Java Application: Adding Integers
Object Oriented Programming
Multiple variables can be created in one declaration
Escape Sequences What if we wanted to print the quote character?
Building Java Programs Chapter 2
An Introduction to Java – Part I, language basics
Chapter 2 Variables.
Program Breakdown, Variables, Types, Control Flow, and Input/Output
Chap 1 Chap 2 Chap 3 Chap 5 Surprise Me
Building Java Programs Chapter 2
Building Java Programs
Introduction to Primitives
Building Java Programs Chapter 2
Presentation transcript:

Names of variables, functions, classes Identifiers: Names of variables, functions, classes (all user defined objects), Examples: if else while int float double main ... Can’t be used as identifiers They are reserved word a b gcd GCD A COSC1373 TAX Tax_Rate Tax Rate No special chars $ “ ; , ... Two identifiers, Tax and Rate 1 123 No numbers 5/6/2019 ITK 168

A name of a location in memory to hold value A variable: A name of a location in memory to hold value A value of what?  11110101 int a; String A; 245  0010 0010 0010 0100 0010 0101 the name the type the value 5/6/2019 ITK 168

Text String Binary: Text T e l : 2 8 7 4 9 EBCDIC E3 85 93 7A 40 F2 F8 ASCII 54 65 6C 2A 20 32 38 37 34 39 Binary: 0101 0100 0110 0101 0110 1100 0010 1010 0010 0000 0011 0010 0011 0010 0011 1000 0011 0111 0011 0010 0011 0100 0011 1001 5/6/2019 ITK 168

ASCII American National Standard Code for Information Interchange http://www.dynamoo.com/technical/ascii.htm American National Standard Code for Information Interchange 7-bit code Arabic ASCII Binary Hex 010 0000 20 1 010 0001 21 2 010 0010 22 3 010 0011 23 4 010 0100 24 5 010 0101 25 6 010 0110 26 7 010 0111 27 8 010 1000 28 9 010 1001 29 Char ASCII Binary Hex a 110 0001 61 b 110 0010 62 c 110 0011 63 … ……… A 100 0001 41 B 100 0010 42 C 100 0011 43 …. ……. : 011 1010 3A # 010 0011 23 5/6/2019 ITK 168

Numbers inside Computers Bits Minimum Maximum Integers Short Signed 8 -128 127 Unsigned 255 Integer 16 -32,768 32,767 65,535 Long 32 -2,147,483,648 2,147,483,647 4,294,967,295 Range Floating Points Single -3.410-38 3.41038 Double 64 -1.710-308 1.710308 Java’s Types short int long float double 5/6/2019 ITK 168

8 primitive data types in Java short i,j; int no; long sum; float total; double tax; char grade; byte b; boolean yes_or_no; i = 3; j = 3.14; tax = 8.25/100; grade = ‘A’; grage = ‘B’; grade = 97; yes_or_no = true; yes_or_no = false; Every variable has to be declared before we use it. 5/6/2019 ITK 168

Variables and Assignments Everything that can receive a value L-value = R-value Everything that can give a value Assignment operator variable function expression literal variable The data types in both sides have to be consistent. If not, type-casting must be done. 5/6/2019 ITK 168

illegal Assignment examples L-value = R-value i = (3+7)*2-4-2*5; i = 3/2-0.5; illegal 3 = j; gcd(24,18) = 2+3; i+1 = j+3; i = 3/2.0-0.5; i = i+2; total = i+j; average = total/2; sum = average*10*tax_rate; i = gcd(24,18); i = Integer.parseInt( ); JOptionPane.showInputDialog("Input y") 5/6/2019 ITK 168

More on Assignments L-value = R-value L-value = R-value L-value = This operation itself will give a value L-value = R-value L-value = R-value L-value = L-value = a = b = c = i+j+3+gcd(15,6); illegal: a = b+1 = c = i+j+3+gcd(15,6); 5/6/2019 ITK 168

Parameter Passing How are parameters passed? Looks simple enough… formal parameters int plus (int a, int b) { return a+b; } int x = plus(1,2); function body actual parameters (arguments) function call How are parameters passed? Looks simple enough… There are some techniques 5/6/2019 ITK 168

Parameter Correspondence Which actual parameters go to which formal parameters? Most common case: positional parameters Correspondence determined by positions nth formal parameter matched with nth actual 5/6/2019 ITK 168

Parameter Passing function call 1  a 2  b int minus (int a, int b) { return a - b; } int x = minus(1, 2); function call 1  a 2  b 5/6/2019 ITK 168

Local variables int minus (int a, int b) { int x = a – b; return x; } public static void main(String[] args) { .... int a = 3; int b = 2; int d = 0; int x = a+b; d = minus(b,a); ..... } 5/6/2019 ITK 168

Arithmetic operators in Java + - * / % (x % y) is the remainder of x divided by y + - * / % (x % y) is the remainder of x divided by y Relational and logical operators in Java Resulting true or false < <= > >= == != && || ! & | ^ (20 < y) && (x <= i) 5/6/2019 ITK 168

Logical Operators || && ! Assume x = 10 true false true true false || && ! Assume x = 10 (1 || 0) ((18 <= x) && (x <= 50)) ((18 <= x) || (x <= 50)) !(x < 5) is same as (x >= 5) (((x % 2) == 0) && ((x % 3) == 0)) true false true true false 5/6/2019 ITK 168