• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

A few questions since I am new to Java

 
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
 
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.
 
Marshal
Posts: 70651
288
  • 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?
 
Ranch Hand
Posts: 47
Netbeans IDE Eclipse IDE Debian
  • 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
Netbeans IDE Eclipse IDE Debian
  • 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
 
lowercase baba
Posts: 12911
64
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.
 
Bartender
Posts: 3225
34
IntelliJ IDE Oracle Spring Chrome Java
  • 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.
 
We cannot change unless we survive, but we will not survive unless we change. Evolving tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic