How to simulate java.lang.OutOfMemoryError in Java
A simple code snippet to simulate the java.lang.OutOfMemoryError: Java heap space
A simple code snippet to simulate the java.lang.OutOfMemoryError: Java heap space
In JAX-RS, we can use response.readEntity(String.class) to read the response body from a post request. import jakarta.ws.rs.core.Response; Response response = //… // read response body String body = response.readEntity(String.class); P.S Tested with Jersey 3.x 1. Problem Below is a JAX-RS POST request endpoint to accept a JSON input and return a JSON response. // POST, …
This article shows how to return a JSON response in the Jersey application, using EclipseLink MOXy. Tested with Jersey 3.0.2 EclipseLink MOXy 3 Jetty 11, HTTP Server Java 11 Maven 3 SLF4J, Logback, redirect Jersey J.U.L logs to logback JUnit 5 and JSONassert 1.5 (Unit Test) org.json 20210307, JSONObject Table of contents 1. EclipseLink MOXy …
This article shows how to fix VirtualBox 6.1.* running slow on macOS, MacBook Pro with retina display. Tested with VirtualBox 6.1.22 macOS Big Sur 11.1 MacBook Pro (16-inch, 2019) Kali Linux, Ubuntu, Debian 1. VirtualBox with more memory, CPU, etc In VirtualBox, clicks on the Settings icon. 1.1 Increase based memory. 1.2 Increase CPU processors. …
Try to start the VirtualBox on macOS and hits the below error? P.S Tested with VirtualBox 6.1 on macOS Big Sur 11.1 1. Solution The reason for this Kernel driver not installed (rc=-1908) is similar to this VirtualBox installation failed error. The macOS blocked the VirtualBox to run, and we need to unblock it in …
A git pull and hits the below "reference broken" error message? Terminal $ git pull error: cannot lock ref ‘refs/remotes/origin/master’: unable to resolve reference ‘refs/remotes/origin/master’: reference broken From bitbucket.org:xx/mkyong-tutorials ! [new branch] master -> origin/master (unable to update local ref) Solution Unsure the root cause of the "reference broken". To fix it, delete this file …
This tutorial shows logging in Java application using the tinylog lightweight logging framework. Table of contents 1. tinylog Dependency 2. tinylog Hello World 3. tinylog Logging Levels 4. Logs with the arguments 5. tinylog.properties 6. tinylog.configuration 7. Send logs to a file 8. Send logs to Console and file 9. Rolling File 10. Tags 11. …
This tutorial shows logging using the Java built-in logging APIs in the java.util.logging package. Table of contents 1. Java Logging APIs Hello World 2. Logging Levels 3. logging.properties 4. java.util.logging.config.file 5. Why choose java.util.logging 6. Download Source Code 7. References P.S The java.util.logging is bundled with the Java since JDK 1.4. 1. Java Logging APIs …
Starts a Java project and hits the below "class not found for com.sun.xml.bind.v2.ContextFactory"? Terminal Caused by: java.lang.ClassNotFoundException: com.sun.xml.bind.v2.ContextFactory at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:606) at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:168) at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522) at jakarta.xml.bind.ServiceLoaderUtil.nullSafeLoadClass(ServiceLoaderUtil.java:92) at jakarta.xml.bind.ServiceLoaderUtil.safeLoadClass(ServiceLoaderUtil.java:125) at jakarta.xml.bind.ContextFinder.newInstance(ContextFinder.java:230) … 43 more Solution The com.sun.xml.bind.v2.ContextFactory is under the JAXB APIs; Java 9 deprecated the JAXB, and Java 11 deleted the JAXB completely. To fix …
Migrate a Java project to Java 11 and hits the below "class not found error for JAXBException" java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException A short history of JAXB on Java The Jakarta XML Binding (JAXB; formerly Java Architecture for XML Binding) is an XML binding framework to convert Java classes to and from XML. The JAXB is part of …
The Java logging APIs (java.util.logging) default loads logging.properties in the $JAVA_HOME/jre/lib/ (Java 8 and before); for Java 9 and above, the logging.properties file moved to $JAVA_HOME/conf. Note Java Logging APIs Tutorial logging.properties Here is the logging.properties file from Java 11. C:\opt\jdk-11.0.1\conf ############################################################ # Default Logging Configuration File # # You can use a different file …
This article shows a shell script to backup, gzips the website files and folders, and uploads the backup file to Amazon S3. Table of contents 1. Install AWS CLI 2. Backup files and folders to Amazon S3 (Shell script) 3. How to run the backup script? 4. Run the backup script every day or weekly …
This article shows how to use HK2 dependency injection framework in Jersey and enable auto-scanning auto-discovery of the declared @Contract and @Service components. Table of contents 1. Jersey and HK2 dependency injection 2. @Contract, @Service, and @Inject 3. HK2 manual register @Contract and @Service 4. HK2 auto scanning @Contract and @Service 4.1 HK2 inhabitant files …
Using Jersey 3x + Jetty to develop endpoints, but hits the jakarta.activation.DataSource warning during application startup? Terminal SLF4J: No SLF4J providers were found. SLF4J: Defaulting to no-operation (NOP) logger implementation SLF4J: See http://www.slf4j.org/codes.html#noProviders for further details. May 27, 2021 10:09:48 AM org.glassfish.jersey.message.internal.MessagingBinders$EnabledProvidersBinder bindToBinder WARNING: A class jakarta.activation.DataSource for a default provider MessageBodyWriter<jakarta.activation.DataSource> was not found. …
Using Jersey 3x + Jetty to develop endpoints, but hits the following error during application startup. Terminal Exception in thread "main" java.lang.NoClassDefFoundError: jakarta/servlet/ServletInputStream at org.glassfish.jersey.jetty.JettyHttpContainerProvider.createContainer(JettyHttpContainerProvider.java:43) at org.glassfish.jersey.server.ContainerFactory.createContainer(ContainerFactory.java:58) at org.glassfish.jersey.jetty.JettyHttpContainerFactory.createServer(JettyHttpContainerFactory.java:110) at com.mkyong.MainApp.startServer(MainApp.java:22) at com.mkyong.MainApp.main(MainApp.java:32) Caused by: java.lang.ClassNotFoundException: jakarta.servlet.ServletInputStream at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583) at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178) at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521) … 5 more 1. jakarta/servlet/* and Servlet API 5.0 Since Servlet API …
This article shows how to start a Jetty HTTP Sever to run a JAX-RS or Eclipse Jersey application. Tested with Jersey 3.0.2 Jetty 11 Jackson 2.12.2 JUnit 5.4.0 (unit test) JSONassert 1.5.0 (unit test) Maven 3.8.3 Java 11 Tables of contents 1. Using Jersey with Jetty HTTP Server 2. Project Directory 3. Project dependencies 4. …
We can use curl -v or curl -verbose to display the request headers and response headers in the cURL command. In the cURL response The > lines are request headers. The < lines are response headers. 1. curl -v http://google.com Try curl -v to the Google search engine. Terminal curl -v http://google.com * Rebuilt URL …
This article shows how to convert a Java project to a Maven project in IntelliJ IDEA. Table of contents 1. A Non-Maven Project 2. Add Framework Support – Maven 3. Update the default pom.xml 4. Reload the Maven project 5. References P.S Tested with IntelliJ IDEA 2021.1.1 1. A Non-Maven Project A non-Maven project (without …
This article shows the difference between r, r+, w, w+, a and a+ in Python open() function. Table of contents 1. Difference between r, r+, w, w+, a and a+ 2. What is + means in open()? 3. Difference between r and r+ in open() 3.1 Read a file with r 3.2 Read and write …
This article shows how to append a text file in Python. Table of contents 1. Append to a file 2. Difference between a and a+ 3. Download Source Code 4. References P.S Tested with Python 3.8 1. Append to a file The a creates a new file or opens an existing file for writing; the …
This article shows how to write a text file in Python. Table of contents 1. Write to a file – open() and close() 2. Write to a file – with statement 3. Write multiple lines to a file 4. Working with two files 5. Find and replace in a file 6. Download Source Code 7. …
This article shows how to read a text file in Python. Table of contents 1. Read a file using open() and close() 2. Read a file using with statement 3. Read a file using try-finally 4. Read a file line by line 5. Read a file and skip the first line 6. Default open mode …
In Java, if we remove items from a List while iterating it, it will throw java.util.ConcurrentModificationException. This article shows a few ways to solve it. Table of contents 1. java.util.ConcurrentModificationException 2. Java 8 Collection#removeIf 2.1 removeIf examples 2.2 removeIf uses Iterator 3. ListIterator example 4. Filter and Collect example 5. References P.S Tested with Java …
In Java Logging APIs or java.util.logging, we use system property java.util.logging.config.file to define the location of the logging.properties file. Table of contents 1. Loads logging.properties at runtime 2. Loads logging.properties from the classpath 2.1 LogManager 2.2 System.setProperty("java.util.logging.config.file") 3. Download Source Code 4. References Note Java Logging APIs Tutorial 1. Loads logging.properties at runtime In the …
This tutorial shows how to use the Streaming API for XML (StAX) writer to write data to an XML file. Table of contents 1. Write to XML (StAX Writer APIs) 2. Write to XML (StAX Cursor API – XMLStreamWriter) 3. Write to XML (StAX Iterator API – XMLEventWriter) 4. Write and pretty print XML content …
This tutorial shows how to use the Streaming API for XML (StAX) parser to read or parse an XML document. Table of contents 1. What is StAX 1.1 Difference between SAX and StAX? 2. StAX Cursor API and Iterator API 2.1 StAX Cursor API 2.2 StAX Iterator API 2.3 which one? Cursor or Iterator APIs? …
This article shows how to solve the popular JAXB exception Implementation of JAXB-API has not been found on module path or classpath. Table of contents 1. JAXBException: Implementation of JAXB-API has not been found 2. We need a JAXB Implementation 3. JAXB Implementation – Jakarta XML Binding 4. JAXB Implementation – EclipseLink MOXy 4.1 Implementation …
This article shows you how to add, check and remove the byte order mark (BOM) from a UTF-8 file. The UTF-8 representation of the BOM is the byte sequence 0xEF, 0xBB, 0xBF (hexadecimal), at the beginning of the file. 1. Add BOM to a UTF-8 file 2. Check if a file contains UTF-8 BOM 3. …
In jQuery, we select an element by id using the # symbol and select elements by class name using the . symbol. Table of contents: 1. Select an element by ID 2. Select elements by Class Name 3. HTML example 4. References 1. Select an element by ID To select an element by ID, we …
Java 16 reached General Availability on 16 March 2021, download Java 16 here. Java 16 has 17 JEP items. 1. JEP 338: Vector API (Incubator) 2. JEP 347: Enable C++14 Language Features 3. JEP 357: Migrate from Mercurial to Git 4. JEP 369: Migrate to GitHub 5. JEP 376: ZGC: Concurrent Thread-Stack Processing 6. JEP …
This article shows a few ways to update or increase a value of a key in a HashMap. Table of contents 1. Update the value of a key in HashMap 2. Increase the value of a key in HashMap 3. Java 8 getOrDefault() 4. Java 8 compute and merge 4.1 Java 8 merge example 4.2 …
This article shows a few ways to get keys from value in HashMap. 1. HashMap can contain null for key and value 2. Get all keys from HashMap – keySet() 3. Get keys from value in HashMap 4. Get keys from value in HashMap (Java 8 Stream) 5. HashMap only has one item 6. References …
The below program launch a Java Swing application; It configures a JFrame and attach a JLabel to display a hello world and center the JLabel component. Read the comment for self-explanatory. SwingHelloWorld.java package com.mkyong.swing import javax.swing.*; import java.awt.*; public class SwingHelloWorld { public static void main(String[] args) { JFrame frame = new JFrame("Hello World Java …
This article shows how to use Java DOM Parser + XSLT to format or pretty print a XML document. Table of contents 1. An XML file 2. Pretty Print XML via Transformer 3. Pretty Print XML via XSLT 4. Download Source Code 5. References P.S Tested with Java 11 1. An XML file staff-simple.xml <?xml …
In Gradle, we can pass an –tests option to run a single unit test class. Read this Gradle Test Filtering. Terminal gradle test –test TestClass P.S Tested with Gradle 6.7.1 1. Run a single test class Review a simple unit test. DummyTest.java package com.mkyong.security.db; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertTrue; public class DummyTest { @Test void …
This article shows how to create or scaffold a Gradle + Quarkus JAX-RS hello world project, which creates a /hello endpoint and returns a string. Technologies used: Quarkus 1.11.0 Gradle 6.7 Maven 3.6.3 Java 11 Topics Creating a new Gradle + Quartus project Gradle + Quarkus Project Structure Quarkus and build.gradle Quarkus Dependencies (runtimeClasspath) Quarkus …
This article shows how to use the quarkus-maven-plugin to create or scaffold a Maven + Quarkus JAX-RS hello world project. Technologies used: Quarkus 1.11.0 Maven 3.6.3 Java 11 Topics Creating a new Maven + Quartus project Maven + Quarkus Project Structure Quarkus and pom.xml Quarkus Dependencies Quarkus JAX-RX endpoint Quarkus and Dockerfile Run Quarkus in …
This article shows how to use a keyboard shortcut to access the parent folder or any item or folder on macOS. 1. Go to the parent folder. (Command + Up Arrow) In Finder, we can press Command + ↑ to access the parent folder of any item or folder. 1.1 For example, in Finder, this …
This article shows how to use a keyboard shortcut to go to a specified folder on macOS. 1. Go to a specified folder. (Shift + Command + G) In Finder, there is no explorer to type the path you want to go. To fix it, we can press Shift + Command + G together to …
This article shows you how to enable Gmail dark mode or dark theme on desktop, Android, and iPhone or iPad (macOS). Topics Gmail Dark Mode on Desktop Gmail Dark Mode on Android Gmail Dark Mode on iPhone and iPad (macOS) 1. Gmail Dark Mode on Desktop PC. 1.1 Any web browsers, log in the Gmail, …