Thursday, August 11, 2011

Ranking of Engineering branches in Kerala

Please refer previous post. This is also based on the 'lastRank'.

1. Aeronautical Engineering
2. Mechanical Engineering
3. Electronics and Communication
4. Civil Engineering
5. Electrical Engineering
6. Computer Science
7. Automobile Engineering
8. Architecture Engineering
9. Instrumentation
10. Chemical
11. Food Technology
12. Bio Medical
13. Printing Technology
14. Production
15. Bio Technology
16. Information Technology
17. Polymer Technology
18. Industrial Engineering

Wednesday, August 10, 2011

Ranking of Engineering Colleges in Kerala

This is an attempt to rank the Engineering colleges in Kerala. This is based on the demand for admission to various branches in 2010. This is calculated using the data of 'LastRank' (last rank who got admission to a specific branch in a specific college). Only Computer Science, Electronics and Electrical branches are considered for rank calculation (mainly as these are the most common branch across all colleges). Only the 'lastRank' for General category has been considered (assuming the demand pattern is similar in all categories).
Note 1: Last rank data is available at http://www.cee-kerala.org/docs/keam2010/allot/lastrank2010.pdf .
Note 2: List of Engineering colleges is available at http://cee.kerala.gov.in/collegelist/main/frame.html (click on 'Engineering' ).
Note 3: NIT Calicut is not included in this list as the admission is not based on the Kerala entrance and hence a rank calculation based on 'last rank' is not possible.

1. COLLEGE OF ENGINEERING TRIVANDRUM ( TVE )
2. GOVT. ENGINEERING COLLEGE,THRISSUR ( TCR )
3. T K M COLLEGE OF ENGINEERING, KOLLAM ( TKM )
4. MODEL ENGINEERING COLLEGE, THRIKKAKKARA, ERNAKULAM ( MDL ) [Govt Self Finance]
5. M A COLLEGE OF ENGINEERING, KOTHAMANGALAM ( MAC )
6. GOVT. RAJIV GANDHI INSTITUTE OF TECH., KOTTAYAM ( KTE )
7. GOVT. ENGINEERING COLLEGE BARTON HILL, TVM ( TRV )
8. S C T COLLEGE OF ENGINEERING, PAPPANAMCODE, TVM ( SCT ) [Govt Self Finance]
9. ENGINEERING COLLEGE, IDUKKI ( IDK )
10. GOVT. ENGINEERING COLLEGE, WAYANAD ( WYD )
11. N S S COLLEGE OF ENGINEERING, PALAKKAD ( NSS )
12. GOVT. COLLEGE OF ENGINEERING, KANNUR ( KNR )
13. SCMS SCHOOL OF ENGINEERING AND TECHNOLOGY ( SCM ) [Private]
14. GOVT. ENGINEERING COLLEGE, SREEKRISHNAPURAM, PALAKKAD ( PKD )
15. COLLEGE OF ENGINEERING, CHENGANNUR, ALAPPUZHA. ( CHN )
16. FEDERAL INSTITUTE OF SCIENCE AND TECHNOLOGY ( FIT ) [Private]
17. LBS INSTITUTE OF TECH. FOR WOMEN, POOJAPURA, TVM ( LBT ) [Govt Self Finance]
18. VIDYA ACADEMY OF SCIENCE AND TECHNOLOGY ( VAS )
19. SAINTGITS COLLEGE OF ENGINEERING, PATHAMUTTOM, KOTTAYAM ( MGP )
20. ADI SHANKARA INSTITUTE OF ENGINEERING AND TECH ( ASI )
21. MOHANDAS COLLEGE OF ENGINEERING AND TECHNOLOGY ( MCT )
22. M E S COLLEGE OF ENGINEERING, KUTTIPPURAM. ( MES )
23. TOC H INSTITUTE OF SCIENCE AND TECHNOLOGY ( TOC )
24. UNIVERSITY COLLEGE OF ENGINEERING, KARIAVATTOM, TVM ( UCK )
25. COLLEGE OF ENGINEERING, KIDANGOOR ( KGR )
26. COLLEGE OF ENGINEERING, ADOOR ( ADR )
27. COLLEGE OF ENGINEERING, THALASSERY, KANNUR. ( TLY )
28. COLLEGE OF ENGINEERING PERUMON, KOLLAM ( PRN )
29. COLLEGE OF ENGINEERING, THRIKARIPPUR, KASARAGOD. ( TKR )
30. UNIVERSITY COLLEGE OF ENGINEERING,THODUPUZHA ( UCE )
31. I E S COLLEGE OF ENGINEERING, CHITTILAPPILLY, THRISSUR. ( IES )
32. NEHRU COLLEGE OF ENGINEERING AND RESEARCH CENTRE ( NCE )
33. SREE NARAYANA GURUKULAM COLLEGE OF ENGINEERING, KOLENCHERRY, KADAYIRUPPU P O, ERNAKULAM. ( SNG )
34. COLLEGE OF ENGINEERING, CHERTHALA, PALLIPPURAM, ALAPPUZHA. ( CEC )
35. CALICUT UNIVERSITY INSTITUTE OF ENGG AND TECH ( UCC )
36. COLLEGE OF ENGINEERING, KALLOOPPARA, PATHANAMTHITTA. ( PTA )
37. LBS COLLEGE OF ENGINEERING, KASARAGOD ( KSD )
38. K M E A ENGINEERING COLLEGE, EDATHALA, ALWAYE. ( KME )
39. P.A.AZIZ COLLEGE OF ENGINEERING AND TECHNOLGY ( PAA )
40. ILAHIA COLLEGE OF ENGINEERING TECH., MULAVOOR, MOOVATTUPUZHA, ERNAKULAM. ( ICE )
41. CO-OPERATIVE INSTITUTE OF TECH.,VADAKARA, KOZHIKODE. ( VDA )
42. AWH ENGINEERING COLLEGE, KOZHIKKODE ( AWH )
43. COLLEGE OF ENGINEERING, ATTINGAL, THIRUVANANTHAPURAM. ( CEA )
44. SNM INSTITUTE OF MANAGEMENT AND TECHNOLOGY ( SNM )
45. SREE BUDDHA COLLEGE OF ENGINEERING, PATTOOR, PATTOOR. P O, PADANILAM, NOORANAD, ALAPPUZHA. ( SBC )
46. JAWAHARLAL COLLEGE OF ENGINEERING AND TECHNOLOGY ( JCE )
47. COLLEGE OF ENGINEERING, KARUNAGAPPALLY, KOLLAM. ( KNP )
48. YOUNUS COLLEGE OF ENGINEERING AND TECHNOLOGY ( YCE )
49. METS SCHOOL OF ENGINEERING, MALA ( MET )
50. COLLEGE OF ENGINEERING, MUNNAR ( MNR )
51. COLLEGE OF ENGINEERING, POONJAR, KOTTAYAM. ( PJR )
52. THEJUS ENGINEERING COLLEGE ( TJE )
53. ROYAL COLLEGE OF ENGINEERING AND TECHNOLOGY ( RCE )
54. SREE NARAYANA GURU COLLEGE OF ENGINEERING AND TECH ( SNC )
55. CAARMEL ENGINEERING COLLEGE ( CML )
56. M E A ENGINEERING COLLEGE, PERINTHALMANNA, VENGOOR ( MEA )
57. MAR BASELIOS INSTITUTE OF TECHNOLOGY AND SCIENCE ( MBI )
58. SARABHAI INSTITUTE OF SCIENCE AND TECHNOLOGY ( SIT )
59. T K M INSTITUTE OF TECHNOLOGY, EZHUKONE, KOLLAM ( TKI )
60. KMCT COLLEGE OF ENGINEERING, MUKKOM, MANASSERY, K ( KMC )
61. MAR BASELIOS CHRISTIAN COLLEGE OF ENGG AND TECH ( MBC )
62. MANGALAM COLLEGE OF ENGINEERING, ETTUMANOOR, KOTTAYAM ( MLM )
63. MALABAR COLLEGE OF ENGINEERING AND TECHNOLOGY ( MEC )
64. MATHA COLLEGE OF TECHNOLOGY, MANAKAPPADI, NORTH PRAVUR, ERNAKULAM ( MTA )
65. RAJADHANI INSTITUTE OF ENGINEERING AND TECHNOLOGY ( RIE )
66. SRI VELLAPPALLY NATESAN COLLEGE OF ENGINEERING ( VPE )
67. MARY MATHA COLLEGE OF ENGINEERING AND TECHNOLOGY ( MMO )
68. SREEPATHY INSTITUTE OF MANAGEMENT AND TECHNOLOGY ( SPT )
69. PANKAJAKASTURI COLLEGE OF ENGINEERING AND TECHNOLOGY ( PKE )
70. AL-AMEEN ENGINEERING COLLEGE ( AAP )
71. JAI BHARATH COLLEGE OF MANAGEMENT AND ENGINEERING ( JBT )
72. MUSALIAR COLLEGE OF ENGINEERING AND TECHNOLOGY ( MCK )
73. BASELIOS MATHEWS II COLLEGE OF ENGG., SASTHAMCOTTA, KOLLAM ( BMC )
74. COLLEGE OF ENGINEERING AND MANAGEMENT PUNNNAPRA ( PRP )
75. MES INSTITUTE OF TECHNOLOGY AND MANAGEMENT ( MEK )
76. JOHN COX MEMORIAL C S I INSTITUTE OF TECHNOLOGY ( JIT )
77. MUSLIM ASSOCIATION COLLEGE OF ENGINEERING, VENJARAMOODU, THIRUVANANTHAPURAM. ( MUS )
78. M G COLLEGE OF ENGINEERING, THIRUVALLM, THIRUVANANTHAPURAM. ( MGC )
79. INDIRA GANDHI INSTITUTE OF ENGINEERING AND TECHNOLOGY ( IGW )
80. KMCT COLLEGE OF ENGINEERING FOR WOMEN ( KMW )
81. COLLEGE OF ENGINEERING, KOTTARAKKARA, KOLLAM. ( CEK )
82. VALIA KOONAMBAIKULATHAMMA COLLEGE OF ENGG AND TECH ( VKE )
83. PALAKKAD INSTITUTE OF SCIENCE AND TECHNOLOGY ( PIT )
84. ARCHANA COLLEGE OF ENGINEERING ( ACE )
85. VEDA VYASA INSTITUTE OF TECHNOLOGY, PONNEMPADAM P O, KARADPARAMBA, MALAPPURAM. ( VVT )
86. TRAVANCORE ENGINEERING COLLEGE, OYOOR, KOLLAM ( TEC )
87. K R GOURI AMMA COLLEGE OF ENGINEERING FOR WOMEN ( GWE )
88. UKF COLLEGE OF ENGINEERING AND TECHNOLOGY ( UKP )
89. MOUNT ZION COLLEGE OF ENGG., PATHANAMTHITTA ( MZC )
90. HINDUSTAN COLLEGE OF ENGINEERING, ARIPPA, CHOZHIYAKODE P.O., KULATHUPUZHA ( HKE )
91. SHAHUL HAMEED MEMORIAL ENGINEERING COLLEGE, KADAKKAL, KOLLAM ( SHM )
92. SREE BUDDHA COLLEGE OF ENGINEERING FOR WOMEN, AYATHIL, ELAVUMTHITTA, PATHANAMTHITTA ( SBW )
93. PRIME COLLEGE OF ENGINEERING FOR WOMEN ( PCE )
94. AXIS COLLEGE OF ENGINEERING AND TECHNOLOGY ( AXE )
95. MOUNT ZION COLLEGE OF ENGINEERING FOR WOMEN ( MZW )
96. YOUNUS COLLEGE OF ENGINEERING FOR WOMEN, THALACHIRA P O, KOTTARAKKARA, KOLLAM. ( YCW )
97. HEERA COLLEGE OF ENGINEERING AND TECHNOLOGY ( HCE )
98. AMMINI COLLEGE OF ENGINEERING ( AME )
99. ST. THOMAS INSTITUTE FOR SCIENCE AND TECHNOLOGY ( STI )

Monday, May 02, 2011

JDB - Debugging Concurrency issues in Java

Typically debugging concurrency issues using debugger is very difficult as it manifests only when multiple requests are processed concurrently. Also in a debugger tracking multiple threads is further difficult.
JDB is a free command line tool for Java. Please refer to my previous post for details about JDB ( http://rejeev.blogspot.com/2011/04/jdb-command-line-debugger-for-java.html ). We can debug concurrency issues much easily using JDB.
Typically concurrency issues are due to updation (or updaton and read) of a shared variable from two threads. Typically the challenge will be to identify which thread update the variable at which code segment. We can use JDB to identify that.

  • run the application with debug enabled

  • attach JDB to the application.

  • set 'watch' on the variable at the suspect variable.

  • set a 'monitor where all' to print the stack trace whenever the variable is accessed.

  • 'run' the application.

  • 'run' each time the application pauses at modification of the watch point.


Now whenever the application is modifying the variable, thread dump shall be printed. From the thread dump we will be able to identify which thread modifies the variable and at code segment.

Let us see an example now


Given below is a very simple example where a variable is shared between two threads and by the time, the thread 'main' prints out the value of the shared variable, the value has been modified by the other thread.
As this program is only few lines of code it is very trivial to go through the code and understand that the second thread is updating the variable at code Main2 (line:11). In a real application the shared variable may be updated from too many places with too many code paths to that. Eventhough you know that some thread updates the shared variable, it is very difficult to identify which thread updates from which code. JDB will help us to identify that.

Let us see how do we identify that



public class Main2 extends Thread {
public static int count;
public static void main(String[] args) throws Exception {
new Main2().start();
count = 5;
Thread.sleep(10);
System.out.println("value: " + count);
}
public void run(){
try{ Thread.sleep(5); }catch(Exception e){}
count = 10;
}
}

Now compile the code

javac -g Main2.java

Now run the program with debug enabled

java -cp . -Xdebug -Xrunjdwp:transport=dt_socket,server=y,address=8000,suspend=y Main2
Listening for transport dt_socket at address: 8000

Now attach the debugger

jdb -sourcepath . -attach 8000
Set uncaught java.lang.Throwable
Set deferred uncaught java.lang.Throwable
Initializing jdb ...

VM Started: No frames on the current call stack
main[1]

Now set 'watch' on the shared variable count. This means whenever the variable 'count' is modified, program will stop execution (as if there is a break point).

watch Main2.count

Now set 'monitor where all'. This means that whenever the program stops (due to a breakpoint or watch) 'where all' command (thread dump) shall be executed.

monitor where all

Now let us start execution by giving the command 'run'. We will get the first thread dump when the varible count is modified first time.

run
> Set deferred watch modification of Main2.count

Field (Main2.count) is 0, will be 5: "thread=main", Main2.main(), line=5 bci=11

Signal Dispatcher:
Finalizer:
[1] java.lang.Object.wait (native method)
[2] java.lang.ref.ReferenceQueue.remove (ReferenceQueue.java:118)
[3] java.lang.ref.ReferenceQueue.remove (ReferenceQueue.java:134)
[4] java.lang.ref.Finalizer$FinalizerThread.run (Finalizer.java:159)
Reference Handler:
[1] java.lang.Object.wait (native method)
[2] java.lang.Object.wait (Object.java:485)
[3] java.lang.ref.Reference$ReferenceHandler.run (Reference.java:116)
main:
[1] Main2.main (Main2.java:5)
Thread-2:
[1] Main2.run (Main2.java:10)
main[1]

'main[1]' as the command prompt indicates that current thread is 'main[1]'. First line of the thread 'main[1]' is Main2.java:5. That means the current line of code is at Main2.java:5.
run 'list' to see the current see the code at line number Main2.java:5

list
1 public class Main2 extends Thread {
2 public static int count;
3 public static void main(String[] args) throws Exception {
4 new Main2().start();
5 => count = 5;
6 Thread.sleep(10);
7 System.out.println("value: " + count);
8 }
9 public void run(){
10 try{ Thread.sleep(5); }catch(Exception e){}

Now resume execution again from there using 'run'. Now we get the thread dump again when the variable 'count' is modified.

run
Field (Main2.count) is 5, will be 10: "thread=Thread-2", Main2.run(), line=11 bci=12
11 count = 10;

Signal Dispatcher:
Finalizer:
[1] java.lang.Object.wait (native method)
[2] java.lang.ref.ReferenceQueue.remove (ReferenceQueue.java:118)
[3] java.lang.ref.ReferenceQueue.remove (ReferenceQueue.java:134)
[4] java.lang.ref.Finalizer$FinalizerThread.run (Finalizer.java:159)
Reference Handler:
[1] java.lang.Object.wait (native method)
[2] java.lang.Object.wait (Object.java:485)
[3] java.lang.ref.Reference$ReferenceHandler.run (Reference.java:116)
main:
[1] java.lang.Thread.sleep (native method)
[2] Main2.main (Main2.java:6)
Thread-2:
[1] Main2.run (Main2.java:11)
Thread-2[1]

Now current thread of execution is Thread-2 and current line of code is Main2.java:11.
To see the line of code at Main2.java:11

list
7 System.out.println("value: " + count);
8 }
9 public void run(){
10 try{ Thread.sleep(5); }catch(Exception e){}
11 => count = 10;
12 }
13 }

This time 'count' is modified by the second thread. From this it can identified that 'Thread 2' is modifying the variable 'count' at Main2(line:11). Also the code path to this operation also can be infered from the thread dump.
Hence the culprit here is 'Thread-2' and code segment 'Main2.java:11' and the execution path as explained in the stack of Thread-2 in the thread dump.

Tuesday, April 19, 2011

JDB - Command line debugger for Java

Introduction


Debugger is an unavoidable tool in any Java developer’s toolkit. A Debugger helps when the application/module/function behaviors different than that of developers expectation. Typically developer will first try to understand difference in behavior by glancing through the code quickly. If he still not able to understand the reason for the unexpected behavior; next step would be step through the program execution using a debugger. I assume readers are familiar with the normal debugging procedures. If not please go through the appendix.
Most of the current debuggers are GUI based (either integrated with IDEs (IntelliJ, Eclipse) or stand alone debuggers (Yourkit).
However GUI based debuggers are not very useful when the application is running on a remote machine, especially when the connectivity between the machine where appication is running and the machine where debugger is running is poor.
In such scenarios a command line debugger which is also running on the same box as the application is running would be useful.

JDB – a free command line debugger


JDB is a free command line debugger. JDB is part of JDK and is supported by Sun JDK on various Operating systems like Windows, Linux, Solaris and Mac OS x.
How to use
  1. We need to run the application with ‘debug enabled’. You need to provide the following JVM arguments ‘-Xdebug –Xrunjdwp:transport=st_socket,server=y,address=8000,suspend=y’ to start the application in debug mode. Please refer to http://download.oracle.com/javase/1.5.0/docs/guide/jpda/conninv.html#Invocation for further details.
  2. Application should be compiled with –g option.
  3. Attach JDB to the application ‘jdb –attach 8000’
  4. You can see the list commands by typing ‘help’
  5. Set breakpoint at some significant point using ‘stop at :
  6. Navigate through the code step by step using ‘step’ and ‘next’ and other commands.
Given below are a list of important commands
  1. stop at : - to set breakpoint
  2. run – to start execution or resume from a breakpoint
  3. locals – list values of local variables
  4. dump this – list variables of the instance ‘this’
  5. where all – to see the thread dump
  6. list – to see current code
  7. step – execute one line (if it is function step into the function)
  8. next – execute one line (if it is a function step over the function)
  9. help – print list of available commands with description
To see the complete list of commands type ‘help’ command.
Let us see an example to illustrate this further.

Example – Debugging Jackson (JSON processing tool)


Jackson is tool for parsing JSON (from JSON to object and Object to JSON parsing).
You can download Jackson source from http://jackson.codehaus.org/1.7.6/jackson-src-1.7.6.zip
Unzip the contents to any convenient location (. Build the source using ‘ant’.
ant jars
All packages shall be generated as /build. We need jackson-mapper-asl-1.7.6.jar and jackson-core-asl-1.7.6.jar
Given below is a small code which converts a Java object to JSON string.
We will navigate through the Jackson processing using debugger.


import org.codehaus.jackson.map.ObjectMapper;
public class Main {
public static void main(String[] args) throws Exception {
System.out.println("entering the program....");
MyEntity obj = new MyEntity();
obj.setId(1);
obj.setName("rejeev");
obj.setAddress("c-48, sree nagar");
ObjectMapper mapper = new ObjectMapper();
String json = mapper.writeValueAsString(obj);
System.out.println("json: " + json);
}
}

public class MyEntity {
private int id;
private String name;
private int age;
private String address;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
}


Save this code at
Compile the classes:

javac –g –cp ./build/jackson-mapper-asl-1.7.6.jar:./build/jackson-core-asl-1.7.6.jar:. –d . MyEntity.java Main.java

Run the application in debug mode.

java –Xbebug –Xrunjdwp:transport =st_socket,server=y,address=8000,suspend=y –cp ./build/Jackson-mapper-asl-1.7.6.jar:./build/Jackson-core-asl-1.7.6.jar:. Main

You will get the following output:

Listening for transport dt_socket at address: 8000

As the option ‘suspend=y’ is specified, the JVM is just started. Method exectution is not yet started. When we trigger ‘run’ command from debugger exectution will start.

Attach debugger to the application

jdb –sourcepath :/src/mapper/java –attach 8000

You will get the following output:

Set uncaught java.lang.Throwable
Set deferred uncaught java.lang.Throwable
Initializing jdb ...
>
VM Started: No frames on the current call stack
main[1]

To start the execution run the command ‘step’

main[1] step
>
Step completed: "thread=main", Main.main(), line=4 bci=0
4 System.out.println("entering the program....");

Now program is at the first line of the function ‘main’
Let us see the code around the current line of execution.

main[1] list
1 import org.codehaus.jackson.map.ObjectMapper;
2 public class Main {
3 public static void main(String[] args) throws Exception {
4 => System.out.println("entering the program....");
5 MyEntity obj = new MyEntity();
6 obj.setId(1);
7 obj.setName("rejeev");
8 obj.setAddress("c-48, sree nagar");
9 ObjectMapper mapper = new ObjectMapper();
10 String json = mapper.writeValueAsString(obj);

The arrow indicates the current line of execution.
Open the java source files (Main, MyEntity and Jackson source files) in a TextEditor or IDE.
Let us start from Main. Main:10 is the line which parse object to JSON string.
Let us set breakpoint at Main:10

main[1] stop at Main:10
Set breakpoint Main:10

To move the execution from the current line to next breakpoint (line 10)

main[1]
main[1] run
Breakpoint hit: "thread=main", Main.main(), line=10 bci=41
10 String json = mapper.writeValueAsString(obj);

To see the code around current line

main[1] list
6 obj.setId(1);
7 obj.setName("rejeev");
8 obj.setAddress("c-48, sree nagar");
9 ObjectMapper mapper = new ObjectMapper();
10 => String json = mapper.writeValueAsString(obj);
11 System.out.println("json: " + json);
12 }
13 }


We can see all local variables using ‘locals’

main[1] locals
Method arguments:
args = instance of java.lang.String[0] (id=867)
Local variables:
obj = instance of MyEntity(id=868)
mapper = instance of org.codehaus.jackson.map.ObjectMapper(id=869)

Now we can inspect the content of any object. Let us inspect ‘obj’.

main[1] dump obj
obj = {
id: 1
name: "rejeev"
age: 0
address: "c-48, sree nagar"
}


Now let us step into ‘writeValueAsString’ using the command ‘step’

main[1] step
>
Step completed: "thread=main", org.codehaus.jackson.map.ObjectMapper.writeValueAsString(), line=1,595 bci=0

Now see the current code again using the command ‘list’

main[1] list
1,591 public String writeValueAsString(Object value)
1,592 throws IOException, JsonGenerationException, JsonMappingException
1,593 {
1,594 // alas, we have to pull the recycler directly here...
1,595 => SegmentedStringWriter sw = new SegmentedStringWriter(_jsonFactory._getBufferRecycler());
1,596 _configAndWriteValue(_jsonFactory.createJsonGenerator(sw), value);
1,597 return sw.getAndClear();
1,598 }

Let us go to the next line using the command ‘next’ and from line 1596, let us step into the function ‘_configAndWriteValue’

main[1] step
>
Step completed: "thread=main", org.codehaus.jackson.JsonFactory.createJsonGenerator(), line=489 bci=0
489 IOContext ctxt = _createContext(out, false);

Instead of stepping into _configAndWriteValue, we are now in JsonFactory.createGenerator. This is because first method parameters are calculated. To get into _configAndWriteValue, let us get out of createJsonGenerator using step up.

main[1] step up
>
Step completed: "thread=main", org.codehaus.jackson.map.ObjectMapper.writeValueAsString(), line=1,596 bci=24
1,596 _configAndWriteValue(_jsonFactory.createJsonGenerator(sw), value);

Now we are back at line no: 1596. Let us invoke step again.

main[1] step
>
Step completed: "thread=main", org.codehaus.jackson.map.ObjectMapper._configAndWriteValue(), line=1,982 bci=0
1,982 SerializationConfig cfg = copySerializationConfig();

Let us see the code around this

main[1] list
1,978 */
1,979 protected final void _configAndWriteValue(JsonGenerator jgen, Object value)
1,980 throws IOException, JsonGenerationException, JsonMappingException
1,981 {
1,982 => SerializationConfig cfg = copySerializationConfig();
1,983 // [JACKSON-96]: allow enabling pretty printing for ObjectMapper directly
1,984 if (cfg.isEnabled(SerializationConfig.Feature.INDENT_OUTPUT)) {
1,985 jgen.useDefaultPrettyPrinter();
1,986 }

Using this approach we can navigate around the code.
At any point we can see the thread dump using ‘where all’

main[1] where all
Signal Dispatcher:
Finalizer:
[1] java.lang.Object.wait (native method)
[2] java.lang.ref.ReferenceQueue.remove (ReferenceQueue.java:118)
[3] java.lang.ref.ReferenceQueue.remove (ReferenceQueue.java:134)
[4] java.lang.ref.Finalizer$FinalizerThread.run (Finalizer.java:159)
Reference Handler:
[1] java.lang.Object.wait (native method)
[2] java.lang.Object.wait (Object.java:485)
[3] java.lang.ref.Reference$ReferenceHandler.run (Reference.java:116)
main:
[1] org.codehaus.jackson.map.ObjectMapper._configAndWriteValue (ObjectMapper.java:1,982)
[2] org.codehaus.jackson.map.ObjectMapper.writeValueAsString (ObjectMapper.java:1,596)
[3] Main.main (Main.java:10)

Appendices:


Basic concept of debugging


A Debugger helps when the application/module/function behaviors different than that of developers expectation. Typically developer will first try to understand difference in behavior by glancing through the code quickly. If he still not able to understand the reason for the unexpected behavior; next step would be step through the program execution using a debugger.
Using a debugger one can put a mark (called breakpoint) on any line in the source code and the program will stop execution when the execution reaches that mark. Then we can do the following:
1. Inspect the state of the program at that point. Typically following states are valuable – (a) Local variables, (b) Instance variables of the current object (this), (b) Execution stack of the request
2. Execute the program from that point (breakpoint), step by step, one line at a time. The current line could be an invocation of a function. In that case we have two options – (a) execute the function as single step and process to next line in the current code segment (step over), (b) step into the function and go to the next line in the function (step in).
3. Continue the execution of program (resume) from the breakpoint (typically to next breakpoint).
Typically we put a breakpoint at a line where we think the beginning of the significant code. Then navigate through the code step by step using either step-over and step-in, also inspecting local variables and instance variables at relevant steps. Once we complete the analysis of one significant code segment, we will move to another significant code segment by putting a breakpoint at the beginning of that segment and using ‘rusume’ to move from old code segment to new code segment.
By this method most of the issues can be explained. However analyzing concurrency issues requires different approach.
Consider a scenario where your program execution is affected by the setting of a Boolean variable which is reset by some other thread which you don’t know.
This can be analyzed by putting a ‘watch’ on that variable. Whenever that variable is modified, execution is stopped at that point, by inspecting the stacktrace, we will be able understand which thread at which code modifies the variable.

Thursday, April 07, 2011

Anna Hazare anti corrupton movement

It is very heartening to see the kind of support Anna Hazare anti corruption movement ( http://www.annahazare.org/anticorruption-movement.html ) is gaining. My full support to the movement. I have observed that lot of educated employed youth also participating in this movement very actively ( despite common lethargy toward politics ). Lot of poeple are participating in fast to show solidarity towards Anna Hazare movement.

Saturday, March 05, 2011

Temperature and Pressure Gradient in Ideal Gas

Introduction


Consider a narrow horizontal tube. The curved surface made with perfect insulator. The flat faces made with perfect heat conductor. One end of the tube is maintained at 100 oC and the other end is maintained at 0 oC. Once the steady state is attained, heat continue to flow from hot end to cold end. A temperature gradient is attained in the gas as the heat flows through it.
Q1. Is the pressure in the gas in tube uniform?
Q2. Is the density in the gas in tube uniform? Else how does it vary?

Derivation



Consider a cross section of the tube a position z=z0.
Assume at z = z0 mean free path of molecules is l

At z = z(0-l):
Density is ρ1 and
Average molecular velocity is c1
Temperature is T1

At z = z(0+l):
Density is ρ2 and
Molecular velocity is c2
Temperature is T2
The number of molecules crossing a unit area in the cross section at z=z0 from left side is:
1/4ρ1c1
The number of molecules crossing from right side is:
1/4ρ2c2
The number molecules crossing from both side has to be equal to maintain the conservation of mass.
Hence ρ1c1 = ρ2c2
That is pressure * molecular velocity is constant
ρc = A
T is proportional to the square of c. Hence:
ρ1sqrt(T1) = ρ2sqrt(T2)
Above equation is equivalent to equation for Thermal transpiration. However from the above argument, it can found that this is equation is valid for any steady state system with temperature or pressure gradient.

Other derivations
ρ1/ρ2 = sqrt(T2/T1) OR
ρ/ρ0 = sqrt(T0/T)
pressure is proportional to ρc^2
p ~ ρc^2
Applying equation (ρc = A) in above equation:
pressure is proportional to c
p ~ c

p1/p2 = c1/c2
c is proportional to square root of temperature
p1/p2 = sqrt(T1/T2) OR
p/p0 = sqrt(T/T0)

Implications
Hot air balloon
Why a hot air balloon is stiff? (see the photograph; courtesy skywaltz)

It is stiff not because of the low density inside. Had it been the case if we fill the balloon with hydrogen (with opening as for hot air balloon), it would have been stiff (Any verification on this?).
My friend Prem suggested that the stiffness may be due to the buoyancy. The upper part of the balloon can be stiff due the buoyancy. However stiffness of all wiered shaped balloons ( http://www.xarj.net/wp-content/uploads/2009/03/crazy-hot-air-balloon14.jpg ) cannot be explained by buoyancy.
It is stiff because of the high pressure inside. Pressure is high due to the high temperature inside.
However is the pressure inside high enough according to the equation (4)? Not really!
Assume the inside temperature is 100 oC (373 K). Then:
Assume outside temperature is 20 oC (293 K) and pressure is 1 kg/cm^2
Inside pressure p = sqrt(373/293) * 1
p = 1.13 kg/cm^2
That is a pressure difference of 0.13 kg/cm^2
That means a force of 1300 kg per square meter of balloon cloth. No balloon cloth can withstand that kind of force considering the area of balloon is many square meters.
Why the pressure inside lower than expected?
I have two hypothesis
(a) Heat convection - Our assumption was heat transfer is entirely through conduction. If heat transfer via convection instead of conduction, then the gas inside the balloon instead of having continuous steady state temperature gradient, there will be macro level big pieces of air cloud with different temperature and density. Heat transfer shall be through movement of such air clouds rather than through conduction. in such case there will not be any pressure build up. We can consider the air inside the balloon as a collection of air clouds (like pebbles in a bag).
In really both conduction and convection contributes and hence there will be some pressure difference (which is much less than otherwise it would have been).
(b) Quantum mechanical non local potential energy reduction - If you consider glass tube in our discussion, the pressure inside is only a local optimization. By re-ordering the molecules, another state with same temperature gradient but with no pressure gradient is possible. However there is no incremental ways to achieve that state. If we consider molecular distribution of molecules as a superimposition of all possible distributions, by a non local state reduction of molecules, pressure reduction is possible. Hence the actual pressure difference shall be less than predicted one and it will be depends on the amount of quantum mechanical state reductions.
Is both (a) and (b) are related? How is heat convection explained in kinetic theory?
Also I think as the opening at the bottom of the balloon is narrow, the pressure difference shall be high (for the same temperature inside) (Needs verification). Narrow opening will prevent heat convection and non local state reductions.
Experimental verifications
To be done.

Wednesday, March 02, 2011

Crookes Radiometer

Crookes Radiometer is device which generates mechanical energy from light. The instrument consists of a shaft with Blades (leaves). The blades are painted black at one side and silver at other side. When light is shown on the device the leaves rotates.
Please refer to http://en.wikipedia.org/wiki/Crookes_radiometer to know more about Crookes Radiometer.
According to the current scientific knowledge base, the explanation of Crookes Radiometer revolves around 'Thermal Transpiration'. However the explanation is very convoluted. Please refer http://math.ucr.edu/home/baez/physics/General/LightMill/light-mill.html for details about the current explanation.
I have better explanation.
The main contention is about how temperature at both sides of the blade (leaf) causes rotation.
First consider what happens at the boundary between the blade and gas around it. The molecules in the gas hit and bounces at the blade. Consider now the temperature of the blade is higher than that of gas. Now heat will flow from blade to gas. How is heat flow from blade to gas? When the molecules hit the blade. When the molecules hit and bounce, it will bounce with faster speed than it was traveling before bouncing*. The increase in speed means increase in energy (the energy transferred from the blade to gas). The increase in speed is depends on the temperature difference between the blade and gas.
Similarly when the temperature of the blade is less than the gas, the molecules will bounce with a lower speed than it was traveling before touching the blade.
In steady state, temperature difference between gas and black side is higher than the temperature difference between the gas and silver side. Hence the molecules at black side bounces faster than the silver side.
As the molecules bounces faster at black side, black side will experience more pressure than silver (note that the pressure = change is momentum; momentum = mass * velocity). This pressure difference causes the rotation of the blade.

* How can a particle travel faster than it's initial speed? Well, actually the real story is not like that. According to quantum theory the particle when hit get absorbed in the surface of the blade and then it get emitted with a higher speed. However this is not important to us.

Tuesday, January 18, 2011

IntelliJ IDEA

I have been using IntelliJ IDEA community edition ( http://www.jetbrains.com/idea/ ) lately and found that it is much better than Eclipse and NetBeans.
Addicted to IDEA!
Addicted toJava IDE with unparalleled java code
analyzer (600+ built-in inspections)

Sunday, July 25, 2010

Pressure and temperature gradient in Ideal Gas



Consider a circular tube with one side is maintained at 100 degree Celsius and other side is maintained at 0 degree Celsius. Temperature at both ends is maintained at constant temperature using an infinite heat source at A and infinite heat sink at B. Faces facing A and B (flat faces) is perfect conductor. Circular face is perfect insulator. Tube is filled with ideal gas.


What will be the temperature and pressure gradients inside the tube?

  1. Will heat flow from A to B?

  2. Will the Temperature at A higher than temperature that at B?

  3. Will the Pressure at A higher than pressure that at B?

  4. Will the Density at A higher than that at B?






Consider the cross section at an arbitrary point in the tube. Consider the kinetic theory of gas. Assume the all particles of the gas are of same weight.

  • Temperature in the tube touching side A shall be 100 and temperature in the tube touching side B shall be 0. Hence there will be a temperature gradient.

  • Hence heat will flow from A to B.

  • Number of particles passing from A to B will be equal to number of particles passing from B to A.

  • Number of particles passing through the cross section is proportional to density of the particles (d) and velocity of the particles (ū). That means throughout the tube, the dū will be constant.

  • Temperature of ideal gas is proportional to the square of the velocity of the particles. Hence velocity of gas particles at side A shall be higher than velocity at side B.

  • As dū is constant, then density at side A shall be less than density at side B.

  • According to kinetic theory, Pressure of a ideal gas is due to the particles of the gas hitting the boundary of the container. Pressure will be equal to the rate of change of momentum at the boundary. Pressure is directly proportional to the number of particles hitting the boundary and momentum of individual particles. Number of particles hitting the boundary is proportional to dū and momentum is proportional to velocity of the particles. Hence pressure is proportional to dū and ū.

  • Since dū is constant across the tube, pressure is directly proportional to velocity of the particles (ū). As we have seen velocity is directly proportional to the square root of temperature.

  • Hence pressure inside tube shall be higher at side A and lower at side B.



This is in fact analogous to Bernoulli’s principle (which states that there will be a pressure gradient along with a velocity gradient).



From this we can conclude that:

  1. There will be pressure gradient along with a temperature gradient. The pressure gradient is directly proportional to the gradient of square root of temperature

  2. There will be density gradient along with temperature gradient. The density gradient is inversely proportional to the square root of the temperature.