Followers

Monday, November 29, 2010

Some common tech jargon:-

Hello,

What I am about to discuss are very trivial technical points for programmers, But just for the sake of Jargons :-

1) Off-by-one error (OBOE): suppose you want to traverse an array from beginning to end. lets say its size is  100. And in the implementation programming language, the index starts from zero.

The following code segment demonstrates OBOE:-

for(i=0;i<=100;i++)

{

----------------------- some code

}

We end up traversing 101 elements. the array ranges from o to 99.

Its very common in C language.

2) Fencepost Error:-

This is an error associated while answering questions such as:-

If you build a straight fence 100m long with posts 10m apart, how many posts do you need?

At first sight we would say:- 100/10 = 10 posts are needed.

But looking closely we find that the answer is ((total_length/individual_length)+1) posts are needed.

See you guys,

Bye


Sunday, November 28, 2010

REASONS FOR: java.net.SocketException: Permission denied: connect

Hello friends,

Was trying to fetch response from a website, through the use of Socket class in a Java program.

Socket s1=new Socket("www.oracle.com",80);

Was getting the error:-

java.net.SocketException: Permission denied: connect

Solution:

The most probable reason for this, is that we are trying to access a port which is below 1023, which requires special privileges. In my case, I did not login as the administrator. Hence the error.


If I run the same lines of code , logged in as administrator, there will be no error.


Hope it helps,

Ashish Mishra

Wednesday, August 18, 2010

Friday, June 18, 2010

Struts CheckBox BUG

Hi friends,

Today I learnt about a bug in struts version 1.2

The checkbox bug :- Its quite famous among struts framework related programmers :-

The bug is that

if you uncheck a checkbox and submit a form, then the corresponding field in the targeted bean (the one in which form elements will be filled) will not be altered and hence, the next time you try to get back the data, you will have the discrepancy of a checked check-box (you will get it checked when you were expecting it to be unchecked).

This is due to the fact that, internally struts 1.2 has a setter method only if the checkbox is checked and not when its unchecked.


Googling about this may help resolve your additional doubts.

Saturday, June 5, 2010

Hi guys,

               Today I had the opportunity of sitting in amdocs fresher's walkin.

The test was conducted online :- It had the following condition:-

1) aptitude test : 20 questions 25 min

2) attention to details :20 questions 25 min

3)  passage - emphasis on attention to detail

4) Core java questions 20 questions

5) SQL - tricky 20 questions

6) Unix. 20 questions




Monday, April 19, 2010

Playing with GridBagLayout

/******************NEW POST********************************/
Hi guys,

This time we're gonna see how to make life easy while working with Swing in java.

Final Year students using java for their BE project, may find this article to be of usage.

  • All of us at some stage(while working with java), decide to build a standalone gui based application.
  • Now, we al like good and organized GUIs, but making one via swing can prove to be a bit tricky !!!
  • To place different items on a window frame in java, we hava something called as Layouts.
  • We've the different layouts like FlowLayout, Border Layout, CardLayout etc..
  • also worth mentioning are Gridlayout and GridBagLayout.
  • Now, I am saying that :-
Instead of using Other layouts or using setLayout(null) kind of things, it is best to use :

The GridBaglayout:-

/**************************************************************/

Funda about : System.out.println(obj); PRINTING AN OBJECT

/******************NEW POST********************************/
Hi guys,
Have you ever thought of:- how the following particular statement gets executed in java, and what's its real meaning:-

public void some_method()
{
....
....
public Object1 obj=new Object1();
System.out.println(obj1);
....
....
....
}


ANSWER:

internally, every object in java extends the "Object" clas, which we can call as the superclass for all the objects in java.

now there is a method "String toString(void)" in "Object" class.
So it gets inherited by all the classes.


the method "toString()" returns the String representation of the object, through which it is called.

When we say:

System.out.println(obj1);


this get internally interpreted as:-

System.out.println( obj1.toString() );

the default implementation of this method in Object returns some cryptic JVM generated code for the object.

Eg:-
for a JFrame object it printed:-

com.fns_issues.gui.Issue_Window[frame0,0,0,400x400,layout=java.awt.BorderLayout,title=,resizable,normal,defaultCloseOperation=EXIT_ON_CLOSE,rootPane=javax.swing.JRootPane[,5,5,390x390,layout=javax.swing.JRootPane$RootLayout,alignmentX=0.0,alignmentY=0.0,border=,flags=16785865,maximumSize=,minimumSize=,preferredSize=],rootPaneCheckingEnabled=true]

com.fns_issues.gui.Issue_Window being the fully qualified class name.



Now we can always override this method in our class of the concerned object.

Simply say:

public String toString()
{
return "hello here i am";
}


and

then:-

System.out.println(obj1);

will print:-

hello here i am.



So, that's all for now. See you guys.

Bye...

/**************************************************************/