Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Open up a new project called Test
- // Make a new class called Test
- //Now try this code
- public class Test {
- public static void main(String[] args) {
- System.out.println("Hello World");
- }
- }
- //
- // When java runs a program, it looks for the main class. This is usually handled
- // by your editor, but the key thing to note is that for all class files, the public
- // class must have the same name (case sensitive) of that of the file (Test.java).
- public class Test {
- // Inside the main class, there must contain the main function. This method is
- // static, since it exists outside the instance of the class Test. You don't have to
- // understand that for now, as it involves an understanding of Object Oriented Programming.
- // The main function is also a void. A function must return something, be it a String
- // (a collection of characters (letters/numbers/etc)) or a number, or an object. However
- // you can also return nothing, which is what void implied. That the function returns nothing.
- // Inside the brackets, we have String[]. I mentioned String earlier, but the [] part is
- // new. It implies that it's actually an Array of Strings. An array is a collection of things
- // that are the same type. In this case, they are all Strings.
- // "args" is a variable name. For here, args is the name assosiated with the array of Strings
- // we mentioned earlier. In other worlds, args is an array of Strings.
- // The curly braces are there to help you and the computer understand what code is within
- // the scope of the function. So when we call this function, everything between { and } will be run.
- // The world public implies this function can be accessed outside of the class. In this case
- // the Java Virtual Machine needs to call this function inside this main class in order to run
- // the program.
- public static void main(String[] args) {
- // System.out.println() is a function. In fact, it's a static function like this one we're in.
- // This function will print the String we enter as an argument, to our console.
- // "" are used to show the start, and end of a String hardcoded into the program.
- System.out.println("Hello World");
- }
- }
Add Comment
Please, Sign In to add comment