Latest Theory



Java Enum Types

The article considers the implementation of Java enum types, starting from the API and ending with examples of the usage of inheritance in enums. The article is recommended reading for all java-programmers, regardless of experience.
Read More

Regular expressions

The article information is constructed in such a way, that everybody will understand how to use them, even those who knows nothing about regular expressions.
Read More

regexp regular expressions


Inner classes in Java

In Java nested class - a class that is declared within another class declaration. Nested classes are divided into static and non-static . Strictly non-static nested classes have another name - inner classes.
Read More

inner classes nested classes


Implementing authorization for API on the top of Play Framework 2.4*

The article considers the implementation of an easy to use authorization mechanism based on Play Framework 2.4* Actions architecture with full power of classical Actions
Read More

Actions Play-Framework BodyParsers AnyContent


Знайомство з Akka Typed. Частина перша: Protocols and Behaviors ([переклад] Tour of Akka Typed: Protocols and Behaviors)

В цій серії публікацій ми будемо розбирати Akka Typed, новий API для роботи з Akka Typed який має істотні переваги порівнюючи з класичною імплементацією.
Read More

akka typed protocols behaviors Tour of Akka Typed

Loading papers...



Break statement

Another point of interest is the break statement. Each break statement terminates the enclosing switch statement. Control flow continues with the first statement following the switch block.
The break statements are necessary because without them, statements in switch blocks fall through: All statements after the matching case label are executed in sequence, regardless of the expression of subsequent case labels, until a break statement is encountered.
Technically, the final break is not required because flow falls out of the switch statement. Using a break is recommended so that modifying the code is easier and less error prone. The default section handles all values that are not explicitly handled by one of the case sections.

switch statement break statement


Garbage collection

The Java interpreter knows exactly what objects and arrays it has allocated. It can also figure out which local variables refer to which objects and arrays, and which objects and arrays refer to which other objects and arrays. Thus, the interpreter is able to determine when an allocated object is no longer referred to by any other object or variable. When the interpreter finds such an object, it knows it can destroy the object safely and does so. The garbage collector can also detect and destroy cycles of objects that refer to each other, but are not referenced by any other active objects. Any such cycles are also reclaimed.

garbage collector gc


Implicit conversions

Implicit conversions are automatically performed when a value is copied to a compatible type. For example:
short a=2000;
int b;
Here, the value of a is promoted from short to int without the need of any explicit operator. This is known as a standard conversion. Standard conversions affect fundamental data types, and allow the conversions between numerical types (short to int, int to float, double to int...), to or from bool, and some pointer conversions.
Converting to int from some smaller integer type, or to double from float is known as promotion, and is guaranteed to produce the exact same value in the destination type. Read more



No-promotion arithmetic types conversions

No-promotion conversions between arithmetic types may not always be able to represent the same value exactly:
  • negative integer to an unsigned type, the resulting value corresponds to its 2's complement bitwise representation (i.e., -1 becomes the largest value representable by the type, -2 the second largest, ...).
  • conv. from/to bool consider false equivalent to zero (for numeric types) and to null pointer (for pointer types); true is equivalent to all other values and is converted to the equivalent of 1.
  • floating-point type to an integer type, the value is truncated (the decimal part is removed). If the result lies outside the range of representable values by the type, the conversion causes undefined behavior.
  • if the conv. is between numeric types of the same kind, the conversion is valid, but the value is implementation-specific (may not be portable).
Read more



Types conversions

No-promotion conversions may imply a loss of precision, which the compiler can signal with a warning. This warning can be avoided with an explicit conversion.
For non-fundamental types, arrays and functions implicitly convert to pointers, and pointers in general allow the following conversions:
  • Null pointers can be converted to pointers of any type
  • Pointers to any type can be converted to void pointers.
  • Pointer upcast: pointers to a derived class can be converted to a pointer of an accessible and unambiguous base class, without modifying its const or volatile qualification.
Read more

types implicit-conversion


Omitting the html, head, and body tags

Omitting the html, head, and body tags is certainly allowed by the HTML specs. The underlying reason is that browsers have always sought to be consistent with existing web pages, and the very early versions of HTML didn't define those elements. When HTML 2.0 first did, it was done in a way that the tags would be inferred when missing.
In the HTML5 standard, the <html> tag, the <body> tag, and the <head> tag can be omitted. The following code will validate as HTML5:
<!DOCTYPE html>
<title>Page Title</title>
<h1>This is a heading</h1>

This is a paragraph.

More details: Stackoverflow: Is it necessary to write HEAD, BODY and HTML tags?

body-tag html-tag head-tag omitting-tags


Switch statement syntax

The switch statement evaluates an expression, matching the expression's value to a case clause, and executes statements associated with that case.


switch (expression) {
  case value1:
    //Statements executed when the result of expression matches value1
  case value2:
    //Statements executed when the result of expression matches value2
  case valueN:
    //Statements executed when the result of expression matches valueN
    //Statements executed when none of the values match the value of the expression

An expression whose result is matched against each case clause.

case valueN

A case clause used to match against expression.

Read more: MDN: Switch


Switch statement

A switch statement first evaluates its expression. It then looks for the first case clause whose expression evaluates to the same value as the result of the input expression (using strict comparison, ===) and transfers control to that clause, executing the associated statements. (If multiple cases match the provided value, the first case that matches is selected, even if the cases are not equal to each other.) If no matching case clause is found, the program looks for the optional default clause, and if found, transfers control to that clause, executing the associated statements. If no default clause is found, the program continues execution at the statement following the end of switch. By convention, the default clause is the last clause, but it does not need to be so.
Read more: MDN: Switch



Break in switch statement

The Switch Statement

The optional break statement associated with each case label ensures that the program breaks out of switch once the matched statement is executed and continues execution at the statement following switch. If break is omitted, the program continues execution at the next statement in the switch statement.

What happens if I forgot a break?

If you forget a break then script will run from the case where criteria is met, and will run the case after that regardless if criteria was met. See example here:
var foo = 0;
switch (foo) {
  case -1:
    console.log('negative 1');
  case 0: 
    // NOTE: the forgotten break 
  case 1:     
    break; //  break 
  case 2:
Console output:

Read more: MDN: Switch



Multi-case - single operation

Multi-case - single operation

This method takes advantage of the fact that if there is no break below a case statement it will continue to execute the next case statement regardless if the case meets the criteria.
This is an example of a single operation sequential switch statement, where four different values perform exactly the same.
var Animal = 'Giraffe';
switch (Animal) {
  case 'Cow':
  case 'Giraffe':
  case 'Dog':
  case 'Pig':
    console.log('This animal will go on Noah\'s Ark.');
  case 'Dinosaur':
    console.log('This animal will not.');
Read more: Stackoverflow: Switch statement multiple cases in JavaScript

switch-statement multi-case-single-operation multi-case

Loading rules...
Sign Up Now
or Subscribe for future quizzes