Learn desktop computer basics: hardware, software, operating systems & essential skills. Master your PC and boost your tech confidence today!
:strip_exif():quality(75)/medias/23649/a6a8302a6611427aa3154610f07e72b6.jpg)
So, you want to learn Java? Awesome! It's a language that powers a lot of stuff you use every day. From big business apps to Android phones, Java is behind the scenes. It's a great choice whether you're brand new to coding or already know a thing or two. I'll walk you through making your first Java program. We'll cover the basics, step by step. Think of this as your starting point for becoming a backend developer or just exploring software development. Let's get started!
Setting Up Your Computer
Before you can write code, you need to get your computer ready. This means installing something called the Java Development Kit (JDK). You might also want an Integrated Development Environment (IDE). It's like a super helpful text editor for coding. Here's how to do it:
1. Getting the JDK
The JDK is what lets you turn your code into something the computer can run.
- Download it: Head over to Oracle's website or a trusted place like Adoptium (Eclipse Temurin). Pick the right version for your computer (Windows, Mac, or Linux). If you're just starting out, grab a Long-Term Support (LTS) version like Java 11 or Java 17. They're more stable.
- Install it: Open the file you downloaded and follow the instructions. Keep track of where you install it. You'll need that info later.
- Tell Your Computer Where Java Is: This is super important. You need to set up something called "Environment Variables." Think of it as telling your computer where to find the JDK.
- Windows: Search for "Environment Variables" in the Start Menu. Click "Edit the system environment variables," then "Environment Variables..." Create a new system variable named
JAVA_HOME. Set its value to where you installed the JDK (likeC:\Program Files\Java\jdk-17). Then, find thePathvariable, edit it, and add%JAVA_HOME%\binto the list. - macOS/Linux: Open your terminal and edit a file called
.bash_profile,.zshrc, or.bashrc. Add these lines (change the JDK path if needed):
Save the file and runexport JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk-17.jdk/Contents/Home export PATH=$JAVA_HOME/bin:$PATHsource ~/.bash_profile(or whatever command your terminal uses) to save the changes.
- Windows: Search for "Environment Variables" in the Start Menu. Click "Edit the system environment variables," then "Environment Variables..." Create a new system variable named
- Make Sure It Worked: Open a new command prompt or terminal window. Type
java -versionandjavac -version. If it's all good, you'll see the Java version info.
2. Getting an IDE (Optional, But Really Helpful)
An IDE makes coding easier. It's like a fancy text editor that helps you write code faster and find mistakes. While you can use a simple text editor, an IDE will make your life much easier.
Some popular ones are:
- IntelliJ IDEA: Powerful and has a lot of features. The Community version is free.
- Eclipse: Free and open-source. Lots of people use it.
- NetBeans: Another free option with good Java support.
To install one:
- Download it: Go to the IDE's website and grab the right version for your computer.
- Install it: Open the file and follow the instructions.
- Tell it Where the JDK Is: When it asks, point the IDE to where you installed the JDK.
Your First Program: "Hello, World!"
Every coder starts with "Hello, World!" It's a simple program that shows you how to display text on the screen.
- Make a New File: Open your text editor or IDE. Create a new file called
HelloWorld.java. Make sure the name matches exactly! - Type This In:
public class HelloWorld { public static void main(String[] args) { System.out.println("Hello, World!"); } }
What Does It All Mean?
public class HelloWorld: This is like creating a container for your code. Everything in Java goes inside a class.publicmeans anyone can use it.public static void main(String[] args): This is the main part of your program. It's where the computer starts reading your code.public: Makes it accessible from anywhere.static: Means you don't need to create a "HelloWorld" object to run it.void: It doesn't give back any value.String[] args: Allows you to pass in commands when you run the program.
System.out.println("Hello, World!");: This is the line that actually displays the text.System.outis where the computer sends its output, andprintln()displays the text.
Making It Run
Now you need to turn your code into something the computer can understand, and then run it.
- Open a Command Prompt or Terminal: Go to the folder where you saved
HelloWorld.java. - Compile It: Type this and press Enter:
javac HelloWorld.javaIf you didn't make any mistakes, it'll create a file called
HelloWorld.class. This is the compiled code. - Run It: Type this and press Enter:
java HelloWorldYou should see "Hello, World!" appear on the screen. 🎉
Some Basic Ideas
Now that you've made your first program, let's look at some important ideas.
1. Variables and Types
Variables are like containers for storing information. Each container has a type, which says what kind of information it can hold.
Some common types are:
int: For whole numbers (like 10, -5, 0).double: For numbers with decimals (like 3.14, -2.5, 0.0).boolean: For true/false values.String: For text (like "Hello", "Java").
For Example:
int age = 30; double price = 19.99; boolean isJavaFun = true; String name = "Alice";2. Operators
Operators are symbols that do things with variables and values. For example, to do math or check if two values are the same.
Common ones:
- Math operators:
+(add),-(subtract),*(multiply),/(divide),%(remainder). - Assignment operators:
=(assign a value),+=(add and assign),-=(subtract and assign). - Comparison operators:
==(equal),!=(not equal),>(greater than),<(less than). - Logical operators:
&&(and),||(or),!(not).
An example:
int x = 10; int y = 5; int sum = x + y; // sum is now 15 boolean isEqual = (x == y); // isEqual is now false3. Control Flow
Control flow statements let you decide which parts of your code run, and when.
Some of the most common are:
if: Runs a block of code if something is true.if-else: Runs one block of code if something is true, and another if it's false.forloop: Runs a block of code multiple times.whileloop: Runs a block of code as long as something is true.
Here's an example:
int age = 18; if (age >= 18) { System.out.println("You can vote!"); } else { System.out.println("Not old enough to vote yet."); } for (int i = 0; i < 5; i++) { System.out.println("Loop number: " + i); } int count = 0; while (count < 3) { System.out.println("The number is: " + count); count++; }What's Next?
This is just the start! To get better at Java, try these:
- Object-Oriented Programming (OOP): Learn about classes, objects, and how to organize your code.
- Data Structures and Algorithms: Study ways to store and organize data (like lists and trees), and learn how to solve problems efficiently.
- Java APIs: Explore the huge collection of tools that come with Java.
- Frameworks: Learn about tools like Spring, Hibernate, and JavaFX that can help you build complex applications faster.
To Summarize
Learning how to create Java programs is a big step towards becoming a software developer. Keep practicing, experiment, and get involved in the Java community. With some hard work, you'll be well on your way to creating impressive applications for the backend and beyond!
Good luck! You got this.

