CSC300 / CSC402: Main [1/11] Previous pageContentsNext page

PythonJava
01
02
03
04
05
def main():
    print("Hello")

if __name__ == "__main__":
    main()
01
02
03
04
05
06
package algs11;
public class Hello {
  public static void main (String[] args) {
    System.out.println ("Hello");
  }
}

Every java program requires a main function. It must be declared exactly as on the third line above.

Every java function resides in a class, in this case Hello.

Every java class resides in a package, in this case algs11.

Java includes visibility annotations, such as public and private. In python, everything is public.

Java functions are written using the keyword static. (More later.)

Java functions must include types for arguments and results, in this case String[] and void.

Both java and python code is compiled before it is run.

Previous pageContentsNext page