# [java] New to Java: How do I recompile code? (no, seriously!)

This topic is 4427 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I can compile code, but it seems I can't REcompile code. Odd, aint it? Ok, here's what I did: I made a simple "Hello World" applet, coded in a .java file. I then went into dos, typed: javac HelloApplet.java, then went into windows, made an html file with the <APPLET CODE="HelloWorld.class" WIDTH=300 HEIGHT=25> </APPLET> tags. To show the applet in action on the page. That worked fine, so then I tried making changes to the code. For starters, I tried making it display the words: "Goodbye World" instead. I recompoiled the code, and opened the html window again, and what did I see? "Hello World!". What?? How is this possible? In desperation, I tried making a whole new .java file, and making a class with a different name, I also made it say: "Goodbye World" instead. I compiled it, changed the HTML tag to point to the new .class file, then opened a browser window. What did I see? "Goodbye World". Ok, so my change worked! Lets see what happens when I make a change... I tried making some cosmetic changes to "Goodbye World", but, of course, every time I run the applet, none of my changes stay. Can someone tell me why this is? Ran into this problem before maybe?

##### Share on other sites
It's probably a problem with your browser.
Try to press Ctrl+R to force a reload of the applet.
If that doesn't help clean the browser cache, especially stored java applets.

##### Share on other sites
As mentioned, this is your browser caching the applet when you don't want it to. For applet development you can either 1. code a very simple skeleton class that makes your applet run as an application (quite simple, lots of examples on the web) or 2. use appletview.exe supplied with the SDK which shouldn't cache anything for you.

##### Share on other sites
Quote:
 1. code a very simple skeleton class that makes your applet run as an application (quite simple, lots of examples on the web)

My application was called HelloWorld. That's how new I am to Java.

Quote:
 If that doesn't help clean the browser cache, especially stored java applets.

Hmm... odd thing. I try cleaning the cache, and it doesn't make any difference. (I'm using Firefox, so I go into tools->options->privacy tab, then press clear on the cache.) I try erasing the .class file and rebuilding it, but again, no difference. I just tried running my applet in Internet explorer, and I don't get any problems. It doesn't cache applets at all. If I delete the applet, it simply won't run the applet! All I have to do is refresh if I change the applet. Now that's how it should work! Granted, I switched to Firefox because I liked it better, but crap like this makes me wonder if firefox is worth it.

##### Share on other sites
"crap like this" will happen with any browser. It's a feature intended to save your bandwidth.

And yeah, learn to write real applications rather than applets.

