
Quick Contact
Java Tutorial
- What is Java?
- History of Java
- Hello Java Program
- Features of Java
- Basic Syntax
- Java Setup
- Data Types in Java
- Java Variables
- Operators in Java
- JVM
- Java If-else Statement
- Switch Case Statement
- Java Loops
- Do-While Loop
- Java While Loop
- Continue Statement
- Break Statement in Java
- Constructors in Java
- Oops Concept in Java
- Features of OOPs
- Inheritance
- Exeception handeling
- Aggregation (HAS-A relationship) in Java
- Method Overriding in Java
- Method Overloading
- Java Static Keyword
- Java This Keyword
- Java Final Keyword
- Polymorphism
- Static Binding and Dynamic Binding
- Abstract class in Java
- Access Modifiers in Java
- Difference between abstract class and interface
- Interface in Java
- Garbage Collection in Java
- Java Package
- Encapsulation
- Serialization and Deserialization in Java
- Java Inner Classes
- Java Applets
- Multithreading in Java
- Thread Priorities in Java
- Thread Creation
- Inter Thread Communication
- Wrapper Classes in Java
- Java Input Output
- Java AWT Introduction
- Java Layout Manager
- Java Layout Policy
- Java AWT Events
- Collection Framework
- Collection Framework List Interface
- Swing in Java
- Swing Utility Classes
- Swing Layout Managers
- Java JDBC
- Hibernate Framework Overview – Architecture and Basics
Springboot
- Spring Environment Setup
- Spring Boot CRUD REST API Project using IntelliJ IDEA | Postman | MySQL
- Dockerizing Spring Boot Application | Spring Boot Docker Tutorial
- spring-boot-restapidocumentation with swagger
- Spring Boot HttpClient Overview
- Apache HttpClient POST HTTP Request Example
- Apache HttpClient PUT HTTP Request Example
- Apache HttpClient DELETE HTTP Request Example
- Apache HttpClient HTML Form POST Request Example
- Spring Boot JSP Exampl
- Deploying Spring Boot WAR file with JSP to Tomcat
- Spring Boot Annotations
- Spring Core Annotations
- Spring MVC Annotations with Examples
- Spring Scheduling Annotations
- Spring - Java-based Container Configuration
- Spring Java Based Configuration Example
Hibernate
- Hibernate 5 hello world
- Hibernate- One to One Unidirectional Mapping Annotation Example
- Hibernate - Batch Processing
- Hibernate - Interceptors
- Hibernate 5 - Create, Read, Update and Delete (CRUD) Operations Example
- Hibernate Transaction Management
- Hibernate One to Many Unidirectional Mapping Example
- Hibernate One to Many Bidirectional Mapping Example
- Hibernate Many to Many Annotation Mapping Example
- Hibernate Primary KeyJoin Column
- Hibernate First Level Cache with Example
- Hibernate XML Configuration Example with Maven + Eclipse + MySQL Database
- Hibernate Java Configuration Example
- JPA 2 with Hibernate 5 Bootstrapping Example
- JPA and Hibernate Cascade Types
- Hibernate/JPA - Primary Key Generation
- Hibernate 5 - Enum Type Mapping Example
- Hibernate Component Mapping
- Hibernate Object States – Transient,Persistent and Detached
- Hibernate 5 - Save an Entity Example
- Hibernate 5 - Persist an Entity Example
- Hibernate 5 - saveOrUpdate() Method Example
- Hibernate 5 - get(), load() and byId() Method Examples
- Hibernate 5 - merge() Example
- Hibernate 5 - Delete or Remove an Entity Example
- Hibernate 5 - load() Method Example
- Hibernate Session Interface Methods
- Hibernate Session.clear() Method Example
- Introduction Of Java strutes to Architecture
- Struts 2 - Architecture
- Struts 2 - Configuration Files
- Struts 2 - Actions
- Struts 2 - Interceptors
- Struts 2 - Results & Result Types
- Struts 2 - Value Stack/OGNL
- Struts 2 - File Uploading
- Struts 2 - Database Access
- Struts 2 - Validations Framework
JAVA FX
- JavaFX Tutorial
- Introduction to JavaFX Pane
- JavaFX Popup
- JavaFX group
- JavaFX Controller
- JavaFX Gradient Color
- JavaFXAnchorPane
- JavaFXTabPane
- JavaFX Scene
- JavaFX Stage
- JavaFXWebView
- JavaFX Timeline
- JavaFX Timer
- JavaFX Image
- JavaFX Background
- JavaFX dialog
- JavaFX Font
- JavaFXTextArea
- JavaFXObservableList
- JavaFX GUI
- JavaFX FXML
- JavaFXEventHandler
- JavaFXGradle
- JavafxScrollpane
- JavaFXAPI
Switch Case Statement
When a value requires different actions for a fixed set of values, the if might get more complex, the more the set of values increases. In this case the more suitable statement is the switch statement.
Syntax
switch ([onvar]) {
case [option]:
[statement;]
break;
…
default:
[statement;]
}
The terms in square brackets are detailed in the following list.
-
[onvar] is the variable that is tested against the case statements to select a statement. It can be of any primitive type, enumerations and starting with Java 7, String. Clearly the switch statement is not limited by conditions evaluated to boolean results, which allows for a lot of flexibility.
-
case [option] is a value the variable is matched upon to make a decision regarding the statement to execute. A case as the keyword states.
-
[statement] is a statement or a groups of statements to execute when [onvar] == [option]. Considering that there is no else branch, we have to make sure that only the statement(s) corresponding to the first match is executed, which is where the break; statement comes in. The break statement stops the current execution path and moves the execution point to the next statement outside the statement that contains it. I’ll cover it later in the chapter. Without it, after the first match, all subsequent cases are traversed, and statements corresponding to them are executed.
-
default [statement;] is a statement that is executed when no match on a case has been found, the default case does not need a break statement. If the previous program is run with any number outside the [1-12] interval, Error is printed because the default statement is executed.
So, if we execute the preceding program and we provide number 7 as an argument, the text Summer is printed. But if the break statements for case 7 and 8 are commented, the output changes to Autumn.
Now that you understand how switch works, let’s look at how we can reduce the previous statement. The month example is suitable here, because it can further be modified to show how the switch statement can be simplified, when a single statement should be executed for multiple cases. In our code, writing each assignment statement three times is a little redundant. switch can be written in a different way to avoid that by grouping the cases.
Example
public class SwitchExample {
public static void main(String[] args) {
//Declaring a variable for switch expression
int number=200;
//Switch expression
switch(number){
//Case statements
case 100: System.out.println(“100”);
break;
case 200: System.out.println(“200”);
break;
case 300: System.out.println(“300”);
break;
//Default case statement
default:System.out.println(“Not in 100, 200 or 300”);
}
}
}
Output
200
Flowchart of Switch Statement

Break statement in Switch case
In Switch case Break statement is optional, but most of the time it is use when we compromise with switch case.
Example
public class SwitchDayExample {
public static void main(String[] args) {
int day=7;
String dayString=””;
switch(day){
case 1: dayString=”1 – Monday”;
break;
case 2: dayString=”2 – Teusday”;
break;
case 3: dayString=”3 – Wednesday”;
break;
case 4: dayString=”4 – Thursday”;
break;
case 5: dayString=”5 – Friday”;
break;
case 6: dayString=”6 – Saturday”;
break;
case 7: dayString=”7 – Sunday”;
break;
default:System.out.println(“Sunday close”);
}
System.out.println(dayString);
}
}
Output
7 – Sunday
Apply now for Advanced Java Training Course