Java Tutorials(the traditional features of the Java, including variables, arrays, data types, operators and control flow)
Language Basics
the traditional features of the Java, including variables, arrays, data types, operators and control flow
Variables
kinds of variables in Java
-
Instance Variables(Non-Static Fields)
Instance Variables are unique to each instance of a object(class), objects store their individual states in "non-statis fields"
-
Class Variables(Static Fields)
Class Variables is governed by the object(class), regardless of how many times the class has been instantiated.
-
Local Variables
A method will often store its temporary state in local variables. Local variables are absolutely only visible to the methods in whhich they are declared,
-
Parameters
Primitive Data Types
The Java programming language is statically-typed, which means that all variables must first be declared before they can be used.
Data Type | Default Value(for fields) |
---|---|
byte | 0 |
short | 0 |
int | 0 |
long | 0 |
float | 0.0 |
double | 0.0 |
char | '\u0000' |
boolean | false |
Local variables are slightly different; the compiler never ever never assgin a default value to an unitialized local variable. You musk make sure assign a local variable a value before you attempt to use it or else result in compile-time error
-
Using Underscore Characters in Numeric Literals to Imporve the readability of code.
Place underscores only between digits. you cannot place underscores in the following places;
1. At the beginning or end of a number 2. Adjacent to a decimal point in a floating point literal 3. Prior to an F or L suffix 4. In positions where a string of digits is expected long creditCardNumber = 1234_6123_2312_2332L; // ✅ float PI = 3.14_15F; //✅ float pi = 3_.1415F; //❌ int x1 = 52_; //❌ int x2 = Ox_52; //❌ int x3 = Ox5_2; //❌
Arrays
An array is a container object that holds a fixed number of values of a single type.The length of an array is established when the array is created.
// Create an array of integers with 10 length int[] anArray = new int[10]; // Create an array with assigned elements int[] arrInt = { 100, 200, 300 400, 500, 600 }
Bullet point
- The term "instance variable" is another name for non-static field.
- The term "class variable" is another name for static field.
- A local variable store termporary state; it is declared inside a method.
- A variable declared within the openming and closing parenthesis of a method is called a parameter.
- What are the eight primitive data types supported by the Java programming language? byte,short,int,long,float,double,boolean,char.
- Character strings are represented by the class java.lang.String.
- An array is a container object that holds a fixed number of values of a single value.
Operators
Assignment, Arithmetic, and Unary Operators
- The Arithmetic Operators
The languages provides operators that perform addition, subtraction, multiplication, and division.
Operators | Description |
---|---|
+ | Additive operator(also used for String concatenation) |
- | Subtraction operator |
* | Multiplication operator |
/ | Division operator |
% | Remainder operator |
- The Unary Operators
The unary operators require only one operand; they perform various operations such as incrementing/decrementing a value by one, negating an expression. or inverting the value of a boolean.
Operator | Description |
---|---|
+ | Unary plus operator; indicates positive value |
- | Unary minus operator; negates an expression |
++ | Increment operator; increments a value by 1 |
-- | Decrement operator; decrements a value by 1 |
! | Logical complement operator; inverts the value of a boolean |
- Equality, Relational, and Conditional Operators
Operator | Description |
---|---|
== | equal to |
!= | not equal to |
> | greater than |
>= | greater than or equal to |
< | less than |
<= | less than or equal to |
-
The conditional Operators
-
&& and || perform Conditional-AND and Conditional-OR operations on two boolean expressions. These operatos exhibit "short-circuiting" behavior.
-
【expressions ? doSth(T) : doSth(F)】as shorthand for an 【if-then-else】
Operator Description && Conditional-And II Conditional-OR ?: Ternary(shorthand for if-then-else statement) -
-
Bitwise and Bit Shift Operators
Operator Description ~ Unary bitwise complement << Signed left shift >> Signed right shift >>> Unsigned right shift & Bitwise And ^ Bitwise exclusive OR I Bitwise inclusive OR
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· winform 绘制太阳,地球,月球 运作规律
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· AI 智能体引爆开源社区「GitHub 热点速览」
· 写一个简单的SQL生成工具