Dasar-Dasar Pemrograman 2: Java Basics: Fariz Darari (Fariz@cs - Ui.ac - Id)
Dasar-Dasar Pemrograman 2: Java Basics: Fariz Darari (Fariz@cs - Ui.ac - Id)
Java Basics
Fariz Darari ([email protected])
• What is a bug?
• What is compile?
Quiz time
• What is a program?
A sequence of instructions that specifies how to perform tasks on a computer.
• What is a bug?
An error in a program.
• What is compile?
To translate a program in a high-level language into a low-level language,
all at once, in preparation for later execution.
Variables
• A variable is a named location that stores a value. Values may be
numbers, text, images, sounds, and other types of data.
Declaration
Assignment
Declare and assign variables on
same line
Printing variables
Arithmetic operators
Floating-point numbers
Error types
• Compile-time error
Compile-time errors occur when you violate the syntax rules of the Java
language. For example, parentheses and braces have to come in matching
pairs. So (1 + 2) is legal, but 8) is not.
• Runtime error
The second type of error is a run-time error, so-called because it does not
appear until after the program has started running.
• Logic error
If your program has a logic error, it will compile and run without generating
error messages, but it will not do the right thing.
Credits: Chapter 1 and 2 of Think Java book by Allen Downey and Chris Mayfield