// comment line, starts with //, for multi-line comments use:/* this kind of thing *//* Save this file as "example.java" somewhere. To run this program, first compile it with "javac example.java", then run it with "java example". To see what the String[] args does, add some words after the "java example", for example "java example this is example" and "java example this_is_example"*/class example // the main class, name has to be the same as the file's name, without .java{ public static void main(String[] args) /* This is the main function, necessary in this kind of program. The String[] args is an array of strings of the arguments you give to the program, for example if you run the program with "java example this is text", args[0] is "this", args[1] is "is", args[2] is "test"*/ { if ( args.length > 0 ) /* Check how many strings the args array has, in this case how many words have been passed as an argument. The .length after args means a "length" named variable in the array*/ { System.out.println(args[0]); // Print the first argument if there are more than one arguments // the "System" is an object class, ".out" is a variable of it, in this case another object, and ".println()" is a function of the .out object } new anotherClass(); // Create a new object anotherClass and continue from the the "public anotherClass" below }}class anotherClass //Create another object{ public anotherClass() // public means this function can be used from outside the class, and as this is the main function (same name as the object), it returns nothing (so "public objectName()" instead of "public int objectName()" or similar) { System.out.println( getNumber() ); /* This here first runs the getNumber() function from this class, and returns its return value to the System.out.println() function*/ System.out.println( this.getNumber() ); // Does exactly the same as above, this time only calling function in object "this", which is the object itself thirdClass object = new thirdClass(); // now create a thirdClass object named "Object". This runs the main function of the class/object, in this case the "public thirdClass()" int number = 0; number = object.getTheNumber(); // this calls the "getTheNumber()" function in the thirdClass object, and puts the return value in the "number" integer variable System.out.println("The number is " + number); // some text joining, the + joins the string "The number is " and the variable "number", then prints the result on screen number = object.number; // the "number" variable in the thirdClass object is public, so it can be directly used. In this we change this class's number variable to the same as the other class's. System.out.println("The number still is " + number); // Show the number, should be same as above object.number = 15; //As the variable is public, we can change it here too. If it wasn't, you'd have to write a object.changeNumber(*number*) function System.out.println("This time the number is: " + object.getTheNumber() + ", and " + object.number + "."); // Use the both ways to see the new value // The example ends here. Below are functions and classes used above. } int getNumber() // New function, returns an int variable { int i = 1; return i; //returns i, could also be "return 1;" to return 1 }}class thirdClass{ public thirdClass() { number = 3; //the number variable from below, set it to 3 } public int getTheNumber() //See where this is used in the anotherClass { return number; } public int number;}/* Some stuff I forgot what they were used for, ignore these. :pint e = getNumber(); // Get the i value from the getNumber() functionSystem.out.println(e); // print the e variable*/