Cyber Monday Deal : Flat 30% OFF! + free self-paced courses  - SCHEDULE CALL

- Java Blogs -

What Is The Solution Of Java Error: Command Not Found?

Having Java installed on your system allows you to run and possibly compile Java programs. If your system does not know where to look for the command you have entered then probably it will show the error-

java: command not found

When you are trying to run the “Java” command, but the compiler is showing the above error, this means the command is not found in the shell search path, or there may be other possible reasons which will be discussed in this blog.

Why do you see the error message: Command not found?

Human beings operate a Computer with the help of commands. While writing the software program, you may have dealt with several commands. If your program shows command not found an error, then it means that the computer is unable to find the program by that name. Before you ask your administrator for help, please consider the following points-

  • Check the name of the command and confirm that there is no typo
  • Ensure that Java is installed in your system
  • Check out the path of the file
  • Command syntax may be entered incorrectly
  • The user’s “path” is incomplete or it has been erroneously set, reset, or removed (this is the most common reason)

Fortunately, all the errors mentioned above can be resolved easily and get the common working again as expected.

Problem Description

When you are trying to run the Java code using Java IDE or command prompt, you may encounter the error java command not found. This error can occur while running Java on any of the platforms like Windows, Linux, or Mac. The solution to this error is the same for all the platforms. Only it varies at-

  • Downloading Java for Windows/Linux/Mac
  • Downloading JDK as per the size of the Windows (32 bit, 64 bit or 128 bit)
  • Different ways of troubleshooting Java errors at different platforms

Possible Reasons and Solutions of Java command Not Found

1). Reason: Java is not installed in your system

Solution: Download and Install the latest version of Java in your system using the internet.

java command not found

Read: Top Java Developer skills To Have For Better Employment Opportunities

Now, in order to make sure that Windows is able to find Java compiler and interpreter, open Command Prompt (cmd) and do the following-

  • 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

Now, to check the version of Java, type the following boldface text. You will see the similar information mentioned below-


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)

Now type-


C:\Users\username>javac -version
javac 1.6.0_27

Now, you can compile your Java program using javac command to convert your Java program into an amendable form of a computer. You can use cmd or ide for this.

For cmd-


C:\Users\username>cd c:\introcs\hello
C:\introcs\hello\>

 If your file HelloWorld.java is in the current working directory, then type-


C:\introcs\hello\>javac HelloWorld.java
C:\introcs\hello\>

Now, as everything went well with no error messages, you are ready to execute the Java program.


C:\introcs\hello\>java HelloWorld
Hello, World

The output of your program will be Hello, World

2). Reason: Path is not correct

java command not found

Read: Frequently Asked J2EE Interview Questions and Answers You Must Read

Solution: Check out the values of the path variable using Command Prompt with the following command-

C:\introcs\hello\> echo %PATH%

The path should begin with

C:\Program Files\Java\jdk1.6.0_27\bin;

Ensure that you have reopened Command Prompt after you have edited the PATH environment variable. You might need to reboot the system to see the modification of environment variable. 

You can make the path of your JDK permanent in your system by following these steps, but PROCEED WITH EXTREME CAUTION-

  • Go to Control Panel, choose "System," click on the "Advanced system settings" link, click on the "Environment variables" button. In the lower list, "System variables," click on Path:java command not found
  • Click "Edit" and at the end append

C:\Program Files\Java\jdk1.8.0_51\bin

  • (or the path to the appropriate folder where the latest version of JDK is installed).  Do not put spaces before the appended path string.
  • Click OK on the path edit box and OK on the Environment Variables box.  The new setting will go into effect next time you run Command Prompt. 

3). Reason: A Typo

