HELLO WORLD IN JAVA: HELLO WORLD IN PYTHON
[Pages:6]HELLO WORLD IN PYTHON:
print("Hello world!")
HELLO WORLD IN JAVA:
public class HelloWorld { public static void main(String[] args) { System.out.println("Hello world!"); }
}
1 / 6
DIFFERENCE #1: EVERY JAVA PROGRAM NEEDS TO BE INSIDE A CLASS. (OBJECT-ORIENTED PROGRAMMING!)
1 public class HelloWorld {
2
3
public static void main(String[] args) {
4
System.out.println("Hello world!");
5
}
6
7}
The rst line in the Java program public class HelloWorld de nes the start of a class named HelloWorld The public class must have the same name as the le we are in (HelloWorld.java), otherwise we'll get an error when compiling The program starts executing at the "main" method of the class that you are running de ned using public static void main(String[] args) (more on that later)
2 / 6
DIFFERENCE #2: WHITESPACE DOESN'T MATTER IN JAVA; USE BRACES INSTEAD
1 public class HelloWorld {
2
3
public static void main(String[] args) {
4
System.out.println("Hello world!");
5
}
6
7}
In Python, whitespace was a Big Deal In Java, whitespace is irrelevant to the computer! Use { .. } braces to group things instead (Although using proper indentation is still highly recommended for readability's sake. In Eclipse, you can use Source -> Format to clean up your code indentation.)
Remember, Eclipse is just an IDE
3 / 6
DIFFERENCE #3: NOW, SEMICOLONS ARE A BIG DEAL
1 public class HelloWorld {
2
3
public static void main(String[] args) {
4
System.out.println("Hello world!");
5
}
6
7}
In Java, every single-line statement must end with a semi-colon
4 / 6
DIFFERENCE #4: STRING QUOTATIONS MUST BE DOUBLE QUOTES IN JAVA
1 public class HelloWorld {
2
3
public static void main(String[] args) {
4
System.out.println("Hello world!");
5
}
6
7}
In Python, the single and double quotes could both be used for strings In Java, it must be the double quotes ".." (Try replacing the quotes in the HelloWorld.java program with single quotes to see how much Java complains)
5 / 6
DIFFERENCE #5: PRINT VS. SYSTEM.OUT.PRINTLN
System.out.println is Java's version of Python's print
6 / 6
................
................
In order to avoid copyright disputes, this page is only a partial summary.
To fulfill the demand for quickly locating and searching documents.
It is intelligent file search solution for home and business.
Related download
- crash course in java
- java basic syntax
- how to run a java program
- java type conversion statements and loops
- the hacker s guide to javac
- java strings and methods
- hello world in java hello world in python
- mips hello world mips assembly 1 virginia tech
- web dynpro tutorial hello world archive
- vfcjava lab 0 hello world mit opencourseware
Related searches
- simple java hello world program
- java program hello world with output
- java hello world example
- java hello world project
- hello world java sample
- print hello world in java
- coding a simple hello world java program
- hello world java class
- java hello world program code
- hello world java code example
- hello world java program
- hello world in java