Program to delete duplicates from a link list

How to do java in command prompt?

How to do java in command prompt?

How to compile and run Java program Here we will see how to write, compile and run Java program.

public class Firstjavaprogram{
public static void main (String[] args) {
System.out.println(“This is my first program in java”);
}// End of main
} // End of Firstjavaprogram class

Output:- This is my first program in java

How to compile and run the above written program?

For this you need to install java on your system.

Step 1

First of all open a text editor like Notepad on windows and TextEdit can be used on Mac. Copy the above program and paste it in the text editor. You can also use IDE to run java program, in the coming tutorial we will cover the IDE part. For the sake of simplicity, only the text editor and command prompt (or terminal) are used in this tutorial.

Step 2

Save or save the file as firstjavaprogram.java. Here the file name firstjavaprogram has been kept because in java the name of the file should always be given in the name of public class. in our program

Step 3

In this step, we will compile the program. For this, open command prompt (cmd) on windows, if you use Mac OS then open terminal. To compile the program, type the following command and hit enter.

javac firstjavaprogram.java

When you try to compile the program, you may get this error, “javac is not recognized as an internal or external command, operable program or batch file.” when in your system.

Step 4

After the compilation of the .java file, the .java file is translated into a .class file (byte code). Now we can run the program. To run or run the program, type the following command and enter.

java firstjavaprogram

It is important to note one thing here that when the java program is run, then the .java file extension is not written with the name of the file.

Now you must have understood how the java program is run, so now

public class Firstjavaprogram {

This is the first line of our java program. Every java application should have at least one class in which class name is followed by class keyword, here keyword means

It is important for you to know that there can be any number of classes in a java file but there can be only one public class in it.

public static void main (String args [] ) {

This is the next line of our java program, let’s understand it –

public – This makes the main method public, which means that the method can be called from outside the class.
static – There is no need to create an object to run a static method.

void – it does not return anything.
(String [] args) – It is used for command line arguments, which are passed as String, we will know these in the coming tutorial.

System.out.println(“This is my first java program”);

This method prints the content inside double quotes in the console, and then inserts a new line.

Also check this:-

codechef problems:-

Wipro :-

Infytq :-

Key Points;-

Hackerrank:-

C-tutorial:-

See more:-

Leave a Reply

Your email address will not be published.