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
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.
- Running programs
- In C++, the check for a command line argument uses "if (argc > 1)". Why?
What is the argument to the program?
- Why is there no equivalent first argument in Java?
- What do the parameters to main mean in general and how do you
supply them?
- Input/Output
- In C++, what are the differences between cout and cerr?
- In Java, what is the equivalent of C++'s cout and cerr?
- In general, what does try and catch mean in Java (and in C++ actually)?
- Collections
- In Java, what is the equivalent package to the STL?
- In C++ and Java respectively, what member function adds an element to
set? map?
- What is the main difference between the C++ and Java set classes and
what impact does that have on the program?
- Including code declarations
- In C++, what are the differences between using angle brackets
< >
and using quotes "" when including header files.
- In C++, what are the differences between including a header file and simply
declaring a class exists?
- In Java there are no header files, how do you include code from other
classes?
- Why do think Java does not have header files?
- In C++ and Java respectively, how do you find the source code for things
you have included in your program?
- In C++, what does using namespace std mean?
- Does Java have an equivalent mechanism? If so, what is it?
- Environment
- How do you run a Java program?
- What is the main difference between running programs in C++ and Java and
what impact does that have on the user?
- What are the phases of compilation for Java?
- What impact does this have on compile-time versus run-time errors?
Comments?