• Post Reply Bookmark Topic Watch Topic
  • New Topic

Trying To Run My First Java App  RSS feed

 
David R James
Greenhorn
Posts: 10
1
Android Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys,

I am trying to run my first app which I have created in Notepad on Windows 10. I am reading the Head First Java book which encourages you to stay away from IDE's until the end of the book (I intent to use Android Studio). I have set up the JRE and the JDK and I have my simple first app:



I am launching cmd on Windows 10 and typing "javac MyFirstApp.java" but I am getting an error saying:

C:\Users\devda>javac MyFirstApp.java
javac: file not found: MyFirstApp.java
Usage: javac <options> <source files>
use -help for a list of possible options

The MyFirstJava.java file is on my Desktop and I have tried:

C:\Users\devda>javac -cp C:/Users/devda/Desktop
javac: no source files
Usage: javac <options> <source files>
use -help for a list of possible options

I can't seem to get it to find and compile the .java file.

Just wondering where I'm going wrong.

Thanks!
 
Liutauras Vilda
Marshal
Posts: 3961
214
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

Davey James wrote:typing "javac MyFirstApp.java" but I am getting an error

Davey James wrote:The MyFirstJava.java file is on my Desktop

Your public class name and source filename must match.
 
John Joe
Ranch Hand
Posts: 314
2
Android Eclipse IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Should be



 
Liutauras Vilda
Marshal
Posts: 3961
214
BSD
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
John Joe, good catch, that probably would be the next issue OP would encounter.

Have a cow for an eagle eye..
 
Dave Tolls
Ranch Hand
Posts: 2556
27
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The easiest fix is to cd to the Desktop from your command prompt.
From where you are at the moment that's simply 'cd Desktop'.
Then your original java command should work (assuming the file name is correct).

You will get other errors, but at least they will be compilation ones.
 
John Joe
Ranch Hand
Posts: 314
2
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Liutauras Vilda wrote:John Joe, good catch, that probably would be the next issue OP would encounter.
Have a cow for an eagle eye..

Thanks a lot 
 
Campbell Ritchie
Sheriff
Posts: 54051
130
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Davey James wrote:. . . . I am reading the Head First Java book which encourages you to stay away from IDE's until the end of the book (I intent to use Android Studio).
Quite right to avoid IDEs. You won't find anything about Android Studio in that book because it was written before Android was developed.
I have set up the JRE and the JDK . . .
The error messages you are getting suggest you have installed a JDK correctly; there is no need to install a JRE as well.
. . .
C:\Users\devda>javac -cp C:/Users/devda/Desktop
. . .
Thanks!
I would suggest you shou‍ld write
javac -cp C:/Users/devda/Desktop MyFirstApp.java
If you get different error messages, like complaints about the spelling error which John Joe found (well done finding that), have you set a System CLASSPATH environment variable? That is something which was necessary a long time ago, but nowadays a System CLASSPATH causes more trouble than it is worth.
I suggest you give the following instructions:-which will take you to a java directory (or such other name as you give it) and use cd java whenever you open the command line. I also suggest you see what happens if you writeIf you set the CLASSPATH from scratch, delete it. All of it. If you didn't set it yourself (some applications set a CLASSPATH while you aren't watching) add the following to its beginning .; (dot‑semicolon). That means “current directory”

And, again, welcome to the Ranch
 
David R James
Greenhorn
Posts: 10
1
Android Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dave Tolls wrote:The easiest fix is to cd to the Desktop from your command prompt.
From where you are at the moment that's simply 'cd Desktop'.
Then your original java command should work (assuming the file name is correct).

You will get other errors, but at least they will be compilation ones.


Thanks Dave, this fixed the issue I can now run the file with "javac MyFirstApp.java"!
 
David R James
Greenhorn
Posts: 10
1
Android Java MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yay I am making progress! You guys are awesome

There was a few syntax issues with the first code snippet but it's all working now.

@Dave Toll. Thanks very much for the "cd Desktop" command.

@John Joe. Big thanks for catching those sneaky errors



Thanks all for the nice welcome, it's a great community here!
 
Liutauras Vilda
Marshal
Posts: 3961
214
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well done for sorting out.

Nice application and output
 
Dave Tolls
Ranch Hand
Posts: 2556
27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Davey James wrote:
Thanks Dave, this fixed the issue I can now run the file with "javac MyFirstApp.java"!


No problem.
Note that that was the easy fix.
I would, if I were you, take note of Campbell's suggestion of creating a directory to put your projects in and getting used to using that instead of dumping it onto the desktop.
 
Campbell Ritchie
Sheriff
Posts: 54051
130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, I like the app Well done.

I still think you are better off creating a java directory instead of using the desktop. The reason will become obvious when you have 1000 Java® program icons all over that nice cliff picture.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!