Java Questions 11 - 20  «Prev Next»

static and non-static methods - Java 13

  1. What is the difference between a "static" and a "non-static" method in Java?
    What is a static method primarily used for?
    Answer:
    You cannot call non-static methods from inside static methods. You can call static methods from within non-static methods.
  2. Are global functions permitted in Java?
    Answer:
    Global functions are not permitted in Java.
    Putting a static Java method inside a class allows it access to other static methods and static fields. With a static method, you do not send a message to an object.
  3. Where does the term standard I/O come from?
    Answer:
    The term standard I/O refers to the Unix concept of a single stream of information that is used by a program.
  4. What kind of input stream is System.in?
    Answer:
    System.in is a raw input stream with no wrapping. System.in is an object of type InputStream
  5. How do byte streams and character streams differentiate themselves?
    Answer:
    Byte streams are used for reading and writing data. Character streams provide a means for handling input and output characters.
  6. What is the scope of a nested class?
    Answer:
    The scope of a nested class is bounded by the scope of its enclosing class. If class B is defined within class A, then B is known to A, but not outside of A. A nested class has access to the members, including private members of the class in which it is nested. Class B can access the private members of Class A. However, the enclosing class does not have access to the members of the nested class.

  7. What does the RandomAccessFile encapsulate?
    Answer:
    RandomAccessFile encapsulates a random access file. It is not derived from InputStream or OutputStream. RandomAccess implements the interfaces DataInput and DataOuput which define the basic I/O methods.
  8. What is RandomAccessFile used for?
    Answer:
    RandomAccessFile is used for files containing records of known size so that you can move from one record to another using seek?
  9. What is an abstract method?
    Answer:
    An abstract method is a method that is declared, but contains no implementation. An abstract class is a class with one or more abstract methods. Abstract methods, with more than one possible implementation represent variable parts of the behavior of an abstract class.
  10. In Java, what is the difference between an "exception" and "error"?
    Answer:
    Typically an error refers to some action that can not be recovered from. In terms of Java programming structures, Exception and Error are both children of the Throwable class. Exception and Error are siblings. All classes that are derived from error relate to system malfunctions (i.e. LinkageError, Stackoverflow, VMError, AWTError) whereas exceptions are either checked or unchecked.