Docsity

Lecture Set 16: Command Line Running Issues and Comments | CMSC 131, Study notes of Computer Science

Toggle sidebar
bg1
1
CMSC 131 Spring 2008
Jan Plane (adapted from Bonnie Dorr)
Lecture Set #16:
Command Line Running
Issues & Comments
1.
Command-line Java
2.
Arguments to Main Method
3.
Commenting Review
CMSC 131 Spring 2008
Jan Plane (adapted from Bonnie Dorr)
1
Command-Line Java
Source File:
an ASCII text file named appropriately for the class it contains
(i.e. ClassDemo.java)
created by an editor (emacs, vi, edit, notepad…)
Translate to byte code:
javac ClassDemo.java
creates a file named ClassDemo.class
Run (and interpret the Byte Code):
java ClassDemo
runs the java application defined in the the ClassDemo file
Finding Things
For the System to be able to find javac and java
Command Search Path must be set it is named PATH
For the System to be able to find the class named as the
argument to the java command
The Class Search Path must be set it is named CLASS PATH
Both of these are set in Windows using the
Control Panel/System/Advanced/Environment Variables
In Class Demonstration
pf3

Partial preview of the text

Download Lecture Set 16: Command Line Running Issues and Comments | CMSC 131 and more Study notes Computer Science in PDF only on Docsity!

CMSC 131 Spring 2008 Jan Plane (adapted from Bonnie Dorr)

Lecture Set #16:

Command Line Running

Issues & Comments

1. Command-line Java

2. Arguments to Main Method

3. Commenting Review

CMSC 131 Spring 2008 Jan Plane (adapted from Bonnie Dorr)

1

Command-Line Java

 Source File:

 an ASCII text file named appropriately for the class it contains

(i.e. ClassDemo.java)

 created by an editor (emacs, vi, edit, notepad…)

 Translate to byte code:

 javac ClassDemo.java

 creates a file named ClassDemo.class

 Run (and interpret the Byte Code):

 java ClassDemo

 runs the java application defined in the the ClassDemo file

 Finding Things

 For the System to be able to find javac and java

 Command Search Path must be set it is named PATH

 For the System to be able to find the class named as the

argument to the java command

 The Class Search Path must be set it is named CLASS PATH

 Both of these are set in Windows using the

Control Panel/System/Advanced/Environment Variables

 In Class Demonstration

CMSC 131 Spring 2008 Jan Plane (adapted from Bonnie Dorr)

2

Arguments to main

 Recall prototype of main method

public static void main (String[] args);

 args is array of Strings

 args come from operating system

 When user runs executable …

 … s/he can provide arguments

 Demonstration from Command Line

 simple arguments

 treating arguments as integers

 Demonstration from within Eclipse

CMSC 131 Spring 2008 Jan Plane (adapted from Bonnie Dorr)

3

Types of Documentation

 Two kinds of code commentary in Java  Implementation comments  Interface comments  JavaDoc  from inside Eclipse  from outside of Eclipse  Common Errors in Commenting Too many comments: This can obscure the flow of your program. Too few comments: Your intent may not be understood (code is never “self-documenting”!) Comments that repeat the code: int total = 0; // initialize integer total to 0 Using comments to conceal unclear code: …just rewrite the code double a = h*w; // set the area (a) to the height (h) // times width (w) double area = height * width; Uninformative comments: “What the heck does that mean?” double d = processValue( ); // Change later (legacy) Misleading / erroneous comment: These are dangerous for ( int i = 0; i < a.length-1; i++) // run through the //whole array