devxlogo

devx-admin

data scientist

Microsoft XNA: Ready for Prime Time?

No longer constrained to enterprise systems, database-driven applications or web service layers, with XNA, .NET developers can now spread their digital wings and let their pixelized imagination run wild. Their

Understanding FULLTEXT Searches

In MySQL, there is a provision to search based on natural mode. Let us consider the following example to understand this in detail. Creation of the table: CREATE TABLE ‘PROP_TBL’

How to Use the Spring Example API

First, define a probe (an instance of the entity class): User user = new User();user.setName(“Ana”);user.setEmail(“[email protected]”); Next create a probe: Example userExample = Example.of(user); Next, define a repository that extends QueryByExampleExecutor

How to log transactions details in Spring Boot

To log transactions details in a Spring Boot application simply add the following settings in application.properties: logging.level.ROOT=INFO logging.level.org.springframework.orm.jpa=DEBUG logging.level.org.springframework.transaction=DEBUG logging.level.org.hibernate.engine.transaction.internal.TransactionImpl=DEBUG

How to log HikariCP details in Spring Boot

To log HikariCP details simply add in application.properties the following settings: logging.level.com.zaxxer.hikari.HikariConfig=DEBUG logging.level.com.zaxxer.hikari=DEBUG  If you need a deeper level of details then replace DEBUG with TRACE.

Explore More Methods in the java.lang.Math Package

The java.lang.Math package is very powerful. Understand more methods in this package that are related to the Euler’s number named e. public class MathMethods{ public static void main(String args[]) { MathMethods

Retrieving a file from a jar file

JAR file in Java is a compressed format and is used for packaging of the deliverables. At times, you may want to manipulate this file.Below example indicates a scenario for the same. import java.util.jar.*;import java.io.*; public class RetrievingJarEntry{   public static void main(String args[])   {      RetrievingJarEntry retrievingJarEntry = new RetrievingJarEntry();      retrievingJarEntry.proceed();   }      private void proceed()   {      String sourceJarFile = “files/contacts.jar”;      String sourceFile = “2.txt”;      String destFile = “files/new2.txt”;      try{                  JarFile jarFile = new JarFile(sourceJarFile);         JarEntry jarEntry = jarFile.getJarEntry(sourceFile);         System.out.println(“Found entry: ” + jarEntry);         if ( jarEntry != null)         {            //Getting the jarEntry into the inputStream            InputStream inputStream = jarFile.getInputStream(jarEntry);             //Creating a output stream to a new file of our choice            FileOutputStream fileOutputStream = new java.io.FileOutputStream(destFile);            System.out.println(“Attempting to create file: ” + destFile);            while (inputStream.available()  0)             {                 fileOutputStream.write(inputStream.read());            }            System.out.println(“Created file: ” + destFile);            fileOutputStream.close();            inputStream.close();         }      }catch(IOException ioe)      {         System.out.println(“Exception: ” + ioe);      }   }} /* Expected output: [root@mypc]# java RetrievingJarEntryFound entry: 2.txtAttempting to create file: files/new2.txtCreated file: files/new2.txt */ //Please note: You have to create a folder with name files and a jar file contacts.jar which has files 1.txt, 2.txt and 3.txt

Navigating an enum

Enums are predefined place holders in Java. Knowing the contents of an enum will be handy in many instancesLet us look at how to navigate the elements of an enum public class NavigatingAnEnum{   public static void main(String args[])   {      NavigatingAnEnum navigatingAnEnum = new NavigatingAnEnum();      navigatingAnEnum.proceed();   }      enum Criteria {      LOW,      MEDIUM,      HIGH   }      private void proceed()   {      System.out.println(“Elements of the enum Criteria…”);      for (Criteria criteria : Criteria.values()) {         System.out.println(criteria);      }   }} /* Expected output: [root@mypc]# java NavigatingAnEnumElements of the enum Criteria…LOWMEDIUMHIGH */