Solution: A typo is a misprint or a spelling mistake made in a while typing. After all, the one who is giving a command to the computer is a human being. If you are making use of IDE, then you can use several editors available to write Java programs. Editors like SublimeText, Eclipse, NetBeans, IntelliJ Idea, Dr.java, JCreator, AndroidStudio, etc. are few of the Java editors which you can use to avoid typos. While writing a Java program in these editors, you will get an “autocomplete” suggestion for the usage of every Library function or the pre-loaded classes available in Java compiler. This autocomplete feature in IDE will help you from making silly typos. For example, if you are writing some looping structure and you are not confident about the syntax. Then start typing a loop (let’s say foreach loop), you will see just when you start typing the name of the loop, you will be able to see related suggestions with it. Now, you can choose the loop you want to choose, and it will complete the rest of the syntax. Only, you need to add your functions and values to it. Smart enough, right! 

java command not found

Read: Java Access Modifiers - Public, Private, Protected & Default

4). Reason: Check if you’re running through CMD or IDE

Solution: Well, if you get a “command not found” error while writing a Java program, then check initially in which platform you are compiling in. Whether it is command prompt or IDE.

  • When you compile your Java program in the command prompt, if you get the same command error then make sure to your text file of Java program.
  • If javac runs but still you get an error, then check your program syntax in the Java text file and check the name of the file (it should be same as the name of class_name)
  • If javac does not run then check the path of the file or check the path of JDK in the environment 

5). Reason: Internal or External Command error 

java command not found

Solution: While compiling a Java program, the most common issue a programmer gets is “Javac is not recognized as an internal or external command”. You can fix this issue in the following ways: -

  • Check whether JDK is installed in your computer
  • If JDK is installed, then check the PATH environment variable points to the Java executable directory. For this, open command prompt then runs “set path.” This will print the current value of the path environment variable. Here, you can see list of directories added. Now, check here if Java SDK path is added or not. If it is added then it should look something like this-

c:\>set path
Path=C:\Program Files (x86)\Windows Resource Kits\Tools\;
C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;
C:\WINDOWS\System32\WindowsPowerShell\v1.0\;
C:\Program Files (x86)\Quarantine\;
C:\Program Files\Perforce;
C:\Program Files\Microsoft Network Monitor 3\;
c:\Program Files\Java\jdk1.7.0_17\bin

If the JDK path is not added, then you can add by the following command on command prompt. Check the folder “C:\Program Files\java” and “c:\Program Files (x86)\java” to find the exact path. If you already have PATH set with the java location, check one more time if you have added path till the bin folder. So, adding c:\Program Files\Java\jdk1.7.0_17 is not correct. You need to add c:\Program Files\Java\jdk1.7.0_17\bin

6). Reason: Syntax Error

Solution: If javac error is there, then check for the proper syntax of all the Java components you have used. Sometimes, there can be a mistake while writing the syntax of Java commands. For instance, if you try to create an if statement that does not include the condition in parentheses, but you have mentioned the condition statement in the same line as if statement, this is a syntax error. There can be other syntactical errors also-

  • Using incorrect capitalization
  • Splitting a string into two lines (maybe a typo)
  • Missing parentheses
  • You forgot to import a class
  • You are treating a static method as an instance method
  • You missed use of curly braces
  • You might have forgotten the class or object name as a part of the calling method
  • You forgot to use break clause in the switch statement
  • You forgot to use a return statement
  • You have mistyped the header in the main() method 

7). Reason: JVM is not detected

Solution: Another reason why your compiler is unable to recognize the command you have entered is that it might not have recognized or detected JVM. Java Virtual Machine (JVM) is the engine that drives the Java code. It is responsible for the conversion of Java bytecode into machine language. In this case, you only need to check the path of JDK by following these steps: -

  • Go to My computer, right click and select properties; another dialogue box will appear and then select advanced system settings.java command not found
  • A new window will appear in which you have to search for Environment Variablesand click on it to open it.
  • Now click on new and in variable name field write path and in variable value field paste the path of the JDK installation as shown. Here, paste the path of your java installation directory and version.java command not found
  • Click Ok and save everything and now try opening IDE to run your Java program. 

8). Reason: Command is not recognized

