UrbanPro

Learn Java Training from the Best Tutors

  • Affordable fees
  • 1-1 or Group class
  • Flexible Timings
  • Verified Tutors

Search in

how to run a java program

Asked by Last Modified  

20 Answers

Learn Java

Follow 0
Answer

Please enter your answer

Computer Science Tutor

go to command prompt then write the following-- For compilation: javac filename.java then press enter For run: java classname then press enter
Comments

Java "name of your class which contains your main method" Example : java sample Note : you need to compile before you run your program (javac filename.java)
Comments

Hello Prem Kumar :-). Here is a complete detail of how to run Java Program with other information which is as follows: Java and the Windows Command Prompt ****************************************** This document instructs you on how to use the Windows Command Prompt with Java. These instructions...
read more
Hello Prem Kumar :-). Here is a complete detail of how to run Java Program with other information which is as follows: Java and the Windows Command Prompt ****************************************** This document instructs you on how to use the Windows Command Prompt with Java. These instructions are specialized to Windows 7, but are similar for Windows... more» read less
Comments

Training Centre

Two ways you can run a Java Program. 1- Through cmd prompt, 2- Through Eclipse. 1- cmd prompt (Write your program and save the file with .java extension. Now open your cmd prompt and give the java file location. (a)- Now type the command "javac yourfilename.java" and click on ENTER button. This will...
read more
Two ways you can run a Java Program. 1- Through cmd prompt, 2- Through Eclipse. 1- cmd prompt (Write your program and save the file with .java extension. Now open your cmd prompt and give the java file location. (a)- Now type the command "javac yourfilename.java" and click on ENTER button. This will compile the program and checks whether you have syntax error. (b)- Now type the next command "java className" and click on ENTER button. Now the program will run. 2- If you are running in Eclipse. Just click on the RUN button at the topmenu. read less
Comments

Software Developer, Expertise in Java/J2ee Technology.

In command prompt, go to java program file location : a.) Compile via command :- javac FileName.java b.) Run via command :- java ClassName Note : FileName is name of java file, which can contain one or more classes. ClassName is name of one of the class in file ie class which...
read more
In command prompt, go to java program file location : a.) Compile via command :- javac FileName.java b.) Run via command :- java ClassName Note : FileName is name of java file, which can contain one or more classes. ClassName is name of one of the class in file ie class which is needed to run ( usually class containing main() method ). read less
Comments

G Chandra babu

If you java beginer just user Notepad or EditPlus editor to write a java program just follow the bellow steps to compile and run a java program steps: 1. develop/ write java code that contain main method 2.save the program as "anyfilename.java"....Note*: you should save with extension of...
read more
If you java beginer just user Notepad or EditPlus editor to write a java program just follow the bellow steps to compile and run a java program steps: 1. develop/ write java code that contain main method 2.save the program as "anyfilename.java"....Note*: you should save with extension of file ".java" 3.open command prompt and change location of developed java program area 4.here just complie the java program using javacompile syntax for compiling: c:\>javac anyfilename.java (press enter) java compliler is successfully compiles the program 5.Now run the compiled program using "java interpretter program" sysntax for running a java program using "java interpretter program" c:\>java anyfilename (press enter) 6.now output of the program is shown on your console. Hope this article help you understand how to compile and run a java program. if you like the article please like read less
Comments

