1001ICT Introduction To Programming Lecture Notes



Similar documents
Handout 1. Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner.

University of Hull Department of Computer Science. Wrestling with Python Week 01 Playing with Python

First Java Programs. V. Paúl Pauca. CSC 111D Fall, Department of Computer Science Wake Forest University. Introduction to Computer Science

WA2099 Introduction to Java using RAD 8.0 EVALUATION ONLY. Student Labs. Web Age Solutions Inc.

LAB 1. Familiarization of Rational Rose Environment And UML for small Java Application Development

How to Install Java onto your system

Introduction to Java

Java CPD (I) Frans Coenen Department of Computer Science

Java Crash Course Part I

Outline. hardware components programming environments. installing Python executing Python code. decimal and binary notations running Sage

Introduction to Java Applications Pearson Education, Inc. All rights reserved.

Chapter 1 Fundamentals of Java Programming

Programmierpraktikum

Moving from CS 61A Scheme to CS 61B Java

How to use the Eclipse IDE for Java Application Development

Java Software Development Kit (JDK 5.0 Update 14) Installation Step by Step Instructions

Online Chapter B. Running Programs

Installing Java (Windows) and Writing your First Program

Creating a Java application using Perfect Developer and the Java Develo...

Simple Java Applications

Topics. Introduction. Java History CS 146. Introduction to Programming and Algorithms Module 1. Module Objectives

Java applets. SwIG Jing He

Third AP Edition. Object-Oriented Programming and Data Structures. Maria Litvin. Gary Litvin. Phillips Academy, Andover, Massachusetts

Week 2 Practical Objects and Turtles

CS 170 Java Programming 1. Welcome to CS 170. All about CS 170 The CS 170 Online Materials Java Mechanics: Your First Program

Installing Java. Table of contents

Data Structures Lecture 1

CS 106 Introduction to Computer Science I

Command Line - Part 1

Witango Application Server 6. Installation Guide for OS X

Java Language Tools COPYRIGHTED MATERIAL. Part 1. In this part...

Tutorial 0A Programming on the command line

Introduction to UNIX and SFTP

CS 1133, LAB 2: FUNCTIONS AND TESTING

Lab 1A. Create a simple Java application using JBuilder. Part 1: make the simplest Java application Hello World 1. Start Jbuilder. 2.

Click Start > Control Panel > System icon to open System Properties dialog box. Click Advanced > Environment Variables.

Introduction to programming

Code Estimation Tools Directions for a Services Engagement

Last Class: OS and Computer Architecture. Last Class: OS and Computer Architecture

Appendix A Using the Java Compiler

Lab 1 Beginning C Program

Programming Languages CIS 443

qwertyuiopasdfghjklzxcvbnmqwerty uiopasdfghjklzxcvbnmqwertyuiopasd fghjklzxcvbnmqwertyuiopasdfghjklzx cvbnmqwertyuiopasdfghjklzxcvbnmq

JDK 1.5 Updates for Introduction to Java Programming with SUN ONE Studio 4

CS170 Lab 11 Abstract Data Types & Objects

9/11/15. What is Programming? CSCI 209: Software Development. Discussion: What Is Good Software? Characteristics of Good Software?

Install Java Development Kit (JDK) 1.8

Chapter 2. println Versus print. Formatting Output withprintf. System.out.println for console output. console output. Console Input and Output

1) Which of the following is a constant, according to Java naming conventions? a. PI b. Test c. x d. radius

Website Development Komodo Editor and HTML Intro

Object-Oriented Programming in Java

CS101 Lecture 24: Thinking in Python: Input and Output Variables and Arithmetic. Aaron Stevens 28 March Overview/Questions

CS 103 Lab Linux and Virtual Machines

Improving learning outcomes for first year introductory programming students

Installing C++ compiler for CSc212 Data Structures

FTP client Selection and Programming

CS1020 Data Structures and Algorithms I Lecture Note #1. Introduction to Java

CPSC 226 Lab Nine Fall 2015

CLC Server Command Line Tools USER MANUAL

Notepad++ The COMPSCI 101 Text Editor for Windows. What is a text editor? Install Python 3

Introduction to Python

COSC282 BIG DATA ANALYTICS FALL 2015 LECTURE 2 - SEP 9

Introduction to Eclipse

CSC230 Getting Starting in C. Tyler Bletsch

Unix Guide. Logo Reproduction. School of Computing & Information Systems. Colours red and black on white backgroun

Getting Started with Mplus Version 7.31 Demo for Mac OS X and Linux

Contents. Java - An Introduction. Java Milestones. Java and its Evolution

AES Crypt User Guide

PuTTY/Cygwin Tutorial. By Ben Meister Written for CS 23, Winter 2007

Basic Java Constructs and Data Types Nuts and Bolts. Looking into Specific Differences and Enhancements in Java compared to C

A Short Introduction to Writing Java Code. Zoltán Majó

LAB4 Making Classes and Objects

MS Visual C++ Introduction. Quick Introduction. A1 Visual C++

Basic C Shell. helpdesk@stat.rice.edu. 11th August 2003

CSE 452: Programming Languages. Acknowledgements. Contents. Java and its Evolution

A Crash Course in OS X D. Riley and M. Allen

Part 1 Foundations of object orientation

Topics. Parts of a Java Program. Topics (2) CS 146. Introduction To Computers And Java Chapter Objectives To understand:

Chapter 1 Java Program Design and Development

Code::Blocks Student Manual

PIC 10A. Lecture 7: Graphics II and intro to the if statement

Remote Access to Unix Machines

Introduction to Object-Oriented Programming

Eventia Log Parsing Editor 1.0 Administration Guide

Software. Programming Language. Software. Instructor Özgür ZEYDAN. Bülent Ecevit University Department of Environmental Engineering

csce4313 Programming Languages Scanner (pass/fail)

Java Programming Unit 1. Your first Java Program Eclipse IDE

MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question.

Example of a Java program

IN STA LLIN G A VA LA N C HE REMOTE C O N TROL 4. 1

Getting Started using the SQuirreL SQL Client

Using Eclipse to Run Java Programs

tutorial.sql Assignment

A Python Tour: Just a Brief Introduction CS 303e: Elements of Computers and Programming

The programming language C. sws1 1

Chapter 1. Introduction to Computers, Programs, and Java

CS 51 Intro to CS. Art Lee. September 2, 2014

Getting Started with Command Prompts

Problem Solving. Software Engineering. Behavior. OCD in a Nutshell. Behavior. Objects Operations Algorithm. Object-Centered Design

Before entering the lab, make sure that you have your own UNIX and PC accounts and that you can log into them.

Transcription:

1001ICT Introduction To Programming Lecture Notes School of Information and Communication Technology Griffith University Semester 2, 2015 1

3 A First MaSH Program In this section we will describe a very simple Making Stuff Happen (MaSH) program and show how to compile and run it. Recall this simple Java program. public class Hello { } public static void main(string[] args) { System.out.println("Hello, World!"); } Only the blue bit actually makes stuff happen. 1001ICT Introduction To Programming 2015-2 2

Here is the simplest MaSH program that does the same thing. import console; println("hello, World!"); The blue bit stays exactly the same. All of the stuff that is about encapsulation is gone. The red bit has been added. We will now show how to run it and explain every part of it. 1001ICT Introduction To Programming 2015-2 3

3.1 How to run a console MaSH program A console program is one that inputs and outputs only plain text and runs in a command line (or console) environment, such as: the Command Prompt on Windows; or the Terminal or xterm on Mac OS X, Unix or Linux. Example console programs are the MaSH and Java compilers. A compiler is a program that reads a high level programming language and translates it into some other (usually lower level) programming language. See appendix A of the lecture notes for an explanation of the way the following command examples are displayed. 1001ICT Introduction To Programming 2015-2 4

3.1.1 Step 1: Create the program file Use your favourite text editor to create a text containing the text of the program. The file must have a name that ends with the filename extension.mash. The file name must start with an upper case letter. The rest of the file name must consist only of letters, digits and underscores (_). Our example program might be saved in a file named Hello.mash. Also good: Hello_2_You.mash. Bad: Hello, World!.mash. 1001ICT Introduction To Programming 2015-2 5

3.1.2 Step 2: Compile with mashc Programming language compilers usually have boring names formed by adding c to the end of the name of the language; e.g. cc. Compile a MaSH program to Java with a command like: $ mashc Program.mash For the program Hello.mash, the command will be: $ mashc Hello.mash If the program has no errors that the compiler (mashc) can find, it will create an output file: Hello.java. 1001ICT Introduction To Programming 2015-2 6

3.1.3 Step 3: Compile with javac Compile a Java program with a command like: $ javac Program.java For the program Hello.java, the command will be: $ javac Hello.java If the program has no errors that the compiler (javac) can find, it will create an output file: Hello.class. javac is a translator from the Java language to Java Java bytecode. Java bytecode is the machine code for the Java virtual machine (JVM). 1001ICT Introduction To Programming 2015-2 7

3.1.4 Step 4: Run with java Run a Java program with a command like: $ java Program For the program Hello, the command will be: $ java Hello java is the Java virtual machine for your computer. It interprets the Java bytecode, which means it executes it. Compilers translate. Interpreters execute. 1001ICT Introduction To Programming 2015-2 8

3.1.5 All steps (Windows): mash The file mash.bat is installed on the lab PCs. It is a DOS batch file. Batch files are scripts containing DOS commands to run in sequence. To run all the steps (mashc, javac, java) in one command, type: > mash Program For the program Hello, the command will be: > mash Hello 1001ICT Introduction To Programming 2015-2 9

3.1.6 All steps (Mac and Linux): mc The file mc is installed on the lab Macs. It is a bash shell script, the Unix equivalent to a Windows batch file. To run all the steps (mashc, javac, java) in one command, type: ] mc Program For the program Hello, the command will be: ] mc Hello 1001ICT Introduction To Programming 2015-2 10

3.1.7 The MaSH judge For console programs only, there is an online service that can test whether a program is the correct solution to one of a list of problems. It can be used from any device with a web browser at: http://www.ict.griffith.edu.au/arock/mash/mash.cgi? problems or from the command line with a mashj command like this: $ mashj problem-id Program.mash where problem-id is a string of characters that identifies the problem being solved. 1001ICT Introduction To Programming 2015-2 11

For example, let s submit Hello.mash for judging. $ mashj 0001-hello Hello.mash Judging problem "0001-hello". Success! Your program is correct. Additional feedback: Congratulations! Runtime = 0.256942 seconds $ In this case our submission is correct. Other outcomes could include, wrong answer, or format error. If you get a format error, check the capitalisation, punctuation and spelling of your output. 1001ICT Introduction To Programming 2015-2 12

3.1.8 MaSH Commands Summary Here is a summary of the MaSH and java commands you will use most often for console programs. Compiling and running programs I want to... on Windows on Mac OS X / Linux compile and run a program. > mash Program ] mc Program Sending programs to the judge $ mashj problem-id Program.mash There is a more complete version of this summary at the front of the A5 format lecture notes. 1001ICT Introduction To Programming 2015-2 13

3.2 Understanding a console MaSH program 3.2.1 The import directive import console; println("hello, World!"); The red bit is called an import directive. It makes stuff happen at compile time. It tells mashc to look for a file called console.mashenv. The file console.mashenv contains instructions to mashc as to how to translate a program intended to run in the console environment. We will use a different environment nxt.mashenv for programming a Lego Mindstorms robot. 1001ICT Introduction To Programming 2015-2 14

Java also has an import directive. Most Java programs require several. The Hello program we started with could have had this at the top: import java.lang.system; It is not required, however, as that part of the Java programming environment is always imported by default. MaSH is simpler. Every MaSH program imports just one environment. 1001ICT Introduction To Programming 2015-2 15

3.2.2 The statement import console; println("hello, World!"); The blue bit is a statement. It makes stuff happen at run time. It is a direct command to do something. Like most statements (and import directives) it ends with a semicolon (;). There are many kinds of statements in Java. This kind is a procedure call. println is the name of a method. A method is a chunk of program code given a name. This one is defined somewhere else (in the console environment). 1001ICT Introduction To Programming 2015-2 16

The println method carries out an action, so it is the kind of method called a procedure. Always, after a method s name come parentheses, ( and ). Between the parentheses comes a value that is being passed to the method to operate on. Values passed to methods are called parameters or arguments. This value is a string of characters to print. The double quotes delimit the string. Some questions that you should be asking: How do you learn all the rules about how to write statements? How do you find out what methods there are and what they do? 1001ICT Introduction To Programming 2015-2 17

3.3 Section summary This section covered: how to save a MaSH program in a text file with the right kind of name; how to use mashc to translate a MaSH program into a Java program; how to use javac to translate a Java program into a bytecode program; how to use java to interpret the bytecode program; the mash shortcut to do them all in sequence; the MaSH import directive; a MaSH statement consisting of a procedure call. 1001ICT Introduction To Programming 2015-2 18

3.4 End of section feedback questions Send us your answers to these questions any time you like by clicking on them. What was the most useful topic in this section? What was the least useful topic in this section? What was the least clear topic in this section? What topic in this section would you like to know more about? Did you find an error in this section? 1001ICT Introduction To Programming 2015-2 19

3.5 Self-practice exercises Do these in your own time. 1. Write any MaSH program that compiles, and submit it to the MaSH Online judge, as practice using the judge. (MaSH Online: 0000- compile. This is the problem-id for the online MaSH judge, and links to the problem on the web site.) 2. Write a help program that prints a summary of the batch file or script commands used to compile and run/upload MaSH programs. 3. Write a program that prints this example of ASCII art. (MaSH Online: 0002-Mona.) 1001ICT Introduction To Programming 2015-2 20

o8%8888, o88%8888888. 8 - -:8888b 8 8888 d8.-=.,==-.:888b >8 : d8888 88,88888 88b. - :88888 888b ==.:88888 88888o--: :::8888 88888 ::: 8888b 8888ˆˆ 8888b d888,%888b. d88% %%%8-- -. /88:., _%- --- - ::===..- = --. 1001ICT Introduction To Programming 2015-2 21