r/javahelp • u/superAA_ • Apr 02 '16
help?
I am new trying to learn java programming i started watching "thenew****" Tutorials, everything was fine untill i reached the second video where i reach the command prompt part to load my code. When i want to put ex " java Hello.java" It says Error: Could not find or load main class. DOnt even know if i have the right java or version anyway this is it . jre1.8.0_45 . Hope i get helped.
1
u/Philboyd_Studge Apr 02 '16
post your code
1
u/superAA_ Apr 03 '16
class apples{ public static void main(String args[]){ System.out.println("HelloHP"); } }
1
u/nutrecht Lead Software Engineer / EU / 20+ YXP Apr 03 '16
When you're starting out make sure that every class you create is public, is in their own .java file and it matches the name of the Java file. So "public class Hello" should be in Hello.java and public class apples should be in apples.java (mind the casing!).
Also: in Java we PascalCase class names so please follow those naming conventions. To get you started:
public class Hello {
public static void main(String[] argv) {
System.out.println("Hello world!");
}
}Paste this into Hello.java (make sure the names match!) and you can compile it with javac Hello.java and run it with java Hello.
Also: programming is precise because computers are incredibly stupid. If you make up your own naming and just randomly change stuff without understanding what you did you're just going to fail 99% of the time.
Last but not least: the new boston is a horrible learning source. This course is much better.
1
u/superAA_ Apr 04 '16
I pasted your code there, when im in command prompt i typed javac Hello.java "javac is not recognized as an internal or external command,operable program or batch file" I also tried java Hello.java and it said could not find or load main class.
1
2
u/Your-Ma Apr 03 '16
im rubbing my forehead but i just cant visualize your work by Clairvoyance unfortunately.
Your gonna have to post your code for this one.
1
u/Rainbow_Rage Apr 03 '16
You need to use ´javac Hello.java´ to compile your code. Then you need to use ´java Hello´ to run it.
If you used a package, you need to use the full name of your class including the package with the Java command. So it would be ´java com.package.Hello´. The command also needs to be run from the root source directory, not the directory with the. Class file
1
u/empire539 "empire"+(((int)-~(byte)+('\''&~'&')<<(' '>>('+'+~'(')))+0x1b); Apr 02 '16
Try
java Helloinstead, after you've compiled usingjavac Hello.java.