Friday, October 22, 2010

Project 12 Program Test Data

For the project 12 subjects I will be comparing Java, C++ and Python. All being object oriented languages they share many things in common, but differ on several points as well.

Java primarily makes use of primitive and reference data types. Declaration follows the same general format for all of them: <data type> variableName;. You fill in <data type> with any given one of the types, int for integer, char for character, boolean for booleans, String for strings and so on. It also allows for printing of the min and max values of types in the form of: System.out.println(<Type>.(MIN/MAX)_VALUE);. Java makes use of several statements controls to decide what portion of code to execute, such as: if and ifelse statements, try catch statements, and switch statements. if and ifelse statements check the if statements in sequence, if elses are tied to an if statement, and as soon as one of their expressions is found true that code segment is run and the others are skipped over. Try catch statements do a portion of code, as as it goes through it checks for (or catches) some exception that may pop up in that code. Switch statements can be used in place of if statements, and check multiple possibilities with just one call of switch, and than subsequent calls of case for each possibility.

C++ uses more or less the same listing of variable types that Java has, (not surprising as Java was influences by C++, amongst others). C++ also uses the same general format for declaration of variables. C++ also makes use of the if, ifelse and else statements, as well as switch statements, to control the flow of the program. Unlike Java and Python, C++ allows for the usage of goto statements to jump to another spot in the code, though the usage of goto is typically shunned in C++, as well as other high level languages. C++ allows you to check the size of a variable with the sizeof(<variable>) command.

Python differs from Java and C++ in its variable declarations. In Python, you do not need to specify what type of variable it is you're putting in, you just assign it a value and it knows what type of variable you want based off of that (100 would be an int, 1000.0 would be floating point, etc.). Python also contains methods for its list and tuple types which allow the programmer to get out the min and max. This is called simply with min(list) and max(list), the same with tuples only you would put in the name of the tuple instead of the list. Python makes use of if, elif (else if) and else statements to decide which segment of code to run and makes use of many fairly standard operators for true/false checking such as ==, !=, >, and <.

No comments:

Post a Comment