How to generate UML Diagrams from Java code in Eclipse

UML diagrams compliment inline documentation ( javadoc ) and allow to better explore / understand a design. Moreover, you can print and bring them to table to discuss a design.

In this post, we will install and use the ObjectAid plugin for Eclipse to produce jUnit lib class diagrams. Then, we will be able to generate UML diagrams by simply dragging and dropping classes into the editor. We can further manipulate the diagram by selecting which references, operations or attributes to display.

Open Eclipse and go to Help > Install New Software
Click on add to add a new repository
Enter name ObjectAid UML Explorer
Enter Location http://www.objectaid.net/update

Maven Installation

 Search Maven package  
 apt-cache search maven  

 Install it  
 sudo apt-get install maven  

 Verification  
 mvn -version  

 Where is Maven installed  
 The command apt-get install the Maven in /usr/share/maven  
 The Maven configuration files are stored in /etc/maven  

Installation of Tomcat7 : using port 80

 Installation Tomcat using apt-get  
 sudo apt-get install tomcat7  

 Install the package using apt-get  
 sudo apt-get install tomcat7-docs  
 sudo apt-get install tomcat7-examples  
 sudo apt-get install tomcat7-admin  

 The above instruction is more than enough to install the tomcat. If any error happened please follow the below the instructions.  
 Setup the JDK path for Tomcat   
 sudo nano /etc/default/tomcat7 : add the JDK path inside the file  
 Set the path   
 sudo nano ~/.bashrc  
 export CATALINA_HOME=/usr/share/tomcat7  

 Stop Server:  
 sudo /etc/init.d/tomcat7 stop  

 Start Server:  
 sudo /etc/init.d/tomcat7 start  

 Folder locations of tomcat :  
 Tomcat bin and lib file location :  
 /usr/share/tomcat7  

 Tomcat xml file :  
 /etc/tomcat7  

 Tomcat config and webapp files:  
 /var/lib/tomcat7/  

 Tomcat JDK and Path Setup   
 sudo nano /etc/default/tomcat7  

 To Run Tomcat on port 80  
 <Connector port="8080" protocol="HTTP/1.1"  
 connectionTimeout="20000" redirectPort=  
 "8443" />  
 Change 8080 to 80 in /config/server.xml file  
  AND  

 Remove the comment using :  
 sudo nano /etc/default/tomcat7 and   
 change #AUTHBIND=no  
 as AUTHBIND=yes  

 To remove all the files   
 sudo apt-get purge libtomcat7-java tomcat6 tomcat6-admin tomcat6-docs tomcat6-examples tomcat7 tomcat7-admin tomcat7-common tomcat7-docs tomcat7-examples tomcat7-user  
 To check what are the process running on port 80  
 netstat -tulpn | grep :80  
 Server.XML user name and password  
 <role rolename="manager-gui"/>  
 <user username="Dhanu" password="" roles="manager-gui"/>  
 <role rolename="admin-gui"/>  
 <user username="Dhanu" password="" roles="admin-gui"/> 
 
 NOTE:  
 Change the Heap memory in tomcat :  
 sudo nano /etc/default/tomcat7 and change the line on -Xms value  
 JAVA_OPTS="-Djava.awt.headless=true -Xmx2048m -XX:+UseConcMarkSweepGC"  
 In Default It’s limited to 128MB.   

Difference between Process and Thread

Process

  • An executing instance of a program is called a process.
  • Some operating systems use the term ‘task‘ to refer to a program that is being executed.
  • A process is always stored in the main memory also termed as the primary memory or random access memory.
  • Therefore, a process is termed as an active entity. It disappears if the machine is rebooted.
  • Several process may be associated with a same program.
  • On a multiprocessor system, multiple processes can be executed in parallel.
  • On a uni-processor system, though true parallelism is not achieved, a process scheduling algorithm is applied and the processor is scheduled to execute each process one at a time yielding an illusion of concurrency.
  • Example: Executing multiple instances of the ‘Calculator’ program. Each of the instances are termed as a process.

Thread

  • A thread is a subset of the process.
  • It is termed as a ‘lightweight process’, since it is similar to a real process but executes within the context of a process and shares the same resources allotted to the process by the kernel (See kquest.co.cc/2010/03/operating-system for more info on the term ‘kernel’).
  • Usually, a process has only one thread of control – one set of machine instructions executing at a time.
  • A process may also be made up of multiple threads of execution that execute instructions concurrently.
  • Multiple threads of control can exploit the true parallelism possible on multiprocessor systems.
  • On a uni-processor system, a thread scheduling algorithm is applied and the processor is scheduled to run each thread one at a time.
  • All the threads running within a process share the same address space, file descriptor, stack and other process related attributes.
  • Since the threads of a process share the same memory, synchronizing the access to the shared data withing the process gains unprecedented importance.

