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

Similar documents
CS 11 java track: lecture 1

Day 2. COMP 1006/1406A Summer M. Jason Hinek Carleton University

Java Bytecode (binary file)

Program Fundamentals

Introduction Basic elements of Java

CS 231 Data Structures and Algorithms, Fall 2016

Inf1-OOP. Textbooks. Who and What. Organisational issues. Why Java? Course Overview. Hello, World! in Java

Inf1-OOP. Textbooks. Who and What. Organizational Issues. Why Java? Course Overview. Hello, World! in Java. Ewan Klein, Perdita Stevens

Lec 3. Compilers, Debugging, Hello World, and Variables

Inf1-OP. Course Overview. Volker Seeker, adapting earlier version by Perdita Stevens and Ewan Klein. February 26, School of Informatics

Who and what can help? Inf1-OP. Lecturer: Timothy Hospedales TA: Natalia Zon

Software and Programming 1

MODULE 02: BASIC COMPUTATION IN JAVA

Basics of Java Programming

Programming Language Concepts: Lecture 2

13 th Windsor Regional Secondary School Computer Programming Competition

An overview of Java, Data types and variables

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

Lecture 02, Fall 2018 Friday September 7

DATA TYPES AND EXPRESSIONS

Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal

COMP-202 Unit 2: Java Basics. CONTENTS: Using Expressions and Variables Types Strings Methods

CS11 Java. Fall Lecture 1

Goals. Java - An Introduction. Java is Compiled and Interpreted. Architecture Neutral & Portable. Compiled Languages. Introduction to Java

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

1. Download the JDK 6, from

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

Full file at

Outline. Overview. Control statements. Classes and methods. history and advantage how to: program, compile and execute 8 data types 3 types of errors

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

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

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal

COMP 110 Introduction to Programming. What did we discuss?

Administrative Stuff. Inf1-OP. Additional help? Who to contact for help? Course Overview

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

Getting started with Java

Computer Science II Lecture 1 Introduction and Background

Getting started with Java

3. Java - Language Constructs I

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

Full file at

Gaddis: Starting Out with Java: From Control Structures through Objects, 6/e

Values and Variables 1 / 30

Lecture Notes CPSC 224 (Spring 2012) Today... Java basics. S. Bowers 1 of 8

What did we talk about last time? Examples switch statements

CMSC131. Introduction to your Introduction to Java. Why Java?

Starting Out with Java: From Control Structures through Data Structures 3e (Gaddis and Muganda) Chapter 2 Java Fundamentals

Advanced Computer Programming

INDEX. A SIMPLE JAVA PROGRAM Class Declaration The Main Line. The Line Contains Three Keywords The Output Line

Software and Programming 1

Fall 2017 CISC124 9/16/2017

Expressions and Data Types CSC 121 Spring 2017 Howard Rosenthal

Introduction to Java

CSE115 / CSE503 Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall Office hours:

1.1 Your First Program

COMP-202: Foundations of Programming

PROGRAMMING FUNDAMENTALS

Java Programming. Atul Prakash

Java Basic Programming Constructs

Chapter 2: Data and Expressions

! Widely available. ! Widely used. ! Variety of automatic checks for mistakes in programs. ! Embraces full set of modern abstractions. Caveat.

Basic Operations jgrasp debugger Writing Programs & Checkstyle

Programming Language Basics

12/22/11. Java How to Program, 9/e. Help you get started with Eclipse and NetBeans integrated development environments.

Administration. Classes. Objects Part II. Agenda. Review: Object References. Object Aliases. CS 99 Summer 2000 Michael Clarkson Lecture 7

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

Branching and Boolean Expressions

1 Introduction Java, the beginning Java Virtual Machine A First Program BlueJ Raspberry Pi...

1 class Lecture2 { 2 3 "Elementray Programming" / References 8 [1] Ch. 2 in YDL 9 [2] Ch. 2 and 3 in Sharan 10 [3] Ch.

Entry Point of Execution: the main Method. Elementary Programming. Learning Outcomes. Development Process

Lecture 3. COMP1006/1406 (the Java course) Summer M. Jason Hinek Carleton University

CSCI 2010 Principles of Computer Science. Data and Expressions 08/09/2013 CSCI

Object-Oriented Programming

Kickstart Intro to Java Part I

CS 177 Recitation. Week 1 Intro to Java

Computational Expression

4 Programming Fundamentals. Introduction to Programming 1 1

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

Assoc. Prof. Dr. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved.

B.V. Patel Institute of BMC & IT, UTU 2014

Introduction To Java. Chapter 1. Origins of the Java Language. Origins of the Java Language. Objects and Methods. Origins of the Java Language

4. If the following Java statements are executed, what will be displayed?

1.1 Your First Program

Welcome to the Primitives and Expressions Lab!

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

CSC Java Programming, Fall Java Data Types and Control Constructs

Midterms Save the Dates!

A very simple program. Week 2: variables & expressions. Declaring variables. Assignments: examples. Initialising variables. Assignments: pattern

Chapter 2 Elementary Programming

Lesson 04: Our First Java Program (W01D4

CISC 370: Introduction to Java

COMP-202 Unit 2: Java Basics. CONTENTS: Using Expressions and Variables Types Strings

Lecture Set 2: Starting Java

Chapter 2: Data and Expressions

Introduction to Java

CS 302: Introduction to Programming

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

Space Exploration EECS /25

Getting Started with Java. Atul Prakash

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

Transcription:

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

today s agenda a quick look back (last Thursday) assignment 0 is posted and is due this Friday at 2pm Java compiling and running a Java program primitive data types (and objects) casting arrays static methods (procedural programming) what s next? 2

last time... /* hello world */ public class HelloWorld{ public static void main(string[] args){ System.out.println("hello, world!"); } } access modifier public top level access modifier specifies who can see HelloWorld member level access modifier specifies who can access main (non access) modifier static allows a method to be called without an instance of the class return type void it is a Java keyword that tells us that a method returns nothing it is not an actual Java type System.out System is a class with three attributes/fields in, out and err out is a PrintStream object, it is standard output println is a method of out 3

last time... /* hello world */ public class HelloWorld{ public static void main(string[] args){ System.out.println("hello, world!"); } } access modifier public top level access modifier specifies who can see HelloWorld member level access modifier specifies who can access main (non access) modifier static allows a method to be called without an instance of the class return type void it is a Java keyword that tells us that a method returns nothing it is not an actual Java type System.out System is a class with three attributes/fields in, out and err out is a PrintStream object, it is standard output println is a method of out 3

last time... /* hello world */ public class HelloWorld{ public static void main(string[] args){ System.out.println("hello, world!"); } } access modifier public top level access modifier specifies who can see HelloWorld member level access modifier specifies who can access main (non access) modifier static allows a method to be called without an instance of the class return type void it is a Java keyword that tells us that a method returns nothing it is not an actual Java type System.out System is a class with three attributes/fields in, out and err out is a PrintStream object, it is standard output println is a method of out 3

last time... /* hello world */ public class HelloWorld{ public static void main(string[] args){ System.out.println("hello, world!"); } } access modifier public top level access modifier specifies who can see HelloWorld member level access modifier specifies who can access main (non access) modifier static allows a method to be called without an instance of the class return type void it is a Java keyword that tells us that a method returns nothing it is not an actual Java type System.out System is a class with three attributes/fields in, out and err out is a PrintStream object, it is standard output println is a method of out 3

last time... /* hello world */ public class HelloWorld{ public static void main(string[] args){ System.out.println("hello, world!"); } } access modifier public top level access modifier specifies who can see HelloWorld member level access modifier specifies who can access main (non access) modifier static allows a method to be called without an instance of the class return type void it is a Java keyword that tells us that a method returns nothing it is not an actual Java type System.out System is a class with three attributes/fields in, out and err out is a PrintStream object, it is standard output println is a method of out 3

last time... /* hello world */ public class HelloWorld{ public static void main(string[] args){ System.out.println("hello, world!"); } } what do we know about System.out.println()? 4

last time... /* hello world */ public class HelloWorld{ public static void main(string[] args){ System.out.println("hello, world!"); } } what do we know about System.out.println()? we can look at the API for the System class <link> API - application programming interface specifies how to use a given class 4

assignment 0 academic regulations coding style for COMP1406/1006 basic Java programs using just a main method using command line arguments assignment 1 user input procedural programming testing writing methods 5

assignment 0 academic regulations coding style for COMP1406/1006 basic Java programs using just a main method using command line arguments assignment 1 user input procedural programming testing writing methods 5

running hello world /* Java hello world */ public class HelloWorld{ public static void main(string[] args){ System.out.println("hello, world!"); } } Java convention is that class name is capitalized (use camel case if more than one word) class XXX must be in the file XXX.java so HellowWorld must be in the file HelloWorld.java first we need to compile the source code into Java bytecode IDE will have a compile button javac HelloWorld.java from console window (shell) this creates HelloWorld.class, which is the Java bytecode next, we run the bytecode in the JVM (Java virtual machine) java HelloWorld from the console window runs out program! the JVM executes the main method of our program 6

running hello world /* Java hello world */ public class HelloWorld { public static void main(string[] args){ System.out.println("hello, world!"); } } Java convention is that class name is capitalized (use camel case if more than one word) class XXX must be in the file XXX.java so HellowWorld must be in the file HelloWorld.java first we need to compile the source code into Java bytecode IDE will have a compile button javac HelloWorld.java from console window (shell) this creates HelloWorld.class, which is the Java bytecode next, we run the bytecode in the JVM (Java virtual machine) java HelloWorld from the console window runs out program! the JVM executes the main method of our program 6

running hello world /* Java hello world */ public class HelloWorld{ public static void main(string[] args){ System.out.println("hello, world!"); } } Java convention is that class name is capitalized (use camel case if more than one word) class XXX must be in the file XXX.java so HellowWorld must be in the file HelloWorld.java first we need to compile the source code into Java bytecode IDE will have a compile button javac HelloWorld.java from console window (shell) this creates HelloWorld.class, which is the Java bytecode next, we run the bytecode in the JVM (Java virtual machine) java HelloWorld from the console window runs out program! the JVM executes the main method of our program 6

running hello world /* Java hello world */ public class HelloWorld{ public static void main(string[] args){ System.out.println("hello, world!"); } } Java convention is that class name is capitalized (use camel case if more than one word) class XXX must be in the file XXX.java so HellowWorld must be in the file HelloWorld.java first we need to compile the source code into Java bytecode IDE will have a compile button javac HelloWorld.java from console window (shell) this creates HelloWorld.class, which is the Java bytecode next, we run the bytecode in the JVM (Java virtual machine) java HelloWorld from the console window runs out program! the JVM executes the main method of our program 6

running hello world /* Java hello world */ public class HelloWorld{ public static void main(string[] args){ System.out.println("hello, world!"); } } Java convention is that class name is capitalized (use camel case if more than one word) class XXX must be in the file XXX.java so HellowWorld must be in the file HelloWorld.java first we need to compile the source code into Java bytecode IDE will have a compile button javac HelloWorld.java from console window (shell) this creates HelloWorld.class, which is the Java bytecode next, we run the bytecode in the JVM (Java virtual machine) java HelloWorld from the console window runs out program! the JVM executes the main method of our program 6

running Java programs XXX.java 7

running Java programs XXX.java 7

running Java programs XXX.java javac XXX.java 7

running Java programs XXX.java javac XXX.java 7

running Java programs XXX.java javac XXX.java java.class 7

running Java programs XXX.java javac XXX.java java.class 7

running Java programs XXX.java javac XXX.java java.class java XXX 7

running Java programs XXX.java javac XXX.java java.class java XXX 7

running Java programs XXX.java javac XXX.java java.class java XXX!!??!! 7

command line arguments vs user input both are ways of providing some information to your program command line arguments input is entered before program runs input is passed as parameters to main method (args) (not practical for many user inputs) user input input is entered while program is running standard input is the keyboard (very flexible and useful) 8

let s take a break... for 3 minutes 9

Java date types in Java, everything is an object 10

Java date types in Java, everything is an object except for the 8 things that aren t! 10

Java date types in Java, everything is an object except for the 8 things that aren t! Java has eight primitive data types byte, short, int, long float, double boolean char (integers) (approximate real numbers) (logical true/false) (unicode characters) 10

Java date types there are four primitive data types for exact integers byte 8-bit signed integers 128 127 short 16-bit signed integers 32, 768 32, 767 int 32-bit signed integers 2,147,483,648 2,147,483,647 long 64-bit signed integers 9,223,372,036,854,775,808 9,223,372,036,854,775,807 11

Java date types there are two primitive data types for approximate decimal numbers (approximation to real numbers) float 32-bit IEEE 754 floating point 1 bit for sign, 8 bits for exponent, 23 bits for fraction accuracy about 7 decimal digits of accuracy double 64-bit IEEE 754 floating point 1 bit for sign, 11 bits for exponent, 52 bits for fraction accuracy about 15-16 decimal digits of accuracy 12

Java date types and two more... boolean true or false char 16-bit Unicode character chars enclosed in single quotes x, 3, Q, etc from \u0000 (zero) to \uffff (65,635) unlike other languages, char is not equivalent to a byte (8-bits) 13

type conversion automatic type conversion JVM will do some conversions for you explicit type conversion cast use a method 14

type conversion automatic type conversion JVM will do some conversions for you explicit type conversion cast use a method expression cat + 22 Integer.parseInt( 32 ) (int) 4.99999 Math.round(2.1) 11 * 0.3 (int) 11 * 0.3 11 * (int) 0.3 (int) (11*0.3) expression value 14

type conversion automatic type conversion JVM will do some conversions for you explicit type conversion cast use a method expression expression value cat + 22 cat22 String Integer.parseInt( 32 ) (int) 4.99999 Math.round(2.1) 11 * 0.3 (int) 11 * 0.3 11 * (int) 0.3 (int) (11*0.3) 14

type conversion automatic type conversion JVM will do some conversions for you explicit type conversion cast use a method expression expression value cat + 22 cat22 String Integer.parseInt( 32 ) 32 int (int) 4.99999 Math.round(2.1) 11 * 0.3 (int) 11 * 0.3 11 * (int) 0.3 (int) (11*0.3) 14

type conversion automatic type conversion JVM will do some conversions for you explicit type conversion cast use a method expression expression value cat + 22 cat22 String Integer.parseInt( 32 ) 32 int (int) 4.99999 4 int Math.round(2.1) 11 * 0.3 (int) 11 * 0.3 11 * (int) 0.3 (int) (11*0.3) 14

type conversion automatic type conversion JVM will do some conversions for you explicit type conversion cast use a method expression expression value cat + 22 cat22 String Integer.parseInt( 32 ) 32 int (int) 4.99999 4 int Math.round(2.1) 2 int 11 * 0.3 (int) 11 * 0.3 11 * (int) 0.3 (int) (11*0.3) 14

type conversion automatic type conversion JVM will do some conversions for you explicit type conversion cast use a method expression expression value cat + 22 cat22 String Integer.parseInt( 32 ) 32 int (int) 4.99999 4 int Math.round(2.1) 2 int 11 * 0.3 3.3 float (int) 11 * 0.3 11 * (int) 0.3 (int) (11*0.3) 14

type conversion automatic type conversion JVM will do some conversions for you explicit type conversion cast use a method expression expression value cat + 22 cat22 String Integer.parseInt( 32 ) 32 int (int) 4.99999 4 int Math.round(2.1) 2 int 11 * 0.3 3.3 float (int) 11 * 0.3 3.3 float 11 * (int) 0.3 (int) (11*0.3) 14

type conversion automatic type conversion JVM will do some conversions for you explicit type conversion cast use a method expression expression value cat + 22 cat22 String Integer.parseInt( 32 ) 32 int (int) 4.99999 4 int Math.round(2.1) 2 int 11 * 0.3 3.3 float (int) 11 * 0.3 3.3 float 11 * (int) 0.3 0 int (int) (11*0.3) 14

type conversion automatic type conversion JVM will do some conversions for you explicit type conversion cast use a method expression expression value cat + 22 cat22 String Integer.parseInt( 32 ) 32 int (int) 4.99999 4 int Math.round(2.1) 2 int 11 * 0.3 3.3 float (int) 11 * 0.3 3.3 float 11 * (int) 0.3 0 int (int) (11*0.3) 3 int 14

operator precedence order matters! 15

operator precedence order matters! BEDMAS 15

operator precedence order matters! BEDMAS elementary school... brackets exponents division and multiplication addition and subtraction 15

operator precedence 15

arrays and memory models let s look at arrays in Java... and lets draw pictures... 16

what s next? tutorial this week creating, compiling and running Java programs command line arguments/user input arrays next class towards OOP testing your code blackbox testing whitebox testing errors 17