Java

Table of Contents

Introduction

Philosophy

History

By version

Basics

Arrays

  • How to sort elements in an array?
    double[] x = {2.3,2.2,1.0,5.7,4.2};
    Arrays.sort(x);
    
  • How to join elements of an array into a string?
    String s = Arrays.toString(x);
    System.out.println(s);
    
  • How to find the index of an element with binary search?
    int[] y = {4,5,1,2,6};
    Arrays.sort( y );
    int idx = Arrays.binarySearch(y, 3);
    System.out.println( idx );
    
  • How to compare two arrays?
    int[] m = {1,2,3}, n = {1,2,3};
    boolean result = Arrays.equals(m, n);
    System.out.println(result);
    

Intermediary

Databases

Options

Javadocs

Inline code snippets

/**
 * @return {@code true} if condition is given, otherwise {@code false}.
 */
private boolean testCondition();

Multi-line Java code snippets

/**
 * <pre>
 * System.out.println("Line 1");
 * System.out.println("Line 2");
 * </pre>
 */

Advanced

Assertions

Java Platform Module System (JPMS)

Internationalization

How to load a resource bundle?

public static ResourceBundle getResourceBundle(String key, Locale locale) {    {
    try {
	URL[] urls = {VarStore.RESOURCE_FOLDER.toURI().toURL()};
	ClassLoader loader = new URLClassLoader(urls);
	ResourceBundle rb = ResourceBundle.getBundle(key, locale, loader);
	return rb;
    } catch (Exception e) {
	throw new RuntimeExcpetion(e)
    }
}

(See stackoverflow.com)

Dependency Injection

Dynamic Proxy

Libraries, tools and frameworks

Static analysis

Sonar graph

Sonarcube

jDepend

Visualize package cycles

Testing

SearchImpressum