public class HelloWorld { // <-- should be familiar  public static void main(String[] args) { // <-- your entry point    // The 'args' array holds any command line arguments that were provided.    // There's nothing special or magical about that parameter name of course    // (it's just convention, like argc and argv in C or C++).    System.out.println("Hello, World!"); // <-- output to console.    // System.out is an instance of class PrintStream; it's roughly    // equivalent to the global 'cout' object in C++.  }}

##### Share on other sites
Learn to write real applications? What's wrong with applets? Actually, my first test of Java looked exactly (minus the comments) like what you just posted. I stopped following that tutorial however, because some of the code they wrote gave me syntax errors. Turns out that tutorial was for a really old version of Java, so I went off to gamedev's intro to Java, and here I am. All I really want to do is learn enough about Java to start making mobile games (say what you will about them, but there's money in making those). I know C++ very well, a teensy bit of HTML, and have never done any web programming.

I understand that the cache thing is to save load times for people who've already been to the site before, but I'd like to know some way of actually clearing the cache so I can see my changes in my app without having to rename it something else: I'd run out of names pretty quickly that way! Until then, I'll just have to use Internet Explorer to test my applets.

##### Share on other sites
In firefox... Tools > Options > Privacy There ya go! A way to clear your cache...

##### Share on other sites
Is it easy to clear the applet cache in Explorer? I remember spending a decent amount of time trying to figure out how to do that, and I came to the conclusion that it was either impossible or just too difficult to do regularly.

Anyway, even if there *is* a button in the options somewhere, you don't want to go find that button every single time you recompile. Being able to modify-recompile-run quickly is key for a good dev workflow. So using appletviewer really is the best choice for development I think. That's what it's here for :)

"learn to write real applications" is a pretty trollish thing to say. =P

##### Share on other sites
Mobile programming is done through the use of the J2ME SDK plus the phone vendor's API for game programming - for instance, Sony Ericsson has an API for 3D mobile gaming, and a fair support for mobile game developers.

But learning Java through J2ME might be a nasty task; I recommend going through the Java Tutorial for the standard J2SE, to learn the basics and the practices of standard desktop programming. Only after a quick look at that tutorial you'll have the proper amount of knowledge needed to better understand the J2ME distribution.

As for applets, well, my experience with them tells me that they are far capable of doing what we want them to do - but not without a lot of work and patience. I don't see much reasons to code applet games nowadays, with web start and all... And it's not a promising "entry point" of learning Java.

Son Of Cain

##### Share on other sites
Quote:
 Original post by pinacoladaIs it easy to clear the applet cache in Explorer? I remember spending a decent amount of time trying to figure out how to do that, and I came to the conclusion that it was either impossible or just too difficult to do regularly.

you pretty much have to shut down the browser completely. That said, I have found a few bugs with 1.4.3 code running in the 1.5 applet runtime. There are a number of things that just don't work right in applets that work absolutely fine in regular applications, especially stuff that involves rendering.

I would avoid applets like the plague given the choice. They just aren't worth the hassle.

##### Share on other sites
There was some way to do this without closing the browser, alas I forget. Perhaps a force refresh will do the trick? (ctrl + refresh)

##### Share on other sites
Yeah, instead of using a browser you can use the Applet Viewer program that comes with the JDK.

I agree with Capn., and many of the other above posters; avoid applets if you can, and if you are using them as a tool to learn Java you are looking in the wrong place. Learn Java using the available trails, and when you want to move on to mobile games there are some good sites out there to help you get started; most should be linked to Gamedev somewhere... I also think that evelyn is a mobile games developer, you might want to ask her nicely for tips.

Jon

##### Share on other sites
Quote:
 In firefox... Tools > Options > Privacy There ya go! A way to clear your cache...

Tried it. Didn't work. Internet explorer though, all you have to do is exit the browser and come back in. Pinacolada said that being able to see your results instantly is good for workflow, and I agree! Faster the better.

Good replies all around, very helpfull. I have some follow-up questions:

1. What's J2ME?
2. What's J2SE?
3.
Quote:
 I don't see much reasons to code applet games nowadays, with web start and all...
. Aha... I see, so Webstart makes it much easier to program games using Java?

4. Ok, so, let me see if I understand this right: If I want to do cell-phone games, I should start out with the gamedev tutorial just to learn Java language basics, then head and use J2ME and/or the phone vendor API.

5. Evelyn is a phone programmer eh? I guess she's a forum member? Alright, perhaps I'll PM her sometime.

Quote:
 There was some way to do this without closing the browser, alas I forget. Perhaps a force refresh will do the trick? (ctrl + refresh)

Nah, that didn't work either (with Firefox anyway)

Thanks for the replies everyone! If you've got more advice, bring it on!

##### Share on other sites
1. Java 2 Micro Edition - the Java language distribution for portable devices such as mobile phones, palm tops, etc... It is a set of classes, a SDK just like the J2SE (see below), but customized for micro devices and their KVMs;

2. Java 2 Standard Edition - the Java language basic distribution for common computational systems, such as desktop PCs. Almost all libraries, APIs and etc are written upon this standard SDK - the J2EE is an example - except for the J2ME, since it has specific needs (altough some level of communications between them is possible).

3. Web startable games are games written in the standard J2SE SDK, deployed through the web via the web start technology. More details here.

4. Right - that's what I would do if I were you ;)

5. Unfortunately, I don't know the girl ^_^

Son Of Cain

PS: Ctrl + F5 works for me on Internet Explorer

##### Share on other sites
Ok if ctrl+F5 isn't working try this: open up the Java console (right click on the icon that should be in your system tray when you start the applet if you haven't changed any settings) and simply type an 'x'. This should clear the cache and your applet will reload when you refresh the page. A pain I know, but better than closing the browser

##### Share on other sites
I tried typing all the following commands, and none of them work, with the result I get in <> brackets.

appletviewer HelloWorld.java <nothing happens>

appletviewer HelloWorld <-I/O exception while reading: C:\jdk5.0\Java apps\HelloWorld\HelloWorld (The system cannot find the file specified)>

appletViewer HelloWorld.class <nothing happens>

I do have an appletviewer.exe file in the bin folder of the jdk5.0. I don't know what's going on there.