Skip to content

Instantly share code, notes, and snippets.

public class StringBufferExample {
public static void main(String[] args) {
StringBuffer strBuf = new StringBuffer();
// Append strings
strBuf.append("Welcome").append(' ').append("to").append(' ').append("Chankok.com");
System.out.println("Append strings : " + strBuf.toString());
@chankok
chankok / countries.json
Last active October 5, 2016 10:43
A JSON file with a list of country names and country codes (ISO Alpha-2)
[
{
"name": "Afghanistan",
"code": "AF"
},
{
"name": "Albania",
"code": "AL"
},
{
public class StringBuilderExample {
public static void main(String[] args) {
StringBuilder sb = new StringBuilder();
// Append strings
sb.append("Welcome").append(' ').append("to").append(' ').append("Chankok.com");
System.out.println("Append strings : " + sb.toString());
// Syntax of catching multiple exceptions
Try {
// Execute statements that may throw exceptions
} catch (ExceptionType1 | ExceptionType2 | ... VariableName) {
// Handle exceptions
package com.chankok.io;
import java.io.FileReader;
import java.io.IOException;
public class Java6ResourceManagementExample {
public static void main(String[] args) {
FileReader fr = null;
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};
/*
package com.chankok.oop;
public class DataEncapsulationExample {
public static void main(String[] args) {
try {
Student student1 = new Student();
student1.setName("Chankok");
package com.chankok.io;
import java.io.FileReader;
import java.io.IOException;
public class Java6ReadEntireFileExample {
public static void main(String[] args) {
FileReader fr = null;
@chankok
chankok / README.md
Last active April 7, 2017 08:22
web.xml Namespace Declaration and Schema Location Example http://www.chankok.com/web-xml-namespace-declaration-and-schema-location/

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
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