Java Reference Card. 1. Classes. 2. Methods. 3. Conditionals. 4. Operators

Similar documents
double float char In a method: final typename variablename = expression ;

CS111: PROGRAMMING LANGUAGE II

int: integers, no fractional part double: floating-point numbers (double precision) 1, -4, 0 0.5, , 4.3E24, 1E-14

First Programs. CSE 1310 Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington

2/9/2012. Chapter Four: Fundamental Data Types. Chapter Goals

First Programs. CSE 1310 Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington

What did we talk about last time? Examples switch statements

Chapter 4 Fundamental Data Types. Big Java by Cay Horstmann Copyright 2009 by John Wiley & Sons. All rights reserved.

PRIMITIVE VARIABLES. CS302 Introduction to Programming University of Wisconsin Madison Lecture 3. By Matthew Bernstein

Lesson 5: Introduction to the Java Basics: Java Arithmetic THEORY. Arithmetic Operators

You should see something like this, called the prompt :

Chapter 4 Fundamental Data Types. Big Java by Cay Horstmann Copyright 2009 by John Wiley & Sons. All rights reserved.

Arithmetic and IO. 25 August 2017

First Programs. CSE 1310 Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington

Using APIs. Chapter 3. Outline Fields Overall Layout. Java By Abstraction Chapter 3. Field Summary static double PI

Interpreted vs Compiled. Java Compile. Classes, Objects, and Methods. Hello World 10/6/2016. Python Interpreted. Java Compiled

Computer Programming, I. Laboratory Manual. Experiment #2. Elementary Programming

Object Oriented Programming. Java-Lecture 1

Introduction to Computer Science Unit 2. Notes

Big Java. Fifth Edition. Chapter 3 Fundamental Data Types. Cay Horstmann

Wentworth Institute of Technology. Engineering & Technology WIT COMP1000. Methods

More Things We Can Do With It! Overview. Circle Calculations. πr 2. π = More operators and expression types More statements

AP CS Unit 3: Control Structures Notes

CIS133J. Working with Numbers in Java

Midterm I - CSE11 Fall 2013 CLOSED BOOK, CLOSED NOTES 50 minutes, 100 points Total.

Chapter 4: Basic C Operators

CS 152: Data Structures with Java Hello World with the IntelliJ IDE

Introduction to Computer Science Unit 2. Notes

CSE 1223: Introduction to Computer Programming in Java Chapter 7 File I/O

Introduction to Computer Programming

COMP 202 Java in one week

Expressions. Arithmetic expressions. Logical expressions. Assignment expression. n Variables and constants linked with operators

Introduction to Java Applications

I. Variables and Data Type week 3

COMP 202. Java in one week

Java Coding 3. Over & over again!

Define a method vs. calling a method. Chapter Goals. Contents 1/21/13

Simple Java Reference

Lesson #3. Variables, Operators, and Expressions. 3. Variables, Operators and Expressions - Copyright Denis Hamelin - Ryerson University

Lecture 6. Assignments. Summary - Variables. Summary Program Parts 1/29/18. Reading: 3.1, 3.2, 3.3, 3.4

Activity 4: Methods. Content Learning Objectives. Process Skill Goals

CSC 1214: Object-Oriented Programming

Section 2.2 Your First Program in Java: Printing a Line of Text

Chapter 2. Elementary Programming

Numerical Data. CS 180 Sunil Prabhakar Department of Computer Science Purdue University

4 WORKING WITH DATA TYPES AND OPERATIONS

Hello World. n Variables store information. n You can think of them like boxes. n They hold values. n The value of a variable is its current contents

Topics. The Development Process

Formatting Output & Enumerated Types & Wrapper Classes

McGill University School of Computer Science COMP-202A Introduction to Computing 1

Primitive Data Types: Intro

Chapter 2: Data and Expressions

FUNDAMENTAL DATA TYPES

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

Programming in Java

CS 302: Introduction to Programming

Chapter 2: Data and Expressions

Check the entries in the home directory again with an ls command and then change to the java directory:

(A) 99 (B) 100 (C) 101 (D) 100 initial integers plus any additional integers required during program execution

Introduction to Software Development (ISD) David Weston and Igor Razgon

Programming and Data Structure Laboratory (CS13002)

COMP 202. Built in Libraries and objects. CONTENTS: Introduction to objects Introduction to some basic Java libraries string

Mid Term Exam 1. Programming I (CPCS 202) Instructor: M. G. Abbas Malik Date: Sunday November 3, 2013 Total Marks: 50 Obtained Marks:

Course Outline. Introduction to java

COSC 123 Computer Creativity. Introduction to Java. Dr. Ramon Lawrence University of British Columbia Okanagan

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

Check out how to use the random number generator (introduced in section 4.11 of the text) to get a number between 1 and 6 to create the simulation.

SECTION 2: CODE REASONING + PROGRAMMING TOOLS. slides borrowed and adapted from Alex Mariakis and CSE 390a

Object-Oriented Programming

AP Computer Science Unit 1. Programs

b. Suppose you enter input from the console, when you run the program. What is the output?

Variables and data types

CONTENTS: Compilation Data and Expressions COMP 202. More on Chapter 2

CS110: PROGRAMMING LANGUAGE I

Building Java Programs

H212 Introduction to Software Systems Honors

