Different Types of Variable
Different Types of Variable
Java comment- used to explain java code, and to make it more readable. (//)
String – store text, such as “hello”. String values are surrounded by double quotes
Int – stores integers (whole numbers), without decimals. Such as 123 or -123
Char- stores single characters, such as ‘a’ or ‘b’. Char values are surrounded by single quotes
Integer types- store the whole number, positive or negative, without decimals
Valid types are byte, short, int and long. Which type you should use, depend on the numeric value
Floating point types – represent numbers with a fractional part, containing one or more decimals.
OPERATORS
JAVA STRING
STRING LENGTH
• A String inn java is actually an object, which contain methods that can perform certain
operation on string. For example, the length of a string can be found with length()
method:
STRING CONCATENATION
• The + operator can be used between strings to add them together to make a new string.
JAVA CONDITION AND IF STATEMENT
• Use else to specify to specific a block of code to be executed, if a scpecified condition is false
Ex.
• Use else if to specify a new condition to test, if the first condition is false
Ex.
• Use Switch tp specify many alternative blocks of code to be executed
- The value of the expression is compared with the value of each case
- If there is a match, the associated block of code to be executed
- The break and default keywords are optional.
DEFAULT KEYWORDS
- Specifies some code to run if there is no case match
JAVA WHILE LOOP
The While loop loops through a block of a code as long a specified condition is true
- is a variant of the while loop. This loop will execute the code block once, before
checking if the condition is true, then it will repeat the loop as long the condition
is true.
FOR LOOP
- When you know exactly how many times you want to loop throung a block of code, use for loop
instead of a whileloop.