0% found this document useful (0 votes)
4 views2 pages

HelloRaspberryPi Java on RaspberryPi

The document provides a step-by-step guide to create a simple Java application named `HelloRaspberryPi` on a Raspberry Pi via SSH. It includes instructions for creating the Java source file, compiling it, and running the program to output 'Hello Raspberry Pi'. This exercise helps verify Java installation and prepares users for Java-based IoT projects.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views2 pages

HelloRaspberryPi Java on RaspberryPi

The document provides a step-by-step guide to create a simple Java application named `HelloRaspberryPi` on a Raspberry Pi via SSH. It includes instructions for creating the Java source file, compiling it, and running the program to output 'Hello Raspberry Pi'. This exercise helps verify Java installation and prepares users for Java-based IoT projects.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Creating a Simple Raspberry Pi Application Using Java (HelloRaspberryPi)

Objective

Now that youve established SSH access to your Raspberry Pi, the goal is to:
- Create a basic Java program named `HelloRaspberryPi`
- Compile it using `javac`
- Run it using the `java` command

This helps verify that Java is installed and working, and that your SSH-based remote development
environment is ready.

What You'll Create

A simple Java program that outputs:

"Hello Raspberry Pi"

Step-by-Step Guide

Step 1: Log in to Raspberry Pi via SSH

Use terminal or PuTTY:


ssh [email protected]
or
ssh [email protected]

Step 2: Create Java Source File Remotely

Use echo to create the file:

echo "class HelloRaspberryPi {


> public static void main(String[] args) {
> System.out.println(\"Hello Raspberry Pi\");
>}
> }" > HelloRaspberryPi.java
This creates HelloRaspberryPi.java in your current directory.

Step 3: Compile the Java Code

Compile using:

javac HelloRaspberryPi.java

If Java is not installed, use:

sudo apt-get install default-jdk

Step 4: Run the Java Program

Run the program:

java HelloRaspberryPi

Expected Output:
Hello Raspberry Pi

Concept Recap Table

| Step | Command/Concept | Purpose |


|------|------------------|---------|
| Create file | `echo ...` | Create Java source file |
| Compile Java | `javac` | Compile to .class file |
| Run Java App | `java` | Execute the class file |
| Escape Quotes | `\"...\"` | Proper syntax in echo |

Real-World Importance

This process helps you:


- Learn remote coding techniques
- Run applications headlessly
- Prepare for Java-based IoT projects on Raspberry Pi

You might also like