I'm only 11, but I know html, CSS, javascript, and C#.

I was wondering, if Java is like C#, as it looks pretty similar, I could just start coding :)!

-worldwaffle

i don't know much about c#, but looking at the syntax, it is much more like c++ than java, it looks like many of the keywords are different, converting to and from languages, if you know the ideas behind it and the concepts, it us usually a matter of learning the new keywords

If you are going to be learning Java I would suggest you look through the resources in this thread.

I'm only 11, but I know html, CSS, javascript, and C#.

I was wondering, if Java is like C#, as it looks pretty similar, I could just start coding :)!

-worldwaffle

Java does not have the delegate system or unsafe context that C# has to offer. Everything done in Java is done within safe context - so there is no pointer arithmetic in Java.

There are also no partial classes in Java, like there are in C#, so you can't have overlapping classes [defined within the same package].

If you really have the need to store an array of methods, you will sadly have to use the Reflection API--

import java.lang.reflect.*;
import java.util.Random;

public class MethodTest{

	Method methods[];

	public MethodTest(){
		Class c = this.getClass(); // assigning the Class of this object (class) to c
		methods = c.getDeclaredMethods(); // returning the methods within this class and assigning them to methods
	}

	public void methodOne(){
		System.out.println("Method number 1");
	}

	public void methodTwo(){
		System.out.println("Method number 2");
	}

	public void methodThree(){
		System.out.println("Method number 3");
	}

	public static void main(String... args){
		Random rgen = new Random(); // for randomness
		MethodTest mt = new MethodTest();

		while(true){
			try{
				mt.methods[rgen.nextInt(3) + 1].invoke((MethodTest)mt); // not quite as convenient as C# Delegation, is it?
				Thread.sleep(rgen.nextInt(2500));
			}catch(Exception e){e.printStackTrace();}
		}
	}
}

--but it's not a good idea. Apparently there's a cost of additional overhead when using reflection calls.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.