Module 1: Questions and Answers

Some of our TAs have put together some short videos of answers to commonly asked questions from Module 1:

And here are some of questions that I found interesting and my answers:

Q: What is "LN" (in println).  

A: It's an abbreviation for "line", as in "print then advance to the next line down".

Q: Why is the "%" useful? 

A: It's really common to need to know how many are "left".  The making change example in the videos is just one example of why.  Another silly example: I once wrote a simple game that allowed characters to go off the right side of the screen and "wrap-around" to the left side.  The % operation was a convenient way to handle this "wrap around" behavior. 

Q: Can int be used rather than long? 

A: It depends on how big the number may get!  If numbers will be within ± 2 billion an int is sufficient. If values may exceed the billions but will be within ±1018 a long is called for.

Q: Why do double operations give values that are slightly off. For example, if you have "x=0.1;", println(x+x+x) may print "0.30000000000000004".  

A: A double is an approximation of a number and only has a limited number of digits.  For example, imagine you were only using two digits after the decimal to represent values.  You'd represent 1/3 with 0.33. And adding your representation of 1/3 to itself three times would yield: 0.33+0.33+0.33 = 0.99.  This slight bit of error is due to an imprecise representation of a real number.  If we represented another value, like 2/3, we may round our representation. We may round up and use .67 (it's really 0.666¯¯¯).  Consequently, repeatedly adding it would slightly exceed the precise value we'd expect.

Q: What is the "public static void main(...)" and the "ArgsProcessor" stuff? 

A: Good questions.   When learning anything you often have to just accept some abstraction until you know enough to understand the underlying details.  For example, when learning chemistry people often just accept atomic models without the need to understand the how/why of subatomic interactions. By the end of the class you'll have enough background to understand many of the details that we're currently glossing over.  

Q: Why does int have a maximum value?  

A: Computers store ints with a fixed number of (binary) digits.  Imagine if you were only allowed to use 3 digits to write a number.  The maximum you could write would be 999.  It's the same principle with ints. 

Q: Can boolean expressions get complicated? 

A: Yes! Some of the most difficult problems we try to solve using computers can be represented as boolean expressions Links to an external site..  These types of problems helped define a lot of computer science theory. That being said, the expressions we'll be using in our Java programs seldom get too complicated.  

Q: What's the purpose of doing a "pull" on the repository? 

A: We'll be placing things in your repository (new code for later modules and some feedback indicating completed material). The "pull" will pull it from BitBucket to your machine.  It's part of synchronizing what's on your machine with what's in the cloud.

Q: Can I get feedback from friends on my code? 

A: Other than studio work, don't show your work to other students. If you want feedback on the quality of your work, ask a TA or instructor.  

Q: What's the different between running the code and compiling the code? 

A: In Eclipse the "Play" button does both as needed.   Java is a language that is somewhere between what people understand and what computers understand.  The word "compile" generally means putting together things to produce something new.  Compiling in computer science is about translating a human-friendly language, like Java, to a more machine-friendly language and then putting those pieces together.  Every time you make a change in the Java code it needs be recompiled (retranslated) into a computer friendly language.  Once you stop making changes, there are ways to just run the resulting file without the recompile step.    

Q: What happens if you divide by zero?  A: Try it!  Write a short program and try the following types of operations: 

int x = 12;  
int y = 0;
System.out.println(x/y);
/* Try different combinations, like:
     make x a  double   while y is an int
     make x an int      while y is a  double
     make both doubles
     Try the int/int combination and % rather than /
  Run the program with each combination and observe the result
 */ 

Question and Synthesis Word Cloud

Module1SynthesisWordCloud.png