they say it is to reduce the number of RAM space used compared to this

if(number1 == 100){ break;}else{number1++;}

I just dont understand why is that possible to write the first line and compile it. I tried to use the same line above to make the same effect however they give me an "illegal start of expression" error

I can't think of this being compilable. the ? is part of a so called ternary operator and is IMHO only useful in assignments:

1 2 3 4 5 6 7

// assingn bar to foo as long as it is less than 100, else assign constant 100intfoo= bar<100?bar:100;

// which is equivalent to the followinrintfoo;if(bar<100) foo=bar;elsebar=100;

I wouldn't use the ternary construct in any other cases but the most simple ones, cause it leads to completely unreadable code. Also I doubt, that the ternary operator takes less space in byte code, but one never know...

That code is MUCH clearer than your code, and also adds an option to let the user press both turn left and turn right at the same time by simply removing all "elses" from the code.In case you thought your code was faster; it isn't. In a microbenchmark, my code ran about 25% faster than your code on my computer, and provided identical output(*).Your code, however, DOES generate a slightly smaller class file.

(* almost. Since I changed the order on some negations for clearer code, there's some minor differences in the double -> float casting results)

So really, you need to test it in your app to see what's smallest, or use a different compiler that's smarter than javac. It's trivial to prove that all those four methods do the same thing, yet javac produces four different bytecodes for them.

That's not line numbers. It's the actual numbers of bytes used for the bytecode.goto, for example, takes up three bytes (opcode, offset high byte, offset low byte). Sure, it's a single instruction, but it makes the byte code three bytes larger.

That's not line numbers. It's the actual numbers of bytes used for the bytecode.goto, for example, takes up three bytes (opcode, offset high byte, offset low byte). Sure, it's a single instruction, but it makes the byte code three bytes larger.

This is most illogical. The number "100" is a integer, it cannot be true or false.Also, this requires incrementing or decrementing number1 variable by one, and then assign value of number1 to number1, which is not necessery.

HOwever I would like to ask.. is there any other special characters like ? used in java and what are they used for and how they are used?

^^

CHeers!

You mean punctuation characters? Sure, there are plenty. Almost all of them you are well aware of (I sure hope you know what the semi colon is used for, for example)

Maybe one you're not thinking of is in Java 5, the new "foreach" loop which uses a colon

for(Foo foo : myFoos) { foo.doSomething();}

it would have been nicer if that loop could have been

foreach(Foo foo in myFoos) {...}

as it is in C#, but introducing new keywords to a language is risky, and so Sun decided to not go that route. If nothing else, old programs that had "foreach" and "in" as variable names would have failed to compile.

HOwever I would like to ask.. is there any other special characters like ? used in java and what are they used for and how they are used?

^^

CHeers!

You mean punctuation characters? Sure, there are plenty. Almost all of them you are well aware of (I sure hope you know what the semi colon is used for, for example)

Maybe one you're not thinking of is in Java 5, the new "foreach" loop which uses a colon

for(Foo foo : myFoos) { foo.doSomething();}

it would have been nicer if that loop could have been

foreach(Foo foo in myFoos) {...}

as it is in C#, but introducing new keywords to a language is risky, and so Sun decided to not go that route. If nothing else, old programs that had "foreach" and "in" as variable names would have failed to compile.

Infact, it'd probably be easier to list the punctuation characters that don't have a special meaning! The only common ones I can think of that have no meaning in Java, and are not valid characters in an identifier, are these 3:- #¬`

java-gaming.org is not responsible for the content posted by its members, including references to external websites,
and other references that may or may not have a relation with our primarily
gaming and game production oriented community.
inquiries and complaints can be sent via email to the info‑account of the
company managing the website of java‑gaming.org