Lecture 3.1: Operator Precedence and Eclipse Tutorial Michael Hsu CSULA.

Slides:



Advertisements
Similar presentations
Introduction to C Programming
Advertisements

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.
Computer Science 1620 Loops.
Introduction to Computers and Programming Lecture 4: Mathematical Operators New York University.
Conditions What if?. Flow of Control The order of statement execution is called the flow of control Unless specified otherwise, the order of statement.
Chapter 2: Java Fundamentals Operators. Introduction to OOP Dr. S. GANNOUNI & Dr. A. TOUIR Page 2 Content Group of Operators Arithmetic Operators Assignment.
 2007 Pearson Education, Inc. All rights reserved Introduction to C Programming.
ECE122 L11: For loops and Arrays March 8, 2007 ECE 122 Engineering Problem Solving with Java Lecture 11 For Loops and Arrays.
© 2004 Pearson Addison-Wesley. All rights reserved5-1 Iterations/ Loops The while Statement Other Repetition Statements.
Fall 2006AE6382 Design Computing1 Relational and Logical Operators Use relational operators to test two values Work with values of true and false Compare.
Introduction to C Programming
1 Expressions, Operators Expressions Operators and Precedence Reading for this class: L&L, 2.4.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Control Statements.
Copyright 2008 by Pearson Education 1 Building Java Programs Chapter 2 Lecture 2-1: Expressions and Variables reading:
While Loops and Do Loops. Suppose you wanted to repeat the same code over and over again? System.out.println(“text”); System.out.println(“text”); System.out.println(“text”);
Expressions, Data Conversion, and Input
CONTROL STATEMENTS IF-ELSE, SWITCH- CASE Introduction to Computer Science I - COMP 1005, 1405 Instructor : Behnam Hajian
Primitive Data Types and Operations Identifiers, Variables, and Constants Primitive Data Types Byte, short, int, long, float, double, char, boolean Casting.
Assignment Statements Operator Precedence. ICS111-Java Programming Blanca Polo 2 Assignment, not Equals  An assignment statement changes the value of.
Building Java Programs Primitive Data and Definite Loops.
Lecture 2: Introduction to C Programming. OBJECTIVES In this lecture you will learn:  To use simple input and output statements.  The fundamental data.
Copyright 2008 by Pearson Education 1 Building Java Programs Chapter 2 Lecture 2-1: Expressions and Variables reading:
PHY-102 SAPVariables and OperatorsSlide 1 Variables and Operators In this section we will learn how about variables in Java and basic operations one can.
COMP Primitive and Class Types Yi Hong May 14, 2015.
Programming in Java (COP 2250) Lecture 4 Chengyong Yang Fall, 2005.
© 2006 Pearson Education 1 Obj: to use assignment operators HW: Prelab Exercises 2 Quiz 3.1 – 3.4 in two class days  Do Now: 1.Read p.144 – 145 (3.4 “more.
Copyright 2010 by Pearson Education 1 Building Java Programs Chapter 2 Lecture 2-1: Expressions and Variables reading:
1 Building Java Programs Chapter 2 Lecture 2-1: Expressions and Variables reading:
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.
Expression and Operator. Expressions and Operators u Examples: 3 + 5; x; x=0; x=x+1; printf("%d",x); u Two types: –Function calls –The expressions formed.
Java Programming: From Problem Analysis to Program Design, Second Edition 1 Lecture 1 Objectives  Become familiar with the basic components of a Java.
CHAPTER 2 PART #4 OPERATOR 1 st semester King Saud University College of Applied studies and Community Service Csc
OPERATORS IN C CHAPTER 3. Expressions can be built up from literals, variables and operators. The operators define how the variables and literals in the.
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.
ECLIPSE IDE & PACKAGES. ECLIPSE IDE Setting up workspace Making a new project How to make classes Packages (will explain more about this) Useful short-cuts.
Java Programming: Guided Learning with Early Objects Chapter 1 Basic Elements of Java.
CSE 220 – C Programming Expressions.
Building Java Programs
Primitive Data Types August 28, 2006 ComS 207: Programming I (in Java)
2.5 Another Java Application: Adding Integers
Loop Structures.
Primitive Data, Variables, Loops (Maybe)
OPERATORS (1) CSC 111.
OPERATORS (2) CSC 111.
Building Java Programs
Building Java Programs
Building Java Programs
Building Java Programs Chapter 2
Chapter 2: Java Fundamentals
Building Java Programs
Chapter 2 Programming Basics.
Building Java Programs
Building Java Programs
Building Java Programs
Building Java Programs
Building Java Programs
Building Java Programs
Building Java Programs
Building Java Programs
Building Java Programs Chapter 2
Building Java Programs
Chap 7. Advanced Control Statements in Java
Assignment Operators Topics Increment and Decrement Operators
Building Java Programs
Building Java Programs
Introduction to C Programming
Advanced Programming TA Session 3
Building Java Programs
Building Java Programs
Presentation transcript:

Lecture 3.1: Operator Precedence and Eclipse Tutorial Michael Hsu CSULA

Clarifications for Lecture 3  a % b  If a > b, then it returns the remainder of the division  If a < b, then it returns a  If a == b, then it returns 0  Testing even and odd  If x is even, then x % 2 == 0 evaluates to true  If x is odd, then x % 2 == 1, or you can use x % 2 != 0

More Clarifications  Recall the fun example: int i =10; int k = i+++i; System.out.println(k);  Why is k == 21?

Expressions, Literals, and Statements  Literals:  Source code representation of a fixed value  Examples:  1, 2, 0, -200, true, false, ‘A’  Expression:  Made up of variables, operators, that evaluates to a single value  Java subexpressions are evaluated left to right  Examples:  2 * 3 * 4  2 % 3  i+++I  K =10 Source:

Statements  “sentences” with semi colons at the end  Assignment  Any Use of ++ or –  You will lean different types later

Operator Precedence In Java  Some key words:  Precedence Order:  When two operators share an operand the operator with the higher precedence goes first  Example: * 3 is the same as 1 + (2 * 3)  Associativity:  When an expression has two operators with the same precedence, the expression is evaluated according to its associativity  Example: x = y = z= 17 is evaluated as x = ( y= (z = 17)), because = operator has right to left associativity Source:

Precedence and Associativity Table 

So how does i+++i work? int i =10; int k = i+++i; System.out.println(k);  i+++i is equivalent to (i++)+i, since ++ has precedence over +  We evaluate from left to right  Since it is post increment, i++ evaluates to 10, (10) + i  After i++ is evaluated, we increment i so i becomes 11  = 21

Using variables in String literals  We did System.out.println() with String literals inside:  System.out.println(“2 divided by 3 in java is zero”);  To use variables in String literals, use the + operator: int num1 = 2; int num2 = 3; System.out.println(num1+ " divided by "+num2+" in Java is " + 2/3);

Eclipse Tutorial  Follow the eclipse setup guide in the resources section on the course website  Key terms:  Workspace  Your working directory  it will contain multiple projects  When you want to move your eclipse files from file explorer, move the entire workspace folder.  Projects  This is where you will put your java files  You can have one workspace for all your courses, and have different projects for each course, or have separate workspaces for each course and have separate projects for each assignments  I recommend having a different workspace for each of your courses with separate projects for each assignment of the course  Makes your life easier

Useful Eclipse Tips  Show Line Numbers:  Window -> Preferences -> expand General -> expand Editors -> click on Text Editors -> check show line numbers  Ctrl+ SPACE  Autocomplete, auto fix  Ctrl + SHIFT + f  Auto format and indentation  Ctrl + d  Delete entire line  Right click on a variable then click refactor  You can rename your variables and Eclipse will update all the occurrences for you

DO NOT delete files in your eclipse workspace from file explorer  Eclipse uses special files to track how your project directory is set up, your interface layout, etc.  Do everything from within eclipse so you don’t screw up your projects  I’ll try to put up an step by step tutorial on the course webpage