Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -213,4 +213,11 @@ marimo/_lsp/
__marimo__/

# Streamlit
.streamlit/secrets.toml
.streamlit/secrets.toml

# Java / Maven
*.class
*.jar
*.war
*.ear
java-hello-world/target/
52 changes: 52 additions & 0 deletions java-hello-world/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.example</groupId>
<artifactId>java-hello-world</artifactId>
<version>1.0.0</version>
<packaging>jar</packaging>

<name>Java Hello World</name>
<description>A simple Java Hello World demo project</description>

<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<junit.version>5.10.2</junit.version>
</properties>

<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.2.5</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.3.0</version>
<configuration>
<archive>
<manifest>
<mainClass>com.example.HelloWorld</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
</project>
15 changes: 15 additions & 0 deletions java-hello-world/src/main/java/com/example/HelloWorld.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.example;

public class HelloWorld {

public static String greet(String name) {
if (name == null || name.isBlank()) {
name = "World";
}
return "Hello, " + name + "!";
}

public static void main(String[] args) {
System.out.println(greet("World"));
}
}
27 changes: 27 additions & 0 deletions java-hello-world/src/test/java/com/example/HelloWorldTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.example;

import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;

class HelloWorldTest {

@Test
void greetWorld() {
assertEquals("Hello, World!", HelloWorld.greet("World"));
}

@Test
void greetCustomName() {
assertEquals("Hello, Java!", HelloWorld.greet("Java"));
}

@Test
void greetNullFallsBackToWorld() {
assertEquals("Hello, World!", HelloWorld.greet(null));
}

@Test
void greetBlankFallsBackToWorld() {
assertEquals("Hello, World!", HelloWorld.greet(" "));
}
}