README
See Also
Javadoc
- Javadoc (Wikipedia)
- How to Write Doc Comments for the Javadoc Tool (Oracle)
- Java - Documentation Comments (TutorialsPoint)
Jargon
- Terminal punctuation (Wikipedia)
Code
Q&A
How do I print a double quote character?
Answer:
public class PrintDoubleQuote { // Used in main private static final char DQ1 = 34; // double quote is 34 private static final char DQ2 = '"'; public static void main(String[] args) { // Technique #1 System.out.println("\""); // Technique #2 System.out.println('"'); // Technique #3 System.out.println('\"'); // Technique #4 System.out.println(DQ1); // More Examples System.out.println("\"I don't know,\" said Grasshopper."); System.out.println('"' + "I don't know," + '"' + " said Grasshopper."); System.out.println('\"' + "I don't know," + '\"' + " said Grasshopper."); System.out.println(DQ1 + "I don't know," + DQ2 + " said Grasshopper."); // Yet Another Example System.out.print('\"'); System.out.print("I don't know,"); System.out.print('"'); System.out.print(" said Grasshopper."); System.out.print('\n'); } }
Notes
- Study the class
UseArgument
shown on page 7. - Note the escape sequences enumerated in the subsection Characters and strings on page 19, especially the escape sequence
\"
.
If you are having trouble using PowerShell, javac, and java to compile and execute Java programs, review the information in the post With great power.
Exercises
Notes for AP Computer Science A (2017-2018) Students
- Some if not all of the exercises below will be components of your first graded programming assignment.
- You must include the following comment at the end of your program file named
PrintProgSays.java
:/***************************************************** * I understand that this is a graded programming * assignment and that I have been instructed to * do my own work and cite all forms of collaboration. * I understand that this means I should not look * at anyone else's source code and that I should * not share my source code with anyone. * * The Java program above is my own work. Unless I * have confessed in writing in this document, * I attest that I did not look at anyone else's * source code, I did not share my code with anyone, * and I have cited my sources, including all forms * of collaboration, in writing in this document. * * I understand that if I have claimed anyone else's * work as my own or if I shared my code with anyone, * then I will be penalized if caught, and I * understand what the penalties for cheating are. * * I understand that I must print a copy of this * document, sign it, and submit the signed document * before my work will be considered for grading. ****************************************************/
Without further ado
- Compare and contrast the four different versions (1.0, 1.1, 1.2 and 1.3) of the program
DrawMeA
shown on the Code tab. - What differences, if any, do you notice when you compile and execute version 1.3 of
DrawMeA
using compilejava.net vs. compiling and executing the same code locally usingjavac
andjava
? If you do notice any differences, what do you think might explain what you are observing? - Use the
javadoc
utility (included in the JDK) to convert the source code forDrawMeA
version 1.3 into a set of HTML files. Then open the file namedindex.html
using a web browser and study it.Hint:
> javadoc DrawMeA.java
- Using Windows Notepad, create a Java program that consists of a public class named
PrintProgSays
and amain
method.- Define the
main
method in terms of a parameter namedargs
. - When you compile and execute the program, the program should print another Java program.
- If, when you execute the program using the
java
interpreter, the first command line argument passed toPrintProgSays
is the stringDraw
and the second argument is the stringSheep
, then the program printed should be identical toDrawMeASheep
version 1.0, except that your name should be listed in the@author
field of the Javadoc comment instead of mine. - If the first argument passed to the program is, say,
Paint
, and the second argument is, say,Dog
, then PrintProgSays should print a program that is analogous toDrawMeASheep
but with all occurrences of the stringDraw
replaced byPaint
, all occurrences of the stringSheep
replaced with the stringDog
, and your name listed in the@author
field of the Javadoc comment. - Include Javadoc style comments with your program, using the programs and comments in this MESS as a guide. Provide end-of-line and multi-line comments as well if you feel they would make your program easier for someone else to understand.
- Define the
- Test your program by redirecting the output to a file and then compiling and executing the file.
- To redirect the output of your program to a file using PowerShell and the
java
class loader, execute a command similar to the following after you have successfully compiled your program.java PrintProgSays Make Goat > MakeMeAGoat.java
- Verify that you created a valid Java program by compiling and executing the file you creating using
PrintProgSays
. Note that you may need to usejavac
’s-encoding
option when you compile the new file as shown here:javac -encoding Unicode MakeMeAGoat.java
Expected output:java MakeMeAGoat
Make me a Goat!
- To redirect the output of your program to a file using PowerShell and the