• Post Reply Bookmark Topic Watch Topic
  • New Topic

New today to Java  RSS feed

 
Jr Morris
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I always join a forum if I can when starting something new like learning a new application or language. I tried my first coding tonight which was just an output to screen of "Hello World". The code was from a book and it worked. I then wanted to change the message to something like "This is cool software" so I just amended the line with the message "Hello World" in it to "This is really cool software" and saved the program as a different name but each time I ran the programme it still kept outputting the original message of "Hello World" - what am I doing wrong or what else in my original programme do I need to update? Like I said I've had an hour on Java and this is a really simple question but I find these forums really useful.
 
Joe Harry
Ranch Hand
Posts: 10128
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The normal cycle is Modify > Compile > Run. Do you now see what you miss in what you are doing?
 
Joe Harry
Ranch Hand
Posts: 10128
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the world of Java and Welcome to the ranch! Have fun learning Java!
 
Campbell Ritchie
Marshal
Posts: 56584
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I presume you got it to compile and run the first time, so you know the commands.

And welcome to the Ranch
 
Jr Morris
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks guys, for your messages. I'm at work now but I'll try to sort things tonight. I can't be certain but I don't think I came across a Modify button. I'm sure you guys are right though in what you say and I'll investigate further tonight. It would be good if code is portable between different things that I decide to do in Java
 
Campbell Ritchie
Marshal
Posts: 56584
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Button? Button?
That sounds like an IDE; we are by no means happy about people starting with IDEs. Start with a text editor, but not the editor they recommend in this tutorial.
You modify the file by editing it with a text editor (or, when you are more experienced, an IDE). Then you compile it, then you run it.
 
J. Kevin Robbins
Bartender
Posts: 1801
28
Chrome Eclipse IDE Firefox Browser jQuery Linux MySQL Database Netbeans IDE
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just in case you are not getting the gist of these responses, let me chime in. The IDE is hurting you more than helping you at this point in your learning. Ditch it and don't touch it for at least a month. Get a good text editor (I like NotePad++) and learn to compile your programs from the command line using the "javac" compiler, and run them using the "java" command.

The IDE is hiding all this from you and unless you do it manually, you'll never understand what's going on under the covers, and that understanding is critical to the learning process.

Good luck and welcome to The Ranch!
 
Jr Morris
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're right Kevin. It is an IDE. I wanted to learn an up to date programming language and saw that Java was considered popular. I wanted to download a platform where I could write Java programs and came across the Oracle JDK via a Google Search. I got a book from the library on Java and got it to output the Hello World message. I then wanted to play about with outputs and I changed the message expecting Oracle to output the new message and saved the new code under a different filename. I think last night I just pressed a green button which compiles it and then runs it automatically.

Why wouldn't Oracle JDK run the new code?



Thanks for your advice
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It works like this:

1. You write source code in a .java file
2. You use the Java compiler to convert the source code into a .class file, which contains executable code
3. You run the code in the .class file

If you modify the .java source file, you have to compile it again (step 2) to update your .class file.

The page About the Java Technology from Oracle's Java Tutorials explains it in detail, with pictures.
 
J. Kevin Robbins
Bartender
Posts: 1801
28
Chrome Eclipse IDE Firefox Browser jQuery Linux MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jr Morris wrote:Why wouldn't Oracle JDK run the new code?


It depends on the IDE. NetBeans automatically compiles every time you save the file. I don't know if other IDE's do that, but it sounds like the one you are using does not. But this just proves my point. The IDE is insulating you from the real process. You need to learn to do things the "hard" way before you move to an IDE with all it's features like auto-compiles and code-completion.

If you have trouble using the command line compiler or setting up your project directory structure, the folks around here are happy to help. Just tell us what you tried and what happened.
 
Campbell Ritchie
Marshal
Posts: 56584
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
J. Kevin Robbins wrote: . . . NetBeans automatically compiles every time you save the file. . . .
Are you sure about that? It is a long time since I used NetBeans, but I have memories of having to push a “compile” button before executing the code. And I think Eclipse is the other way round; unless I have a save automatically option set, it always asks me whether it should save code before compiling, but it does compile automatically every time you try to execute the code.
Just goes to show you how much confusion you can get by using IDEs too soon in the learning process.
 
Paul Clapham
Sheriff
Posts: 22841
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In Eclipse you can configure it to build your project (i.e. compile everything) each time you change a file. Or you can configure it so you have to select the Build option to have your code compiled. I've worked with both ways but I don't remember which is the default. I'm sure Netbeans has a similar option but it's probably called something different and I don't know what its default is either. So yeah, confusion abounds. And that's just to get some code compiled.
 
Jr Morris
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Campbell, you are correct in what you say. I've just made a change to the text I want to output whilst keeping all the other coding the same. I used Netbeans IDE 7.4. When I'd changed the text I wanted to output I clicked on the hammer icon with the brush on it - Clean and build - and then ran the program and the output was correct.

Thanks
 
J. Kevin Robbins
Bartender
Posts: 1801
28
Chrome Eclipse IDE Firefox Browser jQuery Linux MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
NetBeans has a "Clean and Build" option, and a "Build" option, but if you choose it you get a message "This project's source files are compiled automatically when you save them".

This feature can be deactivated if you have a project with a long compile time or a slow computer, but that's the default.
 
Campbell Ritchie
Marshal
Posts: 56584
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you, everybody
I seem to have been just as confused.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!