Saturday, May 28, 2011

Uml and Java

After a long time and constant search I found some material regarding UML and java.

Most developers have java code and then switch to UML to find architecture of the code. I personally do not advise that. Hence I was looking for some tools to reverse engineer or UML to Java parsing softwares. This post consist of list of posts that I found in my journey to find correct tool.

One way to start with searching free online tools is to know about commercial softwares and search for open source software for those softwares. Following link is an example of my search.

Open Source Alternative to Rational Rose

I knew Rational Rose ( IBM ) is IBM's software engineering and very powerful tool. I was looking for open source software and found the above link.

Along the way I found some comments by Waterloo's professor M. Gofrey. It is a professor's remark on all the available tools for software engineering for Java, C#, C and many more languages.

Waterloo Page for Tools

I am personally using eUML which is free and also available commercially. Here is the installation guide.

eUML2 Installation GUIDE

There is a flaw in this installation guide. It was written for students who are working on UML but the new version of eclipse does not necessarily allows same eUML2 zip file.



Tuesday, May 3, 2011

how to automat scp script

Are you looking for a script which does not use ssh key generation and still be able to scp some files?

Advantages is that mostly user has access on one machine to generate ssh key but for the remote machine that is not possible.

Here is the script :

#!/usr/bin/expect -f

# connect via scp
spawn scp "user@example.com:/home/santhosh/file.dmp" /u01/dumps/file.dmp
#######################
expect {
-re ".*es.*o.*" {
exp_send "yes\r"
exp_continue
}
-re ".*sword.*" {
exp_send "PASSWORD\r"
}
}
interact

#===========================================

Source

Sunday, April 17, 2011

Coupons like groupons

Some important links to look at

groupon.com
teambuy.com
livingsocial.com
www.teambuy.ca
www.webpiggy.com
www.wagjag.com
www.stealthedeal.com
http://www.dealradar.com/toronto
http://findmygroupbuy.com/
http://groupbuyunited.com/

http://tomuse.com/group-buying-sites-coupon-deals-discount-savings/

Thursday, March 24, 2011

how do i add project in git

This blog assumes that all the connectivity and credentials has been set up for GiT.

Global setup:
Download and install Git
git config --global user.name "Your Name"
git config --global user.email kushchinu@gmail.com

Next steps:
mkdir JavaHaddi
cd JavaHaddi
git init
touch README
git add README
git commit -m 'first commit'
git remote add origin git@github.com:kushptl/JavaHaddi.git
git push -u origin master

Existing Git Repo?
cd existing_git_repo
git remote add origin git@github.com:kushptl/JavaHaddi.git
git push -u origin master

Thursday, March 3, 2011

List of Imp unix commands


I am trying to list all the important administrative commands here from system point of view :

= Show working directory of the process
pwdx PROCESS_ID

= display the current open file of process
pfiles PROCESS_ID

= Display inter process communication status
ipcs
output :

bash-3.00$ ipcs
IPC status from as of Thu Mar 3 23:56:08 EST 2011
T ID KEY MODE OWNER GROUP
Message Queues:
Shared Memory:
Semaphores:

= List all the processes sorted by CPU usages
top
Explanation : The command shows all the processes sorted by CPU utilization level. Also displays load average, number of processes in different states ( sleeping, zombie, stopped, running 1 ). It updates screen after fix delay ( i think its 1 second ). Also displays level of cpu and memory utilization. i.e. real, free, swap in use.

bash-3.00$ top
load averages: 0.09, 0.11, 0.13 23:59:57
238 processes: 231 sleeping, 6 stopped, 1 on cpu
CPU states: % idle, % user, % kernel, % iowait, % swap
Memory: 2048M real, 922M free, 807M swap in use, 32G swap free

PID USERNAME THR PRI NICE SIZE RES STATE TIME CPU COMMAND
6431 www 3 39 5 8912K 4192K sleep 0:00 0.30% httpd
511 odyssey 18 43 5 0K 0K sleep 0:35 0.26% java
5114 k35patel 1 40 0 3144K 2496K sleep 0:00 0.21% bash
6523 k35patel 1 40 0 1920K 1296K cpu/0 0:00 0.14% top
5919 www 3 33 5 8920K 4280K sleep 0:00 0.07% httpd
5871 www 3 29 5 8960K 4280K sleep 0:00 0.07% httpd
5604 www 3 33 5 9016K 5192K sleep 0:00 0.06% httpd
15650 ikotsire 1 48 0 3648K 3216K sleep 0:00 0.06% tcsh
5082 k35patel 1 58 0 7944K 2696K sleep 0:00 0.06% sshd
6348 www 3 33 5 8944K 4232K sleep 0:00 0.05% httpd
5918 www 3 43 5 8944K 4464K sleep 0:00 0.05% httpd
6427 www 3 29 5 8936K 4216K sleep 0:00 0.05% httpd
5576 www 3 29 5 9040K 5384K sleep 0:00 0.04% httpd
5917 www 3 41 5 8976K 4544K sleep 0:00 0.04% httpd
5916 www 3 40 5 8968K 4504K sleep 0:00 0.03% httpd
6347 www 3 33 5 8944K 4224K sleep 0:00 0.03% httpd
68 root 7 42 0 3744K 2424K sleep 290:43 0.02% picld

Alternative of top command would be "prstat -a"

= How to check what is the page size of the memory?
pagesize

= display the network statistic using simple command.
netstat -a or netstat
So protocol, local to remote address connection is shown. State is also seen.

output would look like :
C:\Windows\system32>netstat

Active Connections

Proto Local Address Foreign Address State
TCP 127.0.0.1:895 kush-PC:6751 ESTABLISHED
TCP 127.0.0.1:1036 kush-PC:27015 ESTABLISHED
TCP 127.0.0.1:4488 kush-PC:4489 ESTABLISHED
TCP 127.0.0.1:4489 kush-PC:4488 ESTABLISHED
TCP 127.0.0.1:4721 kush-PC:4722 ESTABLISHED
TCP 127.0.0.1:4722 kush-PC:4721 ESTABLISHED
TCP 127.0.0.1:4999 kush-PC:5001 ESTABLISHED
TCP 127.0.0.1:5001 kush-PC:4999 ESTABLISHED
TCP 127.0.0.1:5208 kush-PC:5209 ESTABLISHED
TCP 127.0.0.1:5209 kush-PC:5208 ESTABLISHED
TCP 127.0.0.1:6751 kush-PC:895 ESTABLISHED
TCP 127.0.0.1:27015 kush-PC:1036 ESTABLISHED
TCP 192.168.2.5:2869 192.168.2.1:33040 TIME_WAIT
TCP 192.168.2.5:7227 cs:ssh ESTABLISHED
TCP 192.168.2.5:7312 blogger:http ESTABLISHED
TCP 192.168.2.5:7410 clients1:https ESTABLISHED
TCP 192.168.2.5:7411 clients1:http ESTABLISHED
TCP 192.168.2.5:7428 googleads:http ESTABLISHED
TCP 192.168.2.5:7429 googleads:http ESTABLISHED
TCP 192.168.2.5:7430 googleads:http ESTABLISHED
TCP 192.168.2.5:7432 googleads:http ESTABLISHED
TCP 192.168.2.5:7433 googleads:http ESTABLISHED
TCP 192.168.2.5:7434 googleads:http ESTABLISHED
TCP 192.168.2.5:7436 cr:http ESTABLISHED
TCP 192.168.2.5:7438 toolbarqueries:http ESTABLISHED

= print the process tree or which process is connected to which process ?
ptree

output is the formatted tree showing parent and child spawning of process at different levels. A more precise implication is "ptree PROCESS_ID".

= to show show directory size in kilobytes
du -k

= same as prstat what would you use to show io stats
iostat

simple but the output is difficult to analyse. The reads / sec, w / sec, kilo reads / sec, kilo writes / sec, more data to use show page faults, page in / out etc.



A good reference to look at would be Global Guide Line

Thursday, February 24, 2011

Download web content from java program



Downloading the content from java program might be easy. Here is one more example with proxy settings.

I am using htmlUnit.jar and other jars to get through.

import java.io.IOException;

import org.xml.sax.SAXException;

import com.meterware.httpunit.GetMethodWebRequest;
import com.meterware.httpunit.WebConversation;
import com.meterware.httpunit.WebForm;
import com.meterware.httpunit.WebRequest;
import com.meterware.httpunit.WebResponse;

public class start {

public static void main(String[] args) throws IOException, SAXException {
WebConversation conversation = new WebConversation();
conversation.setProxyServer("myproxy.proxy.com", 9087,"domain\\username" ,"password");


WebRequest request = new GetMethodWebRequest("http://www.google.com");

WebResponse response = conversation.getResponse(request);

System.out.println(response.getText());

}
}

output prints the google's page with all text as of page source.

Thanks for reading. Bye !!

How to use wget behind proxy


wget is most powerful at the same time handy tool to crawl a small part of web. Restricted crawling is made easier when wget was invented.

Using wget behind the proxy can be a bit tricky. Here is the sample command

For windows
cmd> wget www.google.com
......................
....................
... failed: Connection Refused.

If you are getting the same error try:

cmd> wget -U="Firefox" www.google.com

Sometimes the proxy has a small setting which checks the user agent only. You may try crack it using -U option. If this also does not work try,

cmd> set http_proxy=myproxy.proxy.com
cmd> wget --proxy=on www.google.com

You should be able to download index.html. But if this is not working because proxy requires username and password, then try

cmd> set http_proxy=myproxy.proxy.com
cmd> wget --proxy=on www.google.com
cmd> wget --proxy-user "domain\foo" --proxy-password="chocolate" www.google.com

If this still does not work, then sorry you are on your on !!

Hope this is helpful. To figure out proxy settings check Internet Options or simple google it.

Tuesday, January 25, 2011

Inner classes and its magic

Inner classes have been bugging me for a long time and now I understood what they are.


For each class / interface it can be
top level OR Nested
Each nested class can be
Static OR Inner
Each Inner class can be
Member, Local or Anonymous.


Top level class

Its your normal class. Which has properties, methods, classes etc.
Nested Class

Class which is residing inside another class (or its method)
Static Inner Class

Acts same as Top level class and has package visibility.
Static inner class does not have package level visibility.

public class String{
private static class CaseInsensitiveComparator implements Comparator { ... }

The CaseInsensitiveComparator has only String class visiblity but does not require instantiations.

Member / Inner Class
Does not have package level visibility.
Outer class / enclosing class can not access variables without creating instance of the class.
Inner class can access the private variables of the outer class.
Gives more simplicity and object orientation. i.e. Car as outer, wheels as inner class.
Static fields / methods cannot be part of Inner Classes. Static can be part of only static or top level classes.

i.e.

class top{
int i = 22;

class myNested{
int k=i;
void food() {}

} // end of nested class

void doSomething(){
myNested mn = new MyNested()
mn.food();


}

} // end top

Local class

Example:

public class f extends Applet{

Button apple = new Button();

public void init () {

// Local class starts from here

Class InnerLocalClass implements java.awt.ActionListener {
int i=1;

public void ActionPerformed(Event e){
System.out.println("Somehting has happned ...");
} // end method

}// end inner local class

// Local class ends here

}// end init method

add(apple);
apple.addActionListener(new InnerLocalClass);

}// end class


Anonymous Classes

We saw that a method that has inner class and that is accessible by the enclosing class. Instance of Local Class is passes to action listener to track events. Now what if we can add the methods / implementation directly to any action listener.

i.e.

public class f extends Applet{

Button apple = new Button("Text Name");

public void init(){
int clickCount = 0;
add(apple);
apple.addActionListener(new ActionListener(){
public void ActionPerformed(ActionEvent e) { ... do something ... }
// you can add more listeners here
}
}
}

clickCount cannot be part of do something. Because it is not final. So when the code is compiled the clickCount is not passes to Inner Anonymous class unless it has final as access modifier.

How these classes are compiled altogether:
- Compiler creates outerclass$something for inner classes and created when compiled. For static they are treated as top level classes.

Sunday, January 23, 2011

Lessons learned from computer science interviews

Interviews and its questions. They always look easy after getting out of interview session. Most of the time people tend to ask technical questions and specifically programming ones. In this blog post I am writing my experience and advises while writing a program.

In the program to understand we have logical parts such as input, output and logical main. To start with your program

:> Identify the returned stuff. Say int is returned to find max out of an array
:> Put a logical method name with proper input or receiving parameters
:> In the start of the program initialize some variables if required
- counter, start and end pointer to string, length of the string
:> if recursive program then check on null or exit conditions in start of program.
:> in recursive program the return can be associative with recursion.
- i.e. return ( node.value < node.right.value && checkTreeisBST(node.right) )
:> do a dry run after finishing the program and test it for edge conditions

A good guide to programming questions is Crack the Interview . Here the answers are wrong but questions are right. So don't trust the answer.

Wednesday, January 12, 2011

XML Parsing Techniques

Parsing is a process that involves break the xml text into nodes.

Pull Parsing:

Application has to pull the next node or element from the parser. Application asks the parse to next node. Pull parsing does not do varification (checking the xml against schema) however definitely do verification.

Push Parsing:

Parser sends the notification to the application about the type of XML nodes / pieces found during parsing. It is also knows as Event Based Parsing. SAX (Simple API for XML) is fast parsing mechnism, but application has to match the speed of the SAX parser for each event. Same as above about validation and verification.

One Step Parsing:

Parser generates the tree based upon the XML document structure. DOM (Docuemnt Object Model) is one of the parsing standard. Very useful when traversing is required in the tree.

Hybrid Parsing:

The application thinks its working with one step parser that has processed the whole document while parsing process has just started. As the pplication keeps accessing more objects on the DOM tree the parsing continues incrementally.

XML Parsing Models and Their Trade-Offs:


ModelControl of ParsingControl of ContextMemory EfficiencyComputational EfficinecySimplicity
PullApplicationApplicationHigh Highest Low
Push (SAX) Parser Application High High Low
One-step(DOM) Parser Parser Lowest Lowest High
One-step (JDOM) Parser Parser Low Low Highest
Hybrid (DOM) Parser Parser Medium Medium High
Hybrid (JDOM) Parser Parser Medium Medium Highest


References:
http://media.techtarget.com/searchSAP/downloads/Building_Web_Services_with_Java_CH02.pdf