CSC300: Python to Java: Syntax [35/43] Previous pageContentsNext page

PythonJava
01
02
03
04
05
06
def main():
  name = "Bob"
  print ("Hello ", end="")
  print (name)

main()
01
02
03
04
05
06
07
08
09
package algs11;
import stdlib.*;
public class Hello {
  public static void main (String[] args) {
    String name = "Bob";
    StdOut.print ("Hello ");
    StdOut.println (name);
  }
}

Java uses semicolons and curly-braces, where python uses newlines, colons and indentation.

When formatting java, the conventions for indentation and newlines mimic those of python. But in java, these are just conventions, not requirements.

Previous pageContentsNext page