What is Java thread


A thread is a thread of execution in a program. The Java Virtual Machine allows an application to have multiple threads of execution running concurrently.

Every thread has a priority. Threads with higher priority are executed in preference to threads with lower priority. Each thread may or may not also be marked as a daemon. When code running in some thread creates a new Thread object, the new thread has its priority initially set equal to the priority of the creating thread, and is a daemon thread if and only if the creating thread is a daemon.

Difference between “implements Runnable” and “extends Thread” in java

In java language, as we all know that there are two ways to create threads. One using Runnable interface and another by extending Thread class.

There has been a good amount of debate on which is better way. Well, I also tried to find out and below is my learning:

1) Implementing Runnable is the preferred way to do it. Here, you’re not really specializing or modifying the thread’s behavior. You’re just giving the thread something to run. That means composition is the better way to go.

2) Java only supports single inheritance, so you can only extend one class.

3) Instantiating an interface gives a cleaner separation between your code and the implementation of threads.

4) Implementing Runnable makes your class more flexible. If you extend thread then the action you’re doing is always going to be in a thread. However, if you extend Runnable it doesn’t have to be. You can run it in a thread, or pass it to some kind of executor service, or just pass it around as a task within a single threaded application.

5) By extending Thread, each of your threads has a unique object associated with it, whereas implementing Runnable, many threads can share the same runnable instance.

6) If you are working on JDK 4 or lesser, then there is bug :

Crop Image Using Java

 import java.awt.image.BufferedImage;  
 import java.io.File;  
 import java.io.IOException;  
 import javax.imageio.ImageIO;  
 public class test {  
      public static void main(String[] args) throws IOException {  
           test t = new test();  
           t.getCropImage();  
      }  
      public void getCropImage() throws IOException {  
           int widthOfNewImage = 100;  
           int heightOfNewImage = 100;  
           int offsetFromLeft = 10;  
           int offsetFromTop = 100;  
           String path = "input.gif";  
           String newPath = "newImage.png";  
           String imageFormat = "png";  
           BufferedImage image = ImageIO.read(new File(path));  
           int height = image.getHeight();  
           int width = image.getWidth();  
           System.out.println("Height : " + height + "\nWidth : " + width);  
           BufferedImage out = image.getSubimage(offsetFromLeft, offsetFromTop,  
                     widthOfNewImage, heightOfNewImage);  
           ImageIO.write(out, imageFormat, new File(newPath));  
      }  
 }  

Import CSS and JQuery files in JSP

 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">  
 <link type="text/css" rel="stylesheet"href="${pageContext.request.contextPath}/css/bootstrap.min.css" />  
 <script type="text/javascript"src="//ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js"></script>  
 <title>Concept Extractor</title>  
 <script type="text/javascript">  
  $(document).ready(function() {  
  alert("asdf");  
  });  
 </script>  

How to change eclipse background Theme

Installation

If you are on Eclipse 3.6 (Helios), the easiest way to install the plugin is from the Eclipse Marketplace. Go to Help→Eclipse Marketplace..., then search for Eclipse Color Theme and install it.
If you are on Eclipse 3.5 (Galileo), go to Help→Install New Software..., press Add Site and enterEclipse Color Theme as the name and http://eclipse-color-theme.github.com/update as the URL. Then select the new entry from the select box labeled Work with, mark Eclipse Color Theme for installation and proceed.
Please note: If you are using a version of the plugin lower than 0.6, please uninstall and reinstall it following the instructions above. Update site and plugin ID have changed.

Usage

After the installation, go to Window→Preferences→General→Appereance→Color Theme to change the color theme.
If you have a feature request, create an issue or a pull request on GitHub.

Is it possible to get HTML of an iframe - CAN'T

You are trying to access content of iframe which points to webpage from another domain. You cannot access content of iframe if the src of that iframe is not pointing to the domain on which your current parent page is. This is called cross domain policy

You will have to use server side language that will grab the html of given url and return it to your index page to display in any div or whatever.

Let me give you an example to explain why javascript cannot have cross domain access.
  • Suppose i have FB like box on my website inside an iframe
  • now whenever any user comes on my website i will trigger a click to the like box which is inside the iframe of like box.
  • This way my FB page will have lakhs of likes.
  • But because of cross domain policy this cannot be done.