Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Running Book Examples

 
Roger Fed
Ranch Hand
Posts: 82
Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Hari r.haran
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Could you please tell which IDE you use for running the source code?

Regards,

Hari
 
Roger Fed
Ranch Hand
Posts: 82
Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm very sorry for this
IDE: NetBeans
 
Hari r.haran
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hi,

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.

Thanks and regards

Hari
 
Hari r.haran
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi again,

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.

Regards,

Hari
 
Roger Fed
Ranch Hand
Posts: 82
Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your help but i want to use NetBeans not command prompt as i seek to use the debugger and
other tools in this IDE
so, I'd be grateful if you can help me in this
 
Roger Fed
Ranch Hand
Posts: 82
Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks again but you don't fix my problem that i state in main topic
 
Hari r.haran
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you don't even want to copy and paste the code?
 
Roger Fed
Ranch Hand
Posts: 82
Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I ask about make a directory or something like this
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic