Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Cover image for Getting Started with Java: A Beginner's Guide
Igor Venturelli
Igor Venturelli

Posted on • Originally published atigventurelli.io

Getting Started with Java: A Beginner's Guide

Get hands-on with Java! Learn to set up, code your first program, and explore the basics of Spring Boot in this beginner-friendly guide

Java has stood the test of time as one of the most versatile, powerful, and widely-used programming languages. Whether you're just starting your coding journey or looking to add a powerful language to your toolkit, Java is a fantastic choice. It’s not only the backbone of Android development but also plays a crucial role in web, enterprise, and server-side applications. This guide will help you get started with Java, walking you through setting up your environment, writing your first program, and even touching on how Java is used with frameworks like Spring Boot.

Setting Up Your Development Environment

Before we dive into coding, let's set up everything you need to write and run Java code.

Step 1: Install Java Development Kit (JDK)

The JDK is your toolkit for Java programming, providing the compiler, runtime, and necessary libraries. To install:

  1. Visit theOracle JDK website.
  2. Download the latest version of JDK suitable for your operating system.
  3. Follow the installation instructions.

Step 2: Choose an Integrated Development Environment (IDE)

Java works well in several IDEs, with IntelliJ IDEA, Eclipse, and Visual Studio Code being among the most popular. For beginners, IntelliJ IDEA (Community Edition) offers a user-friendly interface with many helpful features:

  1. Download IntelliJ IDEA from theJetBrains website.
  2. Follow the instructions to install and launch.

Step 3: Verify Installation

Once you’ve installed the JDK and your preferred IDE, open a terminal or command prompt and type:

java-version
Enter fullscreen modeExit fullscreen mode

If everything was set up correctly, you should see the version number of your JDK displayed.

Writing Your First Java Program

Let's create a simple "Hello, World!" application—a time-honored tradition for beginners. This example will introduce you to the structure of a basic Java program.

  1. Open IntelliJ and create a new project.
  2. In thesrc folder, create a new Java class namedHelloWorld.
  3. Paste in the following code:

    publicclassHelloWorld{publicstaticvoidmain(String[]args){System.out.println("Hello, World!");}}
  4. Run the program by right-clicking on the file and selecting “Run HelloWorld.main()”. You should see "Hello, World!" printed in the console.

Java with Spring Boot: A Quick Glance

Java really shines when combined with frameworks, especially for web and enterprise applications. One of the most popular frameworks for building web applications in Java isSpring Boot. It simplifies the setup and development of standalone, production-ready applications.

Let’s expand our "Hello, World!" example to create a simple RESTful API using Spring Boot.

Step 1: Set Up Your Spring Boot Project

Spring Boot provides a web-based tool to generate boilerplate code for your application. Visitstart.spring.io and select the following:

  • Project: Maven Project
  • Language: Java
  • Spring Boot Version: (Choose the latest stable version)
  • Group:com.example
  • Artifact:hellospring
  • Dependencies: Add “Spring Web”

Download the generated project and open it in IntelliJ.

Step 2: Write Your First Spring Boot Controller

In your new project, navigate tosrc/main/java/com/example/hellospring and create a new Java class namedHelloController.

Add the following code:

importorg.springframework.web.bind.annotation.GetMapping;importorg.springframework.web.bind.annotation.RequestMapping;importorg.springframework.web.bind.annotation.RestController;@RestController@RequestMapping("/api")publicclassHelloController{@GetMapping("/hello")publicStringsayHello(){return"Hello, World!";}}
Enter fullscreen modeExit fullscreen mode

This class defines a REST controller with a single endpoint,/api/hello, which returns "Hello, World!" when accessed.

Step 3: Run the Spring Boot Application

In IntelliJ, find the main application file (usually namedHellospringApplication.java), and run it. Once running, open a browser and navigate tohttp://localhost:8080/api/hello. You should see "Hello, World!" displayed.

Key Java Concepts for Beginners

Now that you've created a simple program and seen Java in action with Spring Boot, here are a few foundational concepts to strengthen your understanding:

  1. Variables and Data Types: In Java, every variable has a specific type, such asint,String, orboolean. Knowing data types will help you manage memory efficiently and avoid errors.
  2. Control Structures: Java provides standard control structures likeif statements,for loops, andwhile loops, essential for logic flow in your applications.
  3. Object-Oriented Programming (OOP): Java is fundamentally an OOP language. Concepts likeclasses,inheritance, andpolymorphism are central to Java programming.
  4. Exceptions: Java uses exceptions to handle errors in a controlled way. Learning how to work withtry,catch, andfinally blocks is essential to write robust programs.

Conclusion

Starting with Java can open doors to a world of opportunities. With strong community support, extensive libraries, and frameworks like Spring Boot, Java remains a powerful language that powers everything from simple web apps to enterprise-grade software. Practice the basics, build small projects, and gradually dive into advanced topics. With dedication, you'll soon be writing efficient, scalable, and well-structured Java applications. Happy coding!


Let’s connect!

➡️ LinkedIn

➡️ Original Post

☕ Buy me a Coffee ☕

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

Software Integration, Simplified
  • Location
    Brazil
  • Joined

More fromIgor Venturelli

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp