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

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

PROGRAMMING FUNDAMENTALS

CSE 201 JAVA PROGRAMMING I. Copyright 2016 by Smart Coding School

Lec 7. for loops and methods

CS 11 java track: lecture 1

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

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

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

Lecture 1: Overview of Java

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

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

Getting started with Java

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

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

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

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

4 Programming Fundamentals. Introduction to Programming 1 1

Full file at

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal

COS 126 Midterm 1 Written Exam, Fall 2009

Basic Operations jgrasp debugger Writing Programs & Checkstyle

Introduction. Lecture 1 MIT 12043, Fundamentals of Programming By: S. Sabraz Nawaz

Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal

B2.52-R3: INTRODUCTION TO OBJECT-ORIENTED PROGRAMMING THROUGH JAVA

Tutorial 1 CSC 201. Java Programming Concepts عؾادئماظربجمةمبادؿكدامماجلاصا

CSCI 161: Introduction to Programming I Lab 1b: Hello, World (Eclipse, Java)

Lesson 04: Our First Java Program (W01D4

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

CT 229 Fundamentals of Java Syntax

Please answer the following questions. Do not re-code the enclosed codes if you have already completed them.

PROGRAMMING STYLE. Fundamentals of Computer Science I

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

Java: Comment Text. Introduction. Concepts

CS 101 Fall 2005 Midterm 2 Name: ID:

CompSci 125 Lecture 02

Introduction to Java

Java Bytecode (binary file)

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

3 CREATING YOUR FIRST JAVA APPLICATION (USING WINDOWS)

DATA TYPES AND EXPRESSIONS

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

CS171:Introduction to Computer Science II

CS Week 2. Jim Williams, PhD

MODULE 02: BASIC COMPUTATION IN JAVA

Software and Programming 1

Introduction to Object Oriented Systems Development. Practical Session (Week 2)

COMP-202: Foundations of Programming

Getting started with Java

CS 177 Spring 2010 Exam I

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

Even though we created a folder for the workspace, we still have to let JCreator do the same. So click File, New, and then Blank Workspace.

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

Java Basic Syntax. Java vs C++ Wojciech Frohmberg / OOP Laboratory. Poznan University of Technology

Object-oriented programming in...

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

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

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

Introduction to Java. Java Programs Classes, Methods, and Statements Comments Strings Escape Sequences Identifiers Keywords

CS 106 Introduction to Computer Science I

Building Java Programs. Introduction to Programming and Simple Java Programs

Computer Science is...

6.092: Java for 6.170

Chapter 2: Data and Expressions

Lab 9: Creating a Reusable Class

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

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

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

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

Cost of Your Programs

COMP 250: Java Programming I. Carlos G. Oliver, Jérôme Waldispühl January 17-18, 2018 Slides adapted from M. Blanchette

Java in 21 minutes. Hello world. hello world. exceptions. basic data types. constructors. classes & objects I/O. program structure.

Lecture 1: Object Oriented Programming. Muhammad Hafeez Javed

Lab5. Wooseok Kim

Data Structures Lecture 1

Java Simple Data Types

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

Chapter 2: Data and Expressions

Public-Service Announcements

Basics of Java Programming

CPSC 213. Introduction to Computer Systems. Numbers and Memory. Unit 1a

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

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

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

Variables. Store information needed by the program

COMP 110 Project 1 Programming Project Warm-Up Exercise

Variables and Functions. ROBOTC Software

CPS109 Lab 1. i. To become familiar with the Ryerson Computer Science laboratory environment.

Software and Programming 1

Variables, Types, Operations on Numbers

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

C212 Early Evaluation Exam Mon Feb Name: Please provide brief (common sense) justifications with your answers below.

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

Expressions and Data Types CSC 121 Spring 2017 Howard Rosenthal

CSC 103: Ho. Spring 2016 Smith Colle Prof. Sheeh

Java Programming. Atul Prakash

Full file at

Welcome to the Using Objects lab!

In Java, data type boolean is used to represent Boolean data. Each boolean constant or variable can contain one of two values: true or false.

2 Getting Started. Getting Started (v1.8.6) 3/5/2007

Key Differences Between Python and Java

Transcription:

Lec 3 Compilers, Debugging, Hello World, and Variables

Announcements First book reading due tonight at midnight Complete 80% of all activities to get 100% HW1 due Saturday at midnight Lab hours posted

Programming Levels Machine code Assembly languages High level languages

You compile a non-java program on your desktop (it uses a Intel x86 processor) and then email the program to your friend to run on his system (it uses an AMD processor). Will it execute? Why? A) Yes. The program is already down to machine code and can execute anywhere B) Yes. Your friend s system will automatically translate the program into a format it can execute C) No. The machine code will be different on the 2 systems D) No. Your friend s system may not have the compiler/assembler installed.

How is Java different

Compiling

You have the file Hello.class how do you make it run on your computer? A) javac Hello.class java Hello B) javac Hello.java java Hello C) java Hello D) javac Hello E) Can t run without the.java file

Your first program

Your first program /* Your first program */ public class Hello { public static void main(string[] args) { System.out.println("Hello world!");

Your first program /* Your first program */ public class Hello { public static void main(string[] args) { System.out.println("Hello world!");

Comments Exist to help the programmer Today or 2 years in the future Should add value to the reader - Single line // - Block comments /* */

Comments Which is not an example of a helpful comment A) i = 0; //set i to 0 B) //#TODO: implement feature to increase BMI accuracy C) /* This program takes two ints as input from the user and calculates their BMI */ D) /* @return double the calculated BMI */

Your first program /* Your first program */ public class Hello { public static void main(string[] args) { System.out.println("Hello world!");

Your first program /* Your first program */ public class Hello { public static void main(string[] args) { System.out.println("Hello world!");

Your first program /* Your first program */ public class Hello { public static void main(string[] args) { System.out.println("Hello world!"); Public class Hello { public.. main() {

Your first program /* Your first program */ public class Hello { public static void main(string[] args) { System.out.println("Hello world!");

Question What happens if there is no main method, e.g. you have the code: public class Hello { public static void notmain(string[] args) { System.out.println("Hello world!"); A) Compiler will report an error B) Program will compile and print Hello World C) Program compiles but nothing happens D) Program compiles, but once executed reports an error similar to no main method

Your first program /* Your first program */ public class Hello { public static void main(string[] args) { System.out.println("Hello world!");

Summary: Program must haves Filename and class name match { and start and stop sections Instructions end with a ; public static void main() For now: always put in your code. This where execution starts

Style Indentation in Java is there for user readability public class Hello { public static void main(string[] args) { System.out.println("Hello world!"); Style requirements for this class Each time you use a { indent farther. Go back when closing with 2 spaces per indent All lines less than 80 characters Use comments to clarify logical parts of program Use blank spaces around logical chunks of code

int x; Variables

Variables int x; x = 200;

Variables int x; x = 200; int y = 100; 100

Variables int is a primitive types: int standard integers, e.g. 5, 100, -37 double decimal numbers, e.g. 5.32, -100.2 char single character, e.g. C,! boolean true/false boolean flag = true;

= vs. == = Does the assignment of a value, if you do: int j = 20; //you are giving a value of 20 to j == int b = j; // also gives the value of 20 to b Used to do comparisons, outcome is either true or false. (Think of as are these equal ) int a=10; int b=20; boolean b = (a == b);

Variables What is the output of this code? int x = 3; int y = x; System.out.println(y == 3); int x = 4; System.out.println(y == 3); A) true B) false C) true D) false E) None of the true false false true above