Java – do while Loop with Example

Sometimes it is necessary that the block or statement must be executed at least once but if the condition is initially at a false state then the block will not be executed. So for the situation where a block of code must be executed at least once, a do-while loop comes in play. do–while is … Read more

Java – Switch Case Statement with Example

A switch statement allows a variable to be tested for equality against multiple values. It provides the case for the different blocks of code to be executed. Switch expression and case value must be of the same type. There must be at least one case or multiple cases with unique case values. In the end, … Read more

Java – if-else if ladder with Example

This statement allows the user to have multiple options to check for different conditions. Here, if one of the if or else-if condition is true then that part of the code will be executed and rest will be bypassed. If none of the conditions is true then the final else statement at the end will … Read more

Java – nested-if statement with Example

Nested-if statement allows the user to use if block inside the other if block. And the inner if is executed only if the outer if is true in condition. Flowchart for nested-if statement in Java: Syntax of nested if statement: Example of a nested-if statement in Java: Output:

Java – if-else statement with Example

There are two-part in an if-else statement. First is the if statement, here it checks for the condition to be true and if it is true then it will execute the code present inside the if-block. But if the condition is false then the code inside the else statement will be executed. Flowchart for if-else … Read more

Java – if statement

Among the decision making statements, if- statement is the most simple one. It checks if the condition is true or not, and if it is true then it executes the block of code inside if otherwise, it will not. The block that is executed is placed within the curly braces({}). Flowchart for if statement in … Read more

Java – Garbage Collection

Garbage collection in java is a way in which the unreachable objects are destroyed to free up space in memory. JVM creates a heap area which is called runtime data area, where all the objects are stored. And the space in that area is limited so it is needed to manage this area efficiently by … Read more

Java – Packages and its types with example

Packages in Java are a way to pack(group) a number of related types such as classes, interfaces, enumerations, and annotations together into a single unit. Think of it as a container for the classes. Packages are used to avoid name conflicts, provide a good structure to the projects with maintainable code that consists of many … Read more

Java – Method Overriding with Example, Super Keyword

In any object-oriented programming language, Method Overriding is a feature that allows the user to declare a method with the same name in a sub-class that is already present in a parent-class. That is when a sub-class inherits from its super-class and both have the same-named method than by overriding features, different tasks can be … Read more

Java – Method Overloading with Example

Method Overloading is one of the features in a class having more than one method with the same name. It is the same as Constructor Overloading in java. The methods are differed by their input parameter that is the data type, the number of parameters, and the order of the parameter list. Note that: Method overloading is not … Read more