CORE API / CATATAN</>↗Core API27 Jul 2006
package org.kodejava.util; import java.util.Arrays; import java.util.List; public class ArrayToListExample { public static void main(String[] args) { // Creates an array of object, in this case we create an // Integer array. Integer[] numbers = {1, 1, 2, 3, 5, 8, 13, 21, 34, 55}; // Convert the created array above to collection, in this // […]
CORE API / CATATAN</>↗Core API25 Jul 2006
package org.kodejava.util; import java.util.ArrayList; import java.util.LinkedList; public class CollectionToArrayList { public static void main(String[] args) { // We create LinkedList collection type at put some values // in it. Here we put A, B, C and D letter into it. LinkedList<String> linkedList = new LinkedList<>(); linkedList.push("A"); linkedList.push("B"); linkedList.push("C"); linkedList.push("D"); // Let say you want to […]
CORE API / CATATAN</>↗Core API21 Jul 2006
Let say you want to know the number of days in a month, or we can say it as the last date of a month. The example below shows you how to obtain the number of days or the date. package org.kodejava.util; import java.util.Calendar; public class MonthDaysExample { public static void main(String[] args) { // […]
CORE API / CATATAN</>↗Core API21 Jul 2006
The java.lang.Math.random() method returns random number between 0.0 and 1.0 including 0.0 but not including 1.0. By multiplying Math.random() result with a number, for example 10 will give us a range of random number between 0.0 and 10.0. To get a random number between two numbers (n and m) we can use the formula of: […]
JDBC / CATATAN</>↗JDBC20 Jul 2006
package org.kodejava.jdbc; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.Statement; public class JdbcQueryExample { // Database connection information private static final String URL = "jdbc:mysql://localhost/kodejava"; private static final String USERNAME = "kodejava"; private static final String PASSWORD = "s3cr*t"; public static void main(String[] args) { // Get a connection to database. try (Connection connection = [...
AWT / CATATAN</>↗AWT18 Jul 2006
package org.kodejava.awt; import java.awt.*; public class ScreenSizeExample { public static void main(String[] args) { Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); System.out.println("Screen Width: " + screenSize.getWidth()); System.out.println("Screen Height: " + screenSize.getHeight()); } } The output of the code snippet above: Screen Width: 2560.0 Screen Height: 1080.0