SupportWriter space ↗
REFERENCE LIBRARY

References from other publishers

Republished articles with source attribution. This collection is separate from Diary Coding’s original guides and does not display ads.

Read original guides → · Editorial policy

FOR YOUR CURIOSITY

Latest notes.

BASIC / NOTES</>↗
Basic18 Sep 2009

How do I use the if-then-else statement?

The if-then-else control flow statement adds a secondary path to the if statement when the expression evaluates to false. When it evaluates to false the else block will be executed. Below is the program that takes input of user test score and evaluates the score to get the corresponding grade. package org.kodejava.basic; import java.io.Console; public […]

Wayan · 1 min read
BASIC / NOTES</>↗
Basic17 Sep 2009

How do I use the if-then statement?

The if-then is the most basic control flow statement. It will execute the block of statement only if the test expression evaluated equals to true. Let’s see the example below: package org.kodejava.basic; public class IfThenDemo { public static void main(String[] args) { int a = 10; int b = 5; // If the evaluation of […]

Wayan · 1 min read
BASIC / NOTES</>↗
Basic15 Sep 2009

How do I count the occurrences of a number in an array?

package org.kodejava.basic; import java.util.HashMap; import java.util.Map; public class NumberOccurrenceInArray { public static void main(String[] args) { int[] numbers = new int[]{1, 8, 3, 4, 3, 2, 5, 7, 3, 1, 4, 5, 6, 4, 3}; Map<Integer, Integer> map = new HashMap<>(); for (int key : numbers) { if (map.containsKey(key)) { int occurrence = map.get(key); occurrence++; […]

Wayan · 1 min read
BASIC / NOTES</>↗
Basic13 Sep 2009

How do I use the double brace initialization?

The double brace initialization {{ … }} is another way for initializing a collection objects in Java. It is offer a simple syntax for initializing a collection object. package org.kodejava.lang; import java.util.ArrayList; import java.util.List; public class DoubleBraceInitialization { public static void main(String[] args) { // Creates a list of colors and add three colors of […]

Wayan · 2 min read
CORE API / NOTES</>↗
Core API12 Sep 2009

How do I count the number of occurrences of a char in a String?

This example show you how to count the number of a character occurrences in a string. We show two ways to do it, using the String.replaceAll(String regex, String replace) method and creating a loop that check every char in the String and count the matched char. package org.kodejava.lang; public class CharCounter { public static void […]

Wayan · 2 min read
APACHE COMMONS / NOTES</>↗
Apache Commons07 Sep 2009

How do I get the content of an InputStream as a String?

We can use the code below to convert the content of an InputStream into a String. At first, we use FileInputStream create to a stream to a file that going to be read. IOUtils.toString(InputStream input, String encoding) method gets the content of the InputStream and returns a string representation of it. package org.kodejava.commons.io; import org.apache.commons.io.IOUtils; […]

Wayan · 1 min read
✳

Knowledge grows when shared.

Stay curious. There is always something new to learn.

Explore notes ↗
Putu Adi Guna Permana
ABOUT THE AUTHOR

Dr (C). Ir. Putu Adi Guna Permana, S.Kom., M.Kom., IPM., ASEAN Eng.

Writer and founder of Diary Coding — sharing notes, tutorials, and experiences about programming for anyone who wants to keep learning.