Showing posts with label Java. Show all posts
Showing posts with label Java. Show all posts

Thursday, March 20, 2014

Evolving Java APIs

How to design a good API and why it matters? (by Joshua Bloch)


After having design a great API, how do they need to evolve?
http://wiki.eclipse.org/Evolving_Java-based_APIs

Sunday, December 29, 2013

Google App Engine Project using Maven

Since folks from google have created the archetypes for Google App Engine Web projects it is takes seconds to actually create a sample web application and deploy it!
In the post I am going to show you how to do just that, read on..
#Create a maven project using app engine archetype 
mvn archetype:generate -Dfilter=com.google.appengine:

#Select an archetype of choice 
#At the time of writing this blog post, following are the options available
Choose archetype:
1: remote -> com.google.appengine.archetypes:appengine-skeleton-archetype (-)
2: remote -> com.google.appengine.archetypes:guestbook-archetype (-)
3: remote -> com.google.appengine.archetypes:skeleton-archetype (-)
4: remote -> com.google.appengine.demos:guestbook-archetype (-)

Note: Run the following maven commands inside the project directory where the .pom exists
#Verify the demo application
mvn verify

#Start the app engine devserver on your machine 
mvn appengine:devserver

#Test the demo application locally
http://localhost:8080

#Update the 'appengine-web.xml' with the following details
{appengine.app.id}
${appengine.app.version}

####### Deploy the application on app engine 
mvn appengine:update

#The END!
Now you will be able to use the app url and access the application default being
http://{appengine.app.id}.appspot.com
https://{appengine.app.id}.appspot.com


Thursday, November 21, 2013

Most frequently used Maven Plugins

maven-assembly-plugin
A plugin to package a runnable jar with all its dependencies.
'SkipAssembly' property when set to false packages the dependencies inside the jar!
false
'manifest' tag can be used to set the jar manifest entries
 
         com.bytemeagain.json.JsonPrettyPrinter
         com.bytemeagain.json

  
    maven-assembly-plugin
    
     
      jar-with-dependencies
      package
      
       single
      
      
       
        jar-with-dependencies
       
       false
       
        
         com.bytemeagain.json.JsonPrettyPrinter
         com.bytemeagain.json
        
        
         development
         https://github.com/homebrewcode/java
        
       
      
     
    
  


maven-javadoc-plugin
A plugin to create java-docs using the java-doc comments in your codebase
   
    org.apache.maven.plugins
    maven-javadoc-plugin
    
     
      attach-javadocs
      
       jar
      
     
    
   

Tuesday, October 29, 2013

Online Tools | Dev buddies

Some of the very useful day to day online tools that can help a jdeveloper a lot
RegEx matcher
http://www.gskinner.com/RegExr/

JSON formatter
http://jsonlint.com/

XML tools
XML formatter
http://www.xmltoolbox.com/
XML to XSD converter
http://www.freeformatter.com/xsd-generator.html#ad-output
Use 'xjc' tool to convert the XSD to Java pojo classes which can be used to marshall and unmarshall using JAXB

Unicode tools
http://www.online-toolz.com/tools/text-unicode-entities-convertor.php

Diff tool
http://text-compare.com/

Eclipse Memory Analyzer

An amazing open source free tool to do memory profiling

http://www.eclipse.org/mat/

Saturday, October 26, 2013

Remote Debugging using Eclipse

   Your java application is running on a remote machine, something goes haywire and the only way to debug your application is through making changes to a piece of code at random and redeploying it multiple time rather than actually stepping through the code??
   Well here is a better solution to that problem. Remote Debugging using Eclipse.

1. Install the Remote System Explorer

2. Establish an ssh connection to the remote server using the Remote System Explorer plugin


3. Start the java application debug server in the remote location(say hostname.company.com) with -Xdebug, -Xrunjdwp VM argument
java -Xdebug -Xrunjdwp:transport=dt_socket,address=8001,server=y,suspend=y -jar

3. Right click on the eclipse project that you would like to hook it to Remote Debugger as in the picture


4. Right click on the Remote Java Application and select 'new'


5. Configure the connection details as shown below


6. Run the debug!
Happy bugging :)
To understand more about how it works.. Head over to
Java Debug Architecture
and
http://docs.oracle.com/javase/1.5.0/docs/guide/jpda/jdwp-spec.html

Thursday, October 24, 2013

Dozer: Bean Mapper Toolkit!

Dozer is a Java Bean to Java Bean mapper
A neat tool to map the beans which uses XML based mapping!
http://dozer.sourceforge.net/

Tuesday, September 24, 2013

Load a resource file in Java

Read a resource file from a web application
new PropertyConfigurator().getClass().getClassLoader().getResourceAsStream("file.properties")

Sunday, September 15, 2013

Java Official Tutorial Page

Where to start learning about Java?
http://docs.oracle.com/javase/tutorial/tutorialLearningPaths.html

Java Memory Management
http://www.oracle.com/technetwork/java/javase/memorymanagement-whitepaper-150215.pdf

Saturday, September 14, 2013

Java Interview!!

Couple of links that I came across to prep for the Java Interview
http://stackoverflow.com/questions/2114212/questions-every-good-java-java-ee-developer-should-be-able-to-answer
http://www.techinterviews.com/interview-questions/java
http://programmers.stackexchange.com/questions/58113/how-to-interview-a-j2ee-developer
http://javarevisited.blogspot.in/2011/09/servlet-interview-questions-answers.html
http://www.javagyan.com/preparing-for-an-interview/java-j2ee-interview-questions

java.util.String

What is the o/p of the code blocks below and why is the difference in o/p's?
  String helloWorld = "Hello, world!";
  if(helloWorld=="Hello, world!"){
   System.out.println("== is true");
  }else{
   System.out.println("== is false");
  }
  
  if(helloWorld.equals("Hello, world!")){
   System.out.println(".equals is true");
  }else{
   System.out.println(".equals is false");
  }

  String helloWorld = new String("Hello, world!");
  if(helloWorld=="Hello, world!"){
   System.out.println("== is true");
  }else{
   System.out.println("== is false");
  }
  
  if(helloWorld.equals("Hello, world!")){
   System.out.println(".equals is true");
  }else{
   System.out.println(".equals is false");
  }

Wednesday, September 11, 2013

Adding code syntax highlighter to your blog post!

Click me to know how to add code snippets to your blog like below!  
public class HelloWorld {
 public static void main(String[] args) {
  System.out.println("Hello, World!");
 }
}