Solution: Possible reasons, in this case, maybe-

  • You have entered a wrong command
  • You have not followed the proper syntax
  • You are not using compilation commands in the right manner
  • You are following wrong steps to compile a Java program using cmd
  • You are following wrong steps to compile a Java program using Java IDE
  • You might be compiling a program from another folder, but the program is in another folder
  • Recheck the syntax of a Java program

Conclusion

Above are some of the possible reasons and the solutions for the Java error – “command not found.” You can learn more important concepts of Java programming like Exception handling, Multithreading, Java with Networking, Java Servlets, Java Frameworks (Struts, Hibernate, etc.), and can perform sample projects and get the hands-on experience with Java at JanBask Training. Enroll yourself now or talk to our counselor.

Read: Java ArrayList: What It Is & How To Create An Arraylist In Java


fbicons FaceBook twitterTwitter lingedinLinkedIn pinterest Pinterest emailEmail

     Logo

    JanBask Training

    A dynamic, highly professional, and a global online training course provider committed to propelling the next generation of technology learners with a whole new way of training experience.


  • fb-15
  • twitter-15
  • linkedin-15

Comments

Trending Courses

Cyber Security Course

Cyber Security

  • Introduction to cybersecurity
  • Cryptography and Secure Communication 
  • Cloud Computing Architectural Framework
  • Security Architectures and Models
Cyber Security Course

Upcoming Class

2 days 14 Dec 2024

QA Course

QA

  • Introduction and Software Testing
  • Software Test Life Cycle
  • Automation Testing and API Testing
  • Selenium framework development using Testing
QA Course

Upcoming Class

8 days 20 Dec 2024

Salesforce Course

Salesforce

  • Salesforce Configuration Introduction
  • Security & Automation Process
  • Sales & Service Cloud
  • Apex Programming, SOQL & SOSL
Salesforce Course

Upcoming Class

2 days 14 Dec 2024

Business Analyst Course

Business Analyst

  • BA & Stakeholders Overview
  • BPMN, Requirement Elicitation
  • BA Tools & Design Documents
  • Enterprise Analysis, Agile & Scrum
Business Analyst Course

Upcoming Class

2 days 14 Dec 2024

MS SQL Server Course

MS SQL Server

  • Introduction & Database Query
  • Programming, Indexes & System Functions
  • SSIS Package Development Procedures
  • SSRS Report Design
MS SQL Server Course

Upcoming Class

1 day 13 Dec 2024

Data Science Course

Data Science

  • Data Science Introduction
  • Hadoop and Spark Overview
  • Python & Intro to R Programming
  • Machine Learning
Data Science Course

Upcoming Class

2 days 14 Dec 2024

DevOps Course

DevOps

  • Intro to DevOps
  • GIT and Maven
  • Jenkins & Ansible
  • Docker and Cloud Computing
DevOps Course

Upcoming Class

5 days 17 Dec 2024

Hadoop Course

Hadoop

  • Architecture, HDFS & MapReduce
  • Unix Shell & Apache Pig Installation
  • HIVE Installation & User-Defined Functions
  • SQOOP & Hbase Installation
Hadoop Course

Upcoming Class

8 days 20 Dec 2024

Python Course

Python

  • Features of Python
  • Python Editors and IDEs
  • Data types and Variables
  • Python File Operation
Python Course

Upcoming Class

9 days 21 Dec 2024

Artificial Intelligence Course

Artificial Intelligence

  • Components of AI
  • Categories of Machine Learning
  • Recurrent Neural Networks
  • Recurrent Neural Networks
Artificial Intelligence Course

Upcoming Class

2 days 14 Dec 2024

Machine Learning Course

Machine Learning

  • Introduction to Machine Learning & Python
  • Machine Learning: Supervised Learning
  • Machine Learning: Unsupervised Learning
Machine Learning Course

Upcoming Class

15 days 27 Dec 2024

 Tableau Course

Tableau

  • Introduction to Tableau Desktop
  • Data Transformation Methods
  • Configuring tableau server
  • Integration with R & Hadoop
 Tableau Course

Upcoming Class

8 days 20 Dec 2024

Search Posts

Reset

Receive Latest Materials and Offers on Java Course

Interviews