Skip to content

Instantly share code, notes, and snippets.

@LazaroIbanez
LazaroIbanez / pom.xml
Last active August 26, 2017 21:54
RestAPI Spring Boot and H2 pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com</groupId>
<artifactId>restapi</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>restapi</name>
@LazaroIbanez
LazaroIbanez / StartApplication.java
Created August 26, 2017 21:56
RestAPI StartApplication.java
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class StartApplication {
public static void main(String[] args) {
SpringApplication.run(StartApplication.class, args);
}
@LazaroIbanez
LazaroIbanez / G.java
Created September 3, 2017 15:57
super java example
public class G extends G1 {
int x = 100;
public void display() {
System.out.println(“Subclass x value: “ + x); // prints 100
System.out.println(“Super class x value: “ + super.x); // prints 10
System.out.println(“Sum of x values: “ + (x + super.x)); // prints 110
super.display(); // calling super class (G1) display()
System.out.println(“From subclass”);
@LazaroIbanez
LazaroIbanez / F.java
Created September 3, 2017 16:01
Use of super in interfaces
public class F implements InterfaceB {
public void m1() {
//super.m1();//This is NOT valid.
//InterfaceA.super.hello(); //This is NOT valid because F does not implement InterfaceA.
InterfaceB.super.m1(); //This is valid.
}
}
interface InterfaceA {
default void m1() {}
@LazaroIbanez
LazaroIbanez / H.java
Created September 3, 2017 16:46
super() example
public class H extends H1 {
public H() {
super(50);
System.out.println(“From H constructor”);
}
public static void main(String args[]) {
H objectH = new H();
}
@LazaroIbanez
LazaroIbanez / C.java
Created September 3, 2017 16:52
Interfaces ambiguous fields
class C implements I1, I2 {
public void m1() {}
public static void main(String… args) {
C tc = new C();
System.out.println(( ( I1) tc).VALUE);
}
}
interface I1 {
int VALUE = 1;
@LazaroIbanez
LazaroIbanez / D.java
Created September 3, 2017 16:58
The default keyword
public class D implements Interface2 {
public static void main (String… args) {
Interface1 acct = new D();
System.out.println(acct.getId());
}
public String getId() {
return “1111”;
}
@LazaroIbanez
LazaroIbanez / D.java
Created September 3, 2017 17:02
D must implement getId
public class D implements Interface1, Interface2 {
public String getId() {
return “1111”;
}
}
interface Interface1 {
public default String getId() {
return “0000”;
}
@LazaroIbanez
LazaroIbanez / E.java
Created September 3, 2017 17:05
Java interface static method is similar to default method except that we can’t override them in the implementation classes.
public class E implements Interf1 {
public String getId() {
return “E: get Id”;
}
public String getOtherId() {
return “E: get Other Id”;
}
@LazaroIbanez
LazaroIbanez / A.java
Created September 3, 2017 17:21
static initialization
public class A {
static { System.out.println(“A Loaded”); }
public static void main(String[] args) {
System.out.println(“A should have been loaded”);
A1 a1 = null;
System.out.println(“A1 should not have been loaded”);
System.out.println(a1.i);
}