Skip to content

Instantly share code, notes, and snippets.

View nowshad-hasan's full-sized avatar
🎯
Focusing

Nowshad Hasan nowshad-hasan

🎯
Focusing
View GitHub Profile
import io.github.solidpotato.PotatoMaker;
import org.springframework.boot.SpringApplication;
@org.springframework.boot.autoconfigure.SpringBootApplication
public class SpringBootApplication {
public static void main(String[] args) {
SpringApplication.run(SpringBootApplication.class, args);
PotatoMaker.makePotato();
}
}
plugins {
id 'java'
id 'maven-publish'
id 'signing'
}
sourceSets {
main {
java {
srcDirs = ['src']
@nowshad-hasan
nowshad-hasan / build.gradle
Created October 3, 2022 16:19
Gradle Build File
plugins {
id 'java'
}
group 'io.github.nowshad-hasan' // your group id
version '1.0-SNAPSHOT'
repositories {
mavenCentral()
}
void checkLocalInterface() {
interface Runner {
void run();
}
Runner runner = () -> System.out.println("Running");
runner.run();
}
void checkLocalEnum() {
public class FileMismatchExample {
/*
Here, hello1 and hello3 have same content, hello2 has different content.
*/
public static void main(String[] args) {
Path path1 = Path.of("hello1.txt");
Path path2 = Path.of("hello2.txt");
Path path3 = Path.of("hello3.txt");
String input = "Hello Java 17!\nIt's a new LTS.";
public static void indentString(String input) {
// Positive value add spaces beginning of each line.
String positiveIndent5 = input.indent(5); // 5 spaces
/*
1. Hello Java 17!
It's a new LTS.
*/
public class NullPointerExceptionExample {
/*
Stack trace at Java 1.8: Exception in thread "main" java.lang.NullPointerException
at exception.NullPointerException.main(NullPointerException.java:14)
Stack trace at Java 17: Exception in thread "main" java.lang.NullPointerException:
Cannot read field "birthPlace" because "book.author" is null at
others.NullPointerExceptionExample.main(NullPointerExceptionExample.java:14)
*/
public class SealedClassWithRecordExample {
sealed interface Exam permits Student {
void giveExam();
}
record Student(String name, String rollNumber) implements Exam {
@Override
public void giveExam() {
}
/*
Interface can be sealed or non-sealed, and it can permit other interface or class.
Permitted interface must be sealed/non-sealed and class must be sealed/non-sealed/final.
Sealed interface and permitted interface/class must be in same module. For unnamed module, they must be in same package.
*/
public sealed interface Move permits Fly, Run {
void move();
}
// Fly is non-sealed. So, it can be implemented by any class or extended by any interface.
// Which classes are permitted to extend this Liquid class, must be sealed/non-sealed/final.
public sealed class Liquid permits Water, Honey, Milk {}
// Now, Water can be extended by any class
public non-sealed class Water extends Liquid {}
// Honey is final. So, it can't be extended by anyone.
public final class Honey extends Liquid {}
// Milk is sealed. So, it starts another sealed hierarchy.