Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/com/company/Puzzle10_ThreadDestroy.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.company;

/**
* Puzzler for Java 8
*/
public class Puzzle10_ThreadDestroy {

public static void main(String[] args) {
Thread.currentThread().destroy();
}

// Все ок, текущий поток завершится
// Не скомпилируется
// NoSuchMethodError
// InterruptedException
}
19 changes: 19 additions & 0 deletions src/com/company/Puzzle11_ThreadStop.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.company;

/**
* Java 8
*/
public class Puzzle11_ThreadStop {
public static class MyException extends Exception {

}

public static void main(String[] args) throws Exception {
Thread.currentThread().stop(new MyException());
}

// Не скомпилируется
// Поток остановится с исключением MyException
// UnsupportedOperationException
// InterruptedException
}
18 changes: 18 additions & 0 deletions src/com/company/Puzzle12_SingleFile.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.company;

/**
* Java 11
*/
public class Puzzle12_SingleFile {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}

// java Puzzle12_SingleFile
// JEP: 330

// Hello, World!
// ClassNotFoundException
// Ты валенок, надо компилить через javac
// Еще вариант нужен
27 changes: 27 additions & 0 deletions src/com/company/Puzzle13_Var.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.company;

public class Puzzle13_Var {
public static void executor(Object parameter) {
// parameter.method2(); // should be uncommented // line 1
}

public static void main(String[] args) {
var value = new Object(){ // line 2
void method1() {
System.out.println("Hello from method 1");
}
void method2() {
System.out.println("Hello from method 2");
}
};

value.method1(); // line 3
executor(value); // line 4
}
}

// Hello from method 1, Hello from method 2
// Compile error at line 1
// Compile error at line 2
// Compile error at line 3
// Compile error at line 4
15 changes: 15 additions & 0 deletions src/com/company/Puzzle14_Double.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.company;

public class Puzzle14_Double {
public static void main(String[] args) {
System.out.println(
Math.min(
Double.MIN_VALUE, 0.0d
)
);
}
}

// 0x0.0000000000001P-1022 - Double.MIN_VALUE
// 0.0d
// Doesn't compile
13 changes: 13 additions & 0 deletions src/com/company/Puzzle15_Comment.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.company;

public class Puzzle15_Comment {
public static void main(String[] args) {
// this is comment
// \u000d System.out.println("Commented too!");
}
}

// Nothing
// Commented too
// Doesn't compile
// Exception at runtime