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

why can't we create an object for abstract class? why wait,notify,notifyall methods were in object class but not in thread class?
Abstract class is having an abstract method. It is empty method, created for future requirements, therefore usage is not certain by specifying objects to it.
Jilani
What are the various Java certifications?
The certifications are : 1) Oracle...
Rama
1 0
5
why string class is override in euals()/ hashCode Hethods?
Equals method and hash code methods compare two objects based the memory location occupied by objects. Two different objects always occupy two different locations in heap memory. So equals and hashCode...
Rami Reddy
What is the best site to learn Java for development?
https://beginnersbook.com/java-tutorial-for-beginners-with-examples/ This is the best website for Java beginners.
Chai
0 0
8

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

Ask a Question

Related Lessons

Features Of Java
There is given many features of java. They are also known as java buzzwords. The Java Features given below are simple and easy to understand. i. Simple ii. Object-Oriented iii. Portable iv. Platform...

Java Program Sample Application
/* WAP to print given message on the console using java*/ // Class declaration in java class sample { // Main function public static void main(String args) { // function for printing on the console System.out.println("Hello...
S

JAVA - Object Cloning
JAVA - Object Cloning Is the way of creating the same copy of object without calling the class constructor. It means we can make any class object multiple times without calling its default constructor....

Why Should We Learn Java Language?
Most of starters has confusion today that which of the programming language should be chosen to work on. It totally depends upon your need. As per my opinion, if you want to grow your career in IT industry...

Java Overview
Java platform overview Java platform components The Java platform consists of the following components. The Java language Like any programming language, the Java language has its own structure, syntax...
A

Akshay Shende

0 0
0

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