Skip to main content

Posts

Solution for the Error : An internal error occured during: "reload maven project"

You might have faced this issue after changing the project name or may be changing project name in pom.xml. When you restart your eclipse it may not launch due to project metadata file is corrupted due to your .project name changes and Maven can not laod your project properly and will displays this error shown above and eclipse console will not be opened. To get rid off this issue follow the solution given below

DOM Parser Vs. SAX Parser

Many developers sometimes confuse which is better to parse the XML document. Ofcourse myself also got doubt which parser I can use for this situation.  Since I have read about DOM and SAX very long back. Just refreshing it again DOM (Document Object Model) Parser: Tree model parser(Object based) (Tree of nodes). DOM loads the file into the memory and then parse the file. Has memory constraints since it loads the whole XML file before parsing. DOM is read and write (can insert or delete the node). If the XML content is small then prefer DOM parser. Backward and forward search is possible for searching the tags and evaluation of the information inside the tags. So this gives the ease of navigation. Slower at run time.

How Java Garbage Collector Works?

The Java runtime environment deletes objects when it determines that they are no longer being used. This process is known as garbage collection. The Java runtime environment supports a garbage collector that periodically frees the memory used by objects that are no longer needed. The Java garbage collector is a mark-sweep garbage collector that scans Java's dynamic memory areas for objects, marking those that are referenced. After all possible paths to objects are investigated, those objects that are not marked (i.e. are not referenced) are known to be garbage and are collected. (A more complete description of our garbage collection algorithm might be "A compacting, mark-sweep collector with some conservative scanning".) The garbage collector runs synchronously when the system runs out of memory, or in response to a request from a Java program. Your Java program can ask the garbage collector to run at any time by calling System.gc(). The garbage collector requires abou...

HTTP + REST Vs. AMQP + RPC

REST, RPC - architecture patterns, AMQP - wire-level and HTTP - application protocol which run on top of TCP/IP AMQP is a specific protocol when HTTP - general-purpose protocol, thus, HTTP has damn high overhead comparing to AMQP AMQP nature is asynchronous where HTTP nature is synchronous Both REST and RPC use data serialization, which format is up to you and it depends of infrastructure. If you are using python everywhere I think you can use python native serialization -   pickle   which should be faster than JSON or any other formats. Both HTTP+REST and AMQP+RPC can run in heterogeneous and/or distributed environment So if you are choosing what to use:  HTTP+REST or AMQP+RPC, the answer is really subject of infrastructure complexity and resource usage. Without any specific requirements both solution will work fine, but i would rather make some abstraction to be able switch between them transparently.

How To Decompile Android APK file(.apk) and Get Source Code

Sometimes you may be amazed to see beautiful android apps with great design and simplicity. You may want to look into the source code of that app and to design the same way they have done. Usually APK file is not readable because its in dex format (Dalvik excutable file) which can be read by dalvik compiler. So there is a trick I found on stackoverflow to decompile any apk file. Just follow the below steps to get source code of any android app, if you have got .apk file Step 1: Create a new folder in your pc and copy over the .apk file that you want to decode. Now rename the extension of this .apk file to .zip (e.g. rename from filename.apk to filename.zip) and save it.  Now you can access the classes.dex files, etc. At this stage you are able to see drawables but not xml and java files, so continue. Step 2: Now extract this .zip file in the same folder (or NEW FOLDER). Download dex2jar and extract it to the same folder (or NEW FOLDER). Move the classes.dex f...

Asynchronous Vs. Synchronous Communications

Synchronous (One thread):   1 thread -> |<---A---->||<----B---------->||<------C----->| Synchronous (multi-threaded):   thread A -> |<---A---->| \ thread B ------------> ->|<----B---------->| \ thread C ----------------------------------> ->|<------C----->|

CASCADE Vs RESTRICT Vs NO ACTION Vs SET NULL in MYSQL

