CS 177 Recitation. Week 1 Intro to Java

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

Java Bytecode (binary file)

Java Programming Fundamentals - Day Instructor: Jason Yoon Website:

Lecture 1 - Introduction (Class Notes)

CMSC 150 LECTURE 1 INTRODUCTION TO COURSE COMPUTER SCIENCE HELLO WORLD

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

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

Wentworth Institute of Technology. Engineering & Technology WIT COMP1000. Java Basics

The name of our class will be Yo. Type that in where it says Class Name. Don t hit the OK button yet.

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

3 CREATING YOUR FIRST JAVA APPLICATION (USING WINDOWS)

Lab # 2. For today s lab:

COMP163. Introduction to Computer Programming. Introduction and Overview of the Hardware

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

Program Fundamentals

BASICS.

CS125 : Introduction to Computer Science. Lecture Notes #4 Type Checking, Input/Output, and Programming Style

List of Slides 1 Title 2 Chapter 2: Sequential execution and program errors 3 Chapter aims 4 Section 2: Example:Hello world 5 Aim 6 Class: programs ar

An overview of Java, Data types and variables

Getting Started with Java. Atul Prakash

Chapter 2: Programming Concepts

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

CSCI 1103: Introduction

Chapter 3 Intro to Java

17 Hello world 18 Type: String: literal 19 Standard API: System: out.println() 20 Hello world 21 Statement 22 Statement: simple statements are ended w

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

1) Log on to the computer using your PU net ID and password.

Lesson 04: Our First Java Program (W01D4

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

COMP 110 Project 1 Programming Project Warm-Up Exercise

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

Week 2: Data and Output

Chapter Two Bonus Lesson: JavaDoc

A Foundation for Programming

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

Summer Assignment for AP Computer Science. Room 302

1.1 Your First Program

1.1 Your First Program

CSC116: Introduction to Computing - Java

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

Program Development. Program Development. A Foundation for Programming. Program Development

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

CSC116: Introduction to Computing - Java

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

CS 231 Data Structures and Algorithms, Fall 2016

Lecture (01) Getting started. Dr. Ahmed ElShafee

! Learn how to think like a computer scientist. ! Learn problem solving. ! Read and write code. ! Understand object oriented programming

1. Download the JDK 6, from

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

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

Intro to Programming & C Why Program? 1.2 Computer Systems: Hardware and Software. Why Learn to Program?

COMP1007 Principles of Programming

CS 220: Introduction to Parallel Computing. Beginning C. Lecture 2

Software and Programming 1

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

1.1 Your First Program

CompSci 125 Lecture 02

CP122 CS I. Hello, World!

CP122 CS I. Chapter 1: Introduction

Conditionals, Loops, and Style

Intro to Programming. Unit 7. What is Programming? What is Programming? Intro to Programming

Computer Science is...

Lecture 2: Intro to Java

Java: Comment Text. Introduction. Concepts

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

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

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

CSC116: Introduction to Computing - Java

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal

Lecture Set 2: Starting Java

At its simplest, a computer is a collection of wires, transistors and electrical components that are connected in a specific way When you send

Lecture Set 2: Starting Java

CS 11 java track: lecture 1

Outline. CIS 110: Introduction to Computer Programming. What is Computer Science? What is computer programming? What is computer science?

Chapter 1 Introduction to Computers, Programs, and Java

Pace University. Fundamental Concepts of CS121 1

CPSC 150 Laboratory Manual. Lab 1 Introduction to Program Creation

CS2900 Introductory Programming with Python and C++ Kevin Squire LtCol Joel Young Fall 2007

Course Outline. Introduction to java

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

AP CS Unit 3: Control Structures Notes

1B1a Programming I Getting Started

Branching and Boolean Expressions

AP Computer Science Unit 1. Programs

COMP 215: INTRO TO PROGRAM DESIGN. Prof. Chris Jermaine Chris Prof. Chris Dr. Chris

Introduction Basic elements of Java

Conditionals, Loops, and Style. Control flow thus far. if statement. Control flow. Common branching statement Evaluate a boolean expression

Java using LEGO Mindstorms and LeJOS. University of Idaho

Full file at

Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal

A sample algorithm to calculate someone s wages for the week might look like:

Welcome to Python 3. Some history

1.1 Your First Program

Lesson 3: Accepting User Input and Using Different Methods for Output

Identifiers. Identifiers are the words a programmer uses in a program Some identifiers are already defined. Some are made up by the programmer:

PROGRAMMING STYLE. Fundamentals of Computer Science I

Index. Course Outline. Grading Policy. Lab Time Distribution. Important Instructions

Algorithms and Programming I. Lecture#12 Spring 2015

Software and Programming 1

Lecture 1: Introduction to Java

Transcription:

CS 177 Recitation Week 1 Intro to Java

Questions?

Computers Computers can do really complex stuff. How? By manipulating data according to lists of instructions. Fundamentally, this is all that a computer can actually do. Different kinds of computers: supercomputers, desktops, laptops, embedded. Different kinds of computer have different sizes, computing powers, uses, etc.

Computers What is hardware? What are some examples? The physical components of the computer (stuff you can touch). monitor, CPU, keyboard, memory, hard drive, etc. What is software? What are some examples? Programs that run on the hardware and make it do stuff. Windows, Firefox, MS Powerpoint, World of Warcraft, etc

Computers What are some important (hardware) parts of a computer? CPU does calculations (the brain) Memory stores data (cache, RAM, hard drive, etc) I/O devices allows the user and the computer to communicate (monitor, mouse, keyboard, etc)

Programming Computers only manipulate data according to a list of instructions. Computers are stupid, but really fast. Computers can only do very simple things (like adding two numbers), but they can do millions or billions of simple things a second. Programming the process of creating lists of instructions for the computer to follow.

Programming The process of software development: 1) Understand the problem that you need to solve. 2) Plan a solution to the problem. 3) Implement the solution (write the program). 4) Test the program (compile and run it), and fix any errors.

Programming Languages We have to use programming languages to give computers instructions because human languages (like English) are too vague. We are going to write programs in a programming language called Java. There are lots of other programming languages too.

Programming Languages We classify programming languages as high or low level. Low level languages are closer to (or are) what the computer actually understands, and have very simple commands. ex) machine code, assembly languages High level languages are easier for humans to understand and have more complex commands. Programs written in high level languages have to be translated to a low level language before they can be run. ex) Java, Python

Compiling What special program translates a program written in a high-level language into a low-level language? a compiler How things usually work: The compiler translates the program directly into machine code and the program can be run.

Compiling Java is weird: The Java compiler translates the program into bytecode, a sort of intermediate language. When the Java program is run, the Java Virtual Machine compiles/translates the bytecode into machine code, and then the program runs. The machine code produced is different depending on the computer. The bytecode will be the same no matter what computer the program is compiled on. The Whatever.class file you get after compiling your Whatever.java file contains the bytecode.

Java Java programs are just text files, and can be written in any text editor or DrJava. Java is a language, and therefore has rules that you have to learn and obey. If you do not follow Java s rules, your program will not compile or won t run correctly.

Anatomy of a Java Program public class NameOfClass { public static void main(string[] args) { } } Every Java program must be inside a class. The keyword class tells Java that you are making a new class. Replace NameOfClass with what you want to call your program. The program will need to be saved in a file called NameOfClass.java. For now, the rest of the stuff is magic words. Just remember to type them in, or your program won t work.

Simple Program public class HelloWorld { public static void main(string[] args) { System.out.print( Hello, world! ); System.out.println(100.34); System.out.println( Programming is fun! ); } } This program just prints some stuff on the screen. You can use System.out.println() to print anything in quotes ( fish, foobar ) or numbers (5, 20.6). System.out.print() does the same thing, but does not put a newline after the printed stuff.

Running a Program Let s run our HelloWorld program and see it in action! There are two different ways to do it. In the terminal or command prompt: Change to the directory where your Java file is saved. To compile, type javac HelloWorld.java If you don t see any messages, your program compiled successfully. Compiling creates a class file with the same name as your Java file (in this case, HelloWorld.class ). To run, type java HelloWorld.

Running a Program In DrJava: To compile, push the Compile button (upper right corner of the window). If it says Compilation completed, everything worked. To run, push the Run button (near the Compile button). NOTE: You don t have to use DrJava if you don t want to, especially at home. It will probably make your life easier, though.

Some Java Details All statements in Java must end with a semicolon (;). Think of it like the period at the end of an English sentence. All classes and methods must have curly braces ({ and }) around their contents. Java is case sensitive ( class is not the same as Class or CLASS or class ).

Comments Programs can be confusing to read. Use comments to leave notes for yourself or anyone else who reads your code. Comments do not affect how the program runs (they re ignored by the computer). Two ways to make comments: // I m a comment Use for single-line comments /* I m a comment. */ Use for comments that are multiple lines long

Coding with Style! Java ignores whitespace, so use whitespace to make your code more readable. Indent all the lines of code between a class or method s curly brackets. This makes your code MUCH easier to read. Really. It does. We WILL take points off on assignments if you do not indent your code nicely!

Indentation Examples Good public class NameOfClass { public static void main(string[] args) { System.out.println( Hello, world! ); } } Bad public class NameOfClass { public static void main(string[] args) { System.out.println( Hello, world! ); } } Horrible! public class NameOfClass { public static void main(string[] args) { System.out.println( Hello, world! ); } }

Questions?