devxlogo

The Latest

Joining Strings with a Delimiter

Starting with Java 8, we can join several strings with a delimiter (e.g., comma) via the String.join() method: String result = String.join(“, “, “One”, “Two”, “Three”);// One, Two, ThreeSystem.out.println(result); Related

Using the Insert on Duplicate Key Update in MySQL

An interesting statement in MySQL is the INSERT ON DUPLICATE KEY UPDATE. This statement tries to INSERT?a record, and on finding a duplicate key, performs the action provided alongside. Example:

Using fn_builtin_permissions

You can make use of the built-in sys.fn_builtin_permissions SQL function to get a list of available permissions, as shown below: SELECT * FROM sys.fn_builtin_permissions(DEFAULT);SELECT * FROM sys.fn_builtin_permissions(”); Related Posts Revolutionary AI

Using Java Variable Type Inference in Java 10

Beginning with JDK 10, we can rely on the Java Local Variable Type Inference (Var Type) in order to avoid explicit typing. Check out the following sample: var outputStream =

Resize Your TempDB in SQL

You can resize the tempdb temporary database in SQL by using the ALTER DATABASE command, as shown below: ALTER DATABASE tempdbMODIFY FILE (Name = tempdb_data, filesize = 100MB),MODIFY FILE (NAME

Understanding the AVG Function in MySQL

Assume there is a column named MARKS in the table STUDENT_DETAILS, and we need to calculate the average. The following query will be necessary: SELECT AVG(MARKS) AVERAGE FROM STUDENT_DETAILS; This

Escape Sequences in Literals

String and character literals provide an escape mechanism that allows express character codes that would otherwise not be allowed in the literal. An escape sequence consists of a backslash character

Get Packages of a Module

Java 9 has added the concept of module via Java Platform Module System. In order to obtain the names of packages from a module we can do it as follows:

Get Current Language ID

You can get the language ID with the following Select statement: SET LANGUAGE ‘French’SELECT @@LANGID AS ‘Language ID’ Related Posts BT amplifies AI usage for cybersecurity defenseRun Your Backbone.js Apps

Force TypeScript Compiler to Ignore Errors

Use the “@ts-ignore” comment before the code and the compiler will ignore errors. // @ts-ignoreimport mathUnit from ‘mathjs/lib/type/unit’ Related Posts Capturing Textboxes Available in a Google Authentification Page Using SeleniumPotential

Understanding the Feature-rich Methods of Math Package

The Math package is feature-rich and some of the methods are illustrated below. public class MathPkg{public static void main(String args[]){MathPkg mathPkg = new MathPkg();mathPkg.proceed();}private void proceed(){int positiveNum = 5;int negativeNum

What is the Advantage of Immutability?

It is difficult to maintain correctness in mutable objects, as multiple threads could be trying to change the state of the same object. This can lead to some threads seeing

Using sys.dm_db_index_physical_stats

Using dm_db_index_physical_stats?returns size and fragmentation information for the data and indexes of the specified table or view in SQL Server. USE master; GO — If Student.Name does not exist in

Swapping Two Numbers

Swapping two numbers without using a new variable is always a good approach. This helps your application to be memory and performance oriented. public class Swap2Numbers{ int firstNum = 10;

Get All the Available Time Zones

Before Java 8, this was obtained as a String[] via TimeZone class: String[] zoneIds = TimeZone.getAvailableIDs(); Java 8 comes with a new approach via java.time.ZoneId class: Set zoneIds = ZoneId.getAvailableZoneIds();

Write SQL Results to a Text file

You can write results of a SELECT query into a text file in the following way: master..xp_cmdshell ‘osql -S SERVERNAME -U USERNAME -P PASSWORD -Q “SELECT * FROM TABLE” -d

Enumerate All the Values in an Enum

See an easy way to enumerate all the values. public enum WorkTypes{Remote = 0,Office = 1,Exempted = 2}foreach (WorkTypes workType in Enum.GetValues(typeof(WorkTypes)))Console.WriteLine(workType); Related Posts Creating an HTML Table with SQLTop

Avoid NPE via JDK 8, Optional

Starting with JDK 8, you can avoid NullPointerException by returning an Optional. For example, instead of returning null, this method returns an empty Optional: public Optional fetchShoppingCart(long id) { ShoppingCart

Diagnose System Slowdowns

One good way to quickly diagnose System slowdowns is to make use of the sp_who2 SQL function in the following way: EXEC sp_who2 This helps identify High CPU Usage, Blocking

Get a Special Folder Path in C#

Use the System.Environment namespace’s GetFolderPath?method to retrieve the path of a special folder. It can also create the folder if it does not exist. System.Environment.GetFolderPath(Environment.SpecialFolder.Recent, Environment.SpecialFolderOption.None)) Related Posts Reading Text

Understanding the FindAny Method

Learn how to use the findAny method in java.util.Stream. This returns an Optional describing an element, or an empty Optional if Stream is empty. Also, remember that the same stream

Escape Characters in Regular Expressions

In Java, characters as  cannot appear in a regular expression without being escaped. For this, rely on the Pattern.quote() method as in the following example: public static boolean contains(String t1, String

Identify Tables Storing GUID Values

You can identify tables that store a GUID (Globally Unique Identifier) value with the following script: SELECT [table] = s.name + N’.’ + t.nameFROM sys.tables AS tINNER JOIN sys.schemas AS

Finding the Java Version Programatically

import java.util.*;public class FindJavaVersion{ public static void main(String args[]) { FindJavaVersion findJavaVersion = new FindJavaVersion(); findJavaVersion.printDetails(); } private void printDetails() { Properties systemProperties = System.getProperties(); System.out.println(“Java version: ” + systemProperties.get(“java.version”));

Using sys.dm_db_missing_index_group_stats

Using sys.dm_db_missing_index_group_stats?returns summary information about groups of missing indexes, excluding spatial indexes. An example follows: SELECT TOP 5 * FROM sys.dm_db_missing_index_group_stats ORDER BY avg_total_user_cost * avg_user_impact * (user_seeks + user_scans)