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

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.