Project 2 - mystery

hard copy checklist
Due: during lab
Project ID: mystery

In this lab we explore the construction of Java programs and other text files. 

Background Knowledge

File: A block of arbitrary information (usually) on a durable storage.

Text vs. Binary File: A file is variable length unit of permanently stored data on a computer.  All data is binary; hence all files are binary files.  A text file is a kind of binary file understood to consist of printable characters organized in lines.

(Text Editor: A computer program that is used to create/change text files. What happens if you edit a binary (let say a .class file) with a text editor.)

(End of Line:  a control character(s) marking the end of line. its '\n' or 0x0A or LF in Unix-like systems, CR+LF in DOS based systems, and CR in Commodore 64 and Mac OS.)

Character Set: Maps the bit patterns to characters of text.  

US-ASCII (American Standard Code for Information Interchange): a character set based on the ordering of English alphabet. US-ASCII is a standard used to represent text files in computer files. 

Unicode: A character set bigger than ASCII that represent almost every language in the world. It is backwards compatible with US-ASCII. Java supports Unicode (only plane 0 actually) not only in Strings, but also in source code. To represent a Unicode character in Java ...

Command Line: a text based interface used to communicate with the OS by typing commands to perform OS tasks.

Run Java Program: to run a java program you need to compile it first (javac command) and run it (using java command).

Capture Output: To capture the output of a java program (or any other program) use '>' sign (greater sign) at the end of the command with a file name to write the output to.

Javap: is a tool to disassemble java class files and see bytecodes. Do you know how to find documentation to Javap?

Mysterious Program

Java programs are text files. As strange as it may seem, the following is a completely legal Java program.
Using any text editor, create a file “” with the contents exactly as above. How many bytes does your file have? (It should have 610 or 620 bytes.) What character set is your file written in? Using the command prompt, compile the file with javac and run the program. Lookup the name of the class file created as the result of compilation. 

java <class name>

What is the output? Capture the exact output in a file output.txt, and TURN IT IN

Try to figure out what the mysterious program “really" looks like by examining the output of javap -c. 

javap –c  <class name> 

. What is the name of the Java class in the mysterious program?  javap produces a representation of any Java class. Using the representation we can guess what the program does.
Capture the representation of the Java class in a file, call it class.txt and TURN IT IN.

The mysterious program is not written in a way that is easily read. Can you write an identical program with better style? By identical 
program, we mean one that has essentially the same class file as the mysterious program, not just the same output behavior.  
Create your Java program, call it, run javap on it. If it has similar class files as the mysterious program, then TURN IT IN
Aside from the use of Unicode escapes, your program undoubtedly has many small differences when compared to the 
mysterious program. Write some of the differences in a text file and name it "answer.txt"

All four parts of this lab are due before you leave:  
  1. Mystery output: output.txt  
  2. Output of javap: class.txt  
  3. Java program: 
  4. Differences between the bytecodes generated by and   answer.txt
Please use the file names exactly as given above, as this makes it easier for us to verify that you have fulfilled the lab requirements.

Don't forget your Header (for java file): 
 * Author: Firstname Lastname, email 
 * Course: CSE 1002, Section 01/02, Fall 2012 
 * Project: project_id 

To add javac and javap to the path, run this command:
set PATH=%PATH%;"c:\Program Files\Java\jdk1.7.0_03\bin"