devxlogo

We are an award-winning tech entrepreneurship website where trusted experts can provide value globally.

Since 1998, DevX has helped people start businesses, build websites, and provide enterprise technology to people globally. Interviewing the likes of Microsoft’s co-founder, Steve Ballmer, the publication brings comprehensive, reliable, and accessible insights to the Internet.

devxlogo

Trusted for 26 years

Over 30K Articles

1M+ Readers

Expert-reviewed

10K+ Tech Terms

As seen in:

microsoft logo
business_insider_logo
wired_logo
berkley
arstechnica_logo
hackernoon

The Latest

Using CAST for Explicit Conversion in MySQL

MySQL allows you to explicitly convert a number to a string with the help of CAST function. The example below illustrates how to use it. SELECT 55.5 AS NUMBER, CAST(55.5

Reverse a String in Python

Python’s str string objects have no built-in .reverse() method like you might expect if you’re coming to Python from a different language. str = “devx”print(“reverse string is “, str[::-1])

Passing a function instead of a function???s result to an another function in Python

Dear Editors,I sent an email to [email protected] on December 1 with an attached tip ???Passing a function instead of a function???s result to an another function in Python???.I used to use her email address a number of years ago. I would like to know if the tip was received and what is its status.My email is [email protected]. Thanks,Boris Eligulashvili

How to Trigger an Async Query

Query methods defined in repositories can be executed asynchronously. This means that the query method will return immediately upon invocation. The sample code below relies on @Async annotation and Future,

Using JSON as a Data Type

MySQL is a very robust database that supports JSON as a data type. This will be very useful for applications that need the JSON data type for certain types of

Concatenate Strings in a List

Use the join operator to concatenate strings in a list. str = [“devx”, “is”, “for”, “developers”] str = (” “.join(str))

How to Selectively Expose CRUD Operations

In order to selectively expose CRUD operations, we need to define an intermediate interface, annotated as below: @NoRepositoryBeaninterface IntermediateRepository extends Repository { // add here the selected CRUD, for example

Types of Engines that Are Supported in MySQL

MySQL supports multiple types of storage engines. There are specific engines that are meant for specific needs. Understanding of these storage engines is beyond the scope of the current discussion.

Working with Multiple Query Windows

Working with and comparing multiple queries at the same time can be a pain, at least for me. Two independent query windows take up more space on screen, or having

Get the Size of an Object in Python

Use getsizeof method to retrieve the size of an object in bytes. See below for an example: str = “devx” print(sys.getsizeof(str))

Finding the TAN of a Given Number

MySQL provides numerous mathematical calculations that can be computed with inbuilt functions. In order to find the TAN of a number, we can use the following: Query: SELECT TAN(400); Sample

How to Convert a List into a Set and Vice Versa

Converting List to Set: List list = Arrays.asList(1, 2, 3);Set set = new HashSet(list); Converting Set to List: Set set = Sets.newHashSet(1, 2, 3);List list = new ArrayList(set);

How to Quickly Sort an Array

The quickest solution for sorting an array in Java relies on Arrays.sort() method as below: int[] arr = {5, 12, 3, 44, 55}; Arrays.sort(arr);

Allow Only One Null Property

Consider a Review object with three properties: article, book and magazine. Let’s assume that only one of these three properties should be set as non-null. For checking this constraint we

Using the SUBSTRING_INDEX in MySQL

The SUBSTRING_INDEX helps in extracting a part of the given string from the beginning to the match in the index. Query: SELECT SUBSTRING_INDEX(‘MySQL Database’, ‘a’, 2) AS SUBSTRING_INDEX; Here, the

How to Declare a Pattern in Java

The best way to declare a Pattern in Java is as a constant, since Pattern is immutable. Use the following code: private static final Pattern PATTERN = Pattern.compile(” +”); Further,

Selecting All Columns, Separated with Commas

Sometimes you want to select all the columns, without using the *. Specifying column names speeds up your query. The problem comes in with large tables or tables with difficult

Handling BindException in Java

Port BindExceptions can occur if a port is already occupied by some other process and you try to use it again. Below is a simple example that demonstrates this and

How to Pass Parameters in @Query

Passing parameters to an SQL query written via @Query can be done via @Param or via positional parameters: // via @Param@Query(value = “SELECT p FROM Product p WHERE p.department=:department”)List fetchByDepartment(@Param(“department”)

Object Explorer Details

I hate repetitive tasks. I am not a robot. However, the problem is that there are some tasks that can be quite repetitive or just take too many steps to

Inspect Class Annotations

Class annotations can be inspected via reflection as follows: Class clazz = Foo.class;Annotation[] clazzAnnotations = clazz.getAnnotations();

Locking a User Account in MySQL

After a user has been created and is currently in use, a need might arise for the user account to be locked. MySQL provides a mechanism to alter the user

Call a Private Constructor

Calling a private constructor from outside its class can be done via Reflection as follows: public final class Users { private Users() {} // static members}Class usersClass = Users.class;Constructor emptyUsersCnstr

Using Multi Edit Mode

This is a neat trick I have learnt recently. When dealing with large lists of information, we, as developers, sometimes need to copy them, then add commas manually. Say, for