Java Switch Statement The Java switch statement executes one statement from multiple conditions. It is like if-else-if ladder statement. The switch statement works with byte, short, int, long, enum types, String and some wrapper types like Byte, Short, Int, and Long. Since Java 7, you can use strings in the switch statement. In other words, the switch statement tests the equality of a variable against multiple values. Points to Remember There can be one or N number of case values for a switch expression. The case value must be of switch expression type only. The case value must be literal or constant . It doesn't allow variables . The case values must be unique . In case of duplicate value, it renders compile-time error. The Java switch expression must be of byte, short, int, long (with its Wrapper type), enums and string . Each case statement can have a break statement which is...
Loops in Java In programming languages, loops are used to execute a set of instructions/functions repeatedly when some conditions become true. There are three types of loops in Java. for loop while loop do-while loop Java For Loop vs While Loop vs Do While Loop Java For Loop The Java for loop is used to iterate a part of the program several times. If the number of iteration is fixed, it is recommended to use for loop. There are three types of for loops in java. Simple For Loop For-each or Enhanced For Loop Labeled For Loop Java Simple For Loop A simple for loop is the same as C / C++ . We can initialize the variable , check condition and increment/decrement value. It consists of four parts: Initialization : It is the initial condition which is executed once when the loop starts. Here, we can initialize the variable, or we can use an already initialized variable. It is an optional condition. Condition : It is the ...
Unicode System Unicode is a universal international standard character encoding that is capable of representing most of the world's written languages. Why java uses Unicode System? Before Unicode, there were many language standards: ASCII (American Standard Code for Information Interchange) for the United States. ISO 8859-1 for Western European Language. KOI-8 for Russian. GB18030 and BIG-5 for chinese, and so on. Problem This caused two problems: A particular code value corresponds to different letters in the various language standards. The encodings for languages with large character sets have variable length.Some common characters are encoded as single bytes, other require two or more byte. Solution To solve these problems, a new language standard was developed i.e. Unicode System . In unicode, character holds 2 byte, so java also uses 2 byte for characters. lowest value:\u0000 highest value:\uFFFF Next Topic: Operators In java Happy Coding