CIS3931 – Intro to JAVA Lecture Note Set 2 17-May-05.

Slides:



Advertisements
Similar presentations
Introduction to Java 2 Programming
Advertisements

Java Syntax Part I Comments Identifiers Primitive Data Types Assignment.
CIS 234: Using Data in Java Thanks to Dr. Ralph D. Westfall.
COMP 14 Introduction to Programming Miguel A. Otaduy May 18, 2004.
Variables, Data Types, & Arithmetic Expressions CSC 1401: Introduction to Programming with Java Lecture 3 Wanda M. Kunkle.
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie June 27, 2005.
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie June 30, 2005.
Java Building Elements Lecture 2 Instructors: Fu-Chiung Cheng ( 鄭福炯 ) Associate Professor Computer Science & Engineering Tatung University
Primitive Data Types and Operations Identifiers, Variables, and Constants Primitive Data Types Byte, short, int, long, float, double, char, boolean Casting.
Chapter 2 Primitive Data Types and Operations F Introduce Programming with an Example  The MyInput class F Identifiers, Variables, and Constants F Primitive.
1 Chapter 2 Primitive Data Types and Operations F Introduce Programming with an Example  The MyInput class F Identifiers, Variables, and Constants F Primitive.
Copyright © 2002 W. A. Tucker1 Chapter 7 Lecture Notes Bill Tucker Austin Community College COSC 1315.
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.
CSE 1301 Lecture 2 Data Types Figures from Lewis, “C# Software Solutions”, Addison Wesley Richard Gesick.
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.
CPS120: Introduction to Computer Science
Flow of Control Part 1: Selection
Data & Data Types & Simple Math Operation 1 Data and Data Type Standard I/O Simple Math operation.
Primitive Variables.
Course Title: Object Oriented Programming with C++ instructor ADEEL ANJUM Chapter No: 03 Conditional statement 1 BY ADEEL ANJUM (MSc-cs, CCNA,WEB DEVELOPER)
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.
Computer Engineering 1 st Semester Dr. Rabie A. Ramadan 3.
VARIABLES, CONSTANTS, OPERATORS ANS EXPRESSION
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
Primitive Variables.
Copyright Curt Hill Variables What are they? Why do we need them?
Chapter 2 Variables.
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
Variables and Constants Objectives F To understand Identifiers, Variables, and Constants.
Developed at Sun Microsystems in 1991 James Gosling, initially named “OAK” Formally announced java in 1995 Object oriented and cant write procedural.
CSM-Java Programming-I Spring,2005 Fundamental Data Types Lesson - 2.
2: Basics Basics Programming C# © 2003 DevelopMentor, Inc. 12/1/2003.
Variables  A piece of memory set aside to store data  When declared, the memory is given a name  by using the name, we can access the data that sits.
 2003 Prentice Hall, Inc. All rights reserved. 1 Basic C++ Programming.
1 1 Chapter 2 Elementary Programming. 2 2 Motivations In the preceding chapter, you learned how to create, compile, and run a Java program. Starting from.
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.
Sudeshna Sarkar, IIT Kharagpur 1 Programming and Data Structure Sudeshna Sarkar Lecture 3.
IAS 1313: OBJECT ORIENTED PROGRAMMING Week 3: Data Type, Control Structure and Array Prepared by: Mrs Sivabalan1.
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.
1 ENERGY 211 / CME 211 Lecture 3 September 26, 2008.
Fundamentals 2.
Chapter # 2 Part 2 Programs And data
Topic 2 Elementary Programming
Chapter 2 Variables.
Elementary Programming
BASIC ELEMENTS OF A COMPUTER PROGRAM
Chapter 2 Elementary Programming
Yanal Alahmad Java Workshop Yanal Alahmad
Documentation Need to have documentation in all programs
Variables A piece of memory set aside to store data
By: Syed Shahrukh Haider
Introduction to Programming in Java
IDENTIFIERS CSC 111.
Building Java Programs Chapter 2
مساق: خوارزميات ومبادئ البرمجة الفصل الدراسي الثاني 2016/2015
An Introduction to Java – Part I, language basics
Variables Numbers can be stored and retrieved while a program is running if they are given a home. The way that integers and decimal numbers are stored.
Chapter 2 Variables.
PHP.
C++ Data Types Data Type
Chapter 2: Java Fundamentals
Chapter # 2 Part 2 Programs And data
elementary programming
Chapter 2: Java Fundamentals
Primitive Types and Expressions
Unit 3: Variables in Java
Chapter 2 Variables.
Chapter 2 Primitive Data Types and Operations
Review of Java Fundamentals
Presentation transcript:

CIS3931 – Intro to JAVA Lecture Note Set 2 17-May-05

Variables - Reminders Variables are Case-Sensitive It must be a legal identifier - May only begin with a letter, the underscore or a dollar sign. - Consist of letters, digits, underscores, and the dollar sign. - Must not start with a number!

Variables - Reminders It must not be one of Java’s reserved keywords. (See Appendix C for a complete list) It must not be a boolean literal – true or false It must not be the reserved word null It can be any length

Built-in Data Types char – used for storing single characters boolean – has two possible values, true or false Integer types: - byte – 8 bits - short – 16 bits - int – 32 bits - long – 64 bits

Data-Types continued Floating point types (for storing decimals) - float – 32 bits - double – 64 bits

Declaring Variables int x; //don’t forget the ; char grade = ‘A’; You can also declare more than one variable in a line. Ex… float x=3.4, y=9.7, z; When declaring on one line, separate by a comma.

Control Structures Provide a method by which you can test variables and conditions in your program Provide a method of flow control and execution if statements if/else statements while loops

Logical Operators Two types – Relational and Conditional Relational : Compares two values and determines the relationship between them Examples : > , < , >= , ==

Relationship operators Use Description > op1 > op2 Returns true if op1 is greater than op2 >= op1 >= op2 Returns true if op1 is greater than or equal to op2 < op1 < op2 Returns true if op1 is less than op2 <= op1 <= op2 Returns true if op1 is less than or equal to op2 == op1 == op2 Returns true if op1 and op2 are equal != op1 != op2 Returns true if op1 and op2 are not equal

Conditional Operators Used with relational operators Combines multiple relational operators with a condition such as (and) or (or)

Conditional Operators Use Description && Op1 && op2 Returns true if both op1 and op2 are true || Op1 || op2 Returns true if either op1 or op2 is true ! !op Returns true if op is false

If statements Execute if the statement returns true int x = 5; if (x == 5) { System.out.print(“x = 5”); } { } are optional if only 1 line under if

If/Else The else executes only when the if statement fails. if (x == 5) System.out.println(“x=5”); else System.out.println(“x != 5”);

Dangling-else if (x > 5) if (y > 5) System.out.println(“x and y are > 5”); else System.out.println(“x is <= 5”); What is the output if… x=10 and y=10? If x=10 and y=2?

Dangling Else p2 Compiler actually sees… if (x > 5) if (y > 5) System.out.println(“x and y are > 5”); else System.out.println(“x is <= 5”); To solve this problem, use { }

While Loops while executes until false. int product = 3; while (product <= 100 ) product = 3 * product; product is initially 3, then it goes to 9, 27, 81, 243. Once it gets to 243, it stops because 243 is not <= 100.

More while loops { } must be used after the while statement if there is more than 1 line. While loops are extremely useful when you want to obtain correct input from the user. Make user keep entering the information until it is correct.

Questions…. http://java.sun.com/docs/books/tutorial/java/nutsandbolts/relational.html