Skip to content

Quick Start

Mercy Ma edited this page Sep 29, 2025 · 2 revisions

Welcome to the Microsphere Java Framework! This guide will help you get up and running with microsphere-java in just a few minutes. The framework provides a comprehensive set of utilities and annotations that can be used across Java projects to simplify common development tasks.

Project Structure

The framework is organized into several key modules:

Module Purpose
microsphere-java-core Provides core utilities across various domains like annotations, collections, concurrency, etc.
microsphere-annotation-processor Offers annotation processing capabilities for compile-time code generation
microsphere-java-dependencies Manages dependency versions across the project
microsphere-java-parent Parent POM with shared configurations

Setting Up Your Project

To use Microsphere Java in your project, you'll need to add the appropriate dependencies. The framework is available on Maven Central, making it easy to include in any Java project.

Adding Dependencies

Add the following dependency to your pom.xml:

<dependency>
    <groupId>io.github.microsphere-projects</groupId>
    <artifactId>microsphere-java-core</artifactId>
    <version>${latest.version}</version>
</dependency>

If you need annotation processing capabilities, also add:

<dependency>
    <groupId>io.github.microsphere-projects</groupId>
    <artifactId>microsphere-annotation-processor</artifactId>
    <version>${latest.version}</version>
</dependency>

Basic Usage Examples

Let's explore some of the most commonly used utilities in the framework.

Using Annotations

Microsphere Java provides several useful annotations that can enhance your code quality and readability. Here's an example using the @Nonnull annotation:

import io.microsphere.annotation.Nonnull;
 
public class UserService {
    public void createUser(@Nonnull String username) {
        // Method implementation
    }
}

The @Nonnull annotation indicates that the username parameter cannot be null, helping to prevent NullPointerExceptions and making your code more self-documenting.

Using Utility Classes

The framework provides numerous utility classes for common operations. Let's look at a few examples:

String Manipulation

import io.microsphere.util.StringUtils;
 
public class StringExample {
    public void processString(String input) {
        if (StringUtils.isBlank(input)) {
            System.out.println("Input is empty or blank");
        } else {
            System.out.println("Processing: " + input);
        }
    }
}

Assertions

The Assert class provides convenient methods for validating arguments:

import io.microsphere.util.Assert;
 
public class AssertExample {
    public void divide(int a, int b) {
        Assert.isTrue(b != 0, "Divisor cannot be zero");
        int result = a / b;
        System.out.println("Result: " + result);
    }
}

Next Steps

Congratulations! You've successfully set up Microsphere Java in your project and explored some of its basic features. Here are some suggested next steps:

  • Explore More Utilities: Dive deeper into the specific utility packages that match your project needs
  • Try Annotation Processing: If you're doing compile-time code generation, explore the annotation processor module
  • Check the API Reference: For detailed documentation of all available classes and methods
  • Contribute: If you find areas for improvement, consider contributing to the project

The framework is designed to grow with your needs, providing foundational utilities that can be used across all your Java projects.