The table containing the foreign key is called the   referencing   or   child table , and the table containing the candidate key is called the   referenced   or   parent table .   SET NULL   : Sets the column value to   NULL   when you delete the parent table row. CASCADE   : CASCADE will   propagate the change   when the parent changes. If you delete a row, rows in constrained tables that reference that row   will also be deleted , etc.  

Resolution for Error: javax.persistence.JoinColumn.foreignKey()Ljavax/persistence/ForeignKey

Error: "javax.persistence.JoinColumn.foreignKey()Ljavax/persistence/ForeignKey" I was  trying to implement Hibernate Search functionality on my current project. I faced the above issue and resolved it with some research. Root cause and Solution:   JoinColumn.foreignKey() was introduced with JPA 2.1, which was not implemented by Hibernate 4 until version 4.3. If you're using an older version of Hibernate 4, you will face this issue. Try to upgrade it to hibernate-jpa-2.1-api   and also Hibernate to 4.3.x. If you're already using Hibernate 4.3 then make sure you're also using hibernate-jpa-2.1-api to make sure the API and implementation match up.

Resolved: “org.hibernate.ObjectNotFoundException: No row with the given identifier exists” but it does exists

Error: “org.hibernate.ObjectNotFoundException: No row with the given identifier exists” but it does exists. I was facing this issue with my current project. There might be 2 possible reasons to occur this error. Root Causes: 1. Whene there is relationship between two tables in the database, the main entity may not exists in the database, You can check it with session.get() method whether it is there or not.

If Runnable interface is better than Thread class, then why we are using Thread class?

If Runnable interface is better than Thread class, than why we are using Thread class? What is the need for Thread class? When you  extends Thread class, after that you can’t extend any other class which you needed. (As you know, Java does not allow multiple inheritance.) If your class is Implementing the Runnable interface then you only override the run() .So this instance creates a separate Thread and every individual Thread runs separately but not as a single heavy Thread in your program. Another thing, Since Java does not support multiple inheritance , if you implement the Runnable you'll avoid problems of multiple extending, so if you implement Runnable interface you can extend any class that you are required other than Thread class. However, the main difference is. When you  extends Thread class, each of your thread creates unique object and associate with it. When you  implements Runnable , it shares the same object to multiple threads. ...

How To Solve "Error: Could not find or load main class org.codehaus.classworlds.Launcher while building Maven 3.0.4"

I was trying to solve this error in my Ubuntu. Since I need to build Hue /Spark Application and when run the "make apps" or "mvn --version" command on terminal, I was getting " Error: Could not find or load main class org.codehaus.classworlds.Launcher while building Maven 3.0.4 This error ate all my day almost. Finally found a solution on one website. Just you need to uninstall old maven versions or existing maven. and sudo apt-get purge maven maven2 maven3 sudo apt-add-repository ppa:andrei-pozolotin/maven3 sudo apt-get update sudo apt-get install maven3  Thanks a lot to those guys for a great help.

Solution For Error: " Current configuration of the parser doesn't allow a maxOccurs attribute value to be set greater than the value 5,000."

Currently I am working on a project where I need to transform Excel sheet data to an XML format in compliance with XSD given by my client. When I am trying to parse the XSD using JAXB I got this error when doing mvn clean install. Error: ""Current configuration of the parser doesn't allow a maxOccurs attribute value to be set greater than the value 5,000." I found many solutions and route cause for this issue. You can find some information on Oracle site the route cause for the issue . It is because of the feature enabled for secure XML processing. This feature was enable in JAXP 1.3 which instructs parsers, transformers to behave in a secure fashion. You can find more information here: https://jaxp.java.net/1.4/JAXP-Compatibility.html#JAXP_security. For me 2 solutions worked out: Solution 1: With code change or implemenetation: //Create SchemaFactory using XSD file SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_UR...

How To Change IPAddress of Linux/Ubuntu ?

Recently I needed to change the existing ipaddress of a linux machine. Since we migrated to our machines in to new cloud servers. Just follow the steps defined below: On terminal window type the following command.            sudo vi /etc/network/interfaces                 or             sudo gedit /etc/network/interfaces

Is It Possible To Define All The Methods In An Abstract Class?

It is possible create an abstract class with all concrete methods. But this class can’t be instantiated. Since it is an abstract class.    We may have situations where we don’t want to instantiate a class which is the base class for all the classes in the system or application. This base class may have lot of methods used for different modules in the application and we do not want to instantiate the object of the base class and want to use only the reference of the class.   An abstract class without any abstract methods should be a rare thing and you should always question your application design if this case arises. Normally you should refactor to use a concrete super class in this scenario.   One specific case where abstract class may justifiably have no abstract methods is where it partially implements an interface, with the intention that its subclasses must complete the interface.

Creating a Docker Group

The docker daemon binds to a Unix socket instead of a TCP port. By default that Unix socket is owned by the user root and other users can access it with sudo. For this reason, docker daemon always runs as the root user. To avoid having to use sudo when you use the docker command, create a Unix group called docker and add users to it. When the docker daemon starts, it makes the ownership of the Unix socket read/writable by the docker group. Note: The docker group is equivalent to the root user; To create the docker group and add your user: Log into Ubuntu as a user with sudo privileges.

What is Docker? How To Install Docker on Ubuntu 14.04?

  Docker is an open source container based software framework that automates the deployment of applications inside a software contains by providing an additional abstraction layer and automation of operating system level virtualization on Linux. Docker uses resource isolation features of the Linux kernel such as cgroups and kernel namespaces to allow independent "containers" to run within a single Linux instance, avoiding the overhead of starting and maintaining virtual machines. How to Install: Open Ubuntu Terminal Window and login as a root. Follow the below steps.

Are Java Constructors Inherited ? If Not, Why Not?

You cannot inherit a constructor. That is, you cannot create a instance of a subclass using a constructor of one of it's super classes. One of the main reasons is because you probably don't want to override the constructor of super class', which would be possible if they were inherited. By giving the developer the ability to override a super class constructor you would erode the main feature of encapsulation abilities of the java programming language.

How To Install Tomcat on Ubuntu?

Recently, I started working on Ubuntu OS 14.04. I feel Ubuntu is much simpler than what I thought earlier. Lets leave about Ubuntu, I want to blog more about Ubuntu OS afterwards. Here I want to brief about how to install Tomcat webserver on Ubuntu.  Apache Tomcat is an open source webserver where we can deploy java applications. Go to terminal window on Ubuntu and login as a root user. 1. Install Java First: Before installing Tomcat server, it is better to install Java. Run the following command on terminal window to check Java is already installed.              java -version  If it returns "The program 'java' can be found in the following packages:" the Java is not installed on Ubuntu. To install Java, just run the below command. After this we have to add Java to environment variables in .bashrc. We will add both Java and Tomcat after the installation of Tomcat webserver.      ...

How to Install Maven ?

Nowadays its very common for Java developers to use Maven tool for building war or ear file their applications instead of ant tool. Since Maven provides an easiest way of building and managing version of applications and relieves you from build path configurations in your eclipse ide. Of course many people knows how to configure how to download and configure maven in their machines. But I want to post it on my blog for my reference and newbies in java world. Just follow the below steps:  Make sure Java (version 1.5 or 1.6 or 1.7 ) is installed on your machine and "JAVA_HOME" variable is added to environment variable list on windows as shown below image.(Windows start -> My Compuetr-> Right Click on ->Properties ->Advanced System Settings ->System Settings-> Click on "Environment Variables") Download latest version of Maven (apache-maven-3.3.3-bin.zip) from Apache Website: http://maven.apache.org/download.cgi to the directory on you...

What happens if your serializable class contains a member which is not serializable in Java?

It is simple, the class will not be serializable, unless the field is declared transient (which will prevent the field from being serialized, i.e. it will not be saved). It'll throw a NotSerializableException when you try to serialize it. To avoid that, make that field a "transient" field.  private transient YourNonSerializableObject dontSerializeMe; // This won't be serialized