Java Beginners FAQ (Beginning Java forum at Coderanch) (original) (raw)
posted 9 years ago
10
Number of slices to send:
Optional 'thank-you' note:
Frequently Asked Questions in the Beginning Java Forum
- How do I fix the compile-time error "Cannot make static reference to the non-static method name() in type class"?
- What's the difference between equals() and the == operator?
- Why doesn't Scanner.nextLine() work? I thought it would stop and wait for me to enter something but it doesn't. (If you're so inclined, you can read a longer explanation here)
- Should I close a Scanner that's tied to System.in? - No, you shouldn't. See the linked wiki article to learn why not and what you can do instead.
Other common questions:
What should every Java greenhorn know?
(For more advanced topics, check out the Java-FAQ.)
- What does a Java program look like?
- See the HelloWorld program
- How do I run my very first Java program?
- Check how to create your first java program
- Mosey on over to the Java Tutorial
- Got no money for books so how can I learn Java?
- See the HereYouWillFindLinksToFreeStuff.
- I want to buy a couple of books about Java. What do you recommend?
- Browse through JavaRanch's book reviews. If you see a book that satisfies your needs a simple click will take you straight to where you can order it.
- Where is the Java API?
- You can both browse and download the documentation. See JavaApiDocs for a description of how to navigate them.
- What non-Windows Support is there for Java?
- OS X, Solaris and Linux
- IBM AIX, Linux, z/OS and IBM i
- various OSes: OpenJDK
- various OSes: Amazon Corretto, also based on OpenJDK
- What's a JAR file, and how do I make it executable?
- See JarFiles
- How do I make an .exe of my Java program?
- Maybe using executable JarFiles would be more appropriate. See the MacOsxFaq for hints on how to build a double-clickable OS X application.
- JWrapper creates native Windows, Linux and OSX apps.
- Classpath, what is it and how do I set it?
- See HowToSetTheClasspath.
- What is a Singleton?
- See SingletonPattern
- What is threading or multi-threading?
- See the ThreadsAndSynchronizationFaq
- What is an object?
- It's a thing with state and behavior, of course.
- It's an instance of a class
- An object is a User-defined Data Type (UDT).
- What is the difference between an object and an instance?
- ObjectVsInstance
- What is a class?
- A class is the definition of some object data type.
- Class is the basic building block of an object oriented system.It is a an entity which acts as a data type and also shows behaviour.A class can have attributes and functions of its own.Thus it can act on messages and also maintain its state.
- What's the difference between a static field and an instance field?
- Instance fields belong to objects (which are instances of a class) with each object having its own copy.
- Static fields belong to a class, and we all know there's only one of each class, so there's only one copy of each static field.
- Static variables are initialized at the class load time, instance variables are initialized before a constructor is executed.
- Can you override a static method?
- See OverridingVsHiding
- Is Java call-by-reference or call-by-value?
- See CallByReferenceVsCallByValue
- What is a JVM? JRE? JDK?
- A JVM (Java Virtual Machine) is an imaginary (theoretical) machine that executes Java bytecodes.
- A JRE (Java Runtime Environment) is a software implementation of a JVM and all the standard Java libraries, and other bits and pieces that are needed to make the thing actually work.
- A JDK (Java Developer's Kit)is the JRE plus tools like the Java compiler, debugger, and other things needed for basic Java development.
- The diagram on this page visualizes it nicely: JDK and JRE are brackets on the left, while the JVM is the layer at the bottom.
- How do I clear the console screen?
- See HowToClearTheConsole
- Why is 1.0 - 2.0/3.0 != 1.0/3.0? (and other arithmetic inaccuracies)
- Arithmetic as done by Java has limits to its accuracy. Some of these have to do with the fact that computer arithmetic is done with base 2, not base 10. Another reason is that 1/3 does not have a finite representation in either base 2 or base 10. You can find a more detailed description here . All the details can be found in the article What Every Computer Scientist Should Know About Floating-Point Arithmetic
- Java implements exact arithmetic with the JavaDoc:java.math.BigInteger and JavaDoc:java.math.BigDecimal classes. As an aside, calculations involving amounts of money should never be done with floats or doubles, but always with BigDecimal.
- Another option is to use decimal arithmetic, which avoids the problems caused by binary numbers. More information about that can be found here
- What are the differences between an interface and an abstract class?
- See InterfaceVsAbstractClass
- Where can I find example code for the XYZ class?
- Java2s also covers advanced Java APIs and 3rd-party APIs. Even more examples are at Kode Java.
- What are the differences between the various JDK versions?
- The documentation of each JDK release contains a page called "New Features and Enhancements" (or similar), which lists the changes from the previous release. You can find links to the documentation of the various releases here. The javadoc page for a class also mentions the JDK version in which it was introduced.
- I'm having trouble understanding how algorithm XYZ works.
- Visualization of sorting algorithms
- Niklaus Wirth's Algorithms and Data Structures covers sorting algorithms and recursive algorithms
- Visualization of string search algorithms
- Visualization of depth-first and breadth-first tree traversal by Renaud Waldura
- Simplex optimization algorithm: graphical visualization
- various algorithms
- even more various algorithms
- How do I work with dates, in particular, convert between dates and strings?
- The JavaDatesFaq has example code for the most common tasks, as well as links to some further material.
- What is a compile-time constant?
- See Henry Wong's in-depth explanation.
- Can I test code without installing anything?
- compilejava.net lets you compile and run classes online
- How do I override the equals and hashCode methods?
- See chapter 3 of Effective Java and the article How to Write an Equality Method in Java
For topics regarding object oriented analysis design and programming, see https://coderanch.com/wiki/659967/OO-Design-FAQ and the various pages it links to