Rounding Out Your Java Knowledge


Java-Specific Terminology

Java Application Architecture

Java Archive (JAR) Files

  • javac *.java compile
  • jar cvf jarfilename.jar list_of_files_to_be_included_in_jar_file create jar.
    • create, verbose, filename
  • jar tvf jarfilename.jar inspect jar file content
  • java –cp path_to_jar_file class_containing_main_method use the bytecode contained within a JAR file java –cp S:\applications\MyJar.jar MyApp
  • jar xvf MyApp.jar *.java extract content from a jar file.

Javadoc Comments

It is a special type of comment from which we can automatically generate HTML documentation for an application. Within the body of a javadoc comment, we are able to use a number of predefined javadoc tags (whose names start with @) to control how the resultant HTML will look.

  • javadoc *.java generate javadoc HTML web page.
  • javadoc -private *.java include private members in documentation.

The Object Nature of Strings

String is a reference type—that is, variables declared to be of type String refer to objects.

Strings are Immutable

Strings are said to be immutable—that is, the value of a particular String object cannot be changed once it has first been assigned at the time of instantiation. When we seem to be programmatically modifying an existing String object’s value, we are actually creating a new String object with the desired value.

The StringBuffer Class

StrinBuilder Video
The StringBuilder and StringBuffer classes are mutable. StringBuffer provides concurrency guarantees, so use it only when needed, to avoid the performance overhead.

The StringTokenizer Class

With this class, we’re able to parse (break apart) a String into tokens (segments/substrings) based on arbitrary delimiters. StringTokenizers are particularly useful when reading and parsing structured records from data files.

Instantiating Strings and the String Literal Pool

String x = "foo";
the JVM checks its String literal pool—a special place in the JVM’s memory that enables automatic shared access to String objects—to see if there is already a String object in the literal pool with that exact same value. If there is already a String object in the literal pool with that exact same value, the JVM reuses that existing instance without creating a second. Conversely, if a matching instance is not found in the literal pool, the JVM creates one and places it in the literal pool.

String z = new String("Foo");
Use of new instructs the JVM to bypass the literal pool—that is, a brand-new instance of a String object with the value "Foo" will be created outside of the literal pool.

Chains of Messages

The ability of use multiple methods in a unique chain without create multiple reference variables to do it. The type of a chained message expression is the type of the result that the last method in the chain returns.

results matching ""

    No results matching ""