---
# System prepended metadata

title: Brief - A simple Java CLI (part 1)

---

# Brief - A simple Java CLI (part 1)

## Prerequisite
- Fulfill "[A simple command-line interpreter](https://hackmd.io/QnsiXMmuSL6dMRTpxB_D_g)" exercise

## Learning objectives
- Be comfortable with command execution from a terminal, inputs and outputs of a computer program
- Be comfortable with the concept of compiling then running a Java program
- Learn about Java syntax and Java keywords
- Learn about features common to any programming language, of course available in Java such as: methods, variable declaration and assignment, types, arrays, flow control and so on
- Discover and make use of the main Java primitive types and classes (and methods), most often used in enterprise projects

## How to?
- Update the existing `Cli` Java program created previously (prerequisite), adding new commands, no new project needed
- Constraint: do not use other methods than `String command = scanner.nextLine();` to retrieve the input from the console
- Share your project in a new GitHub repository with the same name (`java-simple-cli`). Code source only, never share compiled classes!

## Commands to implement
Please note that some of the example outputs may vary from one computer to another.

### Current date
- Add a `date` command that prints the current date
- Arguments: none
- Example output: `2023-10-12`

### Current time
- Add a `time` command that prints the current time
- Arguments: none
- Example output: `10:41:39.576986400`

### Current date and time
- Add a `datetime` command that prints the current date and time
- Arguments: none
- Example output: `2023-10-12T10:41:39.576986400`

### User account name
- Add a `useraccount` command that prints the user account name
- Arguments: none
- Example output: `Frank`
- Tip: system property

### User home directory
- Add a `userhome` command that prints the user home directory
- Arguments: none
- Example output: `C:\Users\Frank`
- Tip: system property

### Operating system information
- Add a `os` command that prints the operating system name and version
- Arguments: none
- Example output: `Windows 10 (10.0)` that is the name then the version in parentheses
- Tip: system properties

### Environment variable
- Add a `printenv` command that prints the value of the specified environment variable. If the environement variable does not exist, prints an empty string
- Arguments: name of the environment variable (example: `JAVA_HOME`)
- Example output: `C:\Program Files\Java\jdk-17.0.5+8` (for `printenv JAVA_HOME`)
- Tip: in order to test your command, check that the environment variables exist and have the same values (better to test with a few environment variables than only one)

### Prints all the passed arguments
- Add a `echo` command that prints all the arguments passed to the command. If no argument (only the name of the command), prints an empty string
- Arguments: from none to any number of arguments
- Examples output: `Hello` (for `echo Hello`), `Hello world!` (for `echo Hello world!`)