Troubleshooting Java: "javac" Command Not Recognized

  • Context: Java 
  • Thread starter Thread starter JasonRox
  • Start date Start date
  • Tags Tags
    Introduction Java
Click For Summary

Discussion Overview

The discussion revolves around troubleshooting issues with the Java programming environment, specifically the "javac" command not being recognized in the command prompt and a related problem with integer division in Java. Participants explore potential solutions and clarify concepts related to Java's behavior in these contexts.

Discussion Character

  • Technical explanation
  • Conceptual clarification
  • Debate/contested

Main Points Raised

  • One participant reports that the "javac" command is not recognized and seeks assistance in resolving this issue.
  • Another participant suggests checking the PATH environment variable to ensure the directory containing "javac" is included.
  • A different participant provides an alternative method to set the PATH directly in the command line using the path command.
  • A new question is raised regarding the result of integer division in Java, specifically why the expression "double y = 2/3;" results in zero.
  • One participant explains that since both 2 and 3 are integers, the division yields an integer result, which is then converted to a double, leading to zero being stored in variable y.
  • Examples of correct usage are provided, including casting integers to doubles to achieve the desired result.
  • Another participant emphasizes the importance of understanding how programming languages process code step-by-step, noting that this can help in writing clearer code.

Areas of Agreement / Disagreement

Participants generally agree on the need to set the PATH variable for the "javac" command and on the explanation of integer division in Java. However, there are no explicit resolutions to the initial problem of the "javac" command not being recognized, and the discussion on integer division presents a conceptual clarification rather than a consensus.

Contextual Notes

Limitations include the assumption that participants have a basic understanding of environment variables and Java syntax. The discussion does not resolve the initial issue of the "javac" command, and the explanation of integer division relies on specific programming behavior that may not be universally applicable without further context.

Who May Find This Useful

Individuals learning Java programming, those troubleshooting Java installation issues, and participants interested in understanding integer division and type casting in programming languages may find this discussion relevant.

JasonRox
Homework Helper
Gold Member
Messages
2,394
Reaction score
4
Alright, I did the whole Hello World! thing, but I got stuck on one part.

I downloaded the Sun.Java thing, but now when I go into the command prompt and to try and compile it... the computer does not recognize the "javac" command.

What's going on? Is there another program?
 
Technology news on Phys.org
Make sure the javac program is in your PATH environment variable. It's usually in c:\j2sdk1.4.2\bin\, for example.

Right click on My Computer, hit Properties, Advanced, Envrionment Variables, and add this directory to the PATH.

- Warren
 
Before you can use the javac command you need to set the path with the path command. Depending on the folder where you jsdk is installed you can type something like this in the command line:
Code:
path "C:\Program Files\j2sdk_nb\j2sdk1.4.2\bin"
and press Enter.
 
A simple question about one of the Java exercises they have.

Why is my 2/3 coming out as zero?

Here is the exact line of declaration:

double y = 2/3;

It doesn't get any easier than that. I tried with brackets around it too. I also tried 1/3 + 1/3, with brackets.

The only way it seems to work is like this...

double x=2;
double y=x/3;

This is not efficient at all, nor practical when I go into loops.

What's the problem?
 
Because 2 and 3 are integers. You have to explicitly cast these as doubles or use 2.0 and/or 3.0.

Code:
import java.util.*;

public class test {

    public static void main (String args[]) {
        double y = 2.0/3;
        System.out.println(y);
    }
}

[edit] Ok, here's what's going on. Java reads the code on the right of the equal sign and performs whatever task is required. Java then yakes the result and stores that in the desired format of the variable. In your case, you are dividing an integer 2 by the integer three. 3 doesn't go evenly into 2 so the result is zero. 0 is converted to a double(0.0) and then stored into your variable y. The above code is one way around this or you can do the following:

Code:
import java.util.*;

public class test {

    public static void main (String args[]) {
        double y = (double)2/3;
        System.out.println(y);
    }
}

Programming languages are not very smart. They don't see the left and right sides at the same time as we do. The see things as a series of steps. If you start thinking in steps then your code will come a little easier.
 
Last edited:
Thanks!

I appreciate it.
 
Programming languages are not very smart. They don't see the left and right sides at the same time as we do. The see things as a series of steps. If you start thinking in steps then your code will come a little easier.

So the poster doesn't get the wrong impression, this fact is often a good thing. While it would be nice for the compiler to figure out what we really meant, it would be extraordinarily annoying when the compiler guesses wrong.
 

Similar threads

  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 25 ·
Replies
25
Views
3K
Replies
17
Views
6K
  • · Replies 2 ·
Replies
2
Views
6K
  • · Replies 2 ·
Replies
2
Views
2K
Replies
14
Views
4K
Replies
4
Views
2K
  • · Replies 3 ·
Replies
3
Views
15K
  • · Replies 12 ·
Replies
12
Views
5K
  • · Replies 3 ·
Replies
3
Views
7K