Week 6: Review. Java is Case Sensitive

Size: px
Start display at page:

Download "Week 6: Review. Java is Case Sensitive"

Transcription

1 Week 6: Review Java Language Elements: special characters, reserved keywords, variables, operators & expressions, syntax, objects, scoping, Robot world 7 will be used on the midterm. Java is Case Sensitive Special Characters // in line comment. /* */ block comment. ; end of line, in for loop syntax. { code block. dot : used to list a member of an object., comma : separates parameters or arguments in a list, values in an array. ( ) encloses parameter lists, used in syntax of conditionals and loops. used to enclose String literals. used to enclose char literals. [] used in array definitions. APSC142 - Prof.McLeod 1

2 Reserved Keywords (Can t be used as variable names) Used in APSC142, so far: boolean, byte, char, class, do, double, else, final, float, for, if, int, long, new, private, public, return, short, static, void, while You should know what these mean and where they are used! Other keywords: abstract, break, case, catch, continue, default, extends, finally, implements, import, instanceof, interface, native, null, package, protected, super, switch, synchronized, this, throw, throws, try (Underlined keywords will be discussed later in course) APSC142 - Prof.McLeod 2

3 Variables - Primitive Types Integral Types: byte, short, int, long, char For byte, from -128 to 127, inclusive For short, from to 32767, inclusive Forint, from to , inclusive For long, from to , inclusive For char, from '\u0000' to '\uffff' inclusive, that is, from 0 to A variable of the char type represents a Unicode character. Can also be represented as a or 8, etc. Floating Point Types: float, double For float, (4 bytes) roughly ±1.4 x to ±3.4 x to 8 significant digits. For double, (8 bytes) roughly ±4.9 x to ±1.7 x to 17 significant digits. APSC142 - Prof.McLeod 3

4 Variables - Types (Cont.) Boolean Types: boolean is either true or false. String is an object, not a primitive type. class is an object. (Arrays are objects.) APSC142 - Prof.McLeod 4

5 Variable Declaration & Naming Rules Variables must be declared before they are used. Variable names cannot start with a number, but otherwise can use a..z, A..Z, 0..9 and _. No spaces in variable names. Convention is that variables start with a lower case letter. Constants are all in upper case. Method names start with a lower case letter. Class names start with an upper case letter. Use descriptive variable names! Variables are usually nouns. Declaration examples: int numstudents; boolean studentisasleep; int numeggsindozen = 12; int icounter, jcounter, kcounter; double bigarea = 1.2e23; APSC142 - Prof.McLeod 5

6 Variable Declaration - Constants & Scoping The keyword final is used to declare constants: final int NUMSCREENROWS = 25; Hint: usually initialize after declaration. Variables declared within a method are local in scope to that method. You don t use private or public or static. Variables declared at the same level as methods within a class are called attributes must be declared public or private and can be static. Examples: public static int numstudents = 50; private final double R = ; public means the attribute can be changed. private attributes cannot be viewed or changed. static attributes occupy the same memory location for each child object. APSC142 - Prof.McLeod 6

7 Expressions - Operators Listed in order of operator precedence: () (parentheses). ( dot operator) ++ (increment) -- (decrement) + (unary plus) - (unary minus)! (boolean not ) (type) (type cast) * (multiplication) / (division) % (modulus) + (addition or concatenation) - (subtraction) < (boolean less than ) <= ( less than or equal to ) > ( greater than ) APSC142 - Prof.McLeod 7

8 Expressions - Operators (Cont.) >= ( greater than or equal to ) == ( equal to, don t use with String s!)!= ( not equal to ) && (boolean and ) (boolean or ) = (assign) += (add and assign) -= (subtract and assign) *= (multiply and assign) /= (divide and assign) %= (modulo and assign) Example: amount *= 25; is the same as: amount = amount * 25; You should know what all these operators do, and in what order they are processed. APSC142 - Prof.McLeod 8

9 Expressions - (Cont.) Expressions can contain operators, variables and literal values. Literals are things like north, 2, 1e-4, true, etc. Watch out for integer division!: 2.0 / 5.0 evaluates to /5 is 0. Type casting: Any integer type can be implicitly changed into a float or double type. You must cast types to go in the other direction. For example: (int)4.8 evaluates to 4. The double value 4.8 has been cast to an int type. Note that casting truncates, not rounds. APSC142 - Prof.McLeod 9

