Overview, Syntax, and Comments
Java is an object-oriented programming language. What this means is that basically everything is an object. We'll learn more about what an object is and why it's important later in this class.
Syntax
Let's look at how we printed Hello World!
again:
JAVApublic class Main {
public static void main(String[] args) {
System.out.println("Hello World!");
}
}
There's definitely a lot going on here, however for the purposes of this class, there's only a few things you need to take away from this for now:
- The code that was run lives inside
main()
- Printing to the console used built-in code from
System
to do so.
When it comes to the syntax, every line of code in Java must end in a semicolon. Unlike some programming languages like Python, indentation doesn't matter here. Your indentation could be a disaster but the code will run the same.
Comments
Comments are useful in programming languages to leave yourself or another developer a note of some kind. This is also called documenting your code. Comments are entirely ignored by the compiler so they do not affect the execution or performance of your code.
Here's how a single-line comment looks like:
JAVApublic class Main {
public static void main(String[] args) {
// this is a comment!
System.out.println("Hello World!");
}
}
You can leave a comment spanning multiple lines like this:
JAVApublic class Main {
public static void main(String[] args) {
/* this
is
a
comment!
*/
System.out.println("Hello World!");
}
}
In both cases, compiling and running your code will result in this:
BASHHello World!
That just about does it for a very basic overview of Java, its syntax and how to leave comments!
- How to Install Node on Windows, macOS and Linux
- Getting Started with Express
- How to Serve Static Files with Nginx and Docker
- How to deploy a Deno app using Docker
- How to deploy a MySQL Server using Docker
- How to deploy an Express app using Docker
- How to Scrape the Web using Node.js and Puppeteer
- Getting Started with Handlebars.js
- Build a Real-Time Chat App with Node, Express, and Socket.io
- Learn how to build a Slack Bot using Node.js
- Getting Started with React
- Setting Up a Local Web Server using Node.js