Java entry practice

  1. Environment setup

Before starting Java programming, you need to set up a development environment. The following are the steps to set up a development environment:

  • Download and install JDK (Java Development Kit): Download and install the appropriate version of JDK from the Oracle official website. After installation, add JAVA_HOME to the environment variable.
  • Download and install IDE (Integrated Development Environment): Eclipse and IntelliJ IDEA are commonly used IDEs in Java development, and you can choose to install them by yourself.
  1. Implementation steps

2.1 Create a new Java project in the IDE

Open the IDE and create a new Java project, creating a class called HelloWorld.

2.2 Writing code

Write the following code in the HelloWorld class:

public class HelloWorld {
  public static void main(String[] args) {
    System.out.println("Hello World!");
  }
}

Code explanation: This program contains a public class HelloWorld, which prints out the string "Hello World!" through the main method.

2.3 Run the program

In the IDE, click the Run button or press the shortcut key Ctrl + F11, the program will be executed and "Hello World!" will be output in the console.

  1. Java basic syntax

3.1 Java keywords

Java has many keywords, such as public, class, void, etc. These keywords have specific meanings in Java and cannot be used as variable names or method names.

3.2 Java data types

Data types in Java include basic data types and reference data types. There are eight basic data types: byte, short, int, long, float, double, boolean, and char. Reference data types include String, array, class, etc.

3.3 Java variable declaration and assignment

The syntax format for declaring variables is: data type variable name;

The syntax format of assigning variables is: variable name = value;

For example:

int num;
String name;
num = 123;
name = "Lucy";

The above code declares two variables num and name, which are integer and string types respectively, and then assigns values.

3.4 Java operators

Operators in Java include arithmetic operators, relational operators, logical operators, bitwise operators, etc. For example:

int a = 10, b = 6;
int c = a + b; //加法运算符
boolean d = a > b; //关系运算符
boolean e = true, f = false;
boolean g = e && f; //逻辑运算符
int h = a & b; //位运算符

The above code demonstrates the use of addition operators, relational operators, logical operators and bitwise operators.

  1. Summarize

This article introduces the basic steps and syntax for getting started with Java development, including environment setup, basic syntax, data types, variable declaration and assignment, operators, etc. I hope that beginners can master the basics of Java through this article, further deepen their understanding of Java programming, and start their Java programming journey.

Guess you like

Origin blog.csdn.net/huolonzhang/article/details/130314687