Java 26 — JEP 530: Primitive patterns and switch (Preview) int i = 1000; if ( i instanceof byte b ) { System.out.println( "fits in byte: " + b ); } boolean v = true; switch ( v ) { case true -> System.out.println( "YES" ); case false -> System.out.println( "NO" ); } • Pattern matching now works with primitive types, not only reference types. • The instanceof test can check whether a conversion is exact before binding a variable. • switch also extends to primitive selectors such as boolean, long, float, and double. #java #jdk26 #java26 #jep #jep530 #pathtojava27 #primitive #switch Go further with Java certification: Java👇 https://bit.ly/javaOCP Spring👇 https://bit.ly/2v7222 SpringBook👇 https://bit.ly/springtify JavaBook👇 https://bit.ly/jroadmap
More Relevant Posts
-
☕ Java 27 — JEP 527: Post-quantum TLS 1.3 hybrid key exchange SSLSocket socket = ( SSLSocket ) SSLContext.getDefault() .getSocketFactory() .createSocket(); SSLParameters params = socket.getSSLParameters(); params.setNamedGroups( new String[]{ "SecP256r1MLKEM768", "X25519MLKEM768", "secp256r1", "x25519" } ); socket.setSSLParameters( params ); • Java 27 adds hybrid post-quantum key exchange options to TLS 1.3. • The important message for developers is that javax.net.ssl users benefit by default, even without code changes. • This is the “quantum” feature worth talking about because it changes how teams think about long-term confidentiality. #java #java27 #jdk27 #tls13 #quantum #postquantum Go further with Java certification: Java👇 https://bit.ly/javaOCP Spring👇 https://bit.ly/2v7222 SpringBook👇 https://bit.ly/springtify JavaBook👇 https://bit.ly/jroadmap
To view or add a comment, sign in
-
Java interrupts : In Java, there is no safe way to forcibly terminate a thread. Instead, Java uses a cooperative interruption mechanism. When Thread 1 (the main thread) decides that Thread 2 is no longer needed—perhaps because the data was found in a cache—it sends an interruption signal to Thread 2. Because this is cooperative, Thread 2 is not forced to stop immediately; rather, it must periodically check its own "interrupted status" and choose to shut down gracefully. Therefore, if Thread 2 is poorly written and ignores these signals, it may continue running indefinitely. Example: public static void main(String[] args) { // start the thread Thread taskThread = new Thread(new Task()); taskThread.start(); taskThread.interrupt(); // some reason System.out.println("Asking to stop"); } The reason of why interrupt method does not called immediately because of : data integrity Opne connections Or some half operation #Java #BackendDevelopment #SoftwareEngineering #MultiThreading #Concurrency #JavaPerformance #CodingTips #Programming #SystemDesign
To view or add a comment, sign in
-
☕ Java 26 — JEP 517: HTTP/3 for the HTTP Client API var client = HttpClient.newBuilder() .version( HttpClient.Version.HTTP_3 ) .build(); var request = HttpRequest.newBuilder( URI.create( "https://vvauban.com/" ) ) .version( HttpClient.Version.HTTP_3 ) .GET() .build(); var response = client.send( request, HttpResponse.BodyHandlers.ofString() ); • Java’s standard HttpClient can now opt into HTTP/3. • That gives developers access to QUIC-based transport without changing libraries. • If the peer does not support HTTP/3, the client can fall back to older HTTP versions. #java #java26 #jdk26 #pathtojava27 #jep517 Go further with Java certification: Java👇 https://bit.ly/javaOCP Spring👇 https://bit.ly/2v7222 SpringBook👇 https://bit.ly/springtify JavaBook👇 https://bit.ly/jroadmap
To view or add a comment, sign in
-
☕ Java 26 — JEP 500: Prepare to make final mean final class C { final int x; C() {x = 100;} } static void main() throws NoSuchFieldException, IllegalAccessException { var f = C.class.getDeclaredField( "x" ); f.setAccessible( true ); var obj = new JEP500().new C(); IO.println( obj.x ); f.set( obj, 200 ); IO.println( obj.x ); /*output: 100 200 WARNING: Final field x in class com.vv.JEP500$C has been mutated ... WARNING: Use --enable-final-field-mutation=ALL-UNNAMED ... WARNING: Mutating final fields will be blocked in a future release .... */ } • JDK 26 starts warning about deep reflection that mutates final fields. • This prepares the ecosystem for a future release where such mutation is denied by default. • For developers, the action item is simple: run tests, find reflection-heavy libraries, and see who still breaks final. #java #java26 #final Go further with Java certification: Java👇 https://bit.ly/javaOCP Spring👇 https://bit.ly/2v7222 SpringBook👇 https://bit.ly/springtify JavaBook👇 https://bit.ly/jroadmap
To view or add a comment, sign in
-
Day 35 of #100DaysOfCode — Java Stacks (Part 2) completed! 📚✅ Topics Covered ✅ 1️⃣ Valid Parentheses — check if brackets are balanced 2️⃣ Duplicate Parentheses — find redundant brackets in expression → ((a+b)+(c+d)) = false | (((a+b))+c) = true 3️⃣ Maximum Rectangular Area in Histogram → Classic stack problem — O(n) solution Key Takeaway 💡 Stack shines in bracket & histogram problems! Duplicate parentheses: if two consecutive ( without operator between → duplicate 35/100 done 🔥 #100DaysOfCode #Java #Stack #DSA #ApnaCollege #BuildInPublic #JavaDeveloper
To view or add a comment, sign in
-
-
#TAPACADEMY Java arrays are used to save more than one value of the same type within a single variable. Arrays may be either single dimensional or multi-dimensional according to requirements. All elements are stored in particular indices, beginning from 0. Elements can be accessed using their respective indices, such as numbers[2] = 30. Some helpful array methods that Java offers are Arrays.sort(), Arrays.toString(), and others. #java #Arrays ###
To view or add a comment, sign in
-
-
🚀 Runnable vs Callable in Java Concurrency — Quick Notes Both Runnable and Callable are Functional Interfaces ✅ 👉 That means you can use Lambda Expressions with them (Java 8+) 🔹 Runnable (Java 1.0) * Functional Interface ✔️ * Method: run() * Return Type: ❌ No return value * Exception Handling: ❌ Cannot throw checked exceptions * Use Case: Fire-and-forget background tasks 🔹 Callable (Java 5.0) * Functional Interface ✔️ * Method: call() * Return Type: ✅ Returns result (Future<V>) * Exception Handling: ✅ Can throw checked exceptions * Use Case: Tasks that need results or error handling 💡 Key Difference * Use Runnable when you don’t care about the result * Use Callable when you need a result or better exception handling ⚡ Lambda Example Runnable r = () -> System.out.println("Running task"); Callable<Integer> c = () -> 10 + 20; 🔥 In modern Java (Java 8+ to Java 21 Virtual Threads), functional style + concurrency = clean & scalable code. #Java #Concurrency #Multithreading #FunctionalProgramming #JavaDeveloper #InterviewPrep
To view or add a comment, sign in
-
-
Hello Connections, Post 14 — Java Fundamentals A-Z This looks correct… but gives a completely wrong result 😵 Can you spot the bug? 👇 int a = 1_000_000; int b = 1_000_000; int result = a * b; System.out.println(result); // 💀 -727379968 Wait… what? 1,000,000 × 1,000,000 should be 1,000,000,000,000 right? But Java prints a negative number! 😱 Here’s what’s happening 👇 • int can store values only up to 2,147,483,647 • The result exceeds this limit • Java silently overflows and wraps around ⚠️ No error. No warning. Just wrong data. This is called integer overflow. Here’s the fix 👇 long result = (long) a * b; System.out.println(result); // ✅ 1000000000000 Post 14 Summary: 🔴 Unlearned → Assuming int is always safe for calculations 🟢 Relearned → Use long when dealing with large numbers to avoid overflow Have you ever faced this in real scenarios? Drop a ⚠️ below! Follow along for more Java & backend concepts 👇 #Java #JavaFundamentals #BackendDevelopment #LearningInPublic #SDE2
To view or add a comment, sign in
-
-
5 things every Java developer should know about null and why Optional is not always the answer. You might reach for Optional the moment you see a possible null. That instinct is not always right. Here are the rules that actually matter: - Optional.of(value) throws NPE if value is null. Always use ofNullable() when you are not certain. - The isPresent() + get() pattern is just a null check in a suit. Use orElse(), orElseGet(), or orElseThrow(). - Never put Optional in a class field. JPA and Jackson do not handle it well. Use nullable fields in entities and DTOs. - Never return Optional<List<T>>. Return an empty list. A collection already signals absence. - orElse(x) evaluates x even when a value is present. orElseGet(supplier) is lazy. Use it for DB calls or object creation. Optional is powerful when used at the right boundary the service layer return type, not everywhere a null could exist. #Java #SpringBoot #CleanCode #JavaDeveloper #SoftwareEngineering
To view or add a comment, sign in
-
-
Today while revising Core Java, I came across a small but interesting concept Anonymous Object ✅ class AnonymousObject { public void AnonymousObj() { System.out.println("Anonymous object practice"); } AnonymousObject() { System.out.println("In constructor"); } } public class Main { public static void main(String[] args) { new AnonymousObject().AnonymousObj(); new AnonymousObject().AnonymousObj(); } } Every time new AnonymousObject() is used, a new object is created and the constructor gets called. Simple concept, but clarity matters. 😊 #Java #CoreJava #Learning
To view or add a comment, sign in
-
More from this author
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development