• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

A few questions since I am new to Java

 
Dj Driver
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 710
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Campbell Ritchie
Sheriff
Pie
Posts: 48940
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch Agree with the advice to use Notepad++. An excellent app.
 
Dj Driver
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 47
Debian Eclipse IDE Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 47
Debian Eclipse IDE Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12123
30
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Dj Driver
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Saloon Keeper
Posts: 3159
33
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic