I need help setting up my program for java. I can not do anything I believe the directory path is incorrect.
Cant save it for save it for some reasons. If you can leave a comment in death of step by step of I need to do that would be great.
I need help setting up my program for java. I can not do anything I believe the directory path is incorrect.
Since Windows vista, writing files to C:\Program Files
is only allowed by the administrator user. Unless the application has been started with administrator priviledges it wont be able to save anywhere inside that folder.
Change your save path to somewhere else, like your Documents folder that the windows popup indicates!
@michalisb I will change the path when I get a chance but it would ask if I would like to save it there and I do. How would I make the build file or what ever I need to run the hello world Java?
First things first, Java is not a language I know much - I am only familiar with it because I did a semester at uni 15 years ago! So, take anything I say with a pinch of salt.
Secondly, sublime is not an IDE but with the help of plugins, syntax definitions and various configuration files it can feel pretty close.
One of those configuration files is for the build systems which you need to familiarise yourself.
I am going to assume that you have the JDK already installed, in your system path and the following works through the command line:
javac MyFancyApp.java
MyFancyApp
java MyFancyApp
Through sublime, select Tools
from the menu, Build System
and then New Build System...
; delete everything in that file and paste the following:
{
"cmd": ["javac", "$file_name", "&&", "java", "$file_base_name"],
"working_dir": "${project_path:${folder}}",
"file_regex": "^(...*?):([0-9]*):?([0-9]*)",
"selector": "source.java",
"shell": true
}
Save this file with an appropriate name (i.e JavaRun.sublime-build
) in the sublime packages folder, which should be the one opened when you elect to save - something along the lines of C:\Users\<your user name>\AppData\Roaming\Sublime Text 3\Packages\User
Now, if you inspect Tools > Build Systems
the new build system should be selected (or select it if not).
Switch to your java file (i.e MyFancyApp.java
bellow) and select Tools > Build
or Ctrl + B
it should print ‘Hello World!’.
class MyFancyApp {
public static void main(String[] args) {
System.out.println("Hello World!"); // Display the string.
}
}
The way that this works is by specfying the command that should be executed when running the build. This is the "cmd"
argument in the build system which will call javac
on the $file_name
, in this case sublime will grab the file name from the tab with your source file. If this was succesful it will then execute java
and the $file_base_name
(the name of the source file without extension).
The rest of the arguments are to specifiy the working directory and how it should handle errors if any, the details can be found in the link about build systems above.
Finally, this is a very simplistic build system, that will only work if you code is contained in a single file or you have already build the dependencies also the name of the file should match (case sensitive) with the name of the class; in the end though, it should get you started.
I have the Java installed but im not sure if this is the right place or not or if i have to go deeper?
If there is a way to share screens even on like Skype that would help a lot. I am going to be on all day so if u wanted to add me let me know to make it go faster.
Couple of things:
What you have there is the JRE - Java Runtime Environment, which is aimed for end users - people running your code. As I mentioned before, what you need to build code, is the Java Development Kit (JDK).
I know that is a lot of information to keep in mind and it can be hard, but one of the most useful skills as a programmer in training is to learn how to search and find the information you need and it never stops being useful.
As simple googling for setting up for java programming
is going to give a 1000 + 1 tutorials.