Skip to main content

Posts

Data Structures using Java

package com.test.count; /**   *     * @author Kiran   *   */ public class LinkedList { Node headNode ; /** *   This method appends the Node at the end of the List *   * @param data */ public void appendNode( int data ) { Node currentNode = headNode ; if ( currentNode == null ) { Node newNode = new Node( data ); headNode = newNode ; return ; } while ( currentNode .getNextNode()!= null ) { currentNode = currentNode .getNextNode(); } currentNode .setNextNode( new Node( data )); } /** * This method prints all the Nodes/Values of the   * LinkedList *   */ public void printNodes() { Node currentNode = headNode ; if ( currentNode == null ) { System. out .println( " The Node is Null" ); return ; } else { System. out .print( "   " + currentNode .getData()); while ( currentNo...

ImageCrawler/WebCrawler for A WebSite

The ImageCrawler/WebCrawler Application is developed to crawl any WebSite to find out missing content or images. This is developed based on Search Algorithm, and has two Versions of Code in it. One  Version  for using Selenium, which takes screenshots of the error page URLs, and another version runs in the background using a shell script and captures all the page URLs. The end results are emailed to the recipient's list. Feel free to use it, the code is available for download on Git. Let me know Your feedback. ImageCrawler  on GitHub

Find the Source Jar of a Class file in Java

/** * * Gets the Source Jar File Location for the given Class, * Useful to troubleshoot Class Related Exceptions/Errors. * @param className * @return */ public String getClassSourceJar(String className) {  Class namedClass = null;  String classSrcJarLocation = null; try { namedClass = Class.forName(className); } catch (ClassNotFoundException e) { throw new RuntimeException("The Requested Class is Not Found "+className); } CodeSource src = null; if(namedClass!=null) { src = namedClass.getProtectionDomain().getCodeSource();  if(src!=null) {  URL jar = src.getLocation();  if(jar!=null) {  classSrcJarLocation = jar.toString();  }  } }  return classSrcJarLocation; }

Adding SOAP Headers for JAX-WS Client

After trying various options none seem to be apt. I could add the Headers using this JAX-WS approach. wsimport -keep -verbose -XadditionalHeaders https:// Your Web Service.asmx? WSDL When You generate the WebService Clients using "XadditionalHeaders" option, it will create the web service methods with the Header as another Parameter, which You can populating using the values You have. I could not find a better option than this. Other Approaches I tried were - Adding a JAX-WS ClientHandler class ,and using a SAAJ client altogether. Reference - JAXWS Implementation. https://jcp.org/en/jsr/detail?id=224

Cryptography

Symmetric Encryption vs Asymmetric Encryption Symmetric Encryption works by encrypting a message file by using a private key. The content can be decrypted using the same private key. If both the parties have the same key then only the message can be encrypted/decrypted. Asymmetric Encryption works with the public key and private key combination.Any message/file encrypted using a public key can only be decrypted using the related private Key. Similarly the message which is encrypted using a private key key can only be decrypted using the related public key. Digital Certificates is  a way of storing the keys and authenticating them through a neutral vendor, like Thawte, Symantec.

Hibernate Locking Strategies

Association Fetching We can fetch the associated entities wither eagerly or lazily. The fetch parameter can be set to FetchType.LAZY or FetchType.EAGER. EAGER tries to use outer join select to retrieve the associated object, while LAZY is triggers a select when the associated object is accessed for the first time. @OneToMany and @ManyToMany are defaulted to LAZY, and @OneToOne and @ManyToOne are defaulted to EAGER. The recommended approach is to use LAZY on all static fetching definitions and override this choice dynamically through JP-QL. JP-QL has a fetch keyword that allows you to override laziness when doing a particular query. This is very useful to improve performance and is decided on a use case to use case basis. Named Queries Though we can write queries in the code, externalizing them makes the code cleaner. - it eases debugging - Named queries are precompiled by Hibernate at start up time. Unfortunately, you lose the type-safety of queries written using the Criteria API. ...