Hello Prem Kumar :-). Here is a complete detail of how to run Java Program with other information which is as follows: Java and the Windows Command Prompt ****************************************** This document instructs you on how to use the Windows Command Prompt with Java. These instructions...
read more
Hello Prem Kumar :-). Here is a complete detail of how to run Java Program with other information which is as follows: Java and the Windows Command Prompt ****************************************** This document instructs you on how to use the Windows Command Prompt with Java. These instructions are specialized to Windows 7, but are similar for Windows XP and Windows Vista. Java You will use the Java compiler javac to compile your Java programs and the Java interpreter java to run them. You should skip the first step if Java is already installed on your machine. Download and install the latest version of the Java Platform, Standard Edition Development Kit (Java SE 6 Update 27). Note the installation directory for later—probably something like C:\Program Files\Java\jdk1.6.0_27\bin. To make sure that Windows can find the Java compiler and interpreter: Select Start -> Computer -> System Properties -> Advanced system settings -> Environment Variables -> System variables -> PATH. [ In Vista, select Start -> My Computer -> Properties -> Advanced -> Environment Variables -> System variables -> PATH. ] [ In Windows XP, Select Start -> Control Panel -> System -> Advanced -> Environment Variables -> System variables -> PATH. ] Prepend C:\Program Files\Java\jdk1.6.0_27\bin; to the beginning of the PATH variable. Click OK three times. Command-line interface You will type commands in an application called the Command Prompt. Launch the command prompt via All Programs -> Accessories -> Command Prompt. (If you already had a command prompt window open, close it and launch a new one.) You should see the command prompt; it will look something like: Microsoft Windows [Version 6.1.7600] Copyright (c) 2009 Microsoft Corporation. All rights reserved. To check that you have the right version of Java installed, type the text in boldface below. You should see something similar to the information printed below. (It's important that you see the number 1.6 or 1.5 for the Java version number, but the rest is not critical.) C:\Users\username>java -version java version "1.6.0_27" Java(TM) 2 Runtime Environment, Standard Edition (build 1.6.0_27-b07) Java HotSpot(TM) Client VM (build 1.6.0_27-b13, mixed mode, sharing) Then type: C:\Users\username>javac -version javac 1.6.0_27 Since you will be using the Command Prompt frequently, we recommend customizing the default settings. Right-click the title bar of an open Command Prompt window, select Properties and then: Set Layout -> Screen Buffer Size to 80 x 500. Select Options -> Edit Options -> QuickEdit Mode. Select Options -> Edit Options -> Insert Mode. Compile the Program You will use the javac command to convert your Java program into a form more amenable for execution on a computer. From the Command Prompt, navigate to the directory containing your .java files, say C:\introcs\hello, by typing the cd command below. C:\Users\username>cd c:\introcs\hello C:\introcs\hello\> Assuming the file, say HelloWorld.java, is in the current working directory, type the javac command in boldface below to compile it. C:\introcs\hello\>javac HelloWorld.java C:\introcs\hello\> If everything went well, you should see no error messages. Execute the Program You will use the java command to execute your program. From the Command Prompt, type the java command below. C:\introcs\hello\>java HelloWorld Hello, World If all goes well, you should see the output of the program - Hello, World. Input and Output If your program gets stuck in an infinite loop, type Ctrl-c to break out. If you are entering input from the keyboard, you can signify to your program that there is no more data by typing Ctrl-z for EOF (end of file). On some DOS systems the first line of output sent to the screen after you enter EOF will be rendered invisible by DOS. This is not a problem with your code, but rather a problem with DOS. To help you debug your program, we recommend including an extra System.out.println(); statement before what you really want to print out. If anyone knows of a better fix, please let us know! Troubleshooting Here are a few suggestions that might help correct any installation woes you are experiencing. If you need assistance, don't hesitate to contact a staff member. When I type, "java -version" I get an error. Check that you edited your PATH environment variable as indicated. A missing ; or an added % is enough to screw things up. Close and re-open a command prompt. Type path at the command prompt and look for an entry that includes C:\Program Files\Java\jdk1.6.0_27\bin;. Check that the version number 1.6.0_27 matches the one you installed—Oracle updates Java periodically and you might have a more recent version. If this doesn't fix the problem, check if you have any old versions of Java on your system. If so, un-install them and re-install Java. The command "java -version" works, but not "javac -version". Any thoughts? It's likely a path issue. Try the suggestions from the previous question. Also check that you installed the JDK properly by checking that the folder C:\Program Files\Java\jdk1.6.0_27\bin exists. How can I check the values of my PATH variable? Type the following at the command prompt. C:\introcs\hello\> echo %PATH% The PATH variable should begin with C:\Program Files\Java\jdk1.6.0_27\bin; Be sure to open the command prompt after you have edited the PATH environment variable. You may also need to reboot for the environment variable change to take effect. I can compile with javac, but I get the error message "Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorld" when I try to execute it with java. First, be sure that HelloWorld.class is now in the current directory. Be sure to type java HelloWorld without a trailing .class or .java. Check that the command "java -version" works. Now try to execute with "java -cp . HelloWorld". If this works, you need to edit your classpath. (iTunes has a proclivity for changing the classpath, so if you recently upgraded iTunes, this is likely the source of the problem.) Where can I learn more about the Windows command line? Here is a short tutorial on the Windows command prompt. Microsoft maintains a complete command line reference. How do I change my directory to the H: drive from the Windows Command Prompt? Type H: at the command prompt. Then cd to the appropriate directory. read less
Comments

Software Developer and Trainer with 10 years of experience

You can run a java program either using any IDE(Integrated Development Environment) like Eclipse or Netbeans or simply through the Command Prompt. As you seems to be beginner, I discuss only about running it in command prompt. First, type your java program in any plain text editor like notepad and...
read more
You can run a java program either using any IDE(Integrated Development Environment) like Eclipse or Netbeans or simply through the Command Prompt. As you seems to be beginner, I discuss only about running it in command prompt. First, type your java program in any plain text editor like notepad and save it in a folder. While saving, name the file by the class name that contains the main function in the program. Save it with .java extension. Before running the program, you have to install Java Development Kit (jdk). Also you need to set the java environment variable. Next, you have to compile your program. To do so, use the "javac" command. Type javac filename.java to compile. If you encounter any errors, clear it and recompile again. Once the compilation is successful, a filename.class file will be created in the same folder where you have stored your .java file. Now your program is ready to run. To run your program use "java" command. Type java classname (same as filename). Now your program will be executed. Hope this will help you . . . Wish you to execute successfully . . . read less
Comments

Unlocking the Power of Education: Transforming Lives Through Expert Java and Salesforce Instruction

Java programs run on the top of JVM which is nothing but the run time engine or support for the java compiled code which allocates the required resources to execute java compiled code. After the completion of the program JVM releases the allocated resources. Simply key in " java program name "...
read more
Java programs run on the top of JVM which is nothing but the run time engine or support for the java compiled code which allocates the required resources to execute java compiled code. After the completion of the program JVM releases the allocated resources. Simply key in " java program name " where program name is a compiled class name containing main function. read less
Comments

First step is JDK installation. After that we need to set the environment variables so that java and javac are available in the class path. Post that the above options suggested can be used.
Comments

View 18 more Answers

Related Questions

I completed my graduation in 2017, now working as an HR Executive in a Consultancy. I want to move to IT Sector. Which course is best for me to learn and get success in life? Please Suggest me
Dear Kumar, My suggestion is to - become good in one programming language - preferably Java and one O/S preferably Linux. Be aware of Open Source systems. Try to identify the opportunities in your existing...
Kumar
What are the advance features in java 1.8 when compare to java 1.6?
Many are there. 1. Lambda expression (functional Programming). 2. Default methods in interfaces.
Naresh N
Which is best to build web applications: PHP, Python, or Ruby? Why?
I have used almost all of the three language in my web working experience.PHP:It may be not that cool and I think it doesn't rely too much on the framework. Yes, PHP is just a language, but it is the only...
Sunil
0 0
7

Now ask question in any of the 1000+ Categories, and get Answers from Tutors and Trainers on UrbanPro.com

Ask a Question

Related Lessons

Java : Compile-time Versus Runtime optimization
While designing and development, one should think in terms of compile-time and run-time.It helps in understanding language basics in a better way.Let's understand this with a question below : What...
S

Java8 Filters and collectors
Lets say we have collection of strings and we would like to filter (remove) out certain strings from collection. We could achive the same in java 7 and earlier versions import java.util.ArrayList; import...

Syntax and example of java
Java syntax: Class Display - - class definition { Void Display() { System.out.println('welcome to Java') ; } Public static void main(String arcs) { Display D=new Display() ;--object creation D. Display } }

Java Hash Map internal implementation
1.Hash Map internal implementation: In hash map it will create an array of table (to store the {Key,Value} pair) which is of type java.util.HashMap.EntryThe Entry object contains {hash, key, next, value}...
R

How to create a Singleton class?
How to create a Singleton class: Q) What is a singleton class? A) In simple words, a singleton class is a class which can have only one instance at any point of time throughout the application and provides...

