×

How to run Java Program in Eclipse

How to run Java Program in Eclipse

In this section, we will learn how to write, save, compile, and execute or run a Java program in Eclipse. Eclipse is one of the important IDE (Integrated Development Environment) used for writing Java programs.

Before moving ahead in this section, ensure that Java and the Eclipse IDE is already installed.

Let’s follow the steps given below.

  1. Open the eclipse.exe file by double-clicking it.
  • After eclipse.exe starts running, it asks for the workspace. In the selected workspace, the source code and .class files reside. After that click on the Launch button.

After selecting the workspace at any desired location, press the Launch button. The eclipse then shows the following.

  • Create a Java project. Click on the File -> New -> Java project

Another way is to press Alt + Shift + N then select Java project. After selecting Java Project, we get the following window.

In the project name, enter the project name of one’s choice and press the Next button. We have entered MyFirstProject as the project name. The Next button takes to the following window.

As we are not concerned about the modules, the check box corresponding to the module-info.java file should be unchecked.

 Now, click on the Finish button, following window appears on the screen.

Now go to the File tab -> New-> Class.

The other way is directly click on the class logo, present just below the menu bar.

After clicking the class logo, the following screen appears.

In the name field, enter the Name of the class that is desired in the code. We have entered HelloExample. Press the Finish button. It creates a HelloExample.java file. The file has the class HelloExample.

In this file, we can write the Java code. For now, let’s print a welcome statement.

FileName: HelloExample.java

public class HelloExample

{

// main method

public static void main(String argvs[])

{

// A given character array

char[] chArr = {'w', 'e', 'l', 'c', 'o', 'm', 'e', ' ' , 't', 'o', ' ', 'T', 'u', 't', 'o', 'r', 'i', 'a', 'l', 'A', 'n', 'd', 'E', 'x', 'a', 'm', 'p', 'l', 'e'};

// Converting the character array to a string

String str = new String(chArr);

// printing the string

System.out.println(str);

}

}

Now, press the run button.

Pressing the run button gives the following output on the console.

Note that output is only generated, if the code is error-free.


Related Topics

All the important string methods in Java

What is a String? Strings are a bundle of different characters that are normally used in Java programming language. Strings are regarded as objects in the Java programming language. “String” is a...

4 minutes read.

How to Iterate a HashMap in Java?

Hash-map is a class of Java collections framework which has the functionality to implement the Map interface of Java. It stores the data in key-value pairs and can be accessed...

5 minutes read.

Timestamp Operation in Java

JDBC escape syntax is supported by Timestamp's formatting and parsing functions. Additionally, it adds support for fractional seconds values for SQL TIMESTAMP.java.util.Date is wrapped in a lightweight wrapper that enables...

3 minutes read.

Generic Linked List in Java

A linear data structure known as a Linked List stores values in nodes. As we already know, each node has two properties: its value and a link to the node...

6 minutes read.

Interleaving string in Java

If the string Str3 contains all of the characters from Str1 and Str2, it is considered interleaving Str1 and Str2. Keep in mind that the order of all characters in...

5 minutes read.

How many ways to create object in Java?

In this article, you will be acknowledged about the different ways to create an object in java. So far you construct an object from a class, as is common knowledge,...

6 minutes read.

How to create an array in Java

An array is a linear data structure stores a collection of fixed number ofelements of similar type. The size of an array is specified when it is created. The array...

14 minutes read.

Deadlock in Java

Deadlock is when two or more processes wait for the state to do their tasks, but none of them can do so. It is a very common problem that one...

6 minutes read.

Java Macros

Macros are additions to the JDK 7 compiler in Java. Compile time macros are added and supported. Macros are Java classes that are instantiated and executed during the compilation process....

2 minutes read.

What are Array strings in Java?

In normal programming, An array is a group and a collection of identical forms of data that are stored in a sequential memory region and may be accessed using their...

4 minutes read.

Pig Latin Program in Java

Pig Latin Program in Java Pig Latin is a method for translating words of the English language into a different language. It is an encrypted word that is generated by using the following steps....

4 minutes read.

Best Java Security Framework

The security of applications is currently our top concern when creating them. The applications or bits of code running over the network are exposed to dangers and may jeopardize integrity,...

3 minutes read.

Sublime Number in Java

In this tutorial, we will understand what is meant by sublime number in java. From the point of the coding interview, it is one of the important topics. We will we will...

4 minutes read.

Practical Number in Java

In this tutorial, we will understand what is meant by practical numbers. We will understand it throughthe aid of examples and implementation in a java programming language. The practical numbers...

5 minutes read.

Java Editors

A straightforward text editor may be used to create Java applications. However, a Java integrated programming environment (IDE) enables the software developer to create programs more quickly. An IDE offers...

4 minutes read.

Display List of TimeZone with GMT and UTC in Java

It is vital to establish the right TimeZone in Java code when working with dates for Daylight Saving Time. In this part, we will present the time zones with GMT. TimeZone Those...

5 minutes read.

Java vs Scala

Java : Java is an object oriented programming language. It is also known as multi threaded language. It was designed by James gosling in the year 1995. We can also say...

4 minutes read.

Java Math acos() Method

The acos() method of Math class computes the trigonometric Arc Cosine (inverse of cosine ) of an angle. The value returned is between 0.0 to pi. Syntax: public static double acos(double a) Parameters: The...

1 minute read.

Sudoku in Java

Sudoku is a combinatorial-number-placement puzzle with a logic-based approach. The goal of a traditional Sudoku puzzle is to fill in the numbers on a 9 by 9 grid so that...

6 minutes read.

Java Externalization

What is Externalization in Java? Externalization is a concept that is advanced to serialization. Serialization is a concept where we can transfer an object from our JVM ( Java virtual machine...

3 minutes read.