JAVA Study Notes

Published 2024-09-03 15:00 711 words 4 min read

JAVA study notes records, JAVA study notes

Part 1: Java Environment Configuration Guide

  1. Download the JDK
  2. Download a compiler
    • vscode

      • Lightweight, requires configuration
      • Supports many languages, and there are many plugins too
      • Free
      • The best IDE in the universe!! Not really!!
    • Intellij IDEA

      • Bloated, ready to use right after downloading
      • Suitable for projects
    • Lightly

      • Cloud storage, ready to use right after downloading
    • Eclipse

      • Haven't really used it
      • Free and open source
      • Low system requirements
    • MYEclipse

      • Haven't really used it
    • Jbuilder

      • Haven't used it
    • NetBeans

      • Haven't really used it
      • Free and open source
      • I heard it has a powerful plugin marketplace, though it uses quite a lot of memory

Part 2: Basic Syntax and Comments

Basic Syntax

package com;

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

Comments

/*
	Multi-line comment
*/

// Single-line comment

/**
* Documentation comment
* You can write multiple sentences
*/

Note: Documentation comments can be extracted into a program documentation file Comments do not affect program execution, because the program is run from the compiled class file

Common Data Types

  1. Integers

    • For example: 66, 88, -88, -66
  2. Decimals

    • For example: 1.1, -1.2
  3. Characters

    • For example: A, O, I
    • In code you write: 'A', 'O', 'I'; single quotes are required, and only one character is allowed
  4. Strings

    • For example: I love you, "I love you", "HelloWorld"
    • In code you must use double quotes, and the content can be anything
  5. Boolean values

    • For example: true and false
    • In code you write: false, true
    • There are only these two values in code, where false means "false" and true means "true"
  6. Null value

    • For example: NULL
    • In code it is written as: Null
    • In a program it is a special value; a null value represents emptiness.
  7. Special characters

    • \n means a line break
    • \t means a tab key was pressed, roughly leaving a gap of two characters

Variables

  1. Variable definition and format

    • A variable is used to store a piece of data; in essence, it is a region in memory
    • 数据类型 变量名 = 数据;
  2. Advantages of variables

    • They can be used to remember the data you want to process, making the code you write more flexible and easier to manage
  3. Characteristics of variables

    • The data stored in a variable can be replaced
  4. Using variables

    • A variable must be declared before it can be used, e.g.: int age = 10;
    • A variable of a certain type can only store data of that type.
      • The difference between int and double
    • Variables have an access scope; a variable is valid within the first {} block from where it is defined. Also, multiple variables defined in the same scope cannot have the same name.
    • You can declare a variable without assigning a value, but it needs a value when you use it
        int age = 10;
        System.out.println(age);
        age = 11;
        System.out.println(age);
        age = age + 1;
        System.out.println(age);
        
        结果为: 
11
12
13

As you can see, the data in a variable can be replaced

Note: In Java, = means assignment, and assignment is read from right to left For example: int age = 10; means assigning the value 10 to age

Keywords and Identifiers

Keywords

In Java, some words that you use have special meanings, such as: public, class, int, double These keywords cannot be used as: class names or variable names For example: int class = 10; cannot be used.

Identifiers

Composition

  1. Digits and letters
  2. The underscore _
  3. The dollar sign $

Requirements

  1. Cannot start with a digit
  2. Cannot use a keyword as a name
  3. Case-sensitive

Conventions

  1. Must satisfy the naming rules
  2. It is recommended to use English
  3. Make it meaningful
  4. Start with a lowercase letter and follow camelCase, e.g.: int studyNumber = 1;

Basic Syntax

If you enjoyed this, leave a comment~

... Page views
© 2021 - 2026 Vullfin @VV
Powered by theme astro-koharu · Inspired by Shoka