CMSC 150 LECTURE 1 INTRODUCTION TO COURSE COMPUTER SCIENCE HELLO WORLD

Similar documents
CS 177 Recitation. Week 1 Intro to Java

Introduction to Java. Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved.

BASICS.

Java Language. Programs. Computer programs, known as software, are instructions to the computer. You tell a computer what to do through programs.

Chapter 1 Introduction to Computers, Programs, and Java

Java Programming Fundamentals - Day Instructor: Jason Yoon Website:

Software and Programming 1

Module 1: Introduction to Computers, Programs, and Java

CONTENTS: What Is Programming? How a Computer Works Programming Languages Java Basics. COMP-202 Unit 1: Introduction

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

Chapter 1 Introduction to Computers, Programs, and Java

CompSci 125 Lecture 02

Software and Programming 1

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

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

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

Introduction. Introduction to OOP with Java. Lecture 01: Introduction to OOP with Java - AKF Sep AbuKhleiF -

Chapter 2 Author Notes

COMP 110 Project 1 Programming Project Warm-Up Exercise

Introduction to OOP with Java. Instructor: AbuKhleif, Mohammad Noor Sep 2017

Java Bytecode (binary file)

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

AP Computer Science Unit 1. Writing Programs Using BlueJ

Class 1: Homework. Intro to Computer Science CSCI-UA.0101 New York University Courant Institute of Mathematical Sciences Fall 2017

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

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

Chapter 1: Introduction to Computers, Programs, and Java

CSC116: Introduction to Computing - Java

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

Introduction to Computers and Java

Chapter 2: Programming Concepts

CHAPTER 1 Introduction to Computers and Java

Lecture 1 - Introduction (Class Notes)

CSC116: Introduction to Computing - Java

Basic Programming Language Syntax

Chapter 1: Introduction to Computers and Java

The NetBeans IDE is a big file --- a minimum of around 30 MB. After you have downloaded the file, simply execute the file to install the software.

8/23/2014. Chapter Topics. Introduction. Java History. Why Program? Java Applications and Applets. Chapter 1: Introduction to Computers and Java

TOPIC 2 INTRODUCTION TO JAVA AND DR JAVA

CSC116: Introduction to Computing - Java

C02: Overview of Software Development and Java

AP Computer Science Unit 1. Writing Programs Using BlueJ

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

2.1. Chapter 2: Parts of a C++ Program. Parts of a C++ Program. Introduction to C++ Parts of a C++ Program

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

AP Computer Science A

COMP 202 Java in one week

Get JAVA. I will just tell you what I did (on January 10, 2017). I went to:

Chapter 1 Introduction to Computers, Programs, and Java

Program Fundamentals

Algorithms and Programming I. Lecture#12 Spring 2015

Full file at

Introduction to Computers and Java

CSCI 1103: Introduction

Full file at

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

Lesson 2: First Java Programs

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

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

