
Q println statements to generate the output: Don't forget: use \" instead of " ! '' is not the same as " "Four score and seven years ago, our 'fore fathers' brought forth on this continent a new nation."Ī "quoted" String is 'much' better if you learn the rules of "escape sequences." Also, "" represents an empty String. This program prints a quote from the Gettysburg Address. Q What println statements will generate this output? Q println statement to produce the line of output: Q Write a println statement to produce this output: Q What is the output of the following println statements?

Multiple programmers working together, who QComments are useful for: Understanding larger, more complex programs. QWhere to place comments: at the top of each file (a "comment header") at the start of every method (see later) to explain complex pieces of code Used only for human readers (i.e., inline documentation) * this comment runs to the terminating symbol, even across line breaks */


QTwo types of comments in Java single-line comments use // // this comment runs to the end of the line QWhite space allows a Java program to be formatted in many ways, and should be formatted to enhance readability o the usage of white space forms part of Symbols in a program extra white space is ignored QWhite space includes spaces, new line characters, tabs white space is used to separate words and $ ls HelloWorld.java HelloWorld.class - Run Java interpreter $ java HelloWorld Take a look to see that HelloWorld.class is generated Compile a Java program $ javac HelloWorld.java Login, Edit, Compile, Run on a Pantheon Machine (Cont.) $ pico HelloWorld.java type in your program, press control-X, type y, press return Change to the directory $ cd cs112 - Edit your Java program using any text editor, e.g., pico Create a directory for your cs112 files for the semester $ mkdir cs112 textĮditor, no IDE) - Login to a pantheon machine using ssh Login, Edit, Compile, Run on a Pantheon Computer - The Pantheon is the first method of Java Programming (ie. Linux General help on pantheon is available at: The "Pantheon" is a collection of computers at Yale named after Greek gods Generally, you use Secure Shell to login to will automatically direct you to one of the machines They run a variant of Unix Q Please follow the directions on the main textbook site - see Part 1 of Assignment 0. Q For simplicity and consistency, we will use DrJava. IDEs need to know where to find the java and javac programs. These features can be very useful and save time.Įxample features are code completion, instant compilation, and syntax highlighting. Note: The underlying file contains pure text, just like a text editor. An IDE usually presents the user with a space for text (like anĮditor) but layers additional features on top of the text for the user's benefit. Q Another way is to use an Integrated Development Environment (IDE) Example IDEs: DrJava, Eclipse, NetBeans, BlueJ, etc. % javac HelloWorld.java % java HelloWorld Hello, World Execute it by typing at the command-line:

This creates a Java bytecode file named: HelloWorld.class. Compile it by typing at the command-line: Public class Hello Ĭreate the program by typing it into a text editor, and Q Execute/run/test bytecode with Java interpreter o Eg. Q Compile into Java bytecode (.class files) o Eg. O Create and edit Java source code (.java files) Eg. Q Programming in Java consists of the same tasks, but they are slightly specialized Q Programming consists of three tasks Create and edit source code file The source code is usually human understandableĬompile the source code into machine code Machine code ranges from vaguely understandable to nondescript 0's and 1sĮxecute/run/test machine code Your computer (specifically the CPU) executes the machine code, 1 instruction at a time. Department of Computer Science Yale UniversityĪcknowledgements: some slides used in this class are taken directly or adapted from those accompanying the two textbooks: Introduction to Programming in Java: An Interdisciplinary Approach by Robert Sedgewick and Kevin Wayne and Building Java Programs: A Back to Basics Approach by Stuart Reges and Marty Stepp