10 Conditionals - if Statements Simple if statement syntax: if ( boolean_expression ) statement_when_true; else statement_when_false; With statement blocks: if ( boolean_expression ) { block_of_code_when_true else { block_of_code_when_false Note that else part is optional. APSC142 - Prof.McLeod 10

11 Conditionals - if Statements (Cont.) Branching if statement: if ( boolean_expression ) { block_of_code_when_true else if ( boolean_expression2 ) { block_of_code_when_2_true else if ( boolean_expression3 ) { block_of_code_when_3_true else if ( boolean_expression4 ) { block_of_code_when_4_true. else { block_of_code_when_all_are_false if statement is ended when one condition is true, no other branches are tested. Note that else part is optional. APSC142 - Prof.McLeod 11

12 Conditionals -switch Statement switch ( controlling_expression ) { (etc.) case case_label1: statement; statement; break; case case_label2: statement; statement; break; case case_label3: statement; statement; break; default: statement; statement; break; Note: case_label s are constants of same type as controlling_expression. APSC142 - Prof.McLeod 12

13 Loops Loops execute a block of instructions until a given condition becomes false. Three kinds of loops: while, do while, for. while loop syntax: while ( boolean_expression ) { block_of_code Loop executes until boolean_expression evaluates to false. Note, if boolean_expression is false to start with, loop will not execute at all. do while loop syntax: do { block_of_code while ( boolean_expression ); This loop will execute at least once. APSC142 - Prof.McLeod 13

14 Loops Cont. for loop syntax: for ( initialization; boolean_expression; update) { block_of_code Example: int sumnumbers = 0; for (int i=1; i <= 20; i++) { sumnumbers = sumnumbers + i; System.out.println(sumNumbers); Hint: Avoid using declarations inside loops. Watch out for infinite loops!! APSC142 - Prof.McLeod 14

15 String literals: String Class Press <enter> to continue. String variable declaration: String teststuff; or: String teststuff = A testing string. ; String concatenation ( addition ): String teststuff = Hello ; System.out.println(testStuff + to me! ); Would print the following to the DOS window: Hello to me! Note that including another type in a String concatenation calls an implicit tostring method. So, in: System.out.println( I am + 2); the number 2 is converted to a String before being concatenated. The digits given after a decimal point in a float or double type variable can be impressive! APSC142 - Prof.McLeod 15

16 String Class, Cont. A String variable is an object, so it has methods as well as a value. String methods include: length() equals(otherstring) equalsignorecase(otherstring) tolowercase() touppercase() trim() charat(position) substring(start) substring(start, End) indexof(searchstring) APSC142 - Prof.McLeod 16

17 Examples: String Class, Cont. int i; boolean abool; char achar; String teststuff = A testing string. ; i = teststuff.length(); // i is 17 abool = teststuff.equals( a testing string. ); // abool is false abool = teststuff.equalsignorecase( A TESTING STRING. ); // abool is true achar = teststuff.charat(2); // achar is t i = teststuff.indexof( test ); // i is 2 APSC142 - Prof.McLeod 17

18 Escape Characters: String Class, Cont. \ Double quote \ Single quote \\ Backslash \n Go to beginning of next line \r Go to beginning of current line \t Tab character For example: String teststuff = Line1\nLine2 ; System.out.println(testStuff); Would print the following to the DOS window: Line1 Line2 APSC142 - Prof.McLeod 18

19 Defining Methods Classes are containers for attributes and methods called encapsulation. Attributes and methods are members of a class. Attributes or instance variables hold data, methods do things. When a child object is created, it inherits all the attributes and methods of the parent object. For example: Robot BagOBolts = new Robot(); BagOBolts, the child object, inherits all the attributes and methods defined in the parent Robot class (ie. Defined in the Robot.java file). APSC142 - Prof.McLeod 19

20 Defining Methods Cont. Example (in first Robot.java file): public class Robot { //***********attributes********** public int row; public int column; public String direction; //************methods************ public void move() { // lines of code here public void turn() { // lines of code here public void printlocation() { // lines of code here // end of class Robot APSC142 - Prof.McLeod 20

21 Defining Methods Cont. Syntax: Scope Optional_static Return_type Method_name(Parameter_list) { Lines_of_code Scope is either public or private. public means that the method is available to other objects. The use of private allows for information hiding. Optional_static is the optional keyword static (Talk about later ) Return_type is either void, or a type such as int or double, etc. or a defined object such as String. void is used when the method does not return anything. If void is not used, then there must be at least one return statement in the method. APSC142 - Prof.McLeod 21

22 Defining Methods Cont. Method_name is whatever you want follow variable naming restrictions. Be descriptive (a verb). Parameter_list provides a means of passing values, or parameters, into a method. It is optional. It can consist of one or many parameters, separated by commas. Each parameter type must be declared in the parameter list. Examples of methods: public void PrintHello() { System.out.println( Hello ); public void PrintHelloName(String yourname) { System.out.println( Hello + yourname); APSC142 - Prof.McLeod 22

23 More Examples: Defining Methods Cont. public void PrintAvg(int a, int b) { System.out.println((a + b) / 2); public double Average(double a, double b) { return (a + b) / 2; public int Lowest(int a, int b) { if (a <= b) return a; else return b; Note that return can be used in a void method to end the method at the return statement rather than at the end of the code. APSC142 - Prof.McLeod 23

24 Defining Methods Cont. Scoping of variables and methods the use of public and private. Can declare variables inside a method: public double Average(double a, double b) { double holdaverage = (a + b) /2; return holdaverage; holdaverage is a local variable to the method. It is not defined or accessible outside the method. Instance variables (or attributes) declared in a class, at the same level as the methods, can be used by any method in the class. If an instance variable is declared public it is also available to objects outside the class as a member of the class. If the variable is declared private it can only be used within the class. If an method is declared public it is also available to objects outside the class as a member of the class. If the method is declared private it can only be used within the class. APSC142 - Prof.McLeod 24

25 Defining Methods Cont. If the static keyword is used in a method definition inside a class, it allows that method to be used without first having to instantiate the class. For example: String Junk = SavitchIn.readLine(); readline() is a public static method defined in the SavitchIn class. APSC142 - Prof.McLeod 25

26 Method Overloading A method can have the same name in many different classes. Overloading is when a method name is used more than once in the same class. The rule is that no two methods with the same name within a class, can have the same number and/or types of parameters in the method declarations. The method signatures must be different. Why bother? Allows the user to call a method without requiring him to supply values for all the parameters. Allows the programmer to keep an old method definition in the class for backwards compatibility. How does it work? Java looks through all methods until the parameters match with what is supplied by the user. If none match, Java tries to convert types in order to get a match. APSC142 - Prof.McLeod 26

27 Method Overloading Cont. Overloaded (and simplified) move() method in Robot class: // Move the robot a single space in the direction // it is facing. public void move() { if (direction.equalsignorecase("north")) row = row - 1; else if (direction.equalsignorecase("south")) row = row + 1; else if (direction.equalsignorecase("east")) column = column + 1; else if (direction.equalsignorecase("west")) column = column - 1; // end move() method // Moves the robot numofspaces in same direction public void move(int numofspaces) { for (int i=1; i <= numofspaces; i++) move(); // end move(numofspaces) method APSC142 - Prof.McLeod 27

28 Constructors In older robot versions, for example: Robot ChugAlong = new Robot(); ChugAlong.row = 0; ChugAlong.column = 1; ChugAlong.direction = south ; ChugAlong.numFlares = 20; When using Robot Version 7, you *must* use: Robot ChugAlong = new Robot(0, 1, south, 20); Robot World 7 attributes, constants and arrays are not longer public, they are private - they way they should have been all along! You can no longer use myrobot.row to get at the robot s row. You will need to use the appropriate get method. APSC142 - Prof.McLeod 28

29 Constructors Cont. Can and should overload constructors. Note that constructor definition cannot contain a return type and does not even have void. A Constructor without parameters is called the default constructor. For example, the Robot() default constructor works to put the robot at the first square from the north-west corner that does not have a wall, faces him east and gives him zero flares. Constructors are called with the new keyword when an object is created. Once an object is created ( instantiated ) then the constructor cannot be called again for that object. So, the only way to change the robot s direction or position is to use the move(), turn(), teleport(), etc. methods. Robot World 7 does not have any set methods for the attributes. APSC142 - Prof.McLeod 29

30 Constructors Cont. What other reasons are there to use constructors? Suppose we tried to use: Robot BadBoy = new Robot(0, 12, South ); Constructors can check for and compensate for illegal values. For example: // A three-parameter Robot constructor public Robot (int initrow, int initcol, String initdir) { if (initrow < 0) row = 0; else if (initrow > MAX_ROW) row = MAX_ROW; else row = initrow; if (initcol < 0) column = 0; else if (initcol > MAX_COL) column = MAX_COL; else column = initcol; direction = initdir.trim(initdir.tolowercase()); Constructors can also make assumptions and create values for those attributes the user does not supply. APSC142 - Prof.McLeod 30

31 Mutators and Accessors If class attributes are public, then they can still be directly changed even after the constructor has been run. In order to prevent direct changes to the attributes, make them private. The constructors can still set the attribute values when the object is created, but what if we want to see or set the attribute values later in the program? Mutator or set methods can change attribute values. Accessor, Selector or get methods can provide attribute values. Robot 7 has various get methods, such as getrow(), getcol() and getnumholding(). Robot 7 does not have any set methods. APSC142 - Prof.McLeod 31

32 Static Methods A public static method can be called without having to create ( instantiate ) an object. For example, all SavitchIn methods are static: String Junk = SavitchIn.readLine(); works. Instead of: SavitchIn readmethods = new SavitchIn(); String Junk = readmethods.readline(); (This also works ) Static methods cannot refer to non-static attributes or non-static methods, without creating an object first. Robot 7 has static get methods: getmaxrow(), getmaxcol(), and numrobots(). So they can be called as in Robot.getMaxRow(). APSC142 - Prof.McLeod 32

33 Static Variables One aspect is similar to static methods. A public static variable is available without having to create an object. For example, the Math class provides a value for π: double circlearea = Math.PI * radius *radius; Somewhere in the Math class is: public static final double PI = ; Every object created from the class can refer to the same static variable (also called class variable ). Static variables are called static because they occupy a static area in memory. Normally each object has its own, completely independent copy of the class s attributes in separate memory locations. Robot 7 has a number of private static constants and variables. APSC142 - Prof.McLeod 33

Variables of class Type. Week 8. Variables of class Type, Cont. A simple class:

Variables of class Type. Week 8. Variables of class Type, Cont. A simple class: Week 8 Variables of class Type - Correction! Libraries/Packages String Class, reviewed Screen Input/Output, reviewed File Input/Output Coding Style Guidelines A simple class: Variables of class Type public

More information

Introduction to Programming Using Java (98-388)

Introduction to Programming Using Java (98-388) Introduction to Programming Using Java (98-388) Understand Java fundamentals Describe the use of main in a Java application Signature of main, why it is static; how to consume an instance of your own class;

More information

Fall 2017 CISC124 10/1/2017

Fall 2017 CISC124 10/1/2017 CISC124 Today First onq quiz this week write in lab. More details in last Wednesday s lecture. Repeated: The quiz availability times will change to match each lab as the week progresses. Useful Java classes:

More information

5/24/2006. Last Time. Announcements. Today. Method Overloading. Method Overloading - Cont. Method Overloading - Cont. (Midterm Exam!

5/24/2006. Last Time. Announcements. Today. Method Overloading. Method Overloading - Cont. Method Overloading - Cont. (Midterm Exam! Last Time Announcements (Midterm Exam!) Assn 2 due tonight. Before that methods. Spring 2006 CISC101 - Prof. McLeod 1 Spring 2006 CISC101 - Prof. McLeod 2 Today Look at midterm solution. Review method

More information

Fall 2017 CISC124 9/27/2017

Fall 2017 CISC124 9/27/2017 CISC124 Assignment 1 due this Friday at 7pm by submission to an onq dropbox. First onq quiz next week write in lab. More details in yesterday s lecture. Today Intro. to 2D Arrays (and iteration examples).

More information

Program Fundamentals

Program Fundamentals Program Fundamentals /* HelloWorld.java * The classic Hello, world! program */ class HelloWorld { public static void main (String[ ] args) { System.out.println( Hello, world! ); } } /* HelloWorld.java

More information

1 Epic Test Review 2 Epic Test Review 3 Epic Test Review 4. Epic Test Review 5 Epic Test Review 6 Epic Test Review 7 Epic Test Review 8

1 Epic Test Review 2 Epic Test Review 3 Epic Test Review 4. Epic Test Review 5 Epic Test Review 6 Epic Test Review 7 Epic Test Review 8 Epic Test Review 1 Epic Test Review 2 Epic Test Review 3 Epic Test Review 4 Write a line of code that outputs the phase Hello World to the console without creating a new line character. System.out.print(

More information

Index COPYRIGHTED MATERIAL

Index COPYRIGHTED MATERIAL Index COPYRIGHTED MATERIAL Note to the Reader: Throughout this index boldfaced page numbers indicate primary discussions of a topic. Italicized page numbers indicate illustrations. A abstract classes

More information

3. Java - Language Constructs I

3. Java - Language Constructs I Educational Objectives 3. Java - Language Constructs I Names and Identifiers, Variables, Assignments, Constants, Datatypes, Operations, Evaluation of Expressions, Type Conversions You know the basic blocks

More information

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal Lesson Goals Understand the basic constructs of a Java Program Understand how to use basic identifiers Understand simple Java data types

More information

Java Primer 1: Types, Classes and Operators

Java Primer 1: Types, Classes and Operators Java Primer 1 3/18/14 Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia, and M. H. Goldwasser, Wiley, 2014 Java Primer 1: Types,

More information

5/3/2006. Today! HelloWorld in BlueJ. HelloWorld in BlueJ, Cont. HelloWorld in BlueJ, Cont. HelloWorld in BlueJ, Cont. HelloWorld in BlueJ, Cont.

5/3/2006. Today! HelloWorld in BlueJ. HelloWorld in BlueJ, Cont. HelloWorld in BlueJ, Cont. HelloWorld in BlueJ, Cont. HelloWorld in BlueJ, Cont. Today! Build HelloWorld yourself in BlueJ and Eclipse. Look at all the Java keywords. Primitive Types. HelloWorld in BlueJ 1. Find BlueJ in the start menu, but start the Select VM program instead (you

More information

CSC 1214: Object-Oriented Programming

CSC 1214: Object-Oriented Programming CSC 1214: Object-Oriented Programming J. Kizito Makerere University e-mail: jkizito@cis.mak.ac.ug www: http://serval.ug/~jona materials: http://serval.ug/~jona/materials/csc1214 e-learning environment:

More information

CSC Web Programming. Introduction to JavaScript

CSC Web Programming. Introduction to JavaScript CSC 242 - Web Programming Introduction to JavaScript JavaScript JavaScript is a client-side scripting language the code is executed by the web browser JavaScript is an embedded language it relies on its

More information

Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal

Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal Lesson Goals Understand the basic constructs of a Java Program Understand how to use basic identifiers Understand simple Java data types and

More information

CS313D: ADVANCED PROGRAMMING LANGUAGE

CS313D: ADVANCED PROGRAMMING LANGUAGE CS313D: ADVANCED PROGRAMMING LANGUAGE Computer Science department Lecture 2 : C# Language Basics Lecture Contents 2 The C# language First program Variables and constants Input/output Expressions and casting

More information

Weiss Chapter 1 terminology (parenthesized numbers are page numbers)

Weiss Chapter 1 terminology (parenthesized numbers are page numbers) Weiss Chapter 1 terminology (parenthesized numbers are page numbers) assignment operators In Java, used to alter the value of a variable. These operators include =, +=, -=, *=, and /=. (9) autoincrement

More information

Basics of Java Programming

Basics of Java Programming Basics of Java Programming Lecture 2 COP 3252 Summer 2017 May 16, 2017 Components of a Java Program statements - A statement is some action or sequence of actions, given as a command in code. A statement

More information

AP Computer Science A

AP Computer Science A AP Computer Science A 1st Quarter Notes Table of Contents - section links Click on the date or topic below to jump to that section Date : 9/8/2017 Aim : Java Basics Objects and Classes Data types: Primitive

More information

Data and Variables. Data Types Expressions. String Concatenation Variables Declaration Assignment Shorthand operators. Operators Precedence

Data and Variables. Data Types Expressions. String Concatenation Variables Declaration Assignment Shorthand operators. Operators Precedence Data and Variables Data Types Expressions Operators Precedence String Concatenation Variables Declaration Assignment Shorthand operators Review class All code in a java file is written in a class public

More information

CS260 Intro to Java & Android 03.Java Language Basics

CS260 Intro to Java & Android 03.Java Language Basics 03.Java Language Basics http://www.tutorialspoint.com/java/index.htm CS260 - Intro to Java & Android 1 What is the distinction between fields and variables? Java has the following kinds of variables: Instance

More information

1 Shyam sir JAVA Notes

1 Shyam sir JAVA Notes 1 Shyam sir JAVA Notes 1. What is the most important feature of Java? Java is a platform independent language. 2. What do you mean by platform independence? Platform independence means that we can write

More information

Lecture 2: Variables and Operators. AITI Nigeria Summer 2012 University of Lagos.

Lecture 2: Variables and Operators. AITI Nigeria Summer 2012 University of Lagos. Lecture 2: Variables and Operators AITI Nigeria Summer 2012 University of Lagos. Agenda Variables Types Naming Assignment Data Types Type casting Operators Declaring Variables in Java type name; Variables

More information

CS5000: Foundations of Programming. Mingon Kang, PhD Computer Science, Kennesaw State University

CS5000: Foundations of Programming. Mingon Kang, PhD Computer Science, Kennesaw State University CS5000: Foundations of Programming Mingon Kang, PhD Computer Science, Kennesaw State University Overview of Source Code Components Comments Library declaration Classes Functions Variables Comments Can

More information

BIT Java Programming. Sem 1 Session 2011/12. Chapter 2 JAVA. basic

BIT Java Programming. Sem 1 Session 2011/12. Chapter 2 JAVA. basic BIT 3383 Java Programming Sem 1 Session 2011/12 Chapter 2 JAVA basic Objective: After this lesson, you should be able to: declare, initialize and use variables according to Java programming language guidelines

More information

AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS

AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS PAUL L. BAILEY Abstract. This documents amalgamates various descriptions found on the internet, mostly from Oracle or Wikipedia. Very little of this

More information

Introduction to Visual Basic and Visual C++ Introduction to Java. JDK Editions. Overview. Lesson 13. Overview

Introduction to Visual Basic and Visual C++ Introduction to Java. JDK Editions. Overview. Lesson 13. Overview Introduction to Visual Basic and Visual C++ Introduction to Java Lesson 13 Overview I154-1-A A @ Peter Lo 2010 1 I154-1-A A @ Peter Lo 2010 2 Overview JDK Editions Before you can write and run the simple

More information

Fall 2017 CISC124 9/16/2017

Fall 2017 CISC124 9/16/2017 CISC124 Labs start this week in JEFF 155: Meet your TA. Check out the course web site, if you have not already done so. Watch lecture videos if you need to review anything we have already done. Problems

More information

Operators and Expressions

Operators and Expressions Operators and Expressions Conversions. Widening and Narrowing Primitive Conversions Widening and Narrowing Reference Conversions Conversions up the type hierarchy are called widening reference conversions

More information

HUDSONVILLE HIGH SCHOOL COURSE FRAMEWORK

HUDSONVILLE HIGH SCHOOL COURSE FRAMEWORK HUDSONVILLE HIGH SCHOOL COURSE FRAMEWORK COURSE / SUBJECT Introduction to Programming KEY COURSE OBJECTIVES/ENDURING UNDERSTANDINGS OVERARCHING/ESSENTIAL SKILLS OR QUESTIONS Introduction to Java Java Essentials

More information

Visual C# Instructor s Manual Table of Contents

Visual C# Instructor s Manual Table of Contents Visual C# 2005 2-1 Chapter 2 Using Data At a Glance Instructor s Manual Table of Contents Overview Objectives s Quick Quizzes Class Discussion Topics Additional Projects Additional Resources Key Terms

More information

Computer Components. Software{ User Programs. Operating System. Hardware

Computer Components. Software{ User Programs. Operating System. Hardware Computer Components Software{ User Programs Operating System Hardware What are Programs? Programs provide instructions for computers Similar to giving directions to a person who is trying to get from point

More information

BASIC COMPUTATION. public static void main(string [] args) Fundamentals of Computer Science I

BASIC COMPUTATION. public static void main(string [] args) Fundamentals of Computer Science I BASIC COMPUTATION x public static void main(string [] args) Fundamentals of Computer Science I Outline Using Eclipse Data Types Variables Primitive and Class Data Types Expressions Declaration Assignment

More information

Object oriented programming. Instructor: Masoud Asghari Web page: Ch: 3

Object oriented programming. Instructor: Masoud Asghari Web page:   Ch: 3 Object oriented programming Instructor: Masoud Asghari Web page: http://www.masses.ir/lectures/oops2017sut Ch: 3 1 In this slide We follow: https://docs.oracle.com/javase/tutorial/index.html Trail: Learning

More information

Accelerating Information Technology Innovation

Accelerating Information Technology Innovation Accelerating Information Technology Innovation http://aiti.mit.edu Cali, Colombia Summer 2012 Lesson 02 Variables and Operators Agenda Variables Types Naming Assignment Data Types Type casting Operators

More information

Chapter 2: Using Data

Chapter 2: Using Data Chapter 2: Using Data TRUE/FALSE 1. A variable can hold more than one value at a time. F PTS: 1 REF: 52 2. The legal integer values are -2 31 through 2 31-1. These are the highest and lowest values that

More information

3. Java - Language Constructs I

3. Java - Language Constructs I Names and Identifiers A program (that is, a class) needs a name public class SudokuSolver {... 3. Java - Language Constructs I Names and Identifiers, Variables, Assignments, Constants, Datatypes, Operations,

More information

Language Fundamentals Summary

Language Fundamentals Summary Language Fundamentals Summary Claudia Niederée, Joachim W. Schmidt, Michael Skusa Software Systems Institute Object-oriented Analysis and Design 1999/2000 c.niederee@tu-harburg.de http://www.sts.tu-harburg.de

More information

Computer Components. Software{ User Programs. Operating System. Hardware

Computer Components. Software{ User Programs. Operating System. Hardware Computer Components Software{ User Programs Operating System Hardware What are Programs? Programs provide instructions for computers Similar to giving directions to a person who is trying to get from point

More information

Object-Oriented Programming

Object-Oriented Programming Object-Oriented Programming Java Syntax Program Structure Variables and basic data types. Industry standard naming conventions. Java syntax and coding conventions If Then Else Case statements Looping (for,

More information

cis20.1 design and implementation of software applications I fall 2007 lecture # I.2 topics: introduction to java, part 1

cis20.1 design and implementation of software applications I fall 2007 lecture # I.2 topics: introduction to java, part 1 topics: introduction to java, part 1 cis20.1 design and implementation of software applications I fall 2007 lecture # I.2 cis20.1-fall2007-sklar-leci.2 1 Java. Java is an object-oriented language: it is

More information

Chapter 2. Elementary Programming

Chapter 2. Elementary Programming Chapter 2 Elementary Programming 1 Objectives To write Java programs to perform simple calculations To obtain input from the console using the Scanner class To use identifiers to name variables, constants,

More information

A variable is a name for a location in memory A variable must be declared

A variable is a name for a location in memory A variable must be declared Variables A variable is a name for a location in memory A variable must be declared, specifying the variable's name and the type of information that will be held in it data type variable name int total;

More information

Java Review. Fundamentals of Computer Science

Java Review. Fundamentals of Computer Science Java Review Fundamentals of Computer Science Link to Head First pdf File https://zimslifeintcs.files.wordpress.com/2011/12/h ead-first-java-2nd-edition.pdf Outline Data Types Arrays Boolean Expressions

More information

Java How to Program, 10/e. Copyright by Pearson Education, Inc. All Rights Reserved.

Java How to Program, 10/e. Copyright by Pearson Education, Inc. All Rights Reserved. Java How to Program, 10/e Education, Inc. All Rights Reserved. Each class you create becomes a new type that can be used to declare variables and create objects. You can declare new classes as needed;

More information

Chapter 2 Using Data. Instructor s Manual Table of Contents. At a Glance. Overview. Objectives. Teaching Tips. Quick Quizzes. Class Discussion Topics

Chapter 2 Using Data. Instructor s Manual Table of Contents. At a Glance. Overview. Objectives. Teaching Tips. Quick Quizzes. Class Discussion Topics Java Programming, Sixth Edition 2-1 Chapter 2 Using Data At a Glance Instructor s Manual Table of Contents Overview Objectives Teaching Tips Quick Quizzes Class Discussion Topics Additional Projects Additional

More information

Objectives. Introduce the core C# language features class Main types variables basic input and output operators arrays control constructs comments

Objectives. Introduce the core C# language features class Main types variables basic input and output operators arrays control constructs comments Basics Objectives Introduce the core C# language features class Main types variables basic input and output operators arrays control constructs comments 2 Class Keyword class used to define new type specify

More information

CMPT 125: Lecture 3 Data and Expressions

CMPT 125: Lecture 3 Data and Expressions CMPT 125: Lecture 3 Data and Expressions Tamara Smyth, tamaras@cs.sfu.ca School of Computing Science, Simon Fraser University January 3, 2009 1 Character Strings A character string is an object in Java,

More information

Java Identifiers. Java Language Essentials. Java Keywords. Java Applications have Class. Slide Set 2: Java Essentials. Copyright 2012 R.M.

Java Identifiers. Java Language Essentials. Java Keywords. Java Applications have Class. Slide Set 2: Java Essentials. Copyright 2012 R.M. Java Language Essentials Java is Case Sensitive All Keywords are lower case White space characters are ignored Spaces, tabs, new lines Java statements must end with a semicolon ; Compound statements use

More information

Chapter 6 Introduction to Defining Classes

Chapter 6 Introduction to Defining Classes Introduction to Defining Classes Fundamentals of Java: AP Computer Science Essentials, 4th Edition 1 Objectives Design and implement a simple class from user requirements. Organize a program in terms of

More information

CS 251 Intermediate Programming Methods and Classes

CS 251 Intermediate Programming Methods and Classes CS 251 Intermediate Programming Methods and Classes Brooke Chenoweth University of New Mexico Fall 2018 Methods An operation that can be performed on an object Has return type and parameters Method with

More information

CS 251 Intermediate Programming Methods and More

CS 251 Intermediate Programming Methods and More CS 251 Intermediate Programming Methods and More Brooke Chenoweth University of New Mexico Spring 2018 Methods An operation that can be performed on an object Has return type and parameters Method with

More information

COMP Primitive and Class Types. Yi Hong May 14, 2015

COMP Primitive and Class Types. Yi Hong May 14, 2015 COMP 110-001 Primitive and Class Types Yi Hong May 14, 2015 Review What are the two major parts of an object? What is the relationship between class and object? Design a simple class for Student How to

More information

Fundamental Java Syntax Summary Sheet for CISC124, Fall Java is Case - Sensitive!

Fundamental Java Syntax Summary Sheet for CISC124, Fall Java is Case - Sensitive! Fundamental Java Syntax Summary Sheet for CISC124, Fall 2015 Notes: Items in italics are things that you must supply, either a variable name, literal value, or expression. Java is Case - Sensitive! Variable

More information

c) And last but not least, there are javadoc comments. See Weiss.

c) And last but not least, there are javadoc comments. See Weiss. CSCI 151 Spring 2010 Java Bootcamp The following notes are meant to be a quick refresher on Java. It is not meant to be a means on its own to learn Java. For that you would need a lot more detail (for

More information

Full file at

Full file at Java Programming, Fifth Edition 2-1 Chapter 2 Using Data within a Program At a Glance Instructor s Manual Table of Contents Overview Objectives Teaching Tips Quick Quizzes Class Discussion Topics Additional

More information

The Warhol Language Reference Manual

The Warhol Language Reference Manual The Warhol Language Reference Manual Martina Atabong maa2247 Charvinia Neblett cdn2118 Samuel Nnodim son2105 Catherine Wes ciw2109 Sarina Xie sx2166 Introduction Warhol is a functional and imperative programming

More information

CS 231 Data Structures and Algorithms, Fall 2016

CS 231 Data Structures and Algorithms, Fall 2016 CS 231 Data Structures and Algorithms, Fall 2016 Dr. Bruce A. Maxwell Department of Computer Science Colby College Course Description Focuses on the common structures used to store data and the standard

More information

Fundamental Java Syntax Summary Sheet for CISC101, Spring Java is Case - Sensitive!

Fundamental Java Syntax Summary Sheet for CISC101, Spring Java is Case - Sensitive! Fundamental Java Syntax Summary Sheet for CISC101, Spring 2006 Notes: Items in italics are things that you must supply, either a variable name, literal value, or expression. Variable Naming Rules Java

More information

Mr. Monroe s Guide to Mastering Java Syntax

Mr. Monroe s Guide to Mastering Java Syntax Mr. Monroe s Guide to Mastering Java Syntax Getting Started with Java 1. Download and install the official JDK (Java Development Kit). 2. Download an IDE (Integrated Development Environment), like BlueJ.

More information

Pace University. Fundamental Concepts of CS121 1

Pace University. Fundamental Concepts of CS121 1 Pace University Fundamental Concepts of CS121 1 Dr. Lixin Tao http://csis.pace.edu/~lixin Computer Science Department Pace University October 12, 2005 This document complements my tutorial Introduction

More information

Java Basic Datatypees

Java Basic Datatypees Basic Datatypees Variables are nothing but reserved memory locations to store values. This means that when you create a variable you reserve some space in the memory. Based on the data type of a variable,

More information

Language Reference Manual simplicity

Language Reference Manual simplicity Language Reference Manual simplicity Course: COMS S4115 Professor: Dr. Stephen Edwards TA: Graham Gobieski Date: July 20, 2016 Group members Rui Gu rg2970 Adam Hadar anh2130 Zachary Moffitt znm2104 Suzanna

More information

The Java language has a wide variety of modifiers, including the following:

The Java language has a wide variety of modifiers, including the following: PART 5 5. Modifier Types The Java language has a wide variety of modifiers, including the following: Java Access Modifiers Non Access Modifiers 5.1 Access Control Modifiers Java provides a number of access

More information

Full file at

Full file at Java Programming: From Problem Analysis to Program Design, 3 rd Edition 2-1 Chapter 2 Basic Elements of Java At a Glance Instructor s Manual Table of Contents Overview Objectives s Quick Quizzes Class

More information

JAVA Programming Fundamentals

JAVA Programming Fundamentals Chapter 4 JAVA Programming Fundamentals By: Deepak Bhinde PGT Comp.Sc. JAVA character set Character set is a set of valid characters that a language can recognize. It may be any letter, digit or any symbol

More information

Points To Remember for SCJP

Points To Remember for SCJP Points To Remember for SCJP www.techfaq360.com The datatype in a switch statement must be convertible to int, i.e., only byte, short, char and int can be used in a switch statement, and the range of the

More information

6.096 Introduction to C++ January (IAP) 2009

6.096 Introduction to C++ January (IAP) 2009 MIT OpenCourseWare http://ocw.mit.edu 6.096 Introduction to C++ January (IAP) 2009 For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms. Welcome to 6.096 Lecture

More information

Cellular Automata Language (CAL) Language Reference Manual

Cellular Automata Language (CAL) Language Reference Manual Cellular Automata Language (CAL) Language Reference Manual Calvin Hu, Nathan Keane, Eugene Kim {ch2880, nak2126, esk2152@columbia.edu Columbia University COMS 4115: Programming Languages and Translators

More information

boolean, char, class, const, double, else, final, float, for, if, import, int, long, new, public, return, static, throws, void, while

boolean, char, class, const, double, else, final, float, for, if, import, int, long, new, public, return, static, throws, void, while CSCI 150 Fall 2007 Java Syntax The following notes are meant to be a quick cheat sheet for Java. It is not meant to be a means on its own to learn Java or this course. For that you should look at your

More information

Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups:

Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups: JAVA OPERATORS GENERAL Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups: Arithmetic Operators Relational Operators Bitwise Operators

More information

Reviewing for the Midterm Covers chapters 1 to 5, 7 to 9. Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013

Reviewing for the Midterm Covers chapters 1 to 5, 7 to 9. Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013 Reviewing for the Midterm Covers chapters 1 to 5, 7 to 9 Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013 2 Things to Review Review the Class Slides: Key Things to Take Away Do you understand

More information

Operators. Java operators are classified into three categories:

Operators. Java operators are classified into three categories: Operators Operators are symbols that perform arithmetic and logical operations on operands and provide a meaningful result. Operands are data values (variables or constants) which are involved in operations.

More information

Chapter 2 Elementary Programming

Chapter 2 Elementary Programming Chapter 2 Elementary Programming Part I 1 Motivations In the preceding chapter, you learned how to create, compile, and run a Java program. Starting from this chapter, you will learn how to solve practical

More information

Client-Side Web Technologies. JavaScript Part I

Client-Side Web Technologies. JavaScript Part I Client-Side Web Technologies JavaScript Part I JavaScript First appeared in 1996 in Netscape Navigator Main purpose was to handle input validation that was currently being done server-side Now a powerful

More information

Declaration and Memory

Declaration and Memory Declaration and Memory With the declaration int width; the compiler will set aside a 4-byte (32-bit) block of memory (see right) The compiler has a symbol table, which will have an entry such as Identifier

More information

Tools : The Java Compiler. The Java Interpreter. The Java Debugger

Tools : The Java Compiler. The Java Interpreter. The Java Debugger Tools : The Java Compiler javac [ options ] filename.java... -depend: Causes recompilation of class files on which the source files given as command line arguments recursively depend. -O: Optimizes code,

More information

Chapter 3: Operators, Expressions and Type Conversion

Chapter 3: Operators, Expressions and Type Conversion 101 Chapter 3 Operators, Expressions and Type Conversion Chapter 3: Operators, Expressions and Type Conversion Objectives To use basic arithmetic operators. To use increment and decrement operators. To

More information

Zheng-Liang Lu Java Programming 45 / 79

Zheng-Liang Lu Java Programming 45 / 79 1 class Lecture2 { 2 3 "Elementray Programming" 4 5 } 6 7 / References 8 [1] Ch. 2 in YDL 9 [2] Ch. 2 and 3 in Sharan 10 [3] Ch. 2 in HS 11 / Zheng-Liang Lu Java Programming 45 / 79 Example Given a radius

More information

Chapter 2: Data and Expressions

Chapter 2: Data and Expressions Chapter 2: Data and Expressions CS 121 Department of Computer Science College of Engineering Boise State University January 15, 2015 Chapter 2: Data and Expressions CS 121 1 / 1 Chapter 2 Part 1: Data

More information

Values and Variables 1 / 30

Values and Variables 1 / 30 Values and Variables 1 / 30 Values 2 / 30 Computing Computing is any purposeful activity that marries the representation of some dynamic domain with the representation of some dynamic machine that provides

More information

CS 106 Introduction to Computer Science I

CS 106 Introduction to Computer Science I CS 106 Introduction to Computer Science I 05 / 31 / 2017 Instructor: Michael Eckmann Today s Topics Questions / Comments? recap and some more details about variables, and if / else statements do lab work

More information

Getting started with Java

Getting started with Java Getting started with Java Magic Lines public class MagicLines { public static void main(string[] args) { } } Comments Comments are lines in your code that get ignored during execution. Good for leaving

More information

Contents. Figures. Tables. Examples. Foreword. Preface. 1 Basics of Java Programming 1. xix. xxi. xxiii. xxvii. xxix

Contents. Figures. Tables. Examples. Foreword. Preface. 1 Basics of Java Programming 1. xix. xxi. xxiii. xxvii. xxix PGJC4_JSE8_OCA.book Page ix Monday, June 20, 2016 2:31 PM Contents Figures Tables Examples Foreword Preface xix xxi xxiii xxvii xxix 1 Basics of Java Programming 1 1.1 Introduction 2 1.2 Classes 2 Declaring

More information

5/23/2015. Core Java Syllabus. VikRam ShaRma

5/23/2015. Core Java Syllabus. VikRam ShaRma 5/23/2015 Core Java Syllabus VikRam ShaRma Basic Concepts of Core Java 1 Introduction to Java 1.1 Need of java i.e. History 1.2 What is java? 1.3 Java Buzzwords 1.4 JDK JRE JVM JIT - Java Compiler 1.5

More information

CS112 Lecture: Working with Numbers

CS112 Lecture: Working with Numbers CS112 Lecture: Working with Numbers Last revised January 30, 2008 Objectives: 1. To introduce arithmetic operators and expressions 2. To expand on accessor methods 3. To expand on variables, declarations

More information

CS 112 Introduction to Computing II. Wayne Snyder Computer Science Department Boston University

CS 112 Introduction to Computing II. Wayne Snyder Computer Science Department Boston University CS 112 Introduction to Computing II Wayne Snyder Department Boston University Today: Java basics: Compilation vs Interpretation Program structure Statements Values Variables Types Operators and Expressions

More information

Chapter 3 Syntax, Errors, and Debugging. Fundamentals of Java

Chapter 3 Syntax, Errors, and Debugging. Fundamentals of Java Chapter 3 Syntax, Errors, and Debugging Objectives Construct and use numeric and string literals. Name and use variables and constants. Create arithmetic expressions. Understand the precedence of different

More information

CSC Java Programming, Fall Java Data Types and Control Constructs

CSC Java Programming, Fall Java Data Types and Control Constructs CSC 243 - Java Programming, Fall 2016 Java Data Types and Control Constructs Java Types In general, a type is collection of possible values Main categories of Java types: Primitive/built-in Object/Reference

More information

Object Oriented Programming with Java

Object Oriented Programming with Java Object Oriented Programming with Java What is Object Oriented Programming? Object Oriented Programming consists of creating outline structures that are easily reused over and over again. There are four

More information

Computer Science II (20073) Week 1: Review and Inheritance

Computer Science II (20073) Week 1: Review and Inheritance Computer Science II 4003-232-01 (20073) Week 1: Review and Inheritance Richard Zanibbi Rochester Institute of Technology Review of CS-I Hardware and Software Hardware Physical devices in a computer system

More information

JAVA Ch. 4. Variables and Constants Lawrenceville Press

JAVA Ch. 4. Variables and Constants Lawrenceville Press JAVA Ch. 4 Variables and Constants Slide 1 Slide 2 Warm up/introduction int A = 13; int B = 23; int C; C = A+B; System.out.print( The answer is +C); Slide 3 Declaring and using variables Slide 4 Declaring

More information

Chapter 2: Using Data

Chapter 2: Using Data Chapter 2: Using Data TRUE/FALSE 1. A variable can hold more than one value at a time. F PTS: 1 REF: 52 2. The legal integer values are -2 31 through 2 31-1. These are the highest and lowest values that

More information

egrapher Language Reference Manual

egrapher Language Reference Manual egrapher Language Reference Manual Long Long: ll3078@columbia.edu Xinli Jia: xj2191@columbia.edu Jiefu Ying: jy2799@columbia.edu Linnan Wang: lw2645@columbia.edu Darren Chen: dsc2155@columbia.edu 1. Introduction

More information

Datatypes, Variables, and Operations

Datatypes, Variables, and Operations Datatypes, Variables, and Operations 1 Primitive Type Classification 2 Numerical Data Types Name Range Storage Size byte 2 7 to 2 7 1 (-128 to 127) 8-bit signed short 2 15 to 2 15 1 (-32768 to 32767) 16-bit

More information

The MaSH Programming Language At the Statements Level

The MaSH Programming Language At the Statements Level The MaSH Programming Language At the Statements Level Andrew Rock School of Information and Communication Technology Griffith University Nathan, Queensland, 4111, Australia a.rock@griffith.edu.au June

More information

Programming Lecture 3

Programming Lecture 3 Programming Lecture 3 Expressions (Chapter 3) Primitive types Aside: Context Free Grammars Constants, variables Identifiers Variable declarations Arithmetic expressions Operator precedence Assignment statements

More information

Chapter 2: Using Data

Chapter 2: Using Data Chapter 2: Using Data Declaring Variables Constant Cannot be changed after a program is compiled Variable A named location in computer memory that can hold different values at different points in time

More information

Exam 1 Prep. Dr. Demetrios Glinos University of Central Florida. COP3330 Object Oriented Programming

Exam 1 Prep. Dr. Demetrios Glinos University of Central Florida. COP3330 Object Oriented Programming Exam 1 Prep Dr. Demetrios Glinos University of Central Florida COP3330 Object Oriented Programming Progress Exam 1 is a Timed Webcourses Quiz You can find it from the "Assignments" link on Webcourses choose

More information

Java Notes. 10th ICSE. Saravanan Ganesh

Java Notes. 10th ICSE. Saravanan Ganesh Java Notes 10th ICSE Saravanan Ganesh 13 Java Character Set Character set is a set of valid characters that a language can recognise A character represents any letter, digit or any other sign Java uses

More information