CS251L REVIEW Derek Trumbo UNM

Similar documents
CS251L REVIEW Derek Trumbo UNM

Getting started with Java

Introduction to Programming Using Java (98-388)

PROGRAMMING FUNDAMENTALS

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 Programming Basics. COMP 401, Spring 2017 Lecture 2

Java is an objet-oriented programming language providing features that support

CS313D: ADVANCED PROGRAMMING LANGUAGE

Programming with Java

Computing Science 114 Solutions to Midterm Examination Tuesday October 19, In Questions 1 20, Circle EXACTLY ONE choice as the best answer

Prof. Navrati Saxena TA: Rochak Sachan

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

Midterm Review Topics Java Basics and Structure Variables Branching Loops Methods Arrays. Midterm Review Kage Weiss Lab 001 TA, SPR 17

Basic Java Syntax. COMP 401, Fall 2015 Lecture 2 1/13/2014

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

Programming Basics. Digital Urban Visualization. People as Flows. ia

CS251L REVIEW Derek Trumbo UNM

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal

13 th Windsor Regional Secondary School Computer Programming Competition

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

School of Computer Science CPS109 Course Notes 5 Alexander Ferworn Updated Fall 15

1.00 Introduction to Computers and Engineering Problem Solving. Quiz 1 March 7, 2003

Lecture 2. COMP1406/1006 (the Java course) Fall M. Jason Hinek Carleton University

CSCI 136 Data Structures & Advanced Programming. Fall 2018 Instructors Bill Lenhart & Bill Jannen

Loops. CSE 114, Computer Science 1 Stony Brook University

Outline. Parts 1 to 3 introduce and sketch out the ideas of OOP. Part 5 deals with these ideas in closer detail.

Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal

CS 231 Data Structures and Algorithms, Fall 2016

Sequence structure. The computer executes java statements one after the other in the order in which they are written. Total = total +grade;

Java Programming Basics. COMP 401, Fall 2017 Lecture 2

Crash Course in Java. Why Java? Java notes for C++ programmers. Network Programming in Java is very different than in C/C++

CS 61C: Great Ideas in Computer Architecture Introduction to C

C - Basics, Bitwise Operator. Zhaoguo Wang

Computational Expression

Lecture Set 4: More About Methods and More About Operators

Introduction to Java

Object-Oriented Programming. Topic 2: Fundamental Programming Structures in Java

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

Course information. Petr Hnětynka 2/2 Zk/Z

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

Course Outline. Introduction to java

Getting started with Java

Object Oriented Software Design

Chapters 1-4 Summary. Syntax - Java or C? Syntax - Java or C?

Following is the general form of a typical decision making structure found in most of the programming languages:

CS 11 java track: lecture 1

Java Bytecode (binary file)

CS 61B Data Structures and Programming Methodology. June David Sun

C and C++ I. Spring 2014 Carola Wenk

CSC 1214: Object-Oriented Programming

Object-oriented programming. and data-structures CS/ENGRD 2110 SUMMER 2018

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

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

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

A Foundation for Programming

Zhifu Pei CSCI5448 Spring 2011 Prof. Kenneth M. Anderson

Lecture Set 4: More About Methods and More About Operators

Java language. Part 1. Java fundamentals. Yevhen Berkunskyi, NUoS

CMPT 125: Lecture 3 Data and Expressions

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

Lecture 1: Overview of Java

Java Basic Programming Constructs

Array. Array Declaration:

Key Differences Between Python and Java

Programming Language Concepts: Lecture 2

Java Identifiers, Data Types & Variables

Java Applets. Last Time. Java Applets. Java Applets. First Java Applet. Java Applets. v We created our first Java application

Review for Test 1 (Chapter 1-5)

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

Java Loop Control. Programming languages provide various control structures that allow for more complicated execution paths.

Java Programming Language. 0 A history

Selec%on and Decision Structures in Java: If Statements and Switch Statements CSC 121 Spring 2016 Howard Rosenthal

A variable is a name that represents a value. For

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

COMP 202 Java in one week

Control Flow. COMS W1007 Introduction to Computer Science. Christopher Conway 3 June 2003

COMP-202: Foundations of Programming. Lecture 2: Java basics and our first Java program! Jackie Cheung, Winter 2016

Selec%on and Decision Structures in Java: If Statements and Switch Statements CSC 121 Fall 2016 Howard Rosenthal

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

CS 112 Introduction to Programming

Admin. CS 112 Introduction to Programming. Recap: Java Static Methods. Recap: Decomposition Example. Recap: Static Method Example

Object-Oriented Programming

Controls Structure for Repetition

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

CS-140 Fall 2017 Test 1 Version Practice Practie for Sept. 27, Name:

DM550 / DM857 Introduction to Programming. Peter Schneider-Kamp

Exercises Software Development I. 05 Conversions and Promotions; Lifetime, Scope, Shadowing. November 5th, 2014

The for Loop, Accumulator Variables, Seninel Values, and The Random Class. CS0007: Introduction to Computer Programming

1.00 Introduction to Computers and Engineering Problem Solving Quiz 1 March 4, 2005

Pace University. Fundamental Concepts of CS121 1

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

C OVERVIEW BASIC C PROGRAM STRUCTURE. C Overview. Basic C Program Structure

Jump Statements. The keyword break and continue are often used in repetition structures to provide additional controls.

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

