hello my friends
I've source code files for examples and solution for some exercises of the book that i learn java from .
when i want to run any file of them i have to make a new project and include this file through copy and paste
i feel that is a boring task .
i wonder if any one can give me an easier way than this???
thanks in advance
I Hear I Forget, I See I Remember, I Do I Understand.
If you don't want to use any IDE, then you could go for manual compilation and interpretation of the code. The following is the set of steps to do so.
1. Create a java file with some name like "Test.java" in java's home directory (Done only for the 1st time)
2. Copy paste the code in the file. If the class code you have, is public, then remove the public modifier in the class declaration and then save it.
3. Open cmd.exe and change to java's home directory. (Done only for the 1st time)
4. Compile using javac Test.java
5. Execute using java className
Afterwards, if you want to execute a new code, overwrite the existing code and save it. Cmd.exe saves all the commands that you type. So you could simply use the up arrow to compile. Only for executing you must just change the className to the new className in the example that you copied.
This might seem very tough, but once you try, it s the basic and the most easiest way.
If you want to use the NetBeans IDE, then just create a java project, and then create a new class file with whatever class name you want, inside the project.
Once you want to try executing a code, you simply copy paste the code in the source file which you have created now in the project. Definitely you will get an error stating that the class name is different from the file name. Since it is netbeans, it will show hints to the right hand side of the error line. Click on that yellow bulb to get a list of error-correction options.
Netbeans would show options for either correcting the class name or the file name. You simply click on the option that changes the file name. After that, you won't get any errors. You can simply do it for all the code you want to try.