Java Programming Basics: Hello, World! and Fundamental Building Blocks
In this chapter, you will learn about the famous Hello, World! program, fundamental building blocks of Java programs, adding comments, object-oriented programming basics, and importing classes. Explore elements of the program, variables, identifiers, and rules for creating identifiers in Java. Enhance your understanding of Java programming with essential concepts and examples.
Download Presentation

Please find below an Image/Link to download the presentation.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.
You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.
E N D
Presentation Transcript
Chapter 1 Java Programming Basics
In This Chapter you will learn The famous Hello, World! program Fundamental Building blocks of Java programs such as keywords, statements, and blocks Different ways to add comments to your programs Basic information about object-oriented programming Ways to import classes
Hello World public class HelloWorld{ public static void main(String[] args) { System.out.println("Hello, World!"); } }
Elements of the program public Class HelloWorld (Identifier) public static
Elements of the program Void main (String[] args) System.out.println("Hello, World!");
Fundamental Building Blocks of Java Programs
Variable is a memory location (or several locations treated as a unit) that has been given a name so that it can be easily referred to and used in a program.
Identifier Is the name assigned to a variable
few simple rules when you create identifiers Identifiers are case-sensitive. As a result, SalesTax and salesTax are distinct identifiers. Identifiers can be made up of upper- or lowercase letters, numerals, underscore characters (_), and dollar signs ($). Thus, identifier names such as Port1, SalesTax$, and Total_Sales.
All identifiers must begin with a letter. Thus, a15 is a valid identifier, but 13Unlucky isn t (because it begins with a numeral). An identifier can t be the same as any of the Java keywords listed in Table 1-1. Thus, you can t create a variable named for or a class named public.
The Java language specification recommends that you avoid using dollar signs in names you create, because code generators use dollar signs to create identifiers. Thus, avoiding dollar signs helps you avoid creating names that conflict with generated names.
Data Type indicates what sort of data it can hold. used to specify the set of values and their operations.
byte byte in Java is 8 bits. It is a primitive data type, meaning it comes packaged with Java. Ex. declaration: byte age = 46;
short The short data type is a 16-bit signed two's complement integer. Ex. declaration: short s = 1000;
int int data type is a 32-bit signed two's complement integer. ex. int deposit = 3200;
long long data type is a 64-bit two's complement integer. ex. long phil_debt = 4346900000L
float float keyword is a primitive data type. It is a single-precision 32-bit IEEE 754 floating point. ex. Average = 87.70;
double double is used to represent floating- point numbers. It uses 64 bits to store a variable value and has a range greater than float type. ex. double phil_debt = 4346900000.34
keyword Is a word that has a special meaning defined by the Java programming language.
Types of statements Declaration statement Assignment statement Executable Statement Comment Block Statement
Declaration statement Statement that create variables to store value. Ex. Int age;
Assignment statement Statement that are used to store value to a variable. Ex. Age = 16;
Executable Statement Statement that are used to perform input, process or output. Ex. Name = Reader.readLine();, a =x + y;, System.out.println( Welcome to Java );.
Comment Statement that are ignored by the compiler during the compilation process and basically used as a form of program documentation, a way to explain a program structure and used as a marker to some statement block.
Two types of comment 1.Block Comment /* */ a.This is used to create a comment that has multiple line statements 2.Inline Comment // a.This is used along a Java statement, before or after a statement.
Block Statement A complex or group of statement that may include branching, iteration, assignment, declaration, executable and or comment. It is indicated with a open and close curly braces ({ }). Note: all statements in Java ends in semi colon (;) except block statement and comment.
Understanding classes and objects a class is code that defines the behavior of a Java programming element called an object. An object is an entity that has both state and behavior.
The state of an object consists of any data that the object might be keeping track of. The behavior consists of actions that the object can perform. The behaviors are represented in the class by one or more methods that can be called on to perform actions.
True or False You can store different types of value to a variable letters and or numbers
True or False Identifier Is the name assigned to a variable.
True or False All identifiers must begin with a letter.
True or False A keyword is a word that has a special meaning defined by the Java programming language.
True or False You can store different types of value to a variable letters and or numbers
True or False All statements in Java ends in semi- colon
Congratulations you have completed this part