×

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

Java throw

Java throw Sometimes it is required in the code to throw an exception deliberately. In order to achieve the same, the Java throw keyword should be used. One can throw either...

3 minutes read.

Heap Sort in Java

Heap Sort in JavaHeap sort in Java uses the data structure binary heap, min-heap, or max heap to do the sorting of elements. Since min-heap always gives the minimum element first,...

8 minutes read.

Arrow Operator in Java

The introduction of arrow functions in ES6 gives you a more precise approach to define JavaScript functions. We can write shorter function syntax thanks to them. Your code will be...

4 minutes read.

Difference Between Java and PHP

The two most used programming languages are PHP and Java. Both of them have a lot of similarities and distinctions. Let's first grasp each of them individually before examining their...

3 minutes read.

Java Command not found

Java Command not found error is displayed if Java is not installed on the computer or if the command prompt cannot find Java.exe to run the program. Our Java software...

3 minutes read.

Swastika Pattern in Java

This part teaches us how to create the Swastika Pattern in Java utilizing user-defined columns and rows as well as stars or other special characters.A Java pattern application that is...

2 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.

Structure of Java Program

Java is well-known as an object-oriented, secure, and platform-independent programming language. The Java programming language allows us to construct a wide variety of programs. Therefore, it is essential to fully...

6 minutes read.

Bean class in Java

The web applications that are created with the help of the JSP or Java Server Pages generally have fairly more functionality than the web pages that specifically are created with...

5 minutes read.

Least Operator to Express Number in Java

In this article, we will learn about how to obtain a target number using a single number or a single integer by leveraging least operators in Java. There can be...

3 minutes read.

Reverse a String using Collections in Java

Generally, a String is a grouping of characters. Yet, in Java, a String is an item that addresses a succession of characters. The Java.lang.String class is utilized to make a...

5 minutes read.

Java String

Definition A string is a series of characters. Consider an example, "Welcome" is a 7-character string. In Java, String is an unchangeable object. That is, the String is perpetual and cannot be replaced after it is created. This is the tutorial in which you...

4 minutes read.

Java Applications

The growth in technology is increasing rapidly, so some languages are used for developing them. Java is one such famous programming language which is having numerous applications. The Java Programming...

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.

Difference between print() and println() in Java

In this tutorial, we will discuss the differences between print and println in Java language. There are mainly two methods to display the text on the console printprintln The above two methods are...

4 minutes read.

Functional Interfaces in Java

Java has forever remained an Object-Oriented Programming language. By object-oriented programming language, we can declare that everything present in the Java programming language rotates throughout the Objects, except for some...

11 minutes read.

Java Integer doubleValue() method

The doubleValue() method of Integer class returns a double value for this Integer after a widening primitive conversion. Syntax public double doubleValue() Parameters NA Specified by This method is specified by doubleValue in class Number Return Value This...

1 minute read.

Volatile keyword in Java

Multiple threads can change a variable's value by using the volatile keyword. Making classes thread-safe is another application for it. It indicates that using a method or an instance of...

3 minutes read.

DatabaseMetaData in Java

The Data about another data is called Meta data. The DatabaseMetaData interface has the meta data of the database present in the system. It consists of database product name, total...

2 minutes read.

Java Math cos() Method

The cos() method of Math class returns the trigonometric cosine of the specified angle. Syntax: public static double cos(double a) Parameters: The parameter ‘a’ represents an angle measured in radians. Return Value: The cos() method returns...

1 minute read.