Java Programming. What is a program? Programs as Recipes. Programs Recipes 8/20/15. Pancakes In one bowl

Similar documents
Java Programming. What is a program? Programs Recipes. Programs as Recipes 8/16/12. Pancakes In one bowl. mix: 1½ cup flour

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

CP122 CS I. Chapter 1: Introduction

Java Programming Constructs Java Programming 2 Lesson 1

CP122 CS I. Hello, World!

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

COMP 102: Computers and Computing

CS 177 Recitation. Week 1 Intro to Java

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

Building Java Programs

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

Creating a Program in JCreator. JCreator is then used to create our program. But the first step is to create a new file.

CS1150 Principles of Computer Science Loops (Part II)

CSE 201 Java Programming I. Smart Coding School website:

CS125 : Introduction to Computer Science. Lecture Notes #6 Compound Statements, Scope, and Advanced Conditionals

The first program: Little Crab

COMP 110/401 APPENDIX: INSTALLING AND USING ECLIPSE. Instructor: Prasun Dewan (FB 150,

Building Java Programs

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.

Building Java Programs

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

Mobile App:IT. Methods & Classes

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

Lecture 1: Introduction

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

Basic Programming Language Syntax

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

Eclipse. JVM, main method and using Eclipse. Dr. Siobhán Drohan. Produced by: Department of Computing and Mathematics

Summer Assignment for AP Computer Science. Room 302

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

Java Bytecode (binary file)

Chapter 4 Defining Classes I

Using Karel with Eclipse

Lab # 2. For today s lab:

Eclipse Environment Setup

COSC 236 Section 101 Computer Science 1 -- Prof. Michael A. Soderstrand

Java Programming Fundamentals - Day Instructor: Jason Yoon Website:

Topic 7 parameters. Based on slides from Marty Stepp and Stuart Reges from

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

Week 2: Data and Output

Chapter 2: Programming Concepts

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

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

3 CREATING YOUR FIRST JAVA APPLICATION (USING WINDOWS)

COSC 236 Section 101 Computer Science 1 -- Prof. Michael A. Soderstrand

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

Using Eclipse for Java. Using Eclipse for Java 1 / 1

Welcome to Python! If you re the type of person who wants to know

Programming with Java

Eclipse Setup. Opening Eclipse. Setting Up Eclipse for CS15

Object-oriented programming in...

Mr.Kailley s AP Chem programming Unit Set up instruction sheet for PC s (Mac will be kind of similar: good luck) 1) Go to the following website:

