Preskočiť na hlavný obsah

Príspevky

What is the minimum app in Java (21)?

Who doesn't know "Hello, World!"? When you start writing a code in a new language, you usually write this simple program. What does it look like in Java code? class App { public static void main(String[] args) { System.out.println("Hello, World!"); } } But, explain to a beginner what "public static void" and strange args are. What would you say if the program could be simplified. class App { void main() { System.out.println("Hello, World!"); } } Let's make it even simpler, without class declaration. void main() { System.out.println("Hello, World!"); } Yes, this is simplest Java code in Java 21 release. Try it yourself. In a Java 21 preview feature (JEP 445) it needs to be enabled by with the --enable-preview flag. Just compile your application by command javac --release 21 --enable-preview App.java and run it as simple as java --enable-preview App This simplification i
Posledné príspevky

Will this Java code run?

Will this Java code run? The Test instance variable via the value() method returns null.  What about NullPointerException? Is it possible to access the pi member through null?

JavaOne is back!

In 2018 and 2019, the famous Java developer conference used the name Code One. For 2022, the name JavaOne is back again! The world's leading developer conference is scheduled to take place in Las Vegas at Oracle CloudWorld in October 2022. Oracle CloudWorld promises to keep you up-to-date on Java innovations in 2022. News on development tools, resources and best practices to accelerate the development and deployment of modern applications in cloud, mobile, local or hybrid environments.  JavaOne participants can choose from hundreds of profi seminars, labs, tutorials and other sessions. Sure, we’ll learn a lot about Java 18 and Java 19, which will be released in September 2022, and definitely we will learn more about the future of the Java platform. JavaOne will be within Oracle CloudWorld in Las Vegas, Nevada, f rom October 16 to October 22, 2022 .

Text Blocks

Od Java 15 sú textové bloky k dispozícii ako štandard. V Java 13 a 14 je potrebné túto feature povoliť (preview). Zatiaľ posledná verzia platformy Java je ver. 15, alebo keď chcete presnejšie JDK 15 rel. 2020-09-16. Posledná LTS (verzia dlhodobej podpory) bola JDK 11 zo septembra 2018. Text Blocks Aj vy máte problém s tým, keď máte dlhý String a potrebujete ho dať do premennej priamo v kóde? Samozrejme, riadok je potom dlhý a pretečie...  Vlastnosť Text Blocks umožňuje zápis textov (string reťazcov) na viac riadkov bez toho, aby ste ich museli spájať operátorom "+". Ide to veľmi jednoducho. Poďme sa na to pozrieť prakticky. Text Blocks  sú na začiatku a konci bloku označené trojitými úvodzovkami (""""). V takejto forme môžu obsahovať text rozdelený do viacerých riadkov bez potreby zadávať znak nového riadku \n. Java kompilátor je pri tejto novej funkcii tak trochu "smart" a snaží sa automaticky odstraňovať prebytočné biele znaky (medzery, tabulá

Java block as a class member

Do you know code block? Of course you know! Block of code defines the scope of variables and puts more statemets together. But what about non-static blocks as a class member? You can put them as other class members such as static blocks, class variables and methods. E.g. static block is executed after class is loaded. This example is clasic block of code... { // block of statements: Fibonacci series int s, f1 = 0, f2 = 1; while (f1 < 100) { System.out.println(f1); s = (f1 + f2); f1 = f2; f2 = s; } } And now, try to find non-static block inside BlockTest class... public class BlockTest { // field without explicit initialization private int id; // field with ininitialization private String value = "UNDEF"; static { System.out.println("static code: executed onece when the class is loaded\n"); } { System.out.println(debug("executed before constructor, but after members initialization&