Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

View RSS Feed

helloworld922

Java FAQ

Rate this Entry
Here are some foolishly answered questions about Java and Java programming:

1. I'm having problems compiling my Java code! I've tried the command-line compiler and the Eclipse JDT compiler, but neither of these gives me the correct results.

Quote Originally Posted by Javac
error: Class names, 'helloworld.jpg', are only accepted if annotation processing is explicitly requested.
Answer:
The javac compiler does not require you to put the extension in. So the correct command should be:
javac helloworld
Additionally, try renaming your file from helloworld.jpg to helloworld.java. Java source files must have the .java extension.

For more answers which may help you with this problem (in particular, what to do if you have a png file instead of a jpeg), see Stack Overflow - Why is this program erroneously rejected (it's for C++, but everyone knows that C/C++ solutions universally apply to everything).

2. I've heard about this thing called JNI. What is it and when should I use it?

Answer:
JNI stands for Java Native Interface. The developers of Java new how bad they were, so decided that the best course of action after a failed attempt at SE1.0 decided was to create JNI to allow programmers to use other languages to code their Java program.

JNI is generally the preferred course of action when it comes to developing a Java application because it has none of the problems associated with running an interpreted language. Future releases of Java have only focused improving the JNI interface.

An alternative to JNI was introduced in SE6, known as OpenJDK. OpenJDK lets developers directly compile their code into the JVM, thus eliminating any associated interface lag between Java and JNI. This method is still under heavy development, though, and it is quite difficult compared to using JNI.

3. People keep telling me that Javascript and Java are different! Are they really?

Of course they're not different! If two things were different, they would have very different names. For example, no one would ever confuse a sandwich with spaghetti because their names are no where near the same. Java is the actual programming language. Javascript is just the scripting version of Java, and can be compiled into Java programs or run directly.

4. What are good practices when it comes to naming Java class/variables?

Always pick the shortest names possible. Each additional character you add introduces another chance that you could type the wrong character. If a variable is named a, there is very little chance you'll type it's name wrong. However, if your variable is named computedLength, there are tons of ways you could misspell it, leading to massive headaches during debugging.

5. If naming java variables as short as possible is desired, why doesn't the Java API do this?

As stated in answer 2, the Java developers are morons. Just because someone is wrong doesn't make it ok to follow them.

6. Should I use comments? From what I hear, they're not even compiled into JavaByte code and don't affect performance at all.

If something has no positive impact on performance, don't use it.

7. What's a good formatting scheme? 1 spaces between item, and then tab each line in with an extra tab after the start of a new block?

Don't. Only when the said formatting has a positive impact on performance. Anything else is just wasted keystrokes.

Ex.:
This code is the best way to program Java
public class HelloWorld{public static void main(String[] args){System.out.println("Hello world!");}}

8. Is there anything else I should keep in mind before starting to program Java?

Yes, ignore everything posted in this faq. Like the Java developers, I too am a moron. My goal one day is to become one of them.

Happy April Fools day (and for those who's calendar says it's April 2, you've set it to the incorrect date. Everyone knows that US MST is the only timezone that should be used).

Updated April 1st, 2011 at 09:21 PM by helloworld922

Tags: faq, java
Categories
Uncategorized

Comments

  1. JavaPF's Avatar
    permalink
    LOL I was reading this thinking someone must of hijacked your account! Let's hope no one takes this information seriousally and reads all the way to the bottom
    I forgot it was April fools day today. I've already been tricked into eating sweets that were so hot I've been crying for an hour. I did wonder why everyone started laughing when I put it in my mouth.. haha
  2. helloworld922's Avatar
    permalink
    I changed the first line from frequently asked to foolishly asked (if anyone else hasn't picked up on the hint yet )