Skip to content

Instantly share code, notes, and snippets.

@tye-shutty
Last active July 18, 2019 14:26
Show Gist options
  • Save tye-shutty/9f52d1908380d5c89a6d115de15d123c to your computer and use it in GitHub Desktop.
Save tye-shutty/9f52d1908380d5c89a6d115de15d123c to your computer and use it in GitHub Desktop.
catch (IOException|FileNotFoundException ex) {
logger.log(ex);
throw ex;
}
//catching multiple exceptions
private volatile int count = 0;
//makes all vars in context write to main memory
///java.util.UUID makes UUIDs
java.net.ServerSocket
//This class implements server sockets. A server socket waits for requests to come in over the network.
//It performs some operation based on that request, and then possibly returns a result to the requester.
//The actual work of the server socket is performed by an instance of the SocketImpl class.
//An application can change the socket factory that creates the socket implementation to configure itself to create sockets appropriate to the local firewall.
import static java.lang.Math.PI;
//or as a group:
import static java.lang.Math.*;
//Once they have been imported, the static members can be used without qualification.
///at com.sun.xml.internal.ws.fault.SOAP11Fault.getProtocolException(SOAP11Fault.java:178)
//package...class.method(file:line)
public interface Processor {
void execute(NotificationListener listener);
interface NotificationListener {
void processingCompleted();
}
}
//Since nested interface cannot be accessed directly, the main purpose of using them is to resolve the
//namespace by grouping related interfaces (or related interface and class) together. This way, we can
//only call the nested interface by using outer class or outer interface name followed by dot( . ),
//followed by the interface name.
//Nested interfaces are static by default. You don’t have to mark them static explicitly as it would be redundant.
//Nested interfaces declared inside class can take any access modifier, however nested interface declared inside
//interface is public implicitly.
///A final class is simply a class that can't be extended.
public class Restricted{
public static void main(String[] args){
System.out.println(RestrictedThing.thing.num);
}
}
class RestrictedThing{
public static final RestrictedThing thing = new RestrictedThing();
private RestrictedThing(){
}
int num = 7;
}
//works! Only allows that one thing.
if( param instanceof Double) {
System.out.println("param is a Double");
}
//can also:
return value instanceof String ? this.resolve((String)value) : value.toString();
java.util.Optional<T>
//A container object which may or may not contain a non-null value.
//If a value is present, isPresent() will return true and get() will return the value.
interface Test {
default double getAvg(int avg) {
return avg;
}
}
class Tester implements Test{
}
//compiles just fine
[Ljava.lang.Object;
///the internal form of the name consists of the name of the element type preceded by one or more '[' characters
//representing the depth of the array nesting. The encoding of element type names is as follows:
//boolean Z; byte B; char C; double D; float F; int I; long J; short S; class or interface Lclassname;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment