intro to programming · 2/21/2017  · 3 brief overview. ・ide vs. command line. ・files and file...

18
Intro to Programming R OBERT S EDGEWICK | KEVIN WAYNE Last updated on 2/21/17 9:31 AM C OMMAND -L INE I NTERFACE brief overview live demo http://introcs.cs.princeton.edu Alan Kaplan and Kevin Wayne

Upload: others

Post on 22-Sep-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Intro to Programming · 2/21/2017  · 3 Brief overview. ・IDE vs. command line. ・Files and file systems. Live demo. ・Navigating the file system. ・Java commands (including

Intro to Programming ROBERT SEDGEWICK | KEVIN WAYNE

Last updated on 2/21/17 9:31 AM

COMMAND-LINE INTERFACE

‣ brief overview

‣ live demo

http://introcs.cs.princeton.edu

Alan Kaplan and Kevin Wayne

Page 2: Intro to Programming · 2/21/2017  · 3 Brief overview. ・IDE vs. command line. ・Files and file systems. Live demo. ・Navigating the file system. ・Java commands (including

http://introcs.cs.princeton.edu

COMMAND-LINE INTERFACE

‣ brief overview

‣ live demo

Page 3: Intro to Programming · 2/21/2017  · 3 Brief overview. ・IDE vs. command line. ・Files and file systems. Live demo. ・Navigating the file system. ・Java commands (including

3

Brief overview.

・IDE vs. command line.

・Files and file systems.

Live demo.

・Navigating the file system.

・Java commands (including accessing stdlib.jar).

・Redirection and piping of standard input and output.

Note: you will need CLI for the Assignment 2.

Today’s plan: command-line interface

Page 4: Intro to Programming · 2/21/2017  · 3 Brief overview. ・IDE vs. command line. ・Files and file systems. Live demo. ・Navigating the file system. ・Java commands (including

Integrated development environment (IDE)

IDE. App designed for developing software.

4

“compile” button “run” button

pseudo-command line

Page 5: Intro to Programming · 2/21/2017  · 3 Brief overview. ・IDE vs. command line. ・Files and file systems. Live demo. ・Navigating the file system. ・Java commands (including

Command-line interface

Command line. App where you type commands.

5

Page 6: Intro to Programming · 2/21/2017  · 3 Brief overview. ・IDE vs. command line. ・Files and file systems. Live demo. ・Navigating the file system. ・Java commands (including

Convergence: Linux, OS X, and Windows

6

(September 1991)

Page 7: Intro to Programming · 2/21/2017  · 3 Brief overview. ・IDE vs. command line. ・Files and file systems. Live demo. ・Navigating the file system. ・Java commands (including

Convergence: Linux, OS X, and Windows

7

(March 2001)

Page 8: Intro to Programming · 2/21/2017  · 3 Brief overview. ・IDE vs. command line. ・Files and file systems. Live demo. ・Navigating the file system. ・Java commands (including

Convergence: Linux, OS X, and Windows

8

(August 2016)

Page 9: Intro to Programming · 2/21/2017  · 3 Brief overview. ・IDE vs. command line. ・Files and file systems. Live demo. ・Navigating the file system. ・Java commands (including

Software for program development: tradeoffs

Command line advantages.

・More control over system.

・Approach works with any language.

・Easy to automate tasks via scripting.

IDE advantages.

・More intuitive for novices.

・Language-specific features.

This course. Use IDE to edit and compile;use command line to execute.

Beyond. Many other platforms embrace command line.

9

Page 10: Intro to Programming · 2/21/2017  · 3 Brief overview. ・IDE vs. command line. ・Files and file systems. Live demo. ・Navigating the file system. ・Java commands (including

Files

File. Sequence of bits stored on a computer.

Filename. String that uniquely identifies a file.

Mac OS X. /Users/wayne/cos126/hello/HelloWorld.java Windows. C:\Users\wayne\cos126\hello\HelloWorld.java

10

note: forward vs. backward slash

Page 11: Intro to Programming · 2/21/2017  · 3 Brief overview. ・IDE vs. command line. ・Files and file systems. Live demo. ・Navigating the file system. ・Java commands (including

File system hierarchy

Directory (folder). Collection of files and other folders.

11

root directory

/

Users

wayne

cos126 Documents Music

Library Applications

Desktop

hello loops

DrJava.app Firefox.app

RandomWalker.javareadme.txt RandomWalker.class

/Users/wayne/cos126/loops/RandomWalker.java

Hello.mp4 Für Elise.mp4

Page 12: Intro to Programming · 2/21/2017  · 3 Brief overview. ・IDE vs. command line. ・Files and file systems. Live demo. ・Navigating the file system. ・Java commands (including

http://introcs.cs.princeton.edu

COMMAND-LINE INTERFACE

‣ brief overview

‣ live demo

Page 13: Intro to Programming · 2/21/2017  · 3 Brief overview. ・IDE vs. command line. ・Files and file systems. Live demo. ・Navigating the file system. ・Java commands (including

Live demo of file system commands

13

Page 14: Intro to Programming · 2/21/2017  · 3 Brief overview. ・IDE vs. command line. ・Files and file systems. Live demo. ・Navigating the file system. ・Java commands (including

Command-line arguments. Provide arguments (strings) to a program.

Standard output stream. Abstraction for writing output (default = screen).

Standard input stream. Abstraction for reading input (default = keyboard).

Standard input and output abstractions

14

standard input command-linearguments

standard output

standard drawing

standard audio

A bird’s-eye view of a Java program (revisited)

standard input command-linearguments

standard output

A bird’s-eye view of a Java program (revisited)

standard input command-linearguments

standard output

A bird’s-eye view of a Java program (revisited)

standard input command-linearguments

standard output

A bird’s-eye view of a Java program (revisited)

standard input command-linearguments

standard output

A bird’s-eye view of a Java program (revisited)

Page 15: Intro to Programming · 2/21/2017  · 3 Brief overview. ・IDE vs. command line. ・Files and file systems. Live demo. ・Navigating the file system. ・Java commands (including

Live demo of standard input and output commands

15

Page 16: Intro to Programming · 2/21/2017  · 3 Brief overview. ・IDE vs. command line. ・Files and file systems. Live demo. ・Navigating the file system. ・Java commands (including

Navigating the file system

Action Mac OS X Terminal Windows Command Prompt

print current directory pwd cd

list contents ofcurrent directory ls dir

move downone subdirectory cd introcs

move upone subdirectory cd ..

move downmultiple subdirectories cd introcs/hello cd introcs\hello

move tospecified directory cd /Users/wayne cd \Users\wayne

copy, move, remove, make directory, remove directory

cp mv rmmkdir rmdir

copy move del

mkdir rmdir

cycle throughcommand history <Up Arrow> <Down Arrow>

autocomplete javac Hello<Tab>

16

Page 17: Intro to Programming · 2/21/2017  · 3 Brief overview. ・IDE vs. command line. ・Files and file systems. Live demo. ・Navigating the file system. ・Java commands (including

Java commands

Action Mac OS X Terminal Windows Command Prompt

compile Java program javac HelloWorld.java

execute Java program java HelloWorld

compile Java program(with our standard libraries) javac-introcs HelloWorld.java

execute Java program(with our standard libraries) java-introcs HelloWorld

file globbing javac *.java

Java compiler version javac -version

Java runtime version java -version

17

Page 18: Intro to Programming · 2/21/2017  · 3 Brief overview. ・IDE vs. command line. ・Files and file systems. Live demo. ・Navigating the file system. ・Java commands (including

Command-line arguments, redirection, and piping

Action Mac OS X Terminal Windows Command Prompt

command-line arguments java Program arg1 arg2

redirect standard input java Program < input.txt

redirect standard input java Program > output.txt

piping java Program1 | java Program2

view contents, onescreenful at a time

more < input.txt

java Program | more

combinationsjava Program1 < input.txt | more

java Program < input.txt > output.txt

java Program1 arg1 | java Program2 arg2

terminate program <Ctrl-C>

signal end-of-file(when typing standard input) <Ctrl-D> <Ctrl-Z>

18