Share your thoughts and find that its getting better every day. This work of mine helps me realize that.
Tuesday, May 12, 2015
Apache Tomcat server runs but does not display home page
Friday, February 13, 2015
Got Crazy with nested classes :)
Step 1: created a class like the following
package com.oz.core.NestedClasses;
public class OuterClass {
public static class NestedClass {
public class SubNestedClass {
public class Level4 {
public class Level5 {
public class Level6 {
public class Level7 {
public class Level8 {
public class Level9 {
public class Level10 {
public class Level11 {
public class Level12 {
public class Level13 {
public class Level14 {
public class Level15 {
public class Level16 {
public class Level17 {
public class Level18 {
public class Level19 {
public class Level20 {
public class Level21 {
public class Level22 {
public class Level {
Level() {
System.out
.println("Road To Eldorado WHOOO...HOOOO");
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
Step 2: instantiated the classes Lol
package com.oz.core.NestedClasses;
import com.oz.core.NestedClasses.OuterClass.NestedClass.SubNestedClass.Level4.Level5;
public class Main {
public static void main(String args[]) {
OuterClass outCls = new OuterClass();
OuterClass.NestedClass nesCls=new OuterClass.NestedClass();
OuterClass.NestedClass.SubNestedClass subNestedClass=
nesCls.new SubNestedClass();
OuterClass.NestedClass.SubNestedClass subNestedClass2=
new OuterClass.NestedClass().new SubNestedClass();
OuterClass.NestedClass.SubNestedClass.Level4 lvl4= subNestedClass2. new Level4();
OuterClass.NestedClass.SubNestedClass.Level4.Level5.Level6.Level7.Level8.Level9.Level10
.Level11.Level12.Level13.Level14.Level15.Level16
.Level17.Level18.Level19.Level20.Level21.Level22
.Level level = lvl4.new Level5().new Level6().new Level7().new Level8().new Level9().new Level10()
.new Level11().new Level12().new Level13().new Level14().new Level15().new Level16().new Level17().new Level18()
.new Level19().new Level20().new Level21().new Level22().new Level();
}
}
Step 3: ran the main program to see the output on the console ☺
Console Output:
Road To Eldorado WHOOO...HOOOO
Wednesday, February 11, 2015
LOL with Arrays in Java
Coming to the point, I grew interest in Nano technology, Astronomy, Relativity, Time Travel, Beyond 3 Diminsions... and there I was, I am not that good in science yet to show you guys the fourth dimension, but how about it in Java ROFL. I went up till 23 dimensions LOL. 23-Dimensional array.
I wrote down the following class
package com.oz.core.Arrays;
public class ArrayExperiments {
public static void main(String args[]) {
int[] intArray = new int[10];
int[][] int2dArray = new int[10][10];
int[][][] int3dArray = new int[10][10][10];
int [][][][] int4dArray=new int [10][10][10][10] ;
int [][][][][] int5dArray=new int [10][10][10][10][10] ;
int [][][][][][] int6dArray=new int [10][10][10][10][10][10] ;
int [][][][][][][] int7dArray=new int [10][10][10][10][10][10][10] ;
int [][][][][][][][] int8dArray=new int [10][10][10][10][10][10][10][10] ;
int [][][][][][][][][] int9dArray=new int [10][10][10][10][10][10][10][10][10] ;
int [][][][][][][][][][] int10dArray=new int [10][10][10][10][10][10][10][10][10][10] ;
int [][][][][][][][][][][] int11dArray=new int [10][10][10][10][10][10][10][10][10][10][10] ;
int [][][][][][][][][][][][] int12dArray=new int [10][10][10][10][10][10][10][10][10][10][10][10] ;
int [][][][][][][][][][][][][] int13dArray=new int [10][10][10][10][10][10][10][10][10][10][10][10][10] ;
int [][][][][][][][][][][][][][] int14dArray=new int [10][10][10][10][10][10][10][10][10][10][10][10][10][10] ;
int [][][][][][][][][][][][][][][] int15dArray=new int [10][10][10][10][10][10][10][10][10][10][10][10][10][10][10] ;
int [][][][][][][][][][][][][][][][] int16dArray=new int [10][10][10][10][10][10][10][10][10][10][10][10][10][10][10][10] ;
int [][][][][][][][][][][][][][][][][] int17dArray=new int [10][10][10][10][10][10][10][10][10][10][10][10][10][10][10][10][10] ;
int [][][][][][][][][][][][][][][][][][] int18dArray=new int [10][10][10][10][10][10][10][10][10][10][10][10][10][10][10][10][10][10] ;
int [][][][][][][][][][][][][][][][][][][] int19dArray=new int [10][10][10][10][10][10][10][10][10][10][10][10][10][10][10][10][10][10][10] ;
int [][][][][][][][][][][][][][][][][][][][] int20dArray=new int [10][10][10][10][10][10][10][10][10][10][10][10][10][10][10][10][10][10][10][10] ;
int [][][][][][][][][][][][][][][][][][][][][] int21dArray=new int [10][10][10][10][10][10][10][10][10][10][10][10][10][10][10][10][10][10][10][10][10] ;
int [][][][][][][][][][][][][][][][][][][][][][] int22dArray=new int [10][10][10][10][10][10][10][10][10][10][10][10][10][10][10][10][10][10][10][10][10][10] ;
int [][][][][][][][][][][][][][][][][][][][][][][] int23dArray=new int [10][10][10][10][10][10][10][10][10][10][10][10][10][10][10][10][10][10][10][10][10][10][10] ;
int5dArray[1][2][3][4][5]=999 ;
int6dArray[1][2][3][4][5][6]=1999 ;
int7dArray[1][2][3][4][5][6][7]=2999 ;
System.out.printf("%d + %d + %d = "+
int5dArray[1][2][3][4][5]+
int6dArray[1][2][3][4][5][6]+
int7dArray[1][2][3][4][5][6][7],
int5dArray[1][2][3][4][5],
int6dArray[1][2][3][4][5][6],
int7dArray[1][2][3][4][5][6][7]);
}
}
And I ran it eagerly to see what happens. LOL the following happened. I did it again, but this time the crashed the JVM and not the LOTUS DOMINO SERVER rofl
JVMDUMP006I Processing dump event "systhrow", detail "java/lang/OutOfMemoryError" - please wait.
JVMDUMP032I JVM requested Heap dump using 'C:\Accurev_work\Ozinisle\heapdump.20150211.175635.9948.0001.phd' in response to an event
JVMDUMP010I Heap dump written to C:\Accurev_work\Ozinisle\heapdump.20150211.175635.9948.0001.phd
JVMDUMP032I JVM requested Java dump using 'C:\Accurev_work\Ozinisle\javacore.20150211.175635.9948.0002.txt' in response to an event
JVMDUMP010I Java dump written to C:\Accurev_work\Ozinisle\javacore.20150211.175635.9948.0002.txt
JVMDUMP032I JVM requested Snap dump using 'C:\Accurev_work\Ozinisle\Snap.20150211.175635.9948.0003.trc' in response to an event
JVMDUMP006I Processing dump event "systhrow", detail "java/lang/OutOfMemoryError" - please wait.
JVMDUMP010I Snap dump written to C:\Accurev_work\Ozinisle\Snap.20150211.175635.9948.0003.trc
JVMDUMP013I Processed dump event "systhrow", detail "java/lang/OutOfMemoryError".
JVMDUMP032I JVM requested Heap dump using 'C:\Accurev_work\Ozinisle\heapdump.20150211.175705.9948.0004.phd' in response to an event
JVMDUMP010I Heap dump written to C:\Accurev_work\Ozinisle\heapdump.20150211.175705.9948.0004.phd
JVMDUMP032I JVM requested Java dump using 'C:\Accurev_work\Ozinisle\javacore.20150211.175705.9948.0005.txt' in response to an event
JVMDUMP010I Java dump written to C:\Accurev_work\Ozinisle\javacore.20150211.175705.9948.0005.txt
JVMDUMP032I JVM requested Snap dump using 'C:\Accurev_work\Ozinisle\Snap.20150211.175705.9948.0006.trc' in response to an event
JVMDUMP010I Snap dump written to C:\Accurev_work\Ozinisle\Snap.20150211.175705.9948.0006.trc
JVMDUMP013I Processed dump event "systhrow", detail "java/lang/OutOfMemoryError".
Exception in thread "main" java.lang.OutOfMemoryError
Exception in thread "Attach API wait loop" at com.oz.core.Arrays.ArrayExperiments.main(ArrayExperiments.java:14)
java.lang.OutOfMemoryError
at com.ibm.tools.attach.javaSE.TargetDirectory.getTargetDirectoryPath(TargetDirectory.java:66)
at com.ibm.tools.attach.javaSE.AttachHandler.connectToAttacher(AttachHandler.java:274)
at com.ibm.tools.attach.javaSE.AttachHandler$WaitLoop.checkReplyAndCreateAttachment(AttachHandler.java:371)
at com.ibm.tools.attach.javaSE.AttachHandler$WaitLoop.waitForNotification(AttachHandler.java:366)
at com.ibm.tools.attach.javaSE.AttachHandler$WaitLoop.run(AttachHandler.java:396)
And this time let me be @%$*&$! Less greedy
package com.oz.core.Arrays;
public class ArrayExperiments {
public static void main(String args[]) {
int[] intArray = new int[10];
int[][] int2dArray = new int[10][10];
int[][][] int3dArray = new int[10][10][10];
int [][][][] int4dArray=new int [10][10][10][10] ;
int [][][][][] int5dArray=new int [10][10][10][10][10] ;
int2dArray[1][2]=999 ;
int3dArray[1][2][3]=1999 ;
int4dArray[1][2][3][4]=2999 ;
System.out.printf("%d + %d + %d = "+
int2dArray[1][2]+
int3dArray[1][2][3]+
int4dArray[1][2][3][4],
int2dArray[1][2],
int3dArray[1][2][3],
int4dArray[1][2][3][4]);
}
}
And this gave a decent out put
999 + 1999 + 2999 = 99919992999
Wait what!!!! Lol rofl
A day for Enumeration perhaps
I understand that an object definition using the Enum keyword is similar to a class definition and can be put in its own file. And that the Enum objects by default will extend java.lang.Enum implicitly
An enum type is a special kind of Java class used to define collections of constants, methods etc. It can hold if statements, switch statements, fields, methods, iterations etc. Following is a simple example of my test with an Enum Object and its results
Enum Object definition
package com.oz.core;
public enum Level {
HIGH(3), // calls constructor with value 3
MEDIUM(2), // calls constructor with value 2
LOW(1) // calls constructor with value 1
; // semicolon needed when fields / methods follow
private final int levelCode;
Level(int levelCode) {
this.levelCode = levelCode;
}
public int getLevelCode() {
return this.levelCode;
}
}
Implementation class definintion
package com.oz.core;
public class EnumerationSample {
public static void main(String args[]) {
EnumerationSample self = new EnumerationSample();
self.caseWithStringArgs("medium");
self.caseWithStringArgs("high");
self.caseWithStringArgs("critical");
Level level = Level.valueOf("LOW");
System.out.println("level="+level);
System.out.println("level.compareTo(Level.valueOf(\"HIGH\"))="+level.compareTo(Level.valueOf("HIGH")));
System.out.println("level.compareTo(Level.valueOf(\"LOW\"))="+level.compareTo(Level.valueOf("LOW")));
System.out.println("level.compareTo(level.HIGH)="+level.compareTo(level.HIGH));
System.out.println("level.compareTo(level.LOW)="+level.compareTo(level.LOW));
System.out.println("level.getLevelCode()="+level.getLevelCode());
System.out.println("level.hashCode()="+level.hashCode());
System.out.println("level.name()="+level.name());
System.out.println("level.ordinal()="+level.ordinal());
System.out.println("level.toString()="+level.toString());
System.out.println("level.equals(Level.LOW)="+level.equals(Level.LOW));
System.out.println("level.equals(Level.MEDIUM)="+level.equals(Level.MEDIUM));
System.out.println("level.equals(Level.valueOf(\"LOW\"))="+level.equals(Level.valueOf("LOW")));
System.out.println("level.equals(Level.valueOf(\"MEDIUM\"))="+level.equals(Level.valueOf("MEDIUM")));
System.out.println("level.getClass()="+level.getClass());
System.out.println("level.getDeclaringClass()="+level.getDeclaringClass());
for (Level lvl : level.values()) {
System.out.println("lvl="+lvl);
}
/*System.out.println("level="+Level.valueOf(arg0, arg1));
System.out.println("level="+level.notify());
System.out.println("level="+level.notifyAll());
System.out.println("level="+level.wait());
System.out.println("level="+level.wait(arg0, arg1));*/
}
String caseWithStringArgs(String arg) {
String evaluatedString = "Not in list";
try {
Level level = Level.valueOf(arg.toUpperCase());
switch (level) {
case HIGH:
evaluatedString = "case statement for High";
break;
case MEDIUM:
evaluatedString = "case statement for Medium";
break;
case LOW:
evaluatedString = "case statement for Low";
break;
default:
break;
}
} catch (IllegalArgumentException exp) {
} finally {
System.out.println(evaluatedString);
return evaluatedString;
}
}
}
Following are the set of obtained console statements
case statement for Medium
case statement for High
Not in list
level=LOW
level.compareTo(Level.valueOf("HIGH"))=2 //HIGH=3, LOW=1, so HIGH-LOW=2
level.compareTo(Level.valueOf("LOW"))=0 //LOW=1, LOW=1, so LOW-LOW=2
level.compareTo(level.HIGH)=2 //HIGH=3, LOW=1, so HIGH-LOW=2
level.compareTo(level.LOW)=0 //LOW=1, LOW=1, so LOW-LOW=2
level.getLevelCode()=1 //LOW=1
level.hashCode()=650651336
level.name()=LOW //name
level.ordinal()=2 //ordinal = 2 - returns its position in its enum declaration
level.toString()=LOW
level.equals(Level.LOW)=true
level.equals(Level.MEDIUM)=false
level.equals(Level.valueOf("LOW"))=true
level.equals(Level.valueOf("MEDIUM"))=false
level.getClass()=class com.oz.core.Level
level.getDeclaringClass()=class com.oz.core.Level //Two enum constants e1 and e2 are of the same enum type if and only if e1.getDeclaringClass() == e2.getDeclaringClass().
lvl=HIGH //printed because of the iteration statement with in enum
lvl=MEDIUM //printed because of the iteration statement with in enum
lvl=LOW //printed because of the iteration statement with in enum
Hope this helps
Saturday, November 15, 2014
Extjs best practises
1.use MVC
2.use xtype
3.define custom xtypes
4.use compressor - give minified files to client
5.use SenchaArchitect or cmd
6.travese dom using up/down etc - dont give ID and dont get by ID to elements
7.use icons instead of "text+icons"
8.inject images using css
9.use theming
10.avoid using deprecated commands and use new commands like using Ext.launch method
instead of Ext.onReady
11.dont declare deep tree... use layouts precisely... try to keep things with in 2 or 3
levels
12.Reuse the components
13. Try to do population and manipulation in afterRenderer than in beforeRenederer
14.Always handle exceptions, especially failure cases of a Ajax call
Wednesday, November 12, 2014
The contents of my "external.html" file are as follows
<div id='karthick'>
My Custom text from an external HTMl
</div>
So the end result is as follows
The highlights in this example are
1. You are using a nested tabbed table created through Ext-js 4.2
2. It implements some inbuilt properties like
- closable:true
- and disable:true
3. You have included an external html file's content into your page
Note: this example wont work if you are trying this example in a local stand alone machine. Use a server like tomcat or IIS, because, the inclusion of content from an other html file includes AJAX requests in the back end by Ext-JS which would definitely fail in local or conclusively it requires a server to operate
Nested Tab example in Ext-Js
Wednesday, November 5, 2014
File Upload using Servlets
<servlet-name>UploadServlet</servlet-name>
<servlet-class>com.practise.karthik.servlet.UploadServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>UploadServlet</servlet-name>
<url-pattern>/UploadServlet</url-pattern>
</servlet-mapping>
Step 6: Now stop your Apache Tomcat Server if its already running.
- Right click on the html file mentioned in step 1,
- click on "Run as" and
- click on "Run on server" option
- choose your installed Tomcat server ( hope you had already added the server to your Servers view in the eclipse) and
- finish
This helped me get to the following screen
Choose your file and click on the "Upload File" button. You should receive a confirmation screen with the name of the file that you just uploaded as follows
This helped me upload my file to my server space configured in the web.xml and I am able to find the uploaded file as follows
Friday, October 17, 2014
replacing newline with characters in java
I had a string named “remarks” with the following value in it
10/17/2014 07:14 AM test1
test1
test1
test1
10/17/2014 07:14 AM dfgdfg
I tried to replace all line feeds in this string with a particular character set in java and so I tried the following
String re = remarks1.replaceAll("\n","$#$”);
System.out.println(re);
This kept giving me illegal arguments exception.
So I tried
String re = remarks1.replaceAll("\\n","$#$");
System.out.println(re);
Now I felt weird. This is not normal behavior as most of my searches said this should work. Hence I felt a little irritated and I tried a different string instead of “$#$”. It was a stupid attempt though. But to my astonishment it worked fine
Curse compiler. Stupid same and its issue with “$” characters
Following worked at last
String re = remarks1.replaceAll("\\n","@#@");
System.out.println(re);
The output was
10/17/2014 07:14 AM test1@#@test1@#@test1@#@test1@#@10/17/2014 07:14 AM dfgdfg@#@
At ease 0.0 grrr
Thursday, August 14, 2014
error c00c0240 - "Could not complete the operation due to error c00c0240." - AJAX request in Struts
I happened to encounter this error when I was attempting to debug an Ajax call to a Struts action. It made me feel miserable for a while as both firebug as well as eclipse debuggers with console showed no trace of the origins of the error. As usual I searched out for the error number and ended up with a lot of stack overflow posts. One of these posts were typically explaining me the same issue that I was facing and had a link to a blog post which contained a solution to the same. And to my relief, my companies network restrictions prevented that page from being loaded. Wait WTF!!! Yes... that’s how grateful I felt roflJ.
Enough of my story, the issue in my case was that the AJAX request that I framed and tested was
var x= new XMLHttpRequest();x.open("GET","http://localhost:7001/****/*************Action.do",false);x.send(null);x.responseText
This was giving me some un relevant message like the following and my debugging points never worked and neither the eclipse console had any logs printed in them through the log4j framework.
"
<html>
<head>
<script type="text/javascript" src="/****/js/*****.js"></script>
<script type="text/JavaScript">
window.document.onkeydown=checkKeyCode;
</script>
</head>
<body>
<table width="100%" valign="top" height="100%">
<tr>
<td align="center"><font color="red"><h4>
There was a problem, please try again!</h4></font>
</td>
</tr>
<tr>
<td align="center"> </td>
</tr>
</table>
</body>
</html>"
And I found the “THE ISSAC NEWTON” in me like most of the times, as something stuck me and I tried “POST” instead of “GET”
And now, I see some positive results. My debugging points in the eclipse is working.. Hurray!!!!!
var x= new XMLHttpRequest();x.open("POST","http://localhost:7001/****/*************Action.do",false);x.send(null);x.responseText
Hurray!!!!! Again. But wait, WTF its just that my debugging points in eclipse are working. So wait my work is not done yet
L J








