• 13
• 15
• 19
• 27
• 9

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

This topic is 4487 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.