Example Program. public class ComputeArea {

Chapter 3 Intro to Java

Laboratory 1: Eclipse and Karel the Robot

A Unicorn Named Sparkle Word Search. A New Friend for Sparkle Coloring Sheet. A Unicorn Named Sparkle s First Christmas Coloring Sheet

Introduction to Computation and Problem Solving

Chapter 1 Introduction to Computers, Programs, and Java

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

Midterms Save the Dates!

CS 231 Data Structures and Algorithms, Fall 2016

Lecture 5: Methods CS2301

Introduction to Multimedia. MMP100 Spring 2017 thiserichagan.com/mmp100

1. Go to the URL Click on JDK download option

1.00 Lecture 2. What s an IDE?

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

Anatomy of a Java Program: Comments

Declaring and ini,alizing 2D arrays

ALICE: An introduction to progamming

Lecture 5: Implementing Lists, Version 1

Lab 4: Introduction to Programming

ICOM 4015 Advanced Programming Laboratory. Chapter 1 Introduction to Eclipse, Java and JUnit

CSE 114 Computer Science I

Lecture 1: Basic Java Syntax

Eclipse Tutorial. For Introduction to Java Programming By Y. Daniel Liang

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

Chapter 9. Exception Handling. Copyright 2016 Pearson Inc. All rights reserved.

CS3901 Intermediate Programming and Data Structures Winter 2008 (Q2 AY 08) Assignment #5. Due: noon Tuesday, 3 March 2008

SDKs - Eclipse. SENG 403, Tutorial 2

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

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

AP Computer Science Unit 1. Programs

CS1622. Semantic Analysis. The Compiler So Far. Lecture 15 Semantic Analysis. How to build symbol tables How to use them to find

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

Lab #1: A Quick Introduction to the Eclipse IDE

First Java Program - Output to the Screen

COSC 2P95. Procedural Abstraction. Week 3. Brock University. Brock University (Week 3) Procedural Abstraction 1 / 26

CMSC 150 LECTURE 1 INTRODUCTION TO COURSE COMPUTER SCIENCE HELLO WORLD

Introduction to Programming in C Department of Computer Science and Engineering. Lecture No. #43. Multidimensional Arrays

Computer Science II Lecture 1 Introduction and Background

Final Exam. Programming Assignment 3. University of British Columbia CPSC 111, Intro to Computation Alan J. Hu. Readings

Chapter 2, Part I Introduction to C Programming

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

CP122 CS I. Iteration

Real World. static methods and Console & JavaFX App Intros. Lecture 16. Go ahead and PULL Lecture Materials & Sign-in on PollEv

Loops! Step- by- step. An Example while Loop. Flow of Control: Loops (Savitch, Chapter 4)

Loops. CSE 114, Computer Science 1 Stony Brook University

Learning objec-ves. Declaring and ini-alizing 2D arrays. Prin-ng 2D arrays. Using 2D arrays Decomposi-on of a solu-on into objects and methods

Final Exam 2, CS154. April 25, 2010

Intro. Scheme Basics. scm> 5 5. scm>

Transcription:

What is a program? Java Programming CS 160, Fall Semester 2012 TOPICS Computer Programs Using Eclipse Program Program Components Definition: a sequence of instructions telling a computer what to do Analogy: cooking recipes Pancakes In one bowl mix: 1½ cup flour 1 tbsp sugar 1 tsp salt 1 tsp baking powder 1 CS 160, Fall Semester 2015 2 Programs as Recipes Recipes specify 1. What ingredients to use 2. What to do with them Sometimes conditional: bake until golden brown, salt to taste Programs specify 1. What information (data) to use 2. What operations to apply Sometimes conditional: while file is not empty, for every element in array Programs Recipes At some point the analogy breaks down: Recipes are read by people People can make inferences. If something goes wrong, people react. People sometimes make mistakes. Programs are read by machines Machines do exactly what they are told! No matter how badly things go wrong. But, they never make mistakes or get tired. CS 160, Fall Semester 2015 3 CS 160, Fall Semester 2015 4 1

Definitions program a set of directions telling a computer exactly what to do programming languages precise languages for specifying sequences of directions to a computer unlike English -- no ambiguities! no nuances! algorithm a sequence of steps to be followed to solve a problem independent of any programming language Object-oriented programming Java programs use objects and methods An object is a collection of code and data that you treat as a unit. Objects have methods code that implements actions that apply to the object. Objects have members data that is associated with the object. A Java cooking program might have a line like egg.scramble() to scramble an egg CS 160, Fall Semester 2015 5 CS 160, Fall Semester 2015 6 What does eclipse look like? Using Eclipse OK, the intro screen isn t too helpful Feel free to hit the X by welcome That will kill the intro screen Create a new project using the menus File - > New - > Project Select a Java project Give it a name/directory Then create a new class File - > New - > Class It will offer to make stubs, etc. Let it make a main stub for you CS 160, Fall Semester 2015 7 CS 160, Fall Semester 2015 8 2

via Eclipse Program // // Author: Chris Wilcox // Date: 1/1/2015 // Class: CS160 // Email: wilcox@cs.colostate.edu import java.lang.*; CS 160, Fall Semester 2015 9 public class { public static void main(string[] args) { System.out.println( "!" ); } } CS 160, Fall Semester 2015 10 Import directive Comments Tells Java what other classes or packages (collecuons of classes) to use. Java.lang.* includes the class System, always assumed by compiler. Must be above the class declarauon, at the top of the program. Eclipse will automaucally create import direcuves as needed. Any line beginning with // or any text between /* and */. Describes the behavior and a\ributes of a program. For humans only Java compiler ignores all comments when generaung code. But really important for humans! CS 160, Fall Semester 2015 11 CS 160, Fall Semester 2015 12 3

Class Heading Curly brackets { and } Creates a new class that can contain code (methods) and data: this one is called Every Java file begins with a class heading, which is always public. Class name must match file name this file is called.java Only one class per file is allowed Used to group statements together into larger units Everything within the outer brackets is part of the class Everything within the inner brackets is part of the method main CS 160, Fall Semester 2015 13 CS 160, Fall Semester 2015 14 Class Body Main Method Everything between { and } of the class header is the class body. The class body defines the data in the object and its methods. This class has no data, and only one method, which is the program starung point. The main funcuon is the acuon taken when a user invokes this class from the command line. Or when run from Eclipse or a program icon on the desktop. The program prints! to the screen or terminal. How do console programs and graphical programs differ? CS 160, Fall Semester 2015 15 CS 160, Fall Semester 2015 16 4

Main Components Main Body Return Value: What the method computes In this case, nothing, so void Method Name: main is reserved for the top- level acuon Names should describe acuons Arguments: Specify the input to a method In this case, command line arguments CS 160, Fall Semester 2015 17 The method body is a sequence of steps or Java statements Statements are separated by semicolons, cannot be omi\ed! In this case, the method has just one statement Calls the system object to output a line of text containing! CS 160, Fall Semester 2015 18 PracUcum Use Eclipse to create a workspace, project, and write a program CS 160, Fall Semester 2015 19 5