JAVA PROGRAMMING
JAVA PROGRAMMING
PROGRAMMING WITH
PYTHON
• Computer programming is the process of designing and building an
executable computer program to accomplish a specific computing result or
to perform a specific task.
• Verification: is checking that data has been accurately copied onto the
computer or transferred from one part of a computer system to another.
• System.out.println(3 + 7);
• System.out.println(3 * 7);
Java Comments
• Comments can be used to explain Java code, and to make it
more readable. It can also be used to prevent execution
when testing alternative code.
• Single-line comments start with two forward slashes (//).
•YES / NO
•ON / OFF
•TRUE / FALSE
For this, Java has a boolean data type, which can only take the
values true or false:
CONT.
Characters
The char data type is
used to store
a single character. The
character must be
surrounded by single
quotes, like 'A' or 'c':
Strings
The String data type is used
to store a sequence of
characters (text). String
values must be surrounded
by double quotes:
Type Casting
Type casting is when you assign a value of one primitive
data type to another type.
In Java, there are two types of casting:
•Widening Casting (automatically) - converting a smaller
type to a larger type size
byte -> short -> char -> int -> long -> float -> double
String Length
String Methods
You can use these conditions to perform different actions for different
decisions.
Java has the following conditional statements:
•Use if to specify a block of code to be executed, if a specified condition is
true
•Use else to specify a block of code to be executed, if the same condition is
false
•Use else if to specify a new condition to test, if the first condition is false
•Use switch to specify many alternative blocks of code to be executed
The if Statement
The else
Statement
The else if
Statement
Switch
Instead of writing many if..else statements, you can use
the switch statement. The switch statement selects one of
many code blocks to be executed:
CONT.
The default Keyword
• The default keyword specifies some code to run if there is
no case match:
Loops
• Loops can execute a block of code as long as a specified
condition is reached.
• Loops are handy because they save time, reduce errors,
and they make code more readable.
Types of Loops
While Loop
Cont.
The while loop loops through a block of code as
long as a specified condition is true:
Do/While Loop