CSE 303 Lecture 2. Introduction to bash shell. read Linux Pocket Guide pp , 58-59, 60, 65-70, 71-72, 77-80

Pace University. Fundamental Concepts of CS121 1

Python for Astronomers. Week 1- Basic Python

Data Types and the while Statement

STUDENT LESSON A7 Simple I/O

static int min(int a, int b) Returns the smaller of two int values. static double pow(double a,

(A) 99 ** (B) 100 (C) 101 (D) 100 initial integers plus any additional integers required during program execution

Lecture 6. Assignments. Java Scanner. User Input 1/29/18. Reading: 2.12, 2.13, 3.1, 3.2, 3.3, 3.4

Loops. CSE 114, Computer Science 1 Stony Brook University

Building Java Programs

Full file at

DM550 / DM857 Introduction to Programming. Peter Schneider-Kamp

CS/IT 114 Introduction to Java, Part 1 FALL 2016 CLASS 3: SEP. 13TH INSTRUCTOR: JIAYIN WANG

M105: Introduction to Programming with Java Midterm Examination (MTA) Makeup Spring 2013 / 2014

Review Chapters 1 to 4. Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013

Data Types. 1 You cannot change the type of the variable after declaration. Zheng-Liang Lu Java Programming 52 / 87

Basic Operations jgrasp debugger Writing Programs & Checkstyle

2/9/2015. Chapter 10 Testing and Debugging UNIT TESTS

last time in cs recitations. computer commands. today s topics.

CS170 (005): Introduction to Computer Science Exam 2

Introduction: The Unix shell and C programming

Chapter Two. Lesson A. Objectives. Exploring the UNIX File System and File Security. Understanding Files and Directories

CS110D: PROGRAMMING LANGUAGE I

Variables and Operators 2/20/01 Lecture #

Transcription:

Java Reference Card 1. Classes The following is an example of a main class: public class Calculator { public static void main(string[] args) { and the following is an example of a utility class (with no methods): public class Geometry { 2. Methods The following is an example of a method declaration with an empty body: public static double circlearea(double radius) { and the following is an example of an invocation of this method (assuming that it is in the Geometry class): area = Geometry.circleArea(radius); 3. Conditionals The following is an example of an if statement with an else clause: if (price > 100.00) { discount = 0.40; else { discount = 0.10; 4. Operators Arithmetic Operators Logical Operators Relational Operators Addition + And & && Equal == Decrement Excl. Or ^ Greater than > Division / Incl. Or Greater than or equal >= Increment ++ Not! Less Than < Int. Division / Less than or equal <= Multiplication * Not equal!= Modulus % Negation - Subtraction -

4. Type Conversion Example Expression Type Value (1 + 2 + 3 + 4) / 4.0 double 2.5 "1234" + 99 String "123499" 11 * 0.25 double 2.75 (int)2.71828 int 2 (int)11 * 0.25 double 2.75 11 * (int)0.25 int 0 (int)(11 * 0.25) int 2 5. Library Methods/Constants Signature Double.parseDouble(String s) Purpose Convert s to a double Integer.parseInt(String s) Convert s to an int Math.abs(double v) Math.cos(double a) Math.max(double x, double y) Math.min(double x, double y) Math.pow(double v, double p) Math.sin(double a) Math.sqrt(double v) Math.tan(double a) Math.toDegrees(double r) Math.toRadians(double d) Absolute value Cosine Maximum Minimum v raised to the p power Since Square root Tangent Radians to degrees Degrees to radians Constant Math.E Math.PI Value The base of the natural log The circumference over the radius

6. Input Input Using a Scanner Object import java.util.scanner; double d; int i; Scanner in; String s; in = new Scanner(System.in); d = in.nextdouble(); i = in.nextint(); s = in.nextline(); 7. Output The System.out object has the following methods. print() println() printf() Can be passed a double, int, or String Can be passed a double, int, or String Is passed a format string and one value for each format specifier Example Specifier Description %d Integer %5d Integer in a field of width 5 %f Floating-point %f5.2 Floating-point in a field of width 5 with 2 places to the right of the. %s String Complete Example 0123456789102345678901234567890 printf("%2d%5.2f", 5, 8.1) 5 8.10 printf("%10d%8.4f", 5, 8.1) 5 8.1000

8. Arrays The following is an example of an array declaration: double[] grades; The following is an example of allocating memory for an array: grades = new double[3]; The following are examples of using elements of an array (that assumes that all of the variables have been declared earlier): grades[2] = 85.5; final = grades[2]; 9. Loops The following is an example of a for loop (that assumes that all of the variables have been declared for (i = 0; i < n; i++) { The following is an example of a while loop (that assumes that all of the variables have been declared while (i < n) { The following is an example of a do-while loop (that assumes that all of the variables have been declared do { while (i < n);

Linux Reference Card 1. Shell Commands Command Description Symbol Meaning cd Change the working directory * Match any characters cp Copy? Match any one character less Display the contents of a file ~ Home directory ls List the contents of a directory / Root directory man Display a manual entry.. The directory above mkdir Make a directory. The current directory mv Move a file rm Remove a file rmdir Remove a directory pwd Display the path of the working directory 2. Tools Compiling: javac ClassName.java Executing: java ClassName java ClassName < test.in > test.out Comparing: meld test.exp test.out