Java notes

Userpic
Matt Arnold
January 14, 2009

Halfway break in Java class.

Everyone was surprised that I was never taught in second grade "Please Excuse My Dear Aunt Sally". First you resolve parentheses and exponents, second you resolve multiplication and division operators, third you resolve addition and subtraction operators. However, Java doesn't have the exponent operator and it does have a remainder operator, so I decided it's "Prosecute My Dirty Rotten Aunt Sally".

It's counter-intuitive for me to do integer arithmetic, in which every step, Java gets rid of the fraction. 7/2=3

It takes me a long time to perform basic arithmetic in my head, on the best of days.

String fullname;

fullname = "John Kennedy"

secondLetter = fullname.charAt(1);

It returns 'o' not 'J' because everything counts from 0. Zero is always the first number. 1 is the second number.

age = age -3; // same as age -= 3;

Today's flashcard:

In an expression, what is the difference between variable++ and ++variable?

With x++ Java waits to resolve the rest of the expression before incrementing x by 1.

Comments


rbradakis on Jan. 15, 2009 1:10 AM

I was never taught that, either. I was just taught the order of operator precedence.

Oh yes. Never forget that programmers count from zero.


users on Jan. 15, 2009 1:22 AM

Yeah, I was always just taught the order... and yes, the 0th rule of programming is that programmers count from 0.


zimzat on Jan. 15, 2009 2:19 AM

Unless you're in VB, in which case you have to explicitly tell it to count from zero. Whee. (I still remember those pre-.NET days, heh)

Also, MySQL counts from 1 when doing str positioning and what-not. >_>


loop-bell on Jan. 15, 2009 3:08 PM

"Programmers count from zero" -- except when they don't. Matlab used to give me headaches because it starts from 1, among other reasons.

But that's getting less common these days with the rise of the so called "curly bracket languages" that tend to build on BCPL conventions for counting as well as syntax.


le-bebna-kamni on Jan. 17, 2009 3:56 AM

I'm guessing it might be an age thing. I wasn't taught any mnemonics when I was growing up either, but some of the younger kids I'm running into (and much younger siblings of friends) are learning some strange stuff...like multiplication tricks that make no sense to me and weird ways of doing addition. No, they're not the old intuitive ways I remember, like thinking of 23 * 25 as 25^2-50 or 2(250)+75.

Leave a Comment

Enter your full name, maximum 100 characters
Email will not be published
Enter a valid email address for comment notifications
Enter your comment, minimum 5 characters, maximum 5000 characters
Minimum 5 characters 0 / 5000