Last active
September 1, 2017 10:20
-
-
Save shaunthomas999/c30c009dd3081aa67e58a2b605b42de9 to your computer and use it in GitHub Desktop.
Java Basics
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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