Question:
Why won't my "hello world" java script work?
unstablegecko
2011-09-19 18:06:01 UTC
I followed a tutorial on YouTube to make a java "hello world" program, and when i go to activate it on command prompt, it says there was an error access was denied. I'm very new at this, but im pretty sure this means it recognizes it as a functional class and there must be something going on in the background making it not work. If anyone can help me that would be great! thanks.
Four answers:
Silent
2011-09-19 18:15:12 UTC
First off: Java and JavaScript are not the same thing. Despite the similarity in names, they're two completely different and largely unrelated languages.



If you want us to help you fix your code, you're going to need to do two things:



1. Show us the code. Post your code at http://www.pastebin.com and include the link here. We can't tell you what's wrong with code we can't see.



2. Post the exact error message you received. Copy and paste it if you can. This is very important.
husoski
2011-09-20 02:10:14 UTC
It sort of depends on what you were doing when you got the message, doesn't it? If it really is JavaScript that you're trying to learn, you need to run that from a browser. If it's Java, then read on.



If "access denied" happens during the javac compile, your environment may not be set up right. Try:



javac -version



...at the command line. If that gives a nice normal response, like:

javac 1.6.0_26



...then you are probably good on that count. Next, try:

type MyJavaClass.java



...replacing "MyJavaClass" with your program's class name, which should match the source file name exactly, including captialization. If that fails, then your source file is not readable. Make sure that it's not open in some strange editor (most text editors don't lock out source files) and try deleting and recreating the file, making sure you create it on the same login that you intend to use to compile and run.



Here's a console session to try:

- - - - - tear here - - - - - -

C:\User\Husoski>javac -version

javac 1.6.0_26



C:\User\Husoski>copy con Sneeze.java

public class Sneeze {

public static void main(String args[]) {

System.out.println("Achoo!");

}

}

^Z

1 file(s) copied.



C:\User\Husoski>javac Sneeze.java



C:\User\Husoski>java Sneeze

Achoo!



C:\User\Husoski>dir Sneeze.*

Volume in drive C has no label.

Volume Serial Number is A42B-08C8



Directory of C:\User\Husoski



09/19/11 06:38 PM 412 Sneeze.class

09/19/11 06:38 PM 102 Sneeze.java

2 File(s) 514 bytes

0 Dir(s) 9,576,185,856 bytes free



C:\User\Husoski>

- - - - - tear here - - - - - -



If you can repeat that, you have a working JDK and can start looking at what's wrong with your Hello World program. (Note: The ^Z at the end of the source program means to type Ctrl+Z, followed by Enter. The command prompt will display "^Z" and close the console input to the copy command. That command is simply copying directly from the console (the "con" device) to a file named Sneeze.java in the current directory.)
modulo_function
2011-09-20 01:14:12 UTC
I don't do much javascript and so when I see a simple question it gives me the motivation to do the research to learn enough to make it work. It improves my javascript skills. It was with that in mind that I clicked on your question. What did I find? You're asking for help with code and you didn't tell use the code! Do you really think that we can help?



Also are you mixing up Java with javascript?
anonymous
2011-09-20 02:17:32 UTC
You're going to want to start with Java & NOT JavaScript. It's as simple as



System.out.println("Hello world!");



You should also get the program Eclipse for programming



http://www.eclipse.org/



http://www.eclipse.org/downloads/packages/eclipse-ide-java-ee-developers/indigor


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...