Module 0-1: Basics
Introduction
The most barebones a Java program can be looks like this. What is this?
This is your main method. This is super important, because without a
mainmainPrint Statements
A print statement lets you output text to the console. The console is a window that displays only text. Basic programs will need to output text to the console if you want to see what's going on. This is how you make a print statement.
Run your code. What should be printed to the console is:
"Hello world!"StringSyntax
Programming languages, just like real languages, have rules on how to make valid statements. In natural languages like English, we would call these rules grammar. In the world of programming languages, we call these rules syntax.
Syntax is important, because computers are very literal. If you give code to your computer that doesn't follow the rules, it doesn't know what to do and it will crash. Likewise, people get awfully confused if you walk up to them and speak gibberish. Your IDE will underline code with a red squiggly if you're breaking syntax rules.
Back to Strings. The syntax for Strings in Java -- in other words, the way you let a computer know that something is a String -- is to wrap the symbols around a pair of double quotation marks (").
Let's talk a little more about syntax. Let's note a few more things about our print statement.
- is spelled with a capital S. Java is case sensitive, so make sure your case matches and that you spelt it right!
System - At the end of the statement, we put a semicolon (;). This is to tell Java that this is the end of the statement. You can think of it like putting a period at the end of your sentences in English.