Skip to main content
GameDev.net gamedev.net
🔒 Locked

[java] Java Forum FAQ

Started by Glass_Knife Dec 2, 2009 at 10:56 AM 3 replies 1.3k views
Original Post
Glass_Knife
Glass_Knife
It will be a lot of work (mostly for me), but I think it is time to update the Java Forum FAQ. If you could help by letting me know what things should be covered as of 2010, let me know. Off the top of my head, I think a list of game libraries and relevant articles would be a good start. I am open to any suggestions...
lithos
lithos
Libraries: Slick, Pulpcore, and similar.

Efficency Myths. programmers mattering more than the language(unless you have the resources to have 40+ hour weeks).

Time savers(default library). Java.awt.geom, a few others, suggesting that you have your game in a "Panel/JPanel" so you can shove it inside of any kind of container(Applet, Frame).

Example Programs would be nice.
justkevin
justkevin
Here's a couple I've run into learning java for a multiplayer server (I'm a Java novice, so don't assume the answers I provide are 100% correct)

Q: What causes "java.lang.OutOfMemoryError: Java heap space" exceptions and how do I stop them?

A: The JVM has run out of memory. If this happens at start-up, you probably need to increase the amount of memory it's allowed. Use the -Xms(initial size) and -Xmx(max size) command line flags. If it happens after your program has been running for a while, you probably have a memory leak. A tool like VisualVM can help you track it down.

Q: What is "Hot code replace"?

A: Hot Code Replace is a debugging technique that allows a developer to change the internal methods of a class while the app is running without restarting the JVM. This is useful, for example, when prototyping some game mechanic to see the results of different formula without requiring a restart. This feature is available since JDK 1.4 and is supported in Eclipse (occurs automatically by default) and Netbeans (Debug-> Apply Code Changes).

There are limitations on what can be changed live, generally you can only change method internals.

Q: Is finalize() the Java equivalent of a destructor?

A: No. Java has a garbage collector that handles reclaiming memory for objects that are no longer accessible. The garbage collector does call the object's finalize() method, but there's no guarantee when the garbage collector will run.
lithos
lithos
Java Memory Model. and how java is always pass by value.

This model may or may not be what's really really going on in all JVM's but it's the model that I used for figuring out what is going on with how values get passed around. and the effects that all JVM's simulate.

There is the stack(instructions that the program follows) and the Heap(which has memory);

the heap also has two places in it. One for primitive values, another for everything else. In addition to the primitive types(int, short, long, etc) there is another type of primitive value called the reference. the reference points to an area in the heap that tells an object which parts in the stack and in the heap belongs to it.

So this means that when you use the equal sign between to Objects(foo2 = foo) you are taking the reference of "foo" and creating a new reference for "foo2" that points to all the same stuff that the "foo" reference does.

java is also PASS BY VALUE ONLY(what this means is you get a copy of any values sent in an arguement). HOWEVER when passing an Object you are passing the primitive reference rather than the object. which means that when passing Objects you essentially get a PASS BY REFERENCE(where you get a copy of of the memory location) because the primitive reference is a reference.
-----------
Primitives are passed by value, and object references are passed by value(faking a pass by reference type effect).

import java.util.Date;public class test {	public static void main(String[] args) {		// TODO Auto-generated method stub		Date one = new Date(0L);		Date two = one;		Date three = one;		int a = 55;		two = new Date(5000000L);   //changes the reference only		System.out.println(one.toString() + "  " + two.toString() + "    " + three.toString() + "times: " + a);		demoMethod1(a, one);		System.out.println("one is unchanged: " + one + " a is unchanged: " + a);  //method didn't change data		demoMethod2(one);		System.out.println(one + " next date " + three);  // method changed the data			}		public static void demoMethod1(int a, Date test)	{		a = 100;		System.out.println("hello from method 1:  " + a + test);		test = new Date(100000000l);   //since we are changing this reference only this reference changes		System.out.println("hello from method 1:  "  + test);	}	public static void demoMethod2(Date test)	{		test.setYear(2009);  // since we are changing through the Object/reference, we change all references that access this data		System.out.println("hello from method 2: " + test);	}}

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.