Agenda Packages and classes Types and identifiers Operators

Slides:



Advertisements
Similar presentations
Control Structures. Decision Making Structures The if and if…else are all selection control structures that introduce decision-making ability into a program.
Advertisements

Introduction to Computers and Programming Midterm Review Sana Odeh.
1 Chapter 4 Language Fundamentals. 2 Identifiers Program parts such as packages, classes, and class members have names, which are formally known as identifiers.
Program Elements We can now examine the core elements of programming (as implemented in Java) We focuse on: data types variable declaration and use, constants.
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.
© The McGraw-Hill Companies, 2006 Chapter 1 The first step.
Introduction to Programming Prof. Rommel Anthony Palomino Department of Computer Science and Information Technology Spring 2011.
1 Variables, Constants, and Data Types Primitive Data Types Variables, Initialization, and Assignment Constants Characters Strings Reading for this class:
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,
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.
JAVA Tokens. Introduction A token is an individual element in a program. More than one token can appear in a single line separated by white spaces.
Chapter 3 Syntax, Errors, and Debugging Fundamentals of Java.
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
Chapter 2: Java Fundamentals
Java Programming: From Problem Analysis to Program Design, 4e Chapter 2 Basic Elements of Java.
Java Programming: From Problem Analysis to Program Design, 5e Chapter 2 Basic Elements of Java.
CPS120: Introduction to Computer Science Operations Lecture 9.
1 Chapter 3 Syntax, Errors, and Debugging Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.
VARIABLES, CONSTANTS, OPERATORS ANS EXPRESSION
Chapter 3 Syntax, Errors, and Debugging Fundamentals of Java.
Primitive Variables.
Java Programming, Second Edition Chapter Two Using Data Within a Program.
Advanced Arithmetic, Conditionals, and Loops INFSY 535.
Programming in Java (COP 2250) Lecture 4 Chengyong Yang Fall, 2005.
Data Types, Variables, and Arithmetic Java Methods A & AB Object-Oriented Programming and Data Structures Maria Litvin ● Gary Litvin Copyright © 2006 by.
Software Technology - I Tools to do operations.....
By Mr. Muhammad Pervez Akhtar
CSM-Java Programming-I Spring,2005 Fundamental Data Types Lesson - 2.
Tokens in C  Keywords  These are reserved words of the C language. For example int, float, if, else, for, while etc.  Identifiers  An Identifier is.
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.
Copyright © 2014 by John Wiley & Sons. All rights reserved.1 Decisions and Iterations.
Sudeshna Sarkar, IIT Kharagpur 1 Programming and Data Structure Sudeshna Sarkar Lecture 3.
 Array ◦ Single & Multi-dimensional  Java Operators ◦ Assignment ◦ Arithmetic ◦ Relational ◦ Logical ◦ Bitwise & other.
Inside Class Methods Chapter 4. 4 What are variables? Variables store values within methods and may change value as the method processes data.
Basic Data Types & Memory & Representation. Basic data types Primitive data types are similar to JAVA: char int short long float double Unlike in JAVA,
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.
CompSci 230 S Programming Techniques
Basic Data Types & Memory & Representation
Chapter 02 Data and Expressions.
Lecture 3 Java Operators.
Chapter 3 Syntax, Errors, and Debugging
Programming in Java Sachin Malhotra, Chairperson, PGDM-IT, IMS Ghaziabad Saurabh Chaudhary, Dean, Academics, IMS Ghaziabad.
2.0 FUNDAMENTALS OF JAVA PROGRAMMING LANGUAGE
Chapter 4 – Fundamental Data Types
Introduction to Computer Science / Procedural – 67130
Yanal Alahmad Java Workshop Yanal Alahmad
Java Primer 1: Types, Classes and Operators
Tokens in C Keywords Identifiers Constants
Primitive Data Types August 28, 2006 ComS 207: Programming I (in Java)
Multiple variables can be created in one declaration
Chapter 3 Assignment Statement
User input We’ve seen how to use the standard output buffer
Java Programming: From Problem Analysis to Program Design, 4e
Java - Data Types, Variables, and Arrays
An Introduction to Java – Part I, language basics
Chapter 2: Basic Elements of Java
Arrays We often want to organize objects or primitive data in a way that makes them easy to access and change. An array is simple but powerful way to.
Review for Final Exam.
Java Tokens & Data types
Lectures on Numerical Methods
Expressions and Assignment
Review for Final Exam.
CS2011 Introduction to Programming I Elementary Programming
Winter 2019 CMPE212 4/7/2019 CMPE212 – Reminders
Primitive Types and Expressions
Building Java Programs
Presentation transcript:

