How to check Nginx version

We can type the command nginx -v (lowercase v) in Linux, macOS, and Windows to show the Nginx version currently installed on our system. 1. Check Nginx version The Nginx with a lowercase v option, the nginx -V show the version and then exits. In the below output, Nginx version 1.21.0 is currently installed. Terminal …

Read more

Reload page with JavaScript

In JavaScript, we can use the location.reload() to reload a page, which is part of the native JavaScript Window interface. location.reload(); Or a longer version. window.location.reload(); Table of contents: 1. Reload the page and bypass the cache 2. Reload page with JavaScript 3. References 1. Reload the page and bypass the cache The location.reload() method …

Read more

jQuery call a function after page loaded

This article uses jQuery to call a function after a page is loaded. Table of contents: 1. $(document).ready() 2. jQuery call a function after page loaded 3. References P.S Tested with jQuery 3.7.1 1. $(document).ready() In jQuery, the code inside the $(document).ready() method will run once when the Document Object Model (DOM) is ready, equivalent …

Read more

JavaFX Transformations Examples

This article will show you different transformations in JavaFX and how to use them. In JavaFX, we use transformations to translate (moves), scale, rotate and shear the nodes. Tested with Java 17 JavaFX 17.0.6 Maven 3 Table of Contents 1. JavaFX Transformations example 2. Translation Transformation 3. Rotation Transformation 4. Scale Transformation 5. Shear Transformation …

Read more

JavaFX Hello World Example

This article will show you how to create a simple "Hello World" application in JavaFX. Tested with Java 17 JavaFX 17.0.6 Maven 3 Table of Contents 1. Project Directory 2. Maven Dependencies 3. JavaFX Hello World 4. Run JavaFX Hello World with Maven 5. Run JavaFX Hello World with Maven and IntelliJ IDEA 6. Download …

Read more

How to check MariaDB version

In the terminal, we can type mariadb -V (uppercase V) to display the current MariaDB version installed on the server. Terminal $ mariadb -V mariadb Ver 15.1 Distrib 10.5.19-MariaDB, for debian-linux-gnu (x86_64) using EditLine wrapper The above output show MariaDB version 10.5.19 is installed on the server. Server System Variables Alternatively, we can connect to …

Read more

How to find all packages installed using Homebrew?

This article show you how to find all packages installed using Homebrew? 1. brew list Open the Terminal and runs the command brew list to list all the installed packages using Homebrew. Terminal % brew list ==> Formulae aom curl giflib imath libevent libssh2 maven ==> Casks adoptopenjdk rar temurin temurin18 2. brew deps –tree …

Read more

Git on macOS, xcrun: error: invalid active developer path

After upgrading to macOS Big Sur 11, macOS Monterey 12, macOS Ventura 13, etc. Does it seem every upgrading macOS will cause the following error message for the git command? How to fix it? Terminal % git xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun Solution Open the Terminal, and run this …

Read more

Spring @PathVariable Annotation

In Spring Web MVC, we can use the @PathVariable annotation to access the captured URI variables. Table of contents: 1. Basic Mapping 2. Basic Mapping – Different Name 3. Basic Mapping – Class and method levels 4. Multiple Captured URI Variables 5. Multiple Captured URI Variables – Map Version 6. Regex Mapping 7. @PathVariable variables …

Read more

Spring MVC – WebMvcConfigurerAdapter is deprecated

I migrated from Spring 3 to Spring 5 and found out the WebMvcConfigurerAdapter class is deprecated; what should we do? SpringWebConfig.java package com.mkyong.helloworld.config; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; import org.springframework.web.servlet.config.annotation.EnableWebMvc; import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; import org.springframework.web.servlet.view.InternalResourceViewResolver; import org.springframework.web.servlet.view.JstlView; @EnableWebMvc @Configuration @ComponentScan({ "com.mkyong.helloworld.web" }) public class SpringWebConfig extends WebMvcConfigurerAdapter { @Override public void addResourceHandlers(ResourceHandlerRegistry registry) …

Read more

IntelliJ IDEA – Cannot connect to the Maven process

In the IntelliJ IDEA, clicks on the download sources, and it shows the error Cannot connect to the Maven process. Terminal Cannot connect to the Maven process. Try again later. If the problem persists, check the Maven Importing JDK settings and restart IntelliJ IDEA Tested with IntelliJ IDEA 2022.2.1 (Community Edition) Build #IC-222.3739.54, built on …

Read more

Spring @RequestBody Annotation

In the Spring framework, the @RequestBody annotation maps the web request’s body to the method’s parameter, usually a domain object or a Map. Table of contents 1. Spring @RequestBody example 2. Spring @RequestBody example – Map version 3. Download Source Code 4. References 1. Spring @RequestBody example Below is a @RequestBody example to map the …

Read more

Spring @Controller and @RestController Annotations

This article shows you what @Controller and @RestController are and their differences. Table of contents: 1. Spring @Controller annotation 2. Spring @RestController annotation 3. Download Source Code 4. References 1. Spring @Controller annotation Spring 2.5 introduced the @Controller as the web controller for the MVC architecture. Spring 3.0 introduced the @ResponseBody to return the method’s …

Read more

Check if element exists in JavaScript

In JavaScript, we can use document.querySelector() to check if an element exists. The document.querySelector() searches for and returns the first element matching a selector or set of selectors. If it finds no matching elements, it returns null. For example, to check if an element with the id elementId exists: if (document.querySelector("#elementId")) { // The element …

Read more

Spring @ResponseBody Annotation

In the Spring framework, the @ResponseBody annotation tells the Spring framework to write the method’s return type to the HTTP response body (not placed in a Model or interpreted as a view name). Spring 3.0 introduced the @ResponseBody annotation on the method level. Spring 4.0 enhanced the @ResponseBody annotation to put on the class level, …

Read more

JavaScript – Remove a specified item from array

In JavaScript, we can use the built-in filter() function to remove a specified item from an array. Table of contents: 1. Remove specified item from the array with filter() 2. Remove two specified items from the array with filters() and includes() 3. JavaScript examples 4. References 1. Remove specified item from the array with filter() …

Read more

How to pass a null value in JUnit 5 parameterized tests

How to pass a null for the below parameterized tests? @ParameterizedTest(name = "#{index} – Run test with args={0}") @ValueSource(strings = {"", " "}) // @ValueSource(strings = {"", " ", null}) // compile error void testBlankIncludeNull(String input) { assertTrue(StringUtils.isBlank(input)); } 1. Solution – @NullSource Since JUnit 5.4 and above, we can use the @NullSource to pass …

Read more

Java String compareTo() examples

The Java String compareTo() method compares two strings lexicographically (alphabetical order). It returns a positive number, negative number, or zero. s1.compareTo(s2) if s1 < s2, it returns negative number. if s1 > s2, it returns positive number. if s1 == s2, it returns 0. Table of contents 1. "a".compareTo("c"), negative integer 2. "c".compareTo("a"), positive integer …

Read more

How to capitalize the first letter of a String in Java

In Java, we can use substring(0, 1).toUpperCase() + str.substring(1) to make the first letter of a String as a capital letter (uppercase letter) String str = "mkyong"; String str1 = str.substring(0, 1).toUpperCase(); // first letter = M String str2 = str.substring(1); // after 1 letter = kyong String result = str.substring(0, 1).toUpperCase() + str.substring(1); // …

Read more

How to convert String to Integer in Java

In Java, we can use Integer.valueOf(String) to convert a String to an Integer object; For unparsable String, it throws NumberFormatException. Integer.valueOf("1"); // ok Integer.valueOf("+1"); // ok, result = 1 Integer.valueOf("-1"); // ok, result = -1 Integer.valueOf("100"); // ok Integer.valueOf(" 1"); // NumberFormatException (contains space) Integer.valueOf("1 "); // NumberFormatException (contains space) Integer.valueOf("2147483648"); // NumberFormatException (Integer max …

Read more

How to format source code in Visual Studio Code (VSCode)

This article shows how to format source code in Visual Studio Code (VSCode). Tables of contents 1. VSCode – Code Formatting Shortcuts 2. VSCode – Code Formatting Shortcut #2 3. Formatter is not installed 4. References 1. VSCode – Code Formatting Shortcuts The code formatting is available in Visual Studio Code (VSCode) through the following …

Read more

Spring Boot – Unable to find a @SpringBootConfiguration

Terminal Unable to find a @SpringBootConfiguration, you need to use @ContextConfiguration or @SpringBootTest(classes=…) with your test The Spring Boot tests @SpringBootTest or @DataJpaTest need to find the @SpringBootConfiguration application class to launch the entire application and do the tests. And if Spring Boot can’t find the SpringBootConfiguration, it throws errors and stops the tests. A …

Read more

Maven error – invalid target release: 17

We upgraded the project from Java 11 to Java 17, and mvn test hits the Fatal error compiling: error: invalid target release: 17 pom.xml <properties> <java.version>17</java.version> </properties> Terminal mvn test [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project spring-boot-hello: Fatal error compiling: error: invalid target release: 17 -> [Help 1] The Java version is …

Read more

What is new in Java 17

Java 17 is a long-term support (LTS) release, reached General Availability on 14 September 2021, download Java 17 here. Java 17 has 14 JEP items. 1. JEP 306: Restore Always-Strict Floating-Point Semantics 2. JEP 356: Enhanced Pseudo-Random Number Generators 3. JEP 382: New macOS Rendering Pipeline 4. JEP 391: macOS/AArch64 Port 5. JEP 398: Deprecate …

Read more

How to get an environment variable in Python

In this article, we will show you how to access the environment variables in Python. import os print(os.environ[‘HOME’]) print(os.getenv(‘HOME’)) P.S Tested with Python 3.9.5 1. Get an environment variable 1.1 The below code uses [os.environ(https://docs.python.org/3/library/os.html#os.environ) to print the environment variable HOME. import os print(os.environ[‘HOME’]) # /Users/mkyong 1.2 If the requested key does not exist, it …

Read more

SSH – Load key “/Users/username/.ssh/id_rsa.pub”: invalid format

Suddenly the git push via SSH failed, and the remote server returned something like invalid format for the public key id_rsa.pub? Terminal git push Load key "/Users/username/.ssh/id_rsa.pub": invalid format [email protected]: Permission denied (publickey). fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists. Last week, …

Read more

GitHub keep asking for username password when git push

git clone one of my existing repo (with SSH key added in the Github), modified some files and tried to git push, and it keeps asking for username and password for git push operation? Terminal git push Username for ‘https://github.com’: Password for ‘https://github.com’: GitHub authentication is successful. Terminal ssh -T [email protected] Hi mkyong! You’ve successfully …

Read more

Convert object to byte[] in Java

This article shows how to convert an object to byte[] or byte array and vice versa in Java. 1. Convert an object to byte[] The below example show how to use ByteArrayOutputStream and ObjectOutputStream to convert an object to byte[]. // Convert object to byte[] public static byte[] convertObjectToBytes(Object obj) { ByteArrayOutputStream boas = new …

Read more

How to decompile class in Java

This article shows how to decompile Java class in Eclipse IDE, IntelliJ IDEA, and command line. Table of contents 1. Java Decompilers 2. Decompile Java class in Eclipse IDE 3. Decompile Java class in IntelliJ IDEA 4. Decompile Java class in Command Line (FernFlower) 5. References 1. Java Decompilers Java decompiler can convert .class files …

Read more

JAX-RS – How to read response body from a post request?

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

Read more