Register now to access 7 million high quality study materials (What's Course Hero?) Course Hero is the premier provider of high quality online educational resources. With millions of study documents, online tutors, digital flashcards and free courseware, Course Hero is helping students learn more efficiently and effectively. Whether you're interested in exploring new subjects or mastering key topics for your next exam, Course Hero has the tools you need to achieve your goals.

2 Pages

Part 3 Precedences of operators

Course: CS 101, Spring 2008
School: Cornell
Rating:

Word Count: 324

Document Preview

of Precedences operators You know that multiplication * takes precedence over addition +, e.g. the expression 5 + 4 * 3 is evaluated as if it were parenthesized like this: 5 + (4 * 3). Mathematics has conventions for precedences of operators in order to reduce the number of parentheses required in writing complex expressions. Some of these conventions are standard throughout the world --like * over +. Others are...

Register Now

Unformatted Document Excerpt

Coursehero >> New York >> Cornell >> CS 101

Course Hero has millions of student submitted documents similar to the one
below including study guides, practice problems, reference materials, practice exams, textbook help and tutor support.

Course Hero has millions of student submitted documents similar to the one below including study guides, practice problems, reference materials, practice exams, textbook help and tutor support.
of Precedences operators You know that multiplication * takes precedence over addition +, e.g. the expression 5 + 4 * 3 is evaluated as if it were parenthesized like this: 5 + (4 * 3). Mathematics has conventions for precedences of operators in order to reduce the number of parentheses required in writing complex expressions. Some of these conventions are standard throughout the world --like * over +. Others are not. Below is a table of precedences for Java operators. Refer to this table, or the one on p. 227 of Gries/Gries, if you forget the precedences. Table of operator precedences ORDER Highest OPERATORS Unary ops: Binary arithmetic ops. Binary arithmetic ops. Arithmetic relations: Equality relations: Logical and: Lowest Logical or: EXAMPLES + ++ ! * / % + < > <= >= == != && || For example, the expression (n != 0) && (10/n > 2) can be easily rewritten as n != 0 && 10/n > 2 because relational operators have precedence over &&. Keep redundant parentheses to a minimum (but don't sacrifice clarity) Your goal in writing expressions should be to make them a clear and simple-looking possible, as and this can often be done by eliminating redundant expressions --but you can help the reader by putting more space around operators with less precedence. For example, the two assignment statements shown below have the same meaning, but the second is easier to read. b= ((x<=y)||(x<=z)); b= x <= y || y <= z; Keep redundant parentheses to a minimum. For example, they are not needed in a return statement within a function body (you will learn about the return statement later): the following two statements are equivalent, but the second is easier to read. return (x >= -10 && x <= 10); return x >= -10 && x <= 10; About AND and OR Java gives && precedence over ||, so that b || c && d is equivalent to b || (c && d). This convention is non-standard, and controversial for some. Therefore, when writing sequences of &&s and ||s, we suggest always putting in parentheses to make the meaning clear. This is a case where the suggestion to eliminate redundant parentheses is overruled in favor of removing confusion and providing clarity.
Find millions of documents on Course Hero - Study Guides, Lecture Notes, Reference Materials, Practice Exams and more. Course Hero has millions of course specific materials providing students with the best way to expand their education.

Below is a small sample set of documents:

Cornell - CS - 101
Type StringType String Type String is different from primitive types int and double. String is a class type. We explain what this means later, after we have explained what a class is. Each value of type String is a sequence of characters. We write
Cornell - CS - 101
Type charThe values of type char are the characters that you can type on your keyboard, plus many more. Literals of type char are written with single-quote marks surrounding the character. The last example below is the blank, or space character, whi
Cornell - CS - 101
Type booleanIn some programming languages, for example Matlab and C, integers are used to represent the logical values true and false. Generally, 0 is used for false, and any other integer can be used for true. Java handles boolean values differentl
Cornell - CS - 101
Safety and strong typingSafetyOne property that is sometimes looked for in a programming language is safety. There is some confusion as to what safety means, but here is a definition used in the year 2000 by an ad hoc committee that recommended tha
Cornell - CS - 101
When you have completed module 1, part 4, on variables, declarations, and assignments, please ask a consultant to give you a quiz on this material. The purpose of the quiz is to make sure that we all have the same idea on what it means to execute an
Cornell - CS - 101
The conditional expressionThe purpose of the conditional expression is to select one of two expressions depending on a third, boolean, expression. The format for the conditional expression is &lt;boolean-expression&gt; ? &lt;expression-1&gt; : &lt;expression-2&gt; If
Cornell - CS - 101
The assignment statementThe assignment statement is used to store a value in a variable. As in most programming languages these days, the assignment statement has the form: &lt;variable&gt;= &lt;expression&gt;; For example, once we have an int variable j, we c
Cornell - CS - 101
Objects of class JFrameThus far, you have seen powerpoint slides that showed what an object is, how to call methods of an object, how to reference fields of an object, and how to create a new object using a new-expression. We now make these concepts
Cornell - CS - 101
Variables and declarationsA variable is a name with an associated value. Throughout this course, we draw a variable as a named box with the value in the box. For example, here is a variable x associated with the value 5. Sometimes, we draw a line in
Cornell - CS - 101
Folders &amp; file drawers - objects and classesIn a dentist office, you are likely to see file drawers filled with manila folders. The file drawer named Patient contains one manila folder for each patient, with each manila folder in the file drawer con
Cornell - CS - 101
Lab 2. Creating objects, calling their methods, and writing subclassesThis lab helps you experiment with creating objects, calling their methods, and writing subclasses. At the end of this handout is a list of oft-used methods of class JFrame. The i
Cornell - CS - 101
Self-help exercises: evaluating new-expressionsAs mentioned in the lecture, evaluation of a new expression like new Animal() is a two-step process: 1. Create (or draw) a new manila folder (object) of class Animal; 2. Yield as value of the new-expres
Cornell - CS - 101
Self-help exercise: Drawing objectsIt is important that you be able to draw manila folders (objects) of a class when you have to. The need will arise when executing some part of a program by hand in order to find an error. Further, the ability to dr
Cornell - CS - 101
PackagesIn the previous lecture, we used the class name javax.swing.JFrame. In this little lecture, we show how it can be abbreviated as JFrame. In Java, a package is a collection of classes that reside in the same directory on your hard drive. In o
Cornell - CS - 101
Types and referencing components of an objectA class name like Patient is also considered to be a type. Its values are the names of manila folders, or objects, of that class. The type has no operations, because one shouldn't be able to operate on th
Cornell - CS - 101
The class definitionWe write our first Java class, in the upper right pane of DrJava. This class definition will describe the components that are placed in each manilla folder, or object, of the class. We start by putting a comment that indicates wh
Cornell - CS - 101
Field declarations and getter/setter methodsConsider writing a class Chapter. Each instance of Chapter will contain information about a chapter of a book, like the chapter number, so we need to declare a variable in the class. The basic form of a de
Cornell - CS - 101
The subclass definitionThe manila folder for subclass Demo Here is a manilla folder -an object or instance- of class JFrame. The tab contains the name of the folder, the name of the class appear in the upper right, and we show only some of the meth
Cornell - CS - 101
Function and Procedure CallsA function call has the form &lt;function-name&gt; ( &lt;arguments&gt; ) and a procedure call has the form &lt;procedure-name&gt; ( &lt;arguments&gt; ) ; / this is a statement / this is an expressionwhere &lt;arguments&gt; is a sequence of expressio
Cornell - CS - 101
Executing method callsIntroduction It is important that you understand how a method call is executed, for several reasons. This knowledge will give you a better understanding of how a program is executed. You may have to execute a call yourself, by
Cornell - CS - 101
Conditional statements and loopsIntroductionEvery procedural programming language has conditional statements (if-statements) and iterative statements (loops). You should be familiar with the concepts -unless your only previous programming language
Cornell - CS - 101
Arrays in JavaIntroductionJava, like most programming languages has arrays -lists of elements of a certain type, where the size of a list is fixed when the array is first created. In Java, arrays are objects. We provide a very brief summary of one-
Cornell - CS - 101
Other wrapper classesEach primitive type has a corresponding wrapper class, which wraps a value of that type and provides constants and functions dealing with that primitive type. We do not go into detail here. Look at the API specs on the web or th
Cornell - CS - 101
Constraining the elements of an ArrayListYou now know that you can create an instance of class java.util.ArrayList and save it using an assignment like ArrayList b= new ArrayList(); The elements of this list have the apparent class Object. When an
Cornell - CS - 101
Class ArrayListAn instance of class java.util.ArrayList contains a list of objects. It may be a list of the courses you have taken, a list of high temperatures for each day in Ithaca in 2006, or a list of objects of totally different classes. There
Cornell - CS - 101
/* Autoboxing Integer b; b= 25; int i; i= b; / Illegal in java version 4: the types / of variable and expression don't match / Illegal in java version 4: the types / of variable and expression don't match= The assignments work in Java version 5 and
Cornell - CS - 101
import junit.framework.TestCase; public class PandaTester extends TestCase { public void testConstructor() { Panda p1 = new Panda(&quot;Shuaung&quot;,2,null); assertEquals(&quot;Shuang&quot;,p1.getName(); assertEquals(2,p1.getChild(); assertEquals(null,p1.getFather(); P
Cornell - CS - 101
Javadoc specificationsA programmer who wants to use your program should be able to look at the specification of the program, its documentation, without having to look at the code itself. Java has a facility for extracting documentation from your pr
Cornell - CS - 101
Introduction to debuggingTesting is the process of running the program against test cases to try to uncover errors. Debugging is the process of looking for the cause of an uncovered error and then fixing it -once the cause has been found. Often the
Cornell - CS - 101
ConstructorsHere's class Chapter, with three fields, the chapter number, chapter title, and the previous chapter. Here is an instance of that class, created using an assignment c= new Chapter(); . The only way to initialize the fields of the new ins
Cornell - CS - 101
import javax.swing.*; /* Answers to self-help exercises on writing your own subclass of JFrame. */ public class JFrameFun extends JFrame { /* Swap the width and height of this window. */ public void SwapHtAndWidth() { setSize(getHeight(), getWidth();
Cornell - CS - 101
Writing your own subclass of JFrameIt is important that you practice writing Java classes, and methods within them, especially in the beginning. Below, we provide some simple exercises in creating subclasses of class JFrame, as done in the topic 2 o
Cornell - CS - 101
When you have completed module 1, part 6, on objects and classes, please ask a consultant to give you a quiz on this material. The purpose of the quiz is to make sure that you understand OO concepts, can draw an object (manila folder) for a class, an
Cornell - CS - 101
Functions toString and equals in class ObjectFunction toString in class Object Function toString in class Object is defined to return the name of the manilla folder, or object in which it appears. For example, evaluate this expression in DrJava's in
Cornell - CS - 101
/* Write a function toString, which gives the values of the fields, in a format that is easy to read. */ /* An instance maintains public class Chapter { private int number; private String title; private Chapter prev; /* = info about a book chapter */
Cornell - CS - 101
TestingTesting is the process of running a program against &quot;test cases&quot; in order to get some evidence of the correctness of the program. If an error is discovered, then the process of debugging attempts to locate the error and fix it. This topic is
Cornell - CS - 101
Specifications of methodsYou know what the first function mini does, because its specification, in the comment preceding it, tells you. You don't need the function body -which we show you now. You have no idea what the second function does, because
Cornell - CS - 101
Wrapper classesAn instance of class Integer contains a field of type int. We haven't given the name of the field because we don't know it. But there is a getter method for it, intValue(). In fact, one can obtain the int value as a primitive value of
Cornell - CS - 101
Finding API specs on the webThe Java API specifications describe what each class that comes with Java is for and how it is to be used. These specifications are on the world wide web, so you have to be connected to the internet to use them. You can
Cornell - CS - 101
AutoboxingUp through version 4 of Java, an assignment like Integer b; b= 25; int i; i= b; were illegal, because the types of the variable and expression did not match -one is an int and the other is class Integer. In version 5 of Java, autoboxing w
Cornell - CS - 101
/* An instance is a point (x, y) in the plane */ public class Point { /* The x and y coordinates of a point */ private double x; private double y; /* Constructor: a point (b, c) */ public Point(double b, double c) { x= b; y= c; } /* = a representatio
Cornell - CS - 101
Return StatementsExecution of a return statement terminates execution of the method body and, hence, of the method call. The return statement in the body of a function differs from the return statement in a procedure or constructor. See below.The
Cornell - CS - 101
Method HeadersWe summarize method headers, define the signature of a method, and discuss its use. This material is covered in more detail in the course text, Gries/Gries. A method declaration consists of a specification (as a comment), a method head
Cornell - CS - 101
Declaring local variables where they belong, logically speakingWe discuss the placement of local variable declarations. Generally, the declarations should go where they belong, logically speaking, and this usually means placing them as close to the
Cornell - CS - 101
Local variablesA local variable is a variable that is declared within a method body. The program you see has two different local variables, both named temp. The syntax of a local variable declaration is: &lt;type&gt; &lt;variable-name&gt; ; and it can be an in
Cornell - CS - 101
Specifications of methodsYou know what the first function mini does, because its specification, in the comment preceding it, tells you. You don't need the function body -which we show you now. You have no idea what the second function does, because
UCF - HUM - 2210
Part 1: The Beginning of Civilization Chap. 1-31. Prehistoric To Civilized Societies (Ch. 1) a. Stone Age Society i. Hunting-gathering to farming settlements ii. Stone and wooden tools to copper b. Religion i. Animism (25): All nature is alive like
UCF - HUM - 2210
Part II: The Greek Legacy: Triumph Humanism and Reason1. Individualism and the Greek Community (Vol. 1, Chap 5 &amp; 6) a. Heroic Age (1200-750 B.C.): i. Homer (750 BC) creates &quot;Epic Heroes&quot; to build a new culture for his time after &quot;dark ages.&quot; ii. Ba
UCF - HUM - 2210
Huynh, Quoc July 2, 2008 HUM-2210 Dr. EvansPart 3: Pax Romana and Roman Legacy, Chap 81. Major Impact of Roman Society a. Government: i. Republic (Res publica) = rule by people (509-31 BC). Elected representatives ii. Forum = common plaza for mee
UCF - HUM - 2210
Part IV: The Shaping of the middle Ages1. The Beginning of Christianity: Ch. 9 a. Jewish Backgrounds i. Hebrew Bible (Torah = Law of Moses): becomes Christian &quot;Old Testament&quot; ii. Monotheism: one universal God for all iii. Supernatural Beings: demon
UCF - HUM - 2210
EvansHUM 2211REVIEW SHEETEXAM 1LISTS 1. Features that identify a society as &quot;civilized&quot; 2. Geographical areas of early civilizations 3. Ages of early Greek mythology to Ovid 4. Dominant and alternate cultural themes in the Iliad 5. Literary w
LSU - PSYCH - 3081
Chapter 20: Summary and Possible Future DirectionsIntroductionPersonality psychologists seek to understand the whole of personality However, understanding the whole may be impossible Instead, the difficult task of understanding the whole person is
LSU - PSYCH - 3081
Chapter 19: Disorders of PersonalityThe Concept of DisorderPsychological disorder o Pattern of behavior or experience that is distressing and painful to the person o Leads to disability or impairment in important life domains o Associated with the
LSU - PSYCH - 3081
Chapter 18: Stress, Coping, Adjustment, and Health Models of the Personality-Illness ConnectionInteractional model o Objective events happen to a person, but personality determines the impact of events by influencing a person's ability to copy o Per
LSU - PSYCH - 3081
Chapter 17: Culture and PersonalityIntroduction Several reasons personality psychologists believe it is useful to explore personality across cultures o Discover whether concepts of personality that are prevalent in one culture are also applicable in
LSU - PSYCH - 3081
Chapter 17 terms Cultural variations: within group similarities and between group differences can be of any sort-physical, psychological, behavioral, or attitudinal. These phenomena are often referred to as cultural variations. Two ingredients are ne
USF - MAR - 3023
To: From: Subject: Reference: Date:Prof. Noel, MAR 3023 #1. Marketing Concept BW Jan 14, 2008 pg. 24 - see attached article Jan 22, 2008In &quot;That Computer Is So You&quot;, a Business Week article by journalists Steve Hamm and Jay Greene, attention is g
USF - MAR - 3023
To: From: Subject: Reference: Date:Prof. Noel, MAR 3023 #4 Marketing Era BW Mar. 17, 2008 pg. 60 - see attached article March 20, 2008In &quot;Upwardly Mobile Stationery&quot;, a Business Week article by Aaron Pressman, Staples is upgrading their image fro
USF - MAR - 3023
To: From: Subject: Reference: Date:Prof. Noel, MAR 3023 #2. Marketing Segmentation BW Feb. 4, 2008 pg. 68 - see attached article February 5, 2008In &quot;Social Networks That Break a Sweat, by Paula Lehman in Business Week, Bode Miller is introduced a
USF - MAR - 3023
To: From: Subject: Reference: Date:Prof. Noel, MAR 3023 #5 Product Life Cycle BW March 17, 2008 - see attached article March 28, 2008Apple is undergoing some changes, as documented in Business Week's &quot;The iPhone in the Gray Flannel Suit&quot;, an arti
USF - MAR - 3023
To: From: Subject: Reference: Date:Prof. Noel, MAR 3023 #3. Positioning BW Feb. 25, 2008 pg. 55 - see attached article February 22, 2008In Business Week article, &quot;Japan: Google's Real-Life Lab&quot; by Kenji Hall, the web-based giant Google is bringin