Java anatomy

From wikinotes

Example

/** com.domain.myclass.MyClass.java
 */

package com.domain.myclass;

/**
* This is a documentation-comment (doctag) for MyOtherClass.
* html tags can be used within javadoc comments.
* 
*/
public class MyOtherClass {

    /**
    * Prints 'print stuff' to  stdout.
    */
    public void print_stuff(){
        System.Out.Prntln("print stuff")
    }

    /**
    * @param text   The text you would like
    *               to capitalize using this method.
    *
    * @return        Returns the capitalized text.
    */
    public String capitalize( String text ){
        return text.toUpperCase()
    }
}


/**
* This class's method is run whenever MyClass.java
* is run directly from the CLI.
*/
public class MyClass {
    public static void main( String[] args ){
        MyOtherClass myothercls = new MyOtherClass
        myothercls.print_stuff()
    }
}

Version

java -version  # prints version info

Execution Environment

The execution environment determines the lowest level of JDK your code requires to run. This changes how the code is compiled (it is compiled for the smallest featureset possible). Maven refers to this as the maven.compiler.target.

I have been using 1.8, since that is where many of the functional programming concepts were introduced to the language (method-references, lambda expressions, ...).

See

Language Semantics

  • java does not have functions, only methods.
  • when run directly from the commandline, the method public static void main(String[] args ){} method is called on the object whose name matches the filename.
  • java does not use header files
  • classes defined in java.lang are automatically imported into all module scopes.

Best Practices

  • modules should contain a single class, and be named after it. (including capitalization)
  • first letter of class names should be capitalized