Skip to content

Instantly share code, notes, and snippets.

@shaunthomas999
Last active September 1, 2017 10:20
Show Gist options
  • Save shaunthomas999/c30c009dd3081aa67e58a2b605b42de9 to your computer and use it in GitHub Desktop.
Save shaunthomas999/c30c009dd3081aa67e58a2b605b42de9 to your computer and use it in GitHub Desktop.
Java Basics
// int Array initialization
int[] intArray = {1,2,3};
// String Array initialization
String[] stringArray = {"a","b","c"};
// Load resources class
File file = new File(getClass().getClassLoader().getResource(jobFileName).getFile());
// Best datatype for saving date & time - Java 8
java.time.Instant;
// Comparable over multiple String attributes
class Car implements Comparable<Car> {
int year;
String make, model;
public int compareTo(Car other) {
if (!this.make.equalsIgnoreCase(other.make))
return this.make.compareToIgnoreCase(other.make);
if (!this.model.equalsIgnoreCase(other.model))
return this.model.compareToIgnoreCase(other.model);
return this.year - other.year;
}
}
// Generate UUID (universally unique identifier), random number
UUID.randomUUID().toString()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment