Java programming starting with Hello World

The JDK does not provide a separate editor. However, simple Java programs can be created with Notepad or an editing program.

The basic code for most programming languages is the code that prints the sentence “Hello World”. It is the most basic structure and relatively easy to understand.

The basic code for outputting Hello World in Java is shown below.

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

Java programs need to write code and then create a Java class file. The compile command is javac.

> javac

If you check the folder where javac command is executed, HelloWorld.class file is created. If you have a Java class file, you can run it with the java command.

> java HelloWorld

This program prints the characters “Hello, Java World” as shown below.

Creating a Hello World with a Java Applet

The applet program runs in the browser or applet viewer. Unlike Java applications, you need to add the required classes yourself.

The applet program that outputs Hello World is shown below.

import java.applet.*;
import java.awt.*;

public class HelloWorldApplet extends Applet {
	public void paint(Graphics g) {
		g.drawString("Hello, Java World", 100, 60);

Java applets also need to create java class files like Java applications.

> javac

When a class file named HelloWorldApplet.class is created, it creates an HTML file to run the applet.

	<title>Java Applet Test</title>
	<applet code="HelloWorldApplet.class" width="400" height="200"></applet>

The applet viewer is used as follows.

> appletviewer java_applet_test.html

Share This Post

댓글 남기기

이메일은 공개되지 않습니다. 필수 입력창은 * 로 표시되어 있습니다

Latest Post