Page 311 - CITS - Computer Software Application -TT
P. 311
COMPUTER SOFTWARE APPLICATION - CITS
Java Program Development
Developing, compiling, and executing Java programs involves several steps. Java is a popular programming
language that follows a “write once, run anywhere” philosophy, meaning you can write code on one platform and
run it on any platform that has a Java Virtual Machine (JVM) installed. Here’s a step-by-step guide:
1 Install Java Development Kit (JDK): To develop Java programs, you need to have the Java Development
Kit (JDK) installed on your computer. You can download the JDK from the official Oracle website or choose
an open-source alternative like OpenJDK. Make sure to set up the PATH environment variable to include the
JDK’s bin directory.
2 Choose a Text Editor or Integrated Development Environment (IDE): You can write Java code using
a simple text editor like Notepad or a more sophisticated Integrated Development Environment (IDE) like
Eclipse, IntelliJ IDEA, or Visual Studio Code. IDEs often provide features like code completion, debugging, and
project management.
3 Write Your Java Code: Create a new Java source code file with a .java extension. For example, you can
create a file named MyProgram.java. Write your Java code in this file. Here’s a simple “Hello, World!” program
in Java
4 Save Your Java File: Save your Java source code file in a directory of your choice.
5 Compile Your Java Code: Open your terminal or command prompt and navigate to the directory where you
saved your Java source file. To compile the code, use the javac command followed by your Java source file’s
name:
If there are no errors in your code, this will generate a bytecode file with a .class’ extension, such as ‘MyProgram.
class’.
6 Execute Your Java Program: After successfully compiling your Java code, you can execute it using the ‘java’
command followed by the class name (excluding the ‘.class’ extension):
If everything is correct, you should see the output of your program in the terminal:
7 Debugging and Testing: Use debugging tools provided by your chosen IDE or standard tools like ‘System.
out.println()’ to debug and test your Java code.
8 Packaging and Distribution (if necessary): If you want to distribute your Java program, you can package it
into a JAR (Java Archive) file, which contains all the necessary class files and resources. This allows others
to run your program easily.
298
CITS : IT&ITES - Computer Software Application - Lesson 78 - 84