Recommended Articles

Before we start on the importance of learning JavaScript, let’s start with a short introduction on the topic. JavaScript is the most popular programming language in the world, precisely it is the language - for Computers, the Web, Servers, Smart Phone, Laptops, Mobiles, Tablets and more. And if you are a beginner or planning...

Read full article >

Designed in a flexible and user-friendly demeanor, Java is the most commonly used programming language for the creation of web applications and platform. It allows developers to “write once, run anywhere” (WORA). It is general-purpose, a high-level programming language developed by Sun Microsystem. Initially known as an...

Read full article >

In the domain of Information Technology, there is always a lot to learn and implement. However, some technologies have a relatively higher demand than the rest of the others. So here are some popular IT courses for the present and upcoming future: Cloud Computing Cloud Computing is a computing technique which is used...

Read full article >

Java is the most famous programming language till date. 20 years is a big time for any programming language to survive and gain strength. Java has been proved to be one of the most reliable programming languages for networked computers. source:techcentral.com Java was developed to pertain over the Internet. Over...

Read full article >

Looking for Java Training Classes?

Learn from the Best Tutors on UrbanPro

Are you a Tutor or Training Institute?

Join UrbanPro Today to find students near you
X

Looking for Java Training Classes?

The best tutors for Java Training Classes are on UrbanPro

  • Select the best Tutor
  • Book & Attend a Free Demo
  • Pay and start Learning

Learn Java Training with the Best Tutors

The best Tutors for Java Training Classes are on UrbanPro

This website uses cookies

We use cookies to improve user experience. Choose what cookies you allow us to use. You can read more about our Cookie Policy in our Privacy Policy

Accept All
Decline All

UrbanPro.com is India's largest network of most trusted tutors and institutes. Over 55 lakh students rely on UrbanPro.com, to fulfill their learning requirements across 1,000+ categories. Using UrbanPro.com, parents, and students can compare multiple Tutors and Institutes and choose the one that best suits their requirements. More than 7.5 lakh verified Tutors and Institutes are helping millions of students every day and growing their tutoring business on UrbanPro.com. Whether you are looking for a tutor to learn mathematics, a German language trainer to brush up your German language skills or an institute to upgrade your IT skills, we have got the best selection of Tutors and Training Institutes for you. Read more