| Author |
A few questions since I am new to Java
|
Dj Driver
Greenhorn
Joined: Nov 11, 2011
Posts: 16
|
|
Just got my Head First Java, 2nd edition Covers Java 5.0 and have a few questions:
-I wrote my first code in a .txt file and then renamed it to .java - is that the way to start off and they way to continue?
-when I execute my java code it flashes on the screen and then goes away. How do I get it to stay on the screen so I can view it?
-is there a java editor I can use so I can see if there is an error in my code before I try to run it?
Thanks in advance
|
 |
W. Joe Smith
Ranch Hand
Joined: Feb 10, 2009
Posts: 710
|
|
Dj Driver wrote:Just got my Head First Java, 2nd edition Covers Java 5.0 and have a few questions:
-I wrote my first code in a .txt file and then renamed it to .java - is that the way to start off and they way to continue?
Normally I just open a new Notepad, and save it as a .java. No need to rename.
-when I execute my java code it flashes on the screen and then goes away. How do I get it to stay on the screen so I can view it?
What do you mean "when I execute"? Are you running from a command prompt? What is the code doing? If all the code does is add 2 numbers then exit, you won't see anything. It is all dependent on the code you are running.
-is there a java editor I can use so I can see if there is an error in my code before I try to run it?
There are tons of IDE's out there, but if you are starting just get a free notepad-like program (Notepad++ is a common suggestion). It will help you with indents and formatting, but not be so cumbersome that you spend your time learning the IDE rather than the language.
|
SCJA
When I die, I want people to look at me and say "Yeah, he might have been crazy, but that was one zarkin frood that knew where his towel was."
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32675
|
|
Welcome to the Ranch Agree with the advice to use Notepad++. An excellent app.
|
 |
Dj Driver
Greenhorn
Joined: Nov 11, 2011
Posts: 16
|
|
I typed up the first MyFirstApp (on page 9) to print out "I Rule!" , "The World" and ran it from the command line (Selecting Start, then Run, typing javac MyFirstApp.java and selecting OK). A box flashed open and then closed so no way for me to see anything. Do I need to enter something in the code to keep the box opened?
|
 |
Ben Ooms
Ranch Hand
Joined: May 16, 2011
Posts: 32
|
|
After selecting run type cmd and enter. In this box you can use javac and java commands. This way the box stays open and you can see the results.
A good alternative to an IDE is notepad++. After install select in the pluginmanager the explorer and exec plugin. In this way you can stay in the notepad++ window and execute the commands inside a commandpanel. With this setup you can learn the Java syntax with a minimum of switching windows.
Regards,
Ben
|
 |
Dj Driver
Greenhorn
Joined: Nov 11, 2011
Posts: 16
|
|
From prevoius post : "After selecting run type cmd and enter. In this box you can use javac and java commands. This way the box stays open and you can see the results. "
This box does not stay open. When I type Start, then Run, typing javac MyFirstApp.java and selecting OK) that is the problem I am having.
|
 |
Ben Ooms
Ranch Hand
Joined: May 16, 2011
Posts: 32
|
|
That's my hole point, in the run box don't enter javac in it but cmd. the cmd command will open a black window, in that window you can enter the javac command and it will stay open.
regards,
Ben
|
 |
fred rosenberger
lowercase baba
Bartender
Joined: Oct 02, 2003
Posts: 9948
|
|
Where are you typing start, run...etc.?
I have never used Notepad++. Here's what i would reccomend.
Hold down the windows key and hit "r". in that box, type "cmd" and hit enter.
navigate to wherever your class file is.
type "java <className>"
the window should stay open.
|
Never ascribe to malice that which can be adequately explained by stupidity.
|
 |
Dj Driver
Greenhorn
Joined: Nov 11, 2011
Posts: 16
|
|
The resolution was as above person said:
navigate to wherever your class file is.
type "java <className>"
I was adding the .class but I should only have used the className without the .class. THANK YOU for the assistance.
|
 |
Mohamed Sanaulla
Bartender
Joined: Sep 08, 2007
Posts: 2927
|
|
I had written a blog post regarding using Notepad++ to run Java programs (Using Notepad++ to Compile and Run Java Programs) - You can google for "notepad++ java" or the blog post title.
I have listed few different ways one can use Notepad++ to execute Java programs.
|
Mohamed Sanaulla | My Blog
|
 |
 |
|
|
subject: A few questions since I am new to Java
|
|
|