Code Ninjas: Introduction to Computer Science. Macomb Science Olympiad Presented by Swati Dharia

Similar documents
C02: Overview of Software Development and Java

Lesson 04: Our First Java Program (W01D4

IT151: Introduction to Programming (java)

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

3 CREATING YOUR FIRST JAVA APPLICATION (USING WINDOWS)

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

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

CS 11 java track: lecture 1

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

INFO Object-Oriented Programming

Getting Started with Java. Atul Prakash

lejos NXJ Problem Solving with Robots [PRSOCO601]

Instructions. First, download the file

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

COMP6700/2140 JDK Tools

Chapter 3 Intro to Java

Java Bytecode (binary file)

Getting Started (1.8.7) 9/2/2009

CS 177 Recitation. Week 1 Intro to Java

History of Java. Java was originally developed by Sun Microsystems star:ng in This language was ini:ally called Oak Renamed Java in 1995

Chapter Two Bonus Lesson: JavaDoc

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

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

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

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

Java: Comment Text. Introduction. Concepts

Fundamentals of Programming. By Budditha Hettige

CS 101 : Introduction to Programming. Lecture 1 22/January/2018 Ashish Sureka

Certified Core Java Developer VS-1036

Chapter 1: A First Program Using C#

1B1a Programming I Getting Started

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

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

Kickstart Intro to Java Part I

COMP1007 Principles of Programming

BASICS.

Introduction to Java. Nihar Ranjan Roy.

CompSci 125 Lecture 02

CPSC 150 Laboratory Manual. Lab 1 Introduction to Program Creation

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

You should see something like this, called the prompt :

Project 1. Java Control Structures 1/17/2014. Project 1 and Java Intro. Project 1 (2) To familiarize with

1. Download the JDK 6, from

Lecture 1: Overview of Java

Lab # 2. For today s lab:

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


Introduction to Java

These two items are all you'll need to write your first application reading instructions in English.

CSE 1223: Introduction to Computer Programming in Java Chapter 1 Computer Basics

Introduction Basic elements of Java

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

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:

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

Java using LEGO Mindstorms and LeJOS. University of Idaho

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

Java with Eclipse: Setup & Getting Started

CSC116: Introduction to Computing - Java

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

Life Without NetBeans

1.1 Your First Program

1001ICT Introduction To Programming Lecture Notes

CHAPTER 1 Introduction to Computers and Java

CSC116: Introduction to Computing - Java

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

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

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

How to make a "hello world" program in Java with Eclipse *

Lecture 4: Introduction to Java and your Development Environment

Chapter Goals. Chapter One: Introduction. Prerequisites. What Is Programming?

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

CS 231 Data Structures and Algorithms, Fall 2016

Getting started with Java

1.1 Your First Program

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

CP122 CS I. Hello, World!

Full file at

Object-oriented programming in...

Options for User Input

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

Kattis Team Guide version 1.1

Algorithms and Programming I. Lecture#12 Spring 2015

Java Socket Workshop. July Purpose of this workshop:

Programming Language. Machine Code. CS200: Computer Science I. Module 3 Programming Languages

Java Foundations: Unit 3. Parts of a Java Program

Programming overview

Welcome to CSE 142! Zorah Fung University of Washington, Spring Building Java Programs Chapter 1 Lecture 1: Introduction; Basic Java Programs

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

CSCI 1103: Introduction

2/9/2012. Chapter One: Introduction. Chapter Goals

Getting Started with Command Prompts

Department of Computer Science University of Pretoria. Introduction to Computer Science COS 151

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

1.1 Your First Program

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

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

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

Chapter 1: Introduction to Computers and Java

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

Programming Language Concepts: Lecture 2

Transcription:

Code Ninjas: Introduction to Computer Science Macomb Science Olympiad Presented by Swati Dharia

Intro to Java Programming The three basic steps required to get a simple program running. As with any application, you need to be sure that Java is properly installed on your computer. You also need an editor and a terminal application. Three popular home operating systems. [ Mac OS X Windows Linux ] For this event, we will not use any computers or compilers

Programming in Java We break the process of programming in Java into three steps: Create the program by typing it into a text editor and saving it to a file named, say, MyProgram.java. Compile it by typing "javac MyProgram.java" in the terminal window. Execute (or run) it by typing "java MyProgram" in the terminal window.

Three Steps The first step creates the program; the second translates it into a language more suitable for machine execution (and puts the result in a file named MyProgram.class); the third actually runs the program.

Creating a Java program. A program is nothing more than a sequence of characters, like a sentence, a paragraph, or a poem. To create one, we need only define that sequence characters using a text editor in the same way as we do for email. HelloWorld.java is an example program. Type these character into your text editor and save it into a file named HelloWorld.java. For this Event, we will not be using any text editor or compilers.

HelloWorld.java public class HelloWorld { public static void main(string[] args) { // Prints "Hello, World" in the terminal window. } } System.out.println("Hello, World");

Compiling a Java program A compiler is an application that translates programs from the Java language to a language more suitable for executing on the computer. It takes a text file with the.java extension as input (your program) and produces a file with a.class extension (the computer-language version). To compile HelloWorld.java type the boldfaced text below at the terminal. (We use the % symbol to denote the command prompt, but it may appear different depending on your system.)

Cont d % javac HelloWorld.java If you typed in the program correctly, you should see no error messages. Otherwise, go back and make sure you typed in the program exactly as it appears above.

Executing (or running) a Java program. Once you compile your program, you can execute it. This is the exciting part, where the computer follows your instructions. To run the HelloWorld program, type the following in the terminal window: % java HelloWorld If all goes well, you should see the following response Hello, World

Understanding a Java program. The key line with System.out.println() prints the text "Hello, World" in the terminal window. When we begin to write more complicated programs, we will discuss the meaning of public, class, main, String[], args, System.out, and so on.

Creating your own Java program. For the time being, all of our programs will be just like HelloWorld.java, except with a different sequence of statements in main(). The easiest way to write such a program is to: Copy HelloWorld.java into a new file whose name is the program name followed by.java. Replace HelloWorld with the program name everywhere. Replace the print statement by a sequence of statements.

Errors Most errors are easily fixed by carefully examining the program as we create it, in just the same way as we fix spelling and grammatical errors when we type an e-mail message. Compile-time errors. These errors are caught by the system when we compile the program, because they prevent the compiler from doing the translation (so it issues an error message that tries to explain why). Run-time errors. These errors are caught by the system when we execute the program, because the program tries to perform an invalid operation (e.g., division by zero). Logical errors. These errors are (hopefully) caught by the programmer when we execute the program and it produces the wrong answer. Bugs are the bane of a programmer's existence. They can be subtle and very hard to find. One of the very first skills that you will learn is to identify errors; one of the next will be to be sufficiently careful when coding to avoid many of them.

Input and Output Typically, we want to provide input to our programs: data that they can process to produce a result. The simplest way to provide input data is illustrated in UseArgument.java. Whenever this program is executed, it reads the commandline argument that you type after the program name and prints it back out to the terminal as part of the message. % javac UseArgument.java % java UseArgument Alice Hi, Alice. How are you? % java UseArgument Bob Hi, Bob. How are you?

Notes https://introcs.cs.princeton.edu/java/11hello/