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

Unit Test Non-Public Methods in C# Unit Tests

To expose non-public methods to the test project, you need to mark the assembly with an attribute called InternalsVisibleTo in the asemblyinfo.cs file?? For example: [assembly: InternalsVisibleTo(“testProjectName”)] You need to

Converting Base 10 numbers to Binary numbers

Programming needs vary. You may have a requirement to convert a Base 10 value to binary as part of a complex logic. Java has easier mechanism to achieve the same. public class Base10ToBinary{   public static void main(String args[])   {      Base10ToBinary base10ToBinary = new Base10ToBinary();      base10ToBinary.proceed();   }      private void proceed()   {      int num = 10;       String binaryNum = Integer.toString(num, 2);         System.out.println(“Binary value of ” + num + ” : ” + binaryNum);    }} /* Expected output: [root@mypc]# java Base10ToBinaryBinary value of 10 : 1010 */

Finding out the Java version.

This is generally useful, specifically if you want to perform some operations based on Java version and so on. public class JavaVersion{   public static void main(String args[])   {      JavaVersion javaVersion = new JavaVersion();      javaVersion.proceed();   }      private void proceed()   {      //This works in Java 8 and prior      //For Java 9, there is a new api available in Runtime class      String javaVersion = System.getProperty(“java.version”);        System.out.println(“Java Version: ” + javaVersion);    }} /* Expected output: [root@mypc]# java JavaVersionJava Version: 1.8.0_221 */

Updating a JAR file

At times, requirement to update an already delivered JAR file will need to be handled. Of course, JAR file is a way of packaging and delivering Java class file and related metadata files in a package. But having an easier way is always welcome by the developer group. The following command when executed on a command line will achieve updating a JAR file with 1 or more files as needed jar uf jar-file input-file-name(s) where uf          :    indicates update and filejar-file    :   the jar file that needs to be updatedinput-file-name(s)   :   the name of file(s) that needs to be updated in the jar file.

How to use JPA, @MappedSuperclass

First, define an abstract class and annotate it with @MappedSuperclass. This is not an entity: @MappedSuperclasspublic abstract class User implements Serializable {   …} Second, each entity should extend the User class. For example, Student and Teacher entitites: @Entitypublic class Student extends User implements Serializable {   …} @Entitypublic class Teacher extends User implements Serializable {   …}

How to define an auto-incremented identifier via JPA annotations

For defining an auto-incremented identifier in an entity we need the @Id annotation and the IDENTITY generator as follows: @Entitypublic class User implements Serializable {     @Id    @GeneratedValue(strategy = GenerationType.IDENTITY)    private Long id;    …}

Read All SQL Server Log Files

You can use a script similar to the following to read through all SQL Server Log files: CREATE PROCEDURE SearchLogFiles (@LogType INT = 1, Filter NVARCHAR(MAX) = ”)ASBEGIN DECLARE @LogsTable

Employing DROP USER in MySQL

As with any database, MySQL provides powerful user management feature. Learn how to remove a user from the database. DROP USER SRIDHAR However, the catch here is that the user

Finding the Current Flush Mode for the JPA EntityManager

Knowing the current flush mode can be done as follows: // via EntityManagerentityManager.getFlushMode();// in Hibernate JPA, via Session(entityManager.unwrap(Session.class)).getFlushMode();// starting with Hibernate 5.2(entityManager.unwrap(Session.class)).getHibernateFlushMode();

Find if a string contains one of the given words in Java

We can use the AnyMatch method to figure out if a string contains any of the given words from an Array. See below for a sample.  List middleEasternCountries = Arrays.asList(“egypt”, “iran”, “turkey”);String sampleString = “Egypt is a famous tourist destination. It contains the Pyramids”; System.out.println(middleEasternCountries.stream().anyMatch(sampleString::contains));

Retrieving remainder of two numbers in Python

Using Math module, we can retrieve the remainder of two numbers For e.g. the following would return 0.import math re = math.remainder(6, 3))

Transpose a Matrix in Python

One of the inbuilt libraries in Python is zip. It can be utilized to transpose a matrix by performing an Unzip followed by zip. Sample code below.   Python comes with many inbuilt libraries zip is among those. The??zip()??function returns an iterator of tuples based on the??iterable??object. In order to get the transpose of the matrix first, we need to unzip the list using??*??operator then zip it. inputMatrix = [ [7, 14, 21], [1, 2, 3] ]zip(*inputMatrix) Output will be as follows:[ (7, 1), (14, 2), (21, 3) ] 

Creating a Secure Socket

Java supports creating of ServerSocket(s) in more than one way. This is an important aspect of security. SSLServerSocketFactory is a secure way of achieving this. This ensures that the socket is

Replace a Web API Response with a Custom JSON

Use StringContent?in the Web API response to return a custom JSON. See below for an example: StringContent responseContent = new StringContent ( ” { ‘handled’ : ‘true’ } “, Encoding.UTF8,

How to Disable Auto-commit Mode in Spring Boot

By default, Spring Boot uses HikariCP as the connection pool. Via the connection pool, we can disable the auto-commit mode. For example, the following setting disabled auto-commit mode from application.properties:

Understanding INSERT IGNORE in MySQL

Usually, if there is an error during the INSERT command execution, the error is thrown and the execution stopped. MySQL supports something named IGNORE along with INSERT, which captures the

How to Use FetchMode.JOIN to Fetch Collection

By annotating an associated collection with FetchMode.JOIN we force it to be loaded EAGER: @OneToMany(fetch = FetchType.LAZY)@Fetch(FetchMode.JOIN)private List = new ArrayList(); Or: @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = “foo_id”) @Fetch(FetchMode.JOIN) private

Using the STRING_AGG SQL Server 2017 Function

The STRING_AGG?SQL Server 2017 function performs grouped string concatenation. Here is an example: SELECT STRING_AGG(value, ‘ ‘) AS Result FROM (VALUES(‘Hannes’),(‘du’),(‘Preez’)) AS I(value); This returns: Hannes du Preez in the

How is HeapHero different?

 There are excellent Heap dump analysis tools like Eclipse MAT, Jprofiler, … These tools are handy when you want to debug/troubleshoot OutOfMemoryError. However, we HeapHero as following unique capabilities which aren’t available in those tools:  1. How much memory wasted?    HeapHero tells you how much memory your application is wasting because of inefficient programming practices by the developers. Today memory is wasted because of reasons like: a. Duplication of stringsb. overallocation, and underutilization of data structuresc. Boxed numbersd. Several more reasons.  You can see HeapHereo reporting how much memory is wasted even in a vanilla pet clinic spring boot application. Other tools don’t provide this vital metric.  2. First cloud application for heap dump analysis  Today’s memory profiling tools need to be installed on your Desktop/Laptops. They can’t run on the cloud. HeapHero can run on  a. Public cloud (AWS, Azure,..)b. Your private data centerc. Local machine Your entire organization can install one instance of HeapHero in a central server, and everyone in the organization can upload and analyze the heap dump from this one server.  3. CI/CD pipeline Integration   As part of CI/CD pipeline, several organizations do static code analysis using tools like coverity, vera code… . Using HeapHero, you can do runtime code analysis. HeapHeroprovides REST API. This API returns JSON response, which contains key metrics related to your application’s memory utilization. You can invoke this API from CI/CD pipeline and see whether your code quality is improving or regressing between each code commit.  4. Instant RCA in production  Debugging OutOfMemoryError in production is a tedious/challenging exercise. You can automate the end-end analysis of OutOfMemoryError using HeapHero. Say if your application’s memory consumption goes beyond certain limits or experience OutOfMemoryError, you can capture heap dumps and do heap dump analysis instantly using our REST API and generate instant root cause analysis report. Production troubleshooting tools like ycrash leverages HeapHero REST API to do this analysis for you.  5. Analyzing heap dumps from remote location  Heap dump files are large in size (several GB). To troubleshoot the heap dump, you have to transmit the heap dump file from your production server to your local machine. From your local machine, you have to upload the heap dump file to your tool. Sometimes heap dump might be stored/archived in remote server, AWS S3 storage,… In those circumstances, you will have to download the heap dump from that remote location and then once again upload it to the tool. HeapHero simplifies this process for you. You can pass the heap dump’s remote location URL as input to the HeapHero API or to web interface  directly. HeapHero will download the heap dump from this remote location to analyze for you.  6. Report Sharing & Team collaboration  Sharing Heap Dumps amongst team is a cumbersome process. Finding a proper location to store the heap dump file is the first challenge. The team member with whom you are sharing this report should have the heap dump analysis tool installed on his local machine. So that he can open the heap dump file with the tool you are sharing to see the analysis report. HeapHero simplifies this process. HeapHero gives you a hyperlink like this. This hyperlink can be embedded in your emails, JIRA, and circulated amongst your team. When your team member clicks on this hyperlink, he can see the entire heap dump analysis report on his browser.  HeapHero also lets you export you heap dump as PDF file. This PDF file can also be circulated amongst your team members. 7. Analyze large size heap dumps  Several memory profilers are good at analyzing heap dumps of smaller size. But they struggle to analyze large size heap dumps. HeapHero is geared to analyze heap dumps easily.  Author bioEvery single day, millions & millions of people in North America???bank, travel, and commerce???use the applications that Ram Lakshmanan has architected. Ram is an acclaimed speaker in major conferences on scalability, availability, and performance topics. Recently, he has founded a startup, which specializes in troubleshooting performance problems.

Using REPEAT in MySQL

MySQL provides a REPEAT command that can be used when you want to repeat a particular string, a defined number of times. Consider the example below: SELECT CONCAT(‘S’,REPEAT(“E”,2)) Here, we

How to Cache Query Results

If em is the EntityManager, then the following query results will be cached: Query query = em .createQuery(“SELECT u FROM User u”); query.setHint(“eclipselink.cache-usage”, “CheckCacheThenDatabase”);

Understanding UNCOMPRESSED_LENGTH in MySQL

In MySQL, once we use the COMPRESS method to compress a particular text, the LENGTH of the resultant text is not the same as that of the original text. However,

Date Settings Problem (Regional Settings)

Regional Settings, especially dates, are always a problem in code. For example, suppose your product is developed in the U.S. and deployed in the UK. DateTime.Parse would throw exceptions because String

Tip: Regional Date Settings Problems

Regional Settings, especially dates, are always a problem in code. For example, suppose your product is developed in the U.S. and deployed in the UK. DateTime.Parse?would throw exceptions because String

SQL Statistic Tests to Look Into

If you want to do statistics in SQL, the following tests will be very useful to look into: Pearson’s Correlation Kendall’s Tau Rank Correlation Simple Linear Regressions The Kruskal-Wallis Test

Understanding sql_mode in MySQL

In MySQL, the sql_mode can have values set, so that the behaviour of the SQL being executed henceforth behaves as per the mode set. Considering the following use case where

How to Call a Macro Every “n” Minutes

We write a lot of macros to automate many of our mundane repeated tasks. Taking it to the next level, we can call the macro in a pre-determined frequency and