Skip to content

Instantly share code, notes, and snippets.

View BreakStatementExample.java
public class BreakStatementExample {
public static void main(String[] args) {
// Using break statement in for loop
System.out.println("Using break statement in for loop");
for (int count = 1; count <= 10; count++) {
if (count == 6) {
break;
}
View EnumSwitchStatementExample.java
public class EnumSwitchStatementExample {
public static void main(String[] args) {
// Using enum Type Argument in The switch Statement
Day day = Day.TUESDAY;
switch (day) {
case MONDAY:
case TUESDAY:
View IfElseStatementExample.java
public class IfElseStatementExample {
public static void main(String[] args) {
// Initialization
int score = 0;
String today = "";
// Example 1: if Statement
score = 150;
View StringArrayToStringExample.java
package com.chankok.arrays;
import java.util.stream.Collectors;
import java.util.stream.Stream;
public class StringArrayToStringExample {
public static void main(String[] args) {
// Initial the string array
View README.md

web.xml Namespace Declaration and Schema Location Example

web.xml is the deployment descriptor for a Java web application.

We can specify the namespace declaration and schema location in web.xml file for different Java servlet version:

  • Java Servlet 3.1
  • Java Servlet 3.0
  • Java Servlet 2.5
  • Java Servlet 2.4
View Java6ReadEntireFileExample.java
package com.chankok.io;
import java.io.FileReader;
import java.io.IOException;
public class Java6ReadEntireFileExample {
public static void main(String[] args) {
FileReader fr = null;
View DataEncapsulationExample.java
package com.chankok.oop;
public class DataEncapsulationExample {
public static void main(String[] args) {
try {
Student student1 = new Student();
student1.setName("Chankok");
View CheckEvenOddNumberExample.java
package com.chankok.operators;
public class CheckEvenOddNumberExample {
public static void main(String[] args) {
// Initial the integer array
int[] intArrays = {-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5};
/*
View Java6ResourceManagementExample.java
package com.chankok.io;
import java.io.FileReader;
import java.io.IOException;
public class Java6ResourceManagementExample {
public static void main(String[] args) {
FileReader fr = null;
View Catch Multiple Exceptions in Java
// Syntax of catching multiple exceptions
Try {
// Execute statements that may throw exceptions
} catch (ExceptionType1 | ExceptionType2 | ... VariableName) {
// Handle exceptions