<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Omal Jayamanne</title>
    <description>The latest articles on DEV Community by Omal Jayamanne (@omal_jayamanne_).</description>
    <link>https://dev.to/omal_jayamanne_</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3065397%2Ffaac6031-3f82-4b4c-b8b0-5e4ced504511.jpg</url>
      <title>DEV Community: Omal Jayamanne</title>
      <link>https://dev.to/omal_jayamanne_</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/omal_jayamanne_"/>
    <language>en</language>
    <item>
      <title>Solidity Structs vs Java Classes Explained for Beginners</title>
      <dc:creator>Omal Jayamanne</dc:creator>
      <pubDate>Thu, 01 May 2025 18:42:19 +0000</pubDate>
      <link>https://dev.to/omal_jayamanne_/solidity-structs-vs-java-classes-explained-for-beginners-3eg2</link>
      <guid>https://dev.to/omal_jayamanne_/solidity-structs-vs-java-classes-explained-for-beginners-3eg2</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Meta Description:&lt;/strong&gt; Discover the key differences between Java classes and Solidity structs with easy-to-understand examples. Perfect for beginners in programming and blockchain technology.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Introduction&lt;/strong&gt;&lt;br&gt;
Are you curious about how programming languages handle data? In this guide, we’ll explore two essential concepts: Java classes and Solidity structs. Whether you’re new to coding or interested in blockchain development, this article breaks down these tools using simple, real-world examples. By the end, you’ll understand how Java powers everyday apps and how Solidity drives smart contracts on platforms like Ethereum.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is a Class in Java?&lt;/strong&gt;&lt;br&gt;
Java is a popular programming language used in mobile apps, games, and business systems. A Java class acts as a blueprint for creating objects—think of it like a recipe for your favorite dish. It defines both data (fields) and actions (methods) an object can have.&lt;/p&gt;

&lt;p&gt;Example: Car Class in Java&lt;br&gt;
Imagine a "Car" class in a driving game:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Fields:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Color: "red"&lt;/li&gt;
&lt;li&gt;Make: "Toyota"&lt;/li&gt;
&lt;li&gt;Model: "Camry"&lt;/li&gt;
&lt;li&gt;Speed: 60 mph&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Methods:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Accelerate: Increases speed&lt;/li&gt;
&lt;li&gt;Brake: Decreases speed&lt;/li&gt;
&lt;li&gt;Honk: Plays a sound&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;When you create a "myCar" object, it gets its own properties and behaviors. This combination makes Java programming ideal for modeling real-world objects.&lt;/p&gt;

&lt;p&gt;Learn more: &lt;a href="https://docs.oracle.com/javase/tutorial/java/concepts/class.html" rel="noopener noreferrer"&gt;Java Classes Documentation&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is a Struct in Solidity?&lt;/strong&gt;&lt;br&gt;
Solidity is a language for writing smart contracts on blockchain platforms like Ethereum. A Solidity struct is a custom data type that groups related variables, like a form with fields—except it doesn’t include actions.&lt;/p&gt;

&lt;p&gt;Example: Voter Struct in Solidity&lt;br&gt;
In a blockchain voting system, a "Voter" struct might include:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Fields:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Name: "Alice"&lt;/li&gt;
&lt;li&gt;Age: 25&lt;/li&gt;
&lt;li&gt;HasVoted: false&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Actions like voting are handled by separate functions in the smart contract, not the struct itself. This design keeps data organized and secure in blockchain programming.&lt;/p&gt;

&lt;p&gt;Learn more: &lt;a href="https://docs.soliditylang.org/en/v0.8.0/types.html#structs" rel="noopener noreferrer"&gt;Solidity Structs Documentation&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key Differences Between Java Classes and Solidity Structs&lt;/strong&gt;&lt;br&gt;
Here’s how these two concepts compare:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzorbs40zjcjgsb0xywim.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzorbs40zjcjgsb0xywim.png" alt="Image description" width="536" height="175"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Java Classes:&lt;/strong&gt; Combine what an object is (e.g., a bank account’s balance) with what it can do (e.g., deposit money).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Solidity Structs:&lt;/strong&gt; Store data (e.g., a collectible’s owner), while actions (e.g., transfer) are defined elsewhere in the contract.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Real-World Examples: Pets in Java and Blockchain&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Let’s bring these ideas to life with pet-related scenarios.&lt;br&gt;
Java Example: Pet Simulation Game&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;In a programming for beginners game, a "Pet" class might look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class Pet {
    String name;         // Pet’s name, e.g., "Buddy"
    String species;      // Pet’s species, e.g., "Dog"
    int happinessLevel;  // Happiness level, starting at 50

    public Pet(String name, String species) {
        this.name = name;
        this.species = species;
        this.happinessLevel = 50;
    }

    public void feed() { // Increases happiness when fed
        happinessLevel += 10;
        System.out.println(name + " is happier after eating!");
    }

    public void play() { // Increases happiness when played with
        happinessLevel += 20;
        System.out.println(name + " had fun playing!");
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each pet object can act on its own, perfect for interactive apps.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Solidity Example: Blockchain Pet Adoption Platform&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In a blockchain development platform, a "Pet" struct and contract might look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

contract PetAdoption {
    struct Pet {        // Stores pet data
        string name;    // e.g., "Luna"
        string species; // e.g., "Cat"
        address owner;  // Ethereum address of the owner
    }

    mapping(uint =&amp;gt; Pet) public pets; // Tracks all pets
    uint public petCount;             // Counts total pets

    function adoptPet(string memory _name, string memory _species) public {
        petCount++;
        pets[petCount] = Pet(_name, _species, msg.sender); // Assigns pet to adopter
    }

    function transferPet(uint _petId, address _newOwner) public {
        require(pets[_petId].owner == msg.sender, "Only the owner can transfer");
        pets[_petId].owner = _newOwner; // Transfers ownership
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, the struct organizes data, and the contract handles actions as blockchain transactions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why These Differences Matter in Programming and Blockchain&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Java:&lt;/strong&gt; Built for flexibility in apps where objects act independently.&lt;br&gt;
&lt;strong&gt;Solidity:&lt;/strong&gt; Designed for secure, transparent smart contracts where data and logic are separated.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;em&gt;For beginners, this shows how programming adapts to its purpose—whether creating a game or a decentralized platform.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion: Mastering Data in Java and Solidity&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;By understanding Java classes and Solidity structs, you’ll see how data works in different tech worlds. Java classes blend data and behavior for dynamic apps, while Solidity structs focus on data for secure blockchain applications. Whether you’re coding a game or exploring smart contracts, these concepts are your foundation.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Share this guide on social media to help others learn about programming and blockchain!&lt;br&gt;
Have questions? Leave a comment below!&lt;/em&gt;&lt;/p&gt;

</description>
      <category>solidity</category>
      <category>blockchain</category>
      <category>web3</category>
      <category>programming</category>
    </item>
    <item>
      <title>Java Coding Best Practices for High-Performance Applications</title>
      <dc:creator>Omal Jayamanne</dc:creator>
      <pubDate>Fri, 25 Apr 2025 16:54:45 +0000</pubDate>
      <link>https://dev.to/omal_jayamanne_/java-coding-best-practices-for-high-performance-applications-3aea</link>
      <guid>https://dev.to/omal_jayamanne_/java-coding-best-practices-for-high-performance-applications-3aea</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;In the fast-paced world of software development, writing efficient and high-performance Java code is critical for building scalable applications. Whether you're optimizing for speed, minimizing resource usage, or handling large datasets, mastering Java best practices can make a significant difference. This article explores key coding examples that improve your Java skills and help you write high-performance code. From efficient logging to cache-aware techniques, these tips will elevate your programming game.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;1. Logging Efficiently in Java&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Logging is essential for debugging and monitoring, but inefficient logging can slow down your application.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;❌ Bad Practice: Logging Too Much&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;System.out.println("Function entered");
System.out.println("User ID: " + userId);
System.out.println("Result: " + result);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This approach uses multiple &lt;strong&gt;System.out.println&lt;/strong&gt; calls, which are slow and produce cluttered output.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;✅ Good Practice: Controlled Logging&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import java.util.logging.*;
Logger logger = Logger.getLogger("MyApp");
logger.setLevel(Level.INFO);  // INFO and above only
logger.info("Processing transaction for user: " + userId);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Using Java’s java.util.logging package with log levels reduces overhead and keeps logs meaningful.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Optimizing Loops for Performance&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Loops are a core part of coding, but their efficiency depends on implementation.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;❌ Bad Practice: Traditional Loop with Appends&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;List&amp;lt;Integer&amp;gt; squares = new ArrayList&amp;lt;&amp;gt;();
for (int i = 1; i &amp;lt;= 1000; i++) {
    squares.add(i * i);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This works but can be inefficient for large datasets due to repeated list resizing.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;✅ Good Practice: Java 8 Streams&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;List&amp;lt;Integer&amp;gt; squares = IntStream.rangeClosed(1, 1000)
                                 .map(i -&amp;gt; i * i)
                                 .boxed()
                                 .collect(Collectors.toList());
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Streams offer a cleaner, more efficient approach, with potential for parallelization.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Avoiding Database Queries Inside Loops&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Database queries inside loops create performance bottlenecks due to repeated database calls.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;❌ Bad Practice: Query Per Iteration&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;for (int id : userIds) {
    User user = userRepository.findById(id);  // Multiple DB hits
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This results in one query per loop iteration, slowing down execution.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;✅ Good Practice: Bulk Query&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;List&amp;lt;User&amp;gt; users = userRepository.findAllById(userIds);
for (User user : users) {
    // Process user
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Fetching all data in one query minimizes database round-trips.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Hardware-Aware Data Handling&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Leveraging hardware behavior, like CPU caches, can boost performance.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;❌ Bad Practice: Random Array Access&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;int[] data = new int[1000000];
Random rand = new Random();
for (int i = 0; i &amp;lt; 1000000; i++) {
    total += data[rand.nextInt(data.length)];
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Random access disrupts cache efficiency, slowing down execution.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;✅ Good Practice: Sequential Access&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;for (int i = 0; i &amp;lt; data.length; i++) {
    total += data[i];
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Sequential access maximizes cache utilization, improving speed.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5. Fixing Memory Fragmentation with Object Pools&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Frequent object creation can fragment memory and increase garbage collection overhead.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;❌ Bad Practice: Frequent Allocations&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;for (int i = 0; i &amp;lt; 1000; i++) {
    byte[] buffer = new byte[1024];  // Allocates memory each time
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This causes unnecessary memory churn.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;✅ Good Practice: Object Pooling&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Queue&amp;lt;byte[]&amp;gt; pool = new LinkedList&amp;lt;&amp;gt;();
for (int i = 0; i &amp;lt; 100; i++) {
    pool.add(new byte[1024]);
}

for (int i = 0; i &amp;lt; 1000; i++) {
    byte[] buffer = pool.poll();
    // Use and then recycle
    pool.add(buffer);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Reusing objects from a pool reduces allocation overhead.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;6. Cache-Aware Matrix Traversal&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Matrix traversal order impacts cache performance in Java’s row-major memory layout.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;❌ Bad Practice: Column-Major Traversal&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;int[][] matrix = new int[1024][1024];
for (int j = 0; j &amp;lt; 1024; j++) {
    for (int i = 0; i &amp;lt; 1024; i++) {
        matrix[i][j] = i + j;
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Column-first traversal causes frequent cache misses.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;✅ Good Practice: Row-Major Traversal&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;for (int i = 0; i &amp;lt; 1024; i++) {
    for (int j = 0; j &amp;lt; 1024; j++) {
        matrix[i][j] = i + j;
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Row-first traversal aligns with memory layout, enhancing cache efficiency.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br&gt;
Mastering these Java coding best practices—efficient logging, optimized loops, bulk queries, hardware-aware data handling, memory management, cache optimization, and minimal object copying—will help you write high-performance applications. Pair these techniques with JMH profiling to validate your improvements. Start applying these tips today to boost your Java coding skills and build faster, more efficient software.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;Bonus Resource Idea&lt;/strong&gt;&lt;br&gt;
Want these examples in a practical format? They can be organized into a downloadable Java project on GitHub or a concise cheat sheet PDF. Let me know if you'd like assistance creating that!&lt;/em&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>programming</category>
      <category>beginners</category>
      <category>java</category>
    </item>
  </channel>
</rss>