:strip_exif():quality(75)/medias/23642/a43683d33b40f413228d54e3c6ed4a2f.jpg)
:strip_exif():quality(75)/medias/23630/a43683d33b40f413228d54e3c6ed4a2f.jpg)
:strip_exif():quality(75)/medias/23593/206d1d775b500f5763f1d339f8d400f6.png)
:strip_exif():quality(75)/medias/23519/2018aaeb871895a6809bc0b4753c85c9.jpeg)
:strip_exif():quality(75)/medias/23449/a698cd2a908750f45d7fa6ff9906c8ac.png)
:strip_exif():quality(75)/medias/23428/7e93c70f6afe0b3631b4b51290601963.jpg)
:strip_exif():quality(75)/medias/23345/a43683d33b40f413228d54e3c6ed4a2f.jpg)
:strip_exif():quality(75)/medias/23283/2916f9a9dfb17cb2def8a76af98ca999.png)
:strip_exif():quality(75)/medias/23250/a43683d33b40f413228d54e3c6ed4a2f.jpg)
:strip_exif():quality(75)/medias/23186/f08042a1450f4350a837107c10eecbd0.png)
:strip_exif():quality(75)/medias/22609/773f06ec12c378dd4bf0c498a2c4fa5c.png)
:strip_exif():quality(75)/medias/23090/a43683d33b40f413228d54e3c6ed4a2f.jpg)
:strip_exif():quality(75)/medias/20143/9a9df12a0235b48a9e976eab99f0ad47.jpg)
:strip_exif():quality(75)/medias/29042/db29275d96a19f0e6390c05185578d15.jpeg)
:strip_exif():quality(75)/medias/13074/7b43934a9318576a8162f41ff302887f.jpg)
:strip_exif():quality(75)/medias/25724/2ca6f702dd0e3cfb247d779bf18d1b91.jpg)
:strip_exif():quality(75)/medias/6310/ab86f89ac955aec5f16caca09699a105.jpg)
:strip_exif():quality(75)/medias/30222/d28140e177835e5c5d15d4b2dde2a509.png)
:strip_exif():quality(75)/medias/18828/f47223907a02835793fa5845999f9a85.jpg)
:strip_exif():quality(75)/medias/30718/25151f693f4556eda05b2a786d123ec7.png)
:strip_exif():quality(75)/medias/30717/fec05e21b472df60bc5192716eda76f0.png)
:strip_exif():quality(75)/medias/30716/60c2e3b3b2e301045fbbdcc554b355c0.png)
![How to [Skill] Without [Requirement]](https://img-cdn.ktx.ro/4TAxy6PmfepLbTuah95rxEuQ48Q=/450x300/smart/filters:format(webp):strip_exif():quality(75)/medias/30715/db51577c0d43b35425b6cd887e01faf1.png)
:strip_exif():quality(75)/medias/30714/2be33453998cd962dabf4b2ba99dc95d.png)
:strip_exif():quality(75)/medias/30713/1d03130b0fb2c6664c214a28d5c953ab.png)
:strip_exif():quality(75)/medias/30712/151df5e099e22a6ddc186af3070e6efe.png)
:strip_exif():quality(75)/medias/30711/e158fd6e905ffcdb86512a2081e1039d.png)