
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.
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
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 */
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 */
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.
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 { …}
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; …}
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
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
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();
Add the check along with the function call as below. Admin Function
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));
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))
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) ]
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
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,
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:
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
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
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
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.
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
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”);
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,
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
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
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
For formatting the SQL statements in a Spring Boot application, we can set hibernate.format_sql in the application.properties as follows: spring.jpa.properties.hibernate.format_sql= true
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
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











