ArtsAutosBooksBusinessEducationEntertainmentFamilyFashionFoodGamesGenderHealthHolidaysHomeHubPagesPersonal FinancePetsPoliticsReligionSportsTechnologyTravel

Java vs Python: Basic Program Structure

Updated on December 31, 2010

The Hello World program

The "hello world" program is one of the most common first programs taught in any language. Basically, you create a program that displays the phrase "hello world" after you execute the code. You can do this from command line or within the IDE.


The typical java program to print "hello world" to the console will have the following structure.*

public class myProgram{
 public static void main(String args[]){
  System.out.println("Hello World");

There are a few rules.

The name of the program must be defined after the class keyword. In this case, we picked the name "myProgram" Therefore, the name of the java source file must be "".

Notice all the keywords - public, static, void, main, etc. Notice all the characters - semicolons, parentheses, brackets. They are all needed. In fact, this is a barebones program. For now, understand that the class section identifies this class. And the "public static void main" section tells the compiler where to enter the program. In more complex programs, this class will have more code inside and outside of this section. The "System.out.println("Hello World");" line tells the compiler to print the line "hello world". It's the only thing special about this program.


The Python program to print "Hello World" to the console is simpler:

print 'Hello World'

You can also write it as:

print "Hello World"

You may have noticed there is

- no need to specify the name of the program and have a filename to match

- no need to specify access modifiers (like public in Java)

- no need specify where the program should enter (like main in Java)

- no need for most punctuation (like semicolons and brackets in Java). Whitespace such as indentation and new lines are important in Python, however. Of course, if you were programming with good practices, you would be using whitespace similarly anyway.

- shorter commands ("print" basically does what "System.out.println" does)

Of course, this was a rather simplistic example. I will be posting more articles to my site - TechTedium. Cheers.

* If you are writing your own java programs, it's very helpful to use an IDE like Eclipse or IntelliJ. If you are writing your own python programs, you can usually get by with IDLE, the IDE that comes with Python. If you want more power, go for Eclipse or Wingware.


    0 of 8192 characters used
    Post Comment

    • profile image

      Elise 7 years ago

      Thanks for the detail on this one.