Anagrams: Comparing Java and C++


Two words are anagrams if they are composed of the same letters. For example, "bagel" and "gable" are anagrams as are "drainage" and "gardenia". In this example, the program reads a dictionary (a list of words) and finds all the words within the list that are anagrams of each other.

Example Solutions

C++ Java

Questions

To help you answer these questions, you may want to check your course readings, the C++ and Java tutorials available from the course resource page.

  1. Running programs
    1. In C++, the check for a command line argument uses "if (argc > 1)". Why? What is the argument to the program?
    2. Why is there no equivalent first argument in Java?
    3. What do the parameters to main mean in general and how do you supply them?
       
  2. Input/Output
    1. In C++, what are the differences between cout and cerr?
    2. In Java, what is the equivalent of C++'s cout and cerr?
    3. In general, what does try and catch mean in Java (and in C++ actually)?
       

  3. Collections
    1. In Java, what is the equivalent package to the STL?
    2. In C++ and Java respectively, what member function adds an element to set? map?
    3. What is the main difference between the C++ and Java set classes and what impact does that have on the program?
       

  4. Including code declarations
    1. In C++, what are the differences between using angle brackets < > and using quotes "" when including header files.
    2. In C++, what are the differences between including a header file and simply declaring a class exists? 
    3. In Java there are no header files, how do you include code from other classes?
    4. Why do think Java does not have header files?
    5. In C++ and Java respectively, how do you find the source code for things you have included in your program?
    6. In C++, what does using namespace std mean?
    7. Does Java have an equivalent mechanism? If so, what is it?
       
  5. Environment
    1. How do you run a Java program?
    2. What is the main difference between running programs in C++ and Java and what impact does that have on the user?
    3. What are the phases of compilation for Java?
    4. What impact does this have on compile-time versus run-time errors?

Comments?