Agenda Packages and classes Types and identifiers Operators Input/output Control structures Errors and exceptions homework

Packages and classes How do you use the classes in the package? How packages do you know? Which package is automatically provided to all java program? The compiler converts source code into machine-readable form called?? What are reserved words? List 5. Java application vs java applet

Types and identifiers What are identifiers? Declaration vs initialization. Data types? What 2 types? Name 4 primitive types. Integer are bounded. What does it mean? What happens if you stores an integer value which is too big? What erros? Give me a signature of declaration.

int vs double Which data type has more storage? Which causes a compile-time error? Assign an int to a double or the other way around? Why What happens when you assign a double to an int? int aInt = 7; double aDouble; aInt = aDouble; => ok?

What happens when you assign an int to a double? int aInt=8; double aDouble=8.0; aDouble = aInt; => ok? What do you prevent the compiling error when you try to assign one data type to another data type? How does the book say about rounding a positive or negative int to the nearest numbers?

Storage of numbers What other primitive(built-in) data type uses one byte of storage? Which bit stores the sign of the integer, what number for positive/negative? What is the largest positive integer that can be store using byte? How many bytes(bits) does Java use for type int? If java uses 6 bytes for a number, what is the number range? What are the 2 java constants for the max/min that an int can hold?

Hexadecimal numbers How a hex number is represented? With symbols … In java, how does a hex number is represented? How to convert from a hex to binary and from binary to hex? 4FA -> 1101 1000 1111 ->

Final variables Also called use-defined constant What is the keyword and where is it placed? What is a common use for a constant? What benefit is it to have a constant?

Arithmetic Operators Arithmetic operators? When any arithmetic operators apply to a double and an int, what happens? What is the result? 3.0 / 4 => 3 / 4.0 => (int) 3.0 / 4 => (double)3 / 4 => (double)(3 / 4 )=>

Relational operators What are they? (6 of them) Where(how) are they used? Can relational operators be used to compare two objects? Can relational operators be used to compare two doubles?

Logical operators What are they? Where(how) are they used? What is short-circuit evaluation? if(num != 0 && scoreTotal/num > 90)… If num is 0, will this statement cause a runtime error when division by 0?

Assignment operators What are they? What are compound assignment operators? Is the following statement allowed? int a, b, c; a = b = c = 0;

Increment and decrement operators What are they? i++ and i-- are equivalent? int x = 10; System.out.println( x++); => x? System.out.println( ++x); => x?

Operator precedence What would you roughly arrange the precedence for the following operators? a) increment/decrement operators b) assignment operators c) logical operators d) relational operators System.out.println(5 + 3 < 6 – 1); => output?

Escape sequences What is an escape sequence? What is its purpose? Name 3 examples. Write a statement which will prints out a) welcome to the party b) His name is “Harry” c) d:\myFile\..

Control structures Nested “if” statement is equivalent to putting the two “if” in one statement with what operator? Loophole: int n = 7; if( n > 0) if( n % 2 == 0) System.out.println(n); else System.out.println(n + “is not positive”);

for loop for(initialization; termination condition; update statement) { body of the loop ..} When will be termination condition be executed, before the body or after? When will be the update statement be executed, before the body or after? for(int k = 20; k >=15; k--) System.out.print(k + “ “ ); => what will be printed?

Enhanced for loop Only for what type of data? for( int element : data) System.out.print(element+ “ “ ); What is data? for( boolean element : data) Can the for-each loop be used to replace or removing elements?

Nested for loop for(int i=1; i<7; i++) { for(int j =0; j <=i; j++) System.out.print(“*”); } System.out.println(“”); What will be printed?

Errors and exceptions Will be covered next class.

homework Read BPJ 37 and Barron’s p68-69 Quiz on materials of Barron’s chapter 1