java

Item 72: Priorize o uso das exceções padrões

Item 72: Priorize o uso das exceções padrões

1. Importância da reutilização de exceções padrão Exceções padrão tornam o código mais fácil de entender e familiar para outros programadores. Melhoram a leitura e o aprendizado da API. Reduzem o consumo de memória e o tempo de carregamento de classes. 2. Exceções padrão mais reutilizadas e seus usos típicos IllegalArgumentException: Usada quando um parâmetro possui um valor inadequado. Exemplo: public void setRepeatCount(int count) { if (count < 0) { throw new IllegalArgumentException("Count cannot be negative"); } this.count = count; } Enter fullscreen mode Exit fullscreen mode IllegalStateException: Lançada quando o estado do objeto não permite a operação. Exemplo: public…
Read More
Strings: Garbage Collection and Immutability in Java

Strings: Garbage Collection and Immutability in Java

In Java, strings play a unique role in memory management due to their immutability and interning characteristics. These concepts not only improve performance but also introduce nuances to memory handling that are often essential in interviews. Let’s explore Garbage Collection, and Immutability in depth, with notes on how the String Pool and JVM memory management interact with these concepts. This post builds on concepts discussed in the previous article on String Pool and Memory Management. Reviewing that article first will provide a helpful foundation for understanding the topics covered here. 1. String Garbage Collection In Java, string literals behave differently…
Read More
Multithreading Concepts Part 3 : Deadlock

Multithreading Concepts Part 3 : Deadlock

Welcome to Part 3 of our multithreading series! In Part 1, we explored Atomicity and Immutability. In Part 2, we discussed Starvation. In this part, we’ll dive into the mechanics of Deadlock in multithreading. What causes it, How to identify and preventive strategies you can use to avoid turning your code into a gridlocked intersection. Application grinds to a halt, often without any visible errors, leaving developers puzzled and systems frozen. Navigating the Complex Tracks of Concurrency A useful analogy to understand deadlock is to imagine a railway network with multiple trains on intersecting tracks. Since each train is waiting…
Read More
Polymorphism: Decoding Method Overloading in Java

Polymorphism: Decoding Method Overloading in Java

Method overloading is a form of compile-time polymorphism that allows us to define multiple methods with the same name but different parameters. This post dives into method overloading concepts, rules, and real-world examples, as well as a demonstration of how Java's println() method handles overloading. What is Method Overloading? Method overloading allows the same method name to perform different functions based on parameter type, number, or order. It is also referred to as static polymorphism since the appropriate method is determined at compile time. Note: Differences in access modifiers or return types alone do not qualify as valid overloads. Rules…
Read More
Abstraction: Decoding Abstract Classes in Java

Abstraction: Decoding Abstract Classes in Java

In this post, we explore Abstract Classes, an essential part of abstraction in Java. We'll build on concepts discussed earlier and examine how abstraction simplifies complex systems. Abstract classes serve as a blueprint for other classes, allowing us to focus only on relevant details while hiding unnecessary complexity. Let’s dive deeper into what abstract classes are, why they exist, and how they are used. What is an Abstract Class? An abstract class is a class that cannot be instantiated on its own. It’s designed to be extended by subclasses that provide concrete implementations for its abstract methods. In other words,…
Read More
Rest Assured Basics: A Beginner’s Guide to Automated API Testing in Java

Rest Assured Basics: A Beginner’s Guide to Automated API Testing in Java

Introduction In today’s digital world, Application Programming Interfaces (APIs) are crucial for software to communicate smoothly. With more and more RESTful APIs being used, it’s vital for testers to ensure they work reliably. Rest Assured, a Java library simplifies this process. It offers a specific language for writing clear and thorough tests. Rest Assured helps Java developers create strong test suites for checking API functionality, performance, and security. Its easy syntax speeds up testing, ensuring high-quality software. In this blog post, we’ll explore the significance of Rest Assured, explaining why it’s essential for both developers and testers. Additionally, we’ll offer…
Read More
Geo Viewer in IntelliJ Idea is cool

Geo Viewer in IntelliJ Idea is cool

Hello old friend Thanks to Poznań Java User Group randomly selecting me during a meetup to get a JetBrains IntelliJ Idea Ultimate license, I started using it daily. It's not entirely new software for me. I've been using Android Studio for almost a decade now, occasionally working on side projects in the Community Edition of IntelliJ. Recently at work, I've been using VS Code and NeoVim. Quite a different IDE philosophy with the latter. I happen to work on the backend currently, and IntelliJ is an absolute beast with built-in tools for everything you can imagine. Next to the usual…
Read More
Java Learning Journey 1.0

Java Learning Journey 1.0

I recently learned Java through the practices in [https://exercism.org/tracks/java/exercises]. My current progress is 13 out of a total of 148 practices. I would like to share what I learned. This post introduce my understanding about .split(), .trim(), .isDigit(), .isLetter(), Comparable<T>, User-defined Java Exceptions, and Interface. 1) .split() Definition: The .split() method divides String into an array based on the separator [1]. Syntax: public String[] split(String regex, int limit) Enter fullscreen mode Exit fullscreen mode Parameter: regex: (required field) pattern of separator limit: (optional field) maximum length of the returned array Example: public class Main{ public void getProductPrice(String products){ double totalPrice…
Read More
Fibonacci, Integer overflow, memoization e um exagero

Fibonacci, Integer overflow, memoization e um exagero

Vamos fazer um exercício. Abaixo deixo um código que retorna o número na posição n da sequência de Fibonacci: public static int fib(int n){ if (n <= 1){ return n; } return fib(n-1) + fib(n-2); } Enter fullscreen mode Exit fullscreen mode Que tal tentarmos mostrar no nosso terminal todos os números da sequência de fibonacci menores que 2147483647? public static int fib(int n){ if (n <= 1){ return n; } return fib(n-1) + fib(n-2); } public static void main(String[] args) { int position = 1; int currentNumber = fib(position); while (currentNumber < 2147483647) { System.out.println(currentNumber); position++; currentNumber = fib(position);…
Read More
Navigating JVM Memory: Key Concepts for Your Java Interview

Navigating JVM Memory: Key Concepts for Your Java Interview

When preparing for Java developer interviews, understanding how memory is organized within the Java Virtual Machine (JVM) can be a key topic of discussion. This post will highlight the different memory areas in the JVM—specifically the Stack, Heap, and MetaSpace—providing essential points that interviewers may focus on. By familiarizing yourself with these concepts, you can enhance your interview readiness and demonstrate your understanding of Java memory management. The Roles of JDK, JRE, and JVM Before diving straight into the JVM's memory spaces, let's quickly explore the connection between the Java Development Kit (JDK), Java Runtime Environment (JRE), and Java Virtual…
Read More
No widgets found. Go to Widget page and add the widget in Offcanvas Sidebar Widget Area.