Tutorials. Inf1-OP. Learning Outcomes for this week. A Foundation for Programming. Conditionals and Loops 1

Expressions & Flow Control

bitwise inclusive OR Logical logical AND && logical OR Ternary ternary? : Assignment assignment = += -= *= /= %= &= ^= = <<= >>= >>>=

Chapter 4 Control Structures

CS321 Languages and Compiler Design I. Winter 2012 Lecture 2

Transcription:

CS251L REVIEW 2010.8.25 Derek Trumbo UNM

Java Applications Java application defined by a Java class with a main method public static void main(string[] args) args is an array of strings represented the command line parameters passed to the application The public class must match the name of the file

Java Applications Though usually hidden when using an IDE, know that the javac command compiles.java files, and the java command executes the resulting Java applications cd MyCode/ javac MyApp.java java MyApp

Java Applications Whereas historically most programming languages have been designed to be completely compiled (C, C++) or completely interpreted (Perl, Python, JavaScript), Java is both compiled, and then interpreted The javac command compiles Java code into bytecode and then the java command interprets this bytecode Eclipse executes both of these for you under the hood One seminal goal of Java was platform independence

Data Types Understanding data types foundation of all programming Two general categories in any language: Primitive data types Abstract data types (classes) Not all programming languages have the exact same primitive data types, but the overlap is large among compiled languages

The Byte 2 7 2 6 2 5 2 4 2 3 2 2 2 1 2 0 64 32 16 8 4 2 1 128 1 Bit 1 Nibble = 4 Bits 1 Byte = 2 Nibbles = 8 Bits Unsigned Byte Min Value: 0 (all off) Max Value: 255 (all on) Total # Possible Values: 256 = 2 8 Signed Byte Min Value: -128 Max Value: 127 Total # Possible Values: 256 still

The Byte 2 7 2 6 2 5 2 4 2 3 2 2 2 1 2 0 64 32 16 8 4 2 1 128 64 + 8 + 2 + 1 = 75 = K 1 Nibble = 4 Bits 1 Byte = 2 Nibbles = 8 Bits 1 Bit Unsigned Byte Min Value: 0 (all off) Max Value: 255 (all on) Total # Possible Values: 256 = 2 8 Signed Byte Min Value: -128 Max Value: 127 Total # Possible Values: 256 still

Primitive Data Types boolean [1 bit]: true, false byte [8 bits]: -128 to 127 (rarely used) char [16 bits]: 0 to 65,535 (e.g. a, B, $, 7 ) short [16 bits]: -32,768 to 32,767 (rarely used) int [32 bits]: -2,147,483,648 to 2,147,483,647 long [64 bits]: -9.2 x 10 18 to 9.2 x 10 18 (approx) float [32 bits]: -1.4 x 10-45 to 3.4 x 10 38 (approx) double [64 bits]: -4.9 x 10-324 to 1.8 x 10 308 (apx)

Operators Arithmetic (+ - * / %) Relational (< <= > >=) Equality (==!=) Logical (&& ) Bitwise (<< >> >>> & ^ ) Assignment (= += -= *= /= etc.) Others (?: ++ -- etc.)

Operator Precedence Just like in math, certain operators execute before others (A + B * C) Refer to this table for precedence: http://download.oracle.com/javase/tutorial/java/nuts andbolts/operators.html

Operator Associativity What happens when multiple operators at the same level of precedence exist in sequence in an expression is defined by associativity Operators either associate left-to-right or rightto-left; most associate left-to-right

Operator Associativity 10 + 20 + 3 * 4 * 5-30 10 + 20 + 12 * 5-30 10 + 20 + 60-30 30 + 60-30 90-30 60

Operator Associativity var1 = var2 = var3 = 0; var1 = var2 = 0; var1 = 0; 0;!!theSame The equality operators associate right-to-left Not only does the equality operator assign a value to the variable, it returns the value for subsequent expressions

Flow Control Statements Decision if-else switch (implemented in PL s as a convenience) Iteration for (counted loop) while (top-tested loop) do-while (bottom-tested loop)

Decision Statements if-else statements if(x > 10) dosomething(); if(x > 10) { } dosomething(); if(x > 10) { dosomething(); dosomethingelse(); }

Decision Statements if-else statements if(x > 10) dosomething(); dosomethingelse(); No-no! Don t confuse yourself if you leave off the braces only the first statement will be in the if and the second statement will always be executed no matter what

Decision Statements if-else statements if(x > 10) { dosomething(); } else { dosomethingelse(); } if(x > 10) { dosomething10(); } else if(x > 5) { dosomething5(); } else { dosomethingelse(); // Executed when x <= 5 }

Decision Statements switch statements (used only with primitives) switch(myint) { case 1: doone(); break; case 2: dotwo(); break; default: dootherwise(); break; } // Used in place of this: if(myint == 1) { doone(); } else if(myint == 2) { dotwo(); } else { dootherwise(); }

Iteration for loops When you know exactly how many times you want some piece of code to execute for(initialization; condition; inc/dec) { } // loop body

Iteration for(int e = 1; e <= 10; e++) sum += e; for(int h = 100; h >= 0; h--) { } System.out.println("height = " + h); int count = 0; for(double d = -2.3; d <= 293.48; d += 5.66) { count++; System.out.println(d + " " + count); }