CHAPTER 3Basic Java Programming
“If you think you can do a thing or think you can't do a thing, you're right.”
—Henry Ford
- 3.1 Introduction
- 3.2 Variables
- 3.3 Operators
- 3.4 Reserved Words
- 3.5 Input and Output
- 3.6 Loops and Selections
- 3.7 Arrays, Matrices, and Vectors
- 3.8 Reading and Writing Files
- 3.9 Methods
- 3.10 Object-Oriented Programming
- 3.11 Multithreading
- 3.12 Date, Time, Timer, and Sleep Methods
- 3.13 Executing System Commands
- 3.14 Packages and Programming on a Large Scale
- 3.15 Software Engineering
- 3.16 Deploying Java Applications
- 3.17 Summary
- 3.18 Chapter Review Questions
3.1 Introduction
This chapter introduces the basic concepts of Java programming, intended for those who have some experience in coding and familiarity with programming concepts but are new to the Java language.
3.2 Variables
Java supports eight primitive types of variables: byte
, short
, int
, long
, float
, double
, char
, and boolean
. Variable names in Java are case-sensitive and must start with a letter, an underscore, or a dollar sign ($
). They cannot start with a number. After the first character, a variable name can include any combination of letters and numbers. Spaces and special symbols, such as !
, ""
, £
, %
, &
, *
, #
, @
, ~
, and so on, are not allowed in variable names. In Java, all variables must be declared before they can be used. To declare a variable, you will need to specify the type, leave at least one space, and then specify the variable name and a semicolon (;
).
type variablename; ...
Get Practical Java Programming for IoT, AI, and Blockchain now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.