[{"content":"OOP, the JVM, concurrency and the Spring ecosystem.\nBooks Effective Java — Joshua Bloch Java Concurrency in Practice — Brian Goetz Spring in Action — Craig Walls Articles 22/10/2026 — Bitwise Operators in Java: What They Are, Where They Came From, and When to Use Them ","permalink":"https://hussyvel.com/languages/java/","summary":"\u003cp\u003eOOP, the JVM, concurrency and the Spring ecosystem.\u003c/p\u003e\n\u003ch2 id=\"books\"\u003eBooks\u003c/h2\u003e\n\u003cul\u003e\n\u003cli\u003e\u003cinput disabled=\"\" type=\"checkbox\"\u003e \u003cem\u003eEffective Java\u003c/em\u003e — Joshua Bloch\u003c/li\u003e\n\u003cli\u003e\u003cinput disabled=\"\" type=\"checkbox\"\u003e \u003cem\u003eJava Concurrency in Practice\u003c/em\u003e — Brian Goetz\u003c/li\u003e\n\u003cli\u003e\u003cinput disabled=\"\" type=\"checkbox\"\u003e \u003cem\u003eSpring in Action\u003c/em\u003e — Craig Walls\u003c/li\u003e\n\u003c/ul\u003e\n\u003ch2 id=\"articles\"\u003eArticles\u003c/h2\u003e\n\n\u003cul\u003e\n  \u003cli\u003e22/10/2026 — \u003ca href=\"/posts/bitwise-operators-java/\"\u003eBitwise Operators in Java: What They Are, Where They Came From, and When to Use Them\u003c/a\u003e\u003c/li\u003e\n\u003c/ul\u003e","title":"Java"},{"content":"In short: use bitwise operators in Java when the problem is genuinely binary. That means compact permissions and flags (hand-written bit masks, as in hardware registers; in everyday application code, prefer EnumSet, which stores the flags as bits for you, without any bitwise operators in your code), binary protocols and formats (parsing headers, RGB/ARGB colors with \u0026lt;\u0026lt;, \u0026gt;\u0026gt; and \u0026amp;), hashes and checksums (hashCode(), CRC, MurmurHash), and low-level algorithms where the bit operation is the algorithm (counting bits, detecting a power of two with (n \u0026amp; (n - 1)) == 0, or swapping without a temporary variable in specific embedded-systems contexts).\nAvoid them when the only goal is to \u0026ldquo;optimize\u0026rdquo;. The compiler and the JIT already do strength reduction automatically, so replacing x * 2 with x \u0026lt;\u0026lt; 1 by hand brings no real gain and only hurts readability. This is the kind of premature optimization that Knuth, and later Bloch in Effective Java, warn about: it is only worth it after measuring with a profiler, never by assumption.\nBitwise operators work on each individual bit of an integer instead of treating the number as a single value. Computers already store everything in binary, and these operators give programmers direct access to those ones and zeros.\nJava has seven of them:\nOperator Name Rule Example (8 bits) \u0026amp; AND 1 only if both bits are 1 1100 \u0026amp; 1010 = 1000 | OR 1 if at least one bit is 1 1100 | 1010 = 1110 ^ XOR 1 if the bits are different 1100 ^ 1010 = 0110 ~ NOT (complement) flips every bit ~00001100 = 11110011 \u0026lt;\u0026lt; left shift shifts left and fills with 0 (multiplies by 2ⁿ) 0011 \u0026lt;\u0026lt; 2 = 1100 \u0026gt;\u0026gt; signed right shift shifts right and copies the sign bit -16 \u0026gt;\u0026gt; 2 = -4 \u0026gt;\u0026gt;\u0026gt; unsigned right shift shifts right and fills with 0 -16 \u0026gt;\u0026gt;\u0026gt; 2 = 1073741820 The Java Language Specification (§15.19) calls \u0026lt;\u0026lt;, \u0026gt;\u0026gt; and \u0026gt;\u0026gt;\u0026gt; the shift operators. The left operand is the value being shifted, and the right operand is the shift distance.\nWhere They Came From The story has three stages: first the mathematics, then the hardware, and finally the programming languages.\n1847–1854: George Boole invents the algebra of logic. Boole published \u0026ldquo;The Mathematical Analysis of Logic\u0026rdquo; in 1847 and \u0026ldquo;The Laws of Thought\u0026rdquo; in 1854, starting what we now call Boolean algebra (Britannica). He treated logical operators as pure mathematics. The modern form of the algebra, with union, intersection and complement, was completed later by Jevons, Peirce, Schröder and Huntington (Wikipedia).\n1937: Claude Shannon brings logic into circuits. At 21, in his master\u0026rsquo;s thesis at MIT, Shannon realized that Boole\u0026rsquo;s true and false map onto the open and closed states of an electrical circuit (Christie\u0026rsquo;s). Switches in series compute AND, switches in parallel compute OR, and a normally closed relay performs NOT (salivity.github.io). Processing logic with electrical switches is the foundation of every modern digital computer (Wikipedia). From then on, processors came with native AND, OR, XOR and shift instructions that the hardware executes directly.\n1960s–1970s: programming languages. CPL was designed to allow high-level programming without giving up control over individual bits (University of Michigan). Ken Thompson\u0026rsquo;s B already had the \u0026amp;, |, ^, \u0026lt;\u0026lt; and \u0026gt;\u0026gt; operators (flash-gordon.me.uk). In BCPL and B, however, \u0026amp; and | changed meaning depending on context. Inside an if they acted as sequential logical tests; everywhere else they were bit operations (Bell Labs, BCPL manual). While creating C between 1971 and 1973, Dennis Ritchie took a suggestion from Alan Snyder and split the logical operators \u0026amp;\u0026amp; and || from the bitwise \u0026amp; and | (Ritchie, \u0026ldquo;The Development of the C Language\u0026rdquo;). That is why Java, which inherited C\u0026rsquo;s syntax, has both pairs.\n1995: Java adds \u0026gt;\u0026gt;\u0026gt;. Java has no unsigned integer types, so it defines two right shifts. \u0026gt;\u0026gt; is arithmetic and preserves the sign, while \u0026gt;\u0026gt;\u0026gt; is logical and fills with zeros (CERT/SEI). \u0026gt;\u0026gt;\u0026gt; also removes an ambiguity from C, where the result of \u0026gt;\u0026gt; on negative numbers depends on the compiler.\nWhy Use Them Performance: these are the cheapest operations a processor can run, usually in a single cycle. Memory savings: one int holds 32 flags and one long holds 64, where you would otherwise need 32 or 64 boolean values. Matching binary formats: network protocols, file formats (PNG, ZIP), hardware and cryptography all define their data bit by bit. Classic algorithms: hashing, Bloom filters, compression and random number generation all depend on these operators. When to Use Them Situation Java example Flags and permissions perms | WRITE, perms \u0026amp; ~WRITE, (perms \u0026amp; READ) != 0 Packing several values into one number ARGB color: (a \u0026lt;\u0026lt; 24) | (r \u0026lt;\u0026lt; 16) | (g \u0026lt;\u0026lt; 8) | b Reading unsigned bytes byte \u0026amp; 0xFF in streams, sockets and files Protocols and binary formats TCP/IP headers, control bits Hashing and table indexing h ^ (h \u0026gt;\u0026gt;\u0026gt; 16) and hash \u0026amp; (n - 1) in HashMap Overflow-safe midpoint (low + high) \u0026gt;\u0026gt;\u0026gt; 1 in binary search Fast checks even/odd (n \u0026amp; 1) == 0; power of two (n \u0026amp; (n - 1)) == 0 Sets of integers BitSet, prime sieves, graphs and games (chess bitboards) Cryptography and checksums XOR, rotations (Integer.rotateLeft), CRC When to Avoid Them Business rules in APIs: as Joshua Bloch argues in Item 36 of Effective Java, prefer EnumSet over bit fields packed into an int. EnumSet is just as fast, and much more readable and type-safe. Micro-optimizing without measuring: the JIT compiler already turns x * 8 into x \u0026lt;\u0026lt; 3 when it pays off. Replace arithmetic with shifts only when it makes the code clearer or a profiler shows a real gain. Tricks that confuse readers: swapping variables with XOR is a curiosity, not a good practice. Known pitfalls: the shift distance is reduced modulo 32 (or 64 for long), byte and short are promoted to int before the operation, and \u0026amp; and | on boolean values do not short-circuit. Hands-on Example: \u0026amp;\u0026amp; vs \u0026amp; on Booleans The last pitfall above is easier to see in code. This small project validates a user through an external service. The Usuario class holds a name and an active flag:\npublic class Usuario { private final String nome; private final boolean ativo; public Usuario(String nome, boolean ativo) { this.nome = nome; this.ativo = ativo; } public String getNome() { return nome; } public boolean isAtivo() { return ativo; } } ServicoExterno stands for any remote call, such as an API or a database. It returns the user as the service sees it:\npublic interface ServicoExterno { Usuario consultar(Usuario usuario); } Validador checks that the user is not null and, only then, asks the service:\npublic class Validador { public static boolean ehValido(Usuario usuario, ServicoExterno servico) { return usuario != null \u0026amp;\u0026amp; servico.consultar(usuario).isAtivo(); } } The \u0026amp;\u0026amp; operator is short-circuit: when the left side is false, the right side never runs. With a null user, the service is not called and the method returns false. If you write \u0026amp; instead, Java evaluates both sides, so servico.consultar(null) runs and the .isAtivo() call on its result can throw a NullPointerException. Besides the exception, it also means a useless call to the external service.\nA main method shows the safe version:\npublic class Main { public static void main(String[] args) { ServicoExterno servico = usuario -\u0026gt; usuario; Usuario usuarioAtivo = new Usuario(\u0026#34;Hussyvel\u0026#34;, true); Usuario usuarioNulo = null; System.out.println(\u0026#34;Active user is valid? \u0026#34; + Validador.ehValido(usuarioAtivo, servico)); System.out.println(\u0026#34;Null user is valid? \u0026#34; + Validador.ehValido(usuarioNulo, servico)); } } Testing It with JUnit 5 The tests below use lambdas as the service, so no mocking library is needed. The key test proves the short-circuit: with a null user, the service must never be called.\nclass ValidadorTest { private final ServicoExterno servicoEco = usuario -\u0026gt; usuario; @Test void deveRetornarTrueParaUsuarioAtivo() { assertTrue(Validador.ehValido(new Usuario(\u0026#34;Ana\u0026#34;, true), servicoEco)); } @Test void deveRetornarFalseParaUsuarioInativo() { assertFalse(Validador.ehValido(new Usuario(\u0026#34;Ana\u0026#34;, false), servicoEco)); } @Test void deveRetornarFalseParaUsuarioNulo() { assertFalse(Validador.ehValido(null, servicoEco)); } @Test void naoDeveChamarServicoQuandoUsuarioForNulo() { AtomicInteger chamadas = new AtomicInteger(); ServicoExterno servico = usuario -\u0026gt; { chamadas.incrementAndGet(); return usuario; }; Validador.ehValido(null, servico); assertEquals(0, chamadas.get()); } @Test void deveUsarOResultadoDoServicoEmVezDoUsuarioOriginal() { Usuario original = new Usuario(\u0026#34;Ana\u0026#34;, true); ServicoExterno servico = usuario -\u0026gt; new Usuario(\u0026#34;Ana\u0026#34;, false); assertFalse(Validador.ehValido(original, servico)); } @Test void devePropagarExcecaoDoServico() { ServicoExterno servico = usuario -\u0026gt; { throw new IllegalStateException(\u0026#34;servico fora do ar\u0026#34;); }; assertThrows(IllegalStateException.class, () -\u0026gt; Validador.ehValido(new Usuario(\u0026#34;Ana\u0026#34;, true), servico)); } } Change \u0026amp;\u0026amp; to \u0026amp; in Validador and naoDeveChamarServicoQuandoUsuarioForNulo fails right away, because the service is called once. A good test suite catches this kind of one-character mistake.\n","permalink":"https://hussyvel.com/posts/bitwise-operators-java/","summary":"\u003cp\u003e\u003cstrong\u003eIn short:\u003c/strong\u003e use bitwise operators in Java when the problem is genuinely binary. That means compact permissions and flags (hand-written bit masks, as in hardware registers; in everyday application code, prefer \u003ccode\u003eEnumSet\u003c/code\u003e, which stores the flags as bits for you, without any bitwise operators in your code), binary protocols and formats (parsing headers, RGB/ARGB colors with \u003ccode\u003e\u0026lt;\u0026lt;\u003c/code\u003e, \u003ccode\u003e\u0026gt;\u0026gt;\u003c/code\u003e and \u003ccode\u003e\u0026amp;\u003c/code\u003e), hashes and checksums (\u003ccode\u003ehashCode()\u003c/code\u003e, CRC, MurmurHash), and low-level algorithms where the bit operation \u003cem\u003eis\u003c/em\u003e the algorithm (counting bits, detecting a power of two with \u003ccode\u003e(n \u0026amp; (n - 1)) == 0\u003c/code\u003e, or swapping without a temporary variable in specific embedded-systems contexts).\u003c/p\u003e","title":"Bitwise Operators in Java: What They Are, Where They Came From, and When to Use Them"},{"content":"Full Stack Java Developer with over 6 years of experience building, modernizing, and optimizing enterprise-level systems across the energy, healthcare, and government sectors.\nAs a Full Stack Engineer at Petrobras, I work on the development and maintenance of critical applications. My routine involves solving complex architectural and performance challenges to ensure operational stability. I am responsible for restructuring Java services, managing Maven build environments, and resolving structural flaws like cyclic package dependencies. I also work heavily on the database layer, analyzing Oracle DB performance logs, monitoring resource consumption (SGA), and tuning long-running SQL queries, while ensuring code quality through unit testing and SonarQube.\nAt a state environmental agency in Brazil, I am part of the development team for GUARÁ, a greenfield platform built with Spring Boot 3, Java 17, Angular, and PostgreSQL. This project replaces a legacy JSF/Java 8 system serving over 6,000 users, introducing a modular architecture, role-based access control, REST APIs, and automated licensing workflows.\nPreviously, at Philips Healthcare, I contributed to backend services and frontend interfaces for medical platforms, working with Java, Angular, and PL/SQL in a high-compliance environment.\nMy experience spans the entire stack: from database modeling and query optimization to building reactive Angular frontends and designing clean Spring Boot backends with JPA/Hibernate, Maven, and Docker.\nCore Stack: Java, Spring Boot, Angular, PostgreSQL, Oracle DB, REST APIs, JPA/Hibernate, Maven, Docker, Git, GitLab CI/CD, Linux.\nI am actively seeking remote work opportunities with international teams (US, EU, UK, Canada) where I can contribute to impactful backend or full-stack projects.\n📩 Open to remote roles. Feel free to connect or reach out on LinkedIn.\n","permalink":"https://hussyvel.com/about/","summary":"\u003cp\u003eFull Stack Java Developer with over 6 years of experience building, modernizing, and optimizing enterprise-level systems across the energy, healthcare, and government sectors.\u003c/p\u003e\n\u003cp\u003eAs a Full Stack Engineer at \u003cstrong\u003ePetrobras\u003c/strong\u003e, I work on the development and maintenance of critical applications. My routine involves solving complex architectural and performance challenges to ensure operational stability. I am responsible for restructuring Java services, managing Maven build environments, and resolving structural flaws like cyclic package dependencies. I also work heavily on the database layer, analyzing Oracle DB performance logs, monitoring resource consumption (SGA), and tuning long-running SQL queries, while ensuring code quality through unit testing and SonarQube.\u003c/p\u003e","title":"Biography"},{"content":"","permalink":"https://hussyvel.com/resume/","summary":"","title":""}]