How to do Java Programs in Debian

 

1. Install Java Development Kit (JDK)

First, ensure you have the JDK installed. You can install it using the package manager:
sudo apt update
sudo apt install default-jdk


2. Verify the Installation


Check if Java is installed correctly:
java -version


3. Write the Java Program

Create a directory for your Java program and navigate to it:sh

mkdir  /java_programs cd  /java_programs


Create a file named HelloWorld.java using your preferred text editor (e.g., nano, vim,edit )

gedit HelloWorld.java


Add the following code to the file:

public class HelloWorld { 
 public static void main(String[] args) 
 System.out.println("Hello, World!"); 
 } 
}

Save the file and exit the text editor.

4. Compile the Java Program

Compile the Java program using the javac command:

javac HelloWorld.java

This will generate a file named HelloWorld.class.

5. Run the Java Program

Run the compiled Java program using the java command:

java HelloWorld

You should see the output:
Hello, World!


Naming Conventions
  • The public class name and the filename must match.
  • If there is no public class in the file, you can name the file anything you like, but this is less common practice.
  • It's good practice to follow Java naming conventions: class names should start with an uppercase letter and use CamelCase.


Comments

Popular posts from this blog

KTU OOP LAB JAVA CSL 203 BTech CS S3 - Dr Binu V P

Syllabus and Practice Questions KTU OOPS Lab Java CSL 203

String Problems