Lesson 04: Our First Java Program (W01D4

Introduction to Java Unit 1. Using BlueJ to Write Programs

Introduction to Java Applications

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

1.1 Your First Program

Lab # 2. For today s lab:

Last Time. University of British Columbia CPSC 111, Intro to Computation Alan J. Hu. Readings

Introduction Basic elements of Java

Java Basics Lecture: January 26, 2012 (On-line Lecture 1)

9/11/08 (c) 2008 Matthew J. Rutherford Class (c) 2008 Matthew J. Rutherford Class

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

Chapter 2 First Java Programs

BIL 104E Introduction to Scientific and Engineering Computing. Lecture 1

Fundamentals of Programming Session 4

Computer Hardware. Java Software Solutions Lewis & Loftus. Key Hardware Components 12/17/2013

Chapter 1 Introduction to Computers, Programs, and Java

Lecture Notes. System.out.println( Circle radius: + radius + area: + area); radius radius area area value

1.5 Input and Output

Week One: Introduction A SHORT INTRODUCTION TO HARDWARE, SOFTWARE, AND ALGORITHM DEVELOPMENT

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

Welcome to the Primitives and Expressions Lab!

CONTENTS: What Is Programming? How a Computer Works Programming Languages Java Basics. COMP-202 Unit 1: Introduction

Chapter 1 Introduction to Computers, Programs, and Java. What is a Computer? A Bit of History

Packages. 1. Every Java object resides in a package. 2. An object s package is explicitly declared on the first line of code in a.

AP Computer Science A: Java Programming

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

Introduction to C CMSC 104 Spring 2014, Section 02, Lecture 6 Jason Tang

3 CREATING YOUR FIRST JAVA APPLICATION (USING WINDOWS)

A PROGRAM IS A SEQUENCE of instructions that a computer can execute to

Refresher workshop in programming for polytechnic graduates General Java Program Compilation Guide

CS 112 Introduction to Programming

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

Introduction to Computers, Programs, and Java. CSE 114, Computer Science 1 Stony Brook University

Pace University. Fundamental Concepts of CS121 1

Chapter 1 - Introduction. Copyright 2014 by John Wiley & Sons. All rights reserved. 1

Advanced Computer Programming

ICOM 4015: Advanced Programming

Chapter 2, Part I Introduction to C Programming

Lecture 02, Fall 2018 Friday September 7

COMP-202: Foundations of Programming. Lecture 3: Boolean, Mathematical Expressions, and Flow Control Sandeep Manjanna, Summer 2015

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

Transcription:

CMSC 150 INTRODUCTION TO COMPUTING ACKNOWLEDGEMENT: THESE SLIDES ARE ADAPTED FROM SLIDES PROVIDED WITH INTRODUCTION TO JAVA PROGRAMMING, LIANG (PEARSON 2014) LECTURE 1 INTRODUCTION TO COURSE COMPUTER SCIENCE HELLO WORLD

WELCOME Questions?

SYLLABUS Questions?

WHAT IS COMPUTER SCIENCE AND COMPUTING? Your thoughts? Google: The study of the principles and use of computers Wikipedia: The scientific and practical approach to computation and its applications Dictionary.com: The science that deals with the theory and methods of processing information in digital computers, the design of computer hardware and software, and the applications of computers Edsgar Dijkstra: Computer Science is no more about computers than astronomy is about telescopes

WHAT IS COMPUTER SCIENCE AND COMPUTING? Study of algorithms Input Study of computing tools It is not just: Programming Microsoft office Typing Electronics Etc. Algorithm Output

PROBLEM! Work in pairs/triplets Create a methodology to perform some task, e.g., Cook something Play a game Buy/sell on the stock market Put another way tell a computer how to do this task

WHAT IS COMPUTER SCIENCE AND COMPUTING?

COMPUTER ORGANIZATION Input Files Keyboard Mouse Etc. Central Processing Unit (CPU) Processes commands as 0 s and 1 s Requests (reads) and writes to/from memory Performs arithmetic (+, -, *, /, %) Output Monitor Force feedback Files Etc. Memory Data encoded as 0s and 1s Cache RAM Random Access Memory Hard drive

PROGRAMMING Even though computer science is not about the computer, we still need to tell the computer what to do! We do this through programming, or the act of writing a computer program, known as software its just instructions to the computer Programming allows us to push the boundaries of science, view imaginary worlds, and improve our daily lives!

PROGRAMMING

COMPUTER ORGANIZATION A SECOND LOOK User Application Programs Operating System Manages all resources (memory, files, etc) Hardware

A BRIEF NOTE ON PROGRAMMING LANGUAGES Machine code 0 s and 1 s or simple commands. It is the set of primitive instructions built into the computer s architecture or circuits. Extremely tedious and error prone Assembly code simple commands (ADD ra rb rc) to make programming easier to understand. An assembler translates the commands to machine code. Extremely tedious but less error prone. High level languages English-like commands that allow programming to be less tedious, less error prone, and much more expressive! Examples: Java, C++, Matlab, etc Why we don t use Natural language (English) Its ambiguous which vs which or break vs break or run vs run ah the madness!!!!

COMPILING A HIGH LEVEL PROGRAM Program In Java Program In Java Compiler (javac for us) Translation to another language Interpreter Reads language directly Machine Code Specific for an architecture Execute Program (java for us) Execute Program Output Using a compiler Output Using an interpreter

HOW DO WE PROGRAM THE COMPUTER? We will use Java NOTE This is an arbitrary choice. All languages build on the same basic building blocks discussed in the course. So Java is merely the vessel to our exploration of computing! Specifically: Any Program Objects Methods Arrays Control Flow Math/String Primitive data types I/O Expressions

WHY JAVA? Java Widely used. Widely available. Embraces full set of modern abstractions. Variety of automatic checks for mistakes in programs. Our study will Minimal subset of Java. Develop general programming skills that are applicable to many languages. IT IS NOT ABOUT THE LANGUAGE!!! There are only two kinds of programming languages: those people always [gripe] about and those nobody uses. Bjarne Stroustrup

1.1 YOUR FIRST PROGRAM

SUBLIME TEXT AND TERMINAL In this class, we will exclusively use Sublime text editor to write programs and use the terminal to compile and run our programs Log in Open a terminal Open sublime

TERMINAL REFERENCE GUIDE A terminal is a window to interact with your operating system through commands. Things to know: You are always in a specific directory, called the current (or working) directory Filenames are specified relative ly this means you have to be in the same directory or refer to the location relative to your current directory Common commands (to move through folders and create them) pwd print the current directory cd change directory, e.g., cd Desktop ls print everything in a directory mkdir make a new directory, e.g., mkdir HelloWorldProject

HELLO WORLD HelloWorld.java 1.// This program prints Hello World! 2.public class HelloWorld { 3. public static void main(string[] args) { 4. System.out.println( Hello World!"); 5. } 6.} Compile: Run: javac HelloWorld.java java HelloWorld

ANATOMY OF A JAVA PROGRAM Class name Main method Statements Statement terminator Reserved words Comments Blocks

CLASS NAME Every Java program must have at least one class. Each class has a name. By convention, class names start with an uppercase letter. 1.// This program prints Hello World! 2.public class HelloWorld { 3. public static void main(string[] args) { 4. System.out.println( Hello World!"); 5. } 6.}

MAIN METHOD Line 2 defines the main method. In order to run a class, the class must contain a method named main. The program is executed from the main method. 1.// This program prints Hello World! 2.public class HelloWorld { 3. public static void main(string[] args) { 4. System.out.println( Hello World!"); 5. } 6.}

STATEMENT A statement represents an action or a sequence of actions. The statement System.out.println( Welcome to Java! ) in the program in Listing 1.1 is a statement to display the greeting Welcome to Java!. 1.// This program prints Hello World! 2.public class HelloWorld { 3. public static void main(string[] args) { 4. System.out.println( Hello World!"); 5. } 6.}

STATEMENT TERMINATOR Every statement in Java ends with a semicolon (;). 1.// This program prints Hello World! 2.public class HelloWorld { 3. public static void main(string[] args) { 4. System.out.println( Hello World!"); 5. } 6.}

RESERVED WORDS Reserved words or keywords are words that have a specific meaning to the compiler and cannot be used for other purposes in the program. For example, when the compiler sees the word class, it understands that the word after class is the name for the class. 1. // This program prints Hello World! 2. public class HelloWorld { 3. public static void main(string[] args) { 4. System.out.println( Hello World!"); 5. } 6. }

BLOCKS A pair of braces in a program forms a block that groups components of a program. 1.// This program prints Hello World! 2.public class HelloWorld { 3. public static void main(string[] args) { 4. System.out.println( Hello World!"); 5. } 6.} Class Block Method Block

SPECIAL SYMBOLS Character Name Description {} () [] // " " ; Opening and closing braces Opening and closing parentheses Opening and closing brackets Double slashes Opening and closing quotation marks Semicolon Denotes a block to enclose statements. Used with methods. Denotes an array. Precedes a comment line. Enclosing a string (i.e., sequence of characters). Marks the end of a statement.

ASIDE, ALGORITHMIC PSEUDOCODE In this class, we are learning the basic tools to express and model algorithms and software. We will learn not only Java, but something called Pseudocode. Pseudocode is a detailed and stylized description for program and algorithm design. Often more natural than true language Java code Sometimes hard to read Can only use a restricted subset of math and natural language Generates compile errors if done improperly Runs on a computer Pseudocode Stylized and easy to read Can use math and natural language Is not compiled, therefor ;, {}, etc don t matter Does not run on a computer

ASIDE, ALGORITHMIC PSEUDOCODE JAVA CODE HelloWorld.java 1. // This program prints 2. // Hello World! 3. public class HelloWorld { 4. public static void 5. main(string[] args) { 6. System.out.println( 7. Hello World!"); 8. } 9. } PSEUDOCODE HelloWorld 1. // This algorithm prints 2. // Hello World! 3. Output( Hello World );

PROGRAMMING STYLE AND DOCUMENTATION Appropriate Comments Naming Conventions Proper Indentation and Spacing Lines Block Styles

APPROPRIATE COMMENTS Include a summary at the beginning of the program to explain what the program does, its key features, its supporting data structures, and any unique techniques it uses. Document each variable and method Include your name, and a brief description at the beginning of the program.

NAMING CONVENTIONS Choose meaningful and descriptive names. Class names: Capitalize the first letter of each word in the name, called CamelCasing. For example, the class name ComputeExpression.

PROPER INDENTATION AND SPACING Indentation Indent two spaces. Spacing Use blank line to separate segments of the code.

BLOCK STYLES Use end-of-line style for braces. Next-line style public class Test { public static void main(string[] args) { System.out.println("Block Styles"); } } public class Test { public static void main(string[] args) { System.out.println("Block Styles"); } } End-of-line style

PROGRAMMING ERRORS Syntax Errors Detected by the compiler Runtime Errors also called Exceptions Causes the program to abort Logic Errors Produces incorrect result

SYNTAX ERRORS Syntax errors are errors from incorrectly written Java code. The compiler (javac) tells you these Anatomy of a compiler error: filename.java:line_num: error: Confusing description of error including code where it occurs. Deal with errors by experience, google, stack overflow, etc. After you have exhausted these resources piazza/ask me. Advice, always handle the first error not the last one. 1. // This program prints Hello World! 2. public class HelloWorld { 3. public static void main(string[] args) { 4. System.out.println( Hello World!") 5. } 6. }

RUNTIME ERRORS Runtime errors occur from impossible to complete commands encountered while executing the program (with java) 1. // This program prints Hello World! 2. public class HelloWorld { 3. public static void main(string[] args) { 4. System.out.println(1/0) 5. } 6. }

LOGIC ERRORS 1.// This program prints Hello World! 2.public class HelloWorld { 3. public static void main(string[] args) 4. System.out.println( 5. "Celsius 35 is Fahrenheit degree "); 6. System.out.println((9 / 5) * 35 + 32); 7. } 8.}

STANDARD DRAWING

STANDARD DRAWING Standard drawing (StdDraw) is library for producing graphical output library developed for an introduction course (not for broad usage!)

STANDARD DRAW Practice with StdDraw. To use: download StdDraw.java and put in working directory. 1. public class Triangle { 2. public static void main(string[] args) { 3. StdDraw.line(0.0, 0.0, 1.0, 0.0); 4. StdDraw.line(1.0, 0.0, 0.5, 0.866); 5. StdDraw.line(0.5, 0.866, 0.0, 0.0); 6. } 7. } (½, ½ 3) (0, 0) (1, 0)

SET SIZE OF WINDOW Use StdDraw.setCanvasSize(width, height) Width and height are integers representing pixels This is the window Height Width

COORDINATE SYSTEM WITH STDDRAW Use StdDraw.setXscale(xmin, xmax) and StdDraw.setYscale(ymin, ymax) xmin, xmax, ymin, and ymax are real numbers. Note the difference between pixels! (x max, y max ) Default: 1, 1 This is the window x min, y min Default: 0, 0

COLORS Change color with StdDraw.setPenColor(Color) Use StdDraw.BLACK, StdDraw.WHITE, StdDraw.BLUE, StdDraw.RED, etc Can define own colors with Java color library (uses RGB) import java.awt.color; //put at top of file StdDraw.setPenColor(new Color(r, g, b));

SPECIAL EFFECTS Images. Put.gif,.png, or.jpg file in the working directory and use StdDraw.picture() to draw it.

EXERCISES 1. Create a program to share three things about yourself. Please have each of the items nicely formatted with multiple System.out.println() commands. 2. Write a program using StdDraw to show a wireframe of a cube. Try to use different colors for the edges to show faces. 3. Work on Programming Assignment 1