Interpreting Java syntax
1. Interpreting Java syntax
Welcome back! Now, let's dive into some Java syntax.2. Class
In Java, all code lives inside a class.3. Classes organize related code
Think of a class as a container that helps organize related code - such as keeping different documents in different folders!4. Classes keep things organized
As a Java application grows to thousands or even millions of lines of code it helps keep everything organized.5. Defining class
Here's a simple example. The line `class Greeting` defines a `class` called `Greeting`. The curly brackets mark where the class begins and ends.6. Class and the main method
Inside the class, we have a method called `main()`, where Java starts running the code. We'll introduce classes and methods later, but for now, remember that every Java program is inside a class.7. Case
Java is case-sensitive, so we must use the correct capitalization - lowercase main and uppercase MAIN are different in Java!8. Case, semicolons
Every line inside the method must end with a semicolon, such as this print statement.9. Case, semicolons, and white space
Java doesn't care about whitespace, such as spaces, indents, or blank lines. We use blank lines to separate code and indentation to make related sections easier to read.10. Println as a calculator
Remember the println statement needed to produce output? We can use println also as a calculator! Just add a sum without quotes into the brackets, as shown here.11. Adding comments
Sometimes, we want to add notes in our code for ourselves or others. That's where comments come in! They help us document our code. We start a single-line comment using //, and Java will ignore anything that's after it on the same line. Comments help us explain what the code does, making it easier to read.12. Let's practice!
Now that you know how Java organizes code in classes and how to use comments, let's practice writing your class in the next exercise!Create Your Free Account
or
By continuing, you accept our Terms of Use, our Privacy Policy and that your data is stored in the USA.