Memory control for Eclipse

12 11 2008

- Install Memory Monitor and Status Memory Monitor from Kyrsoft.
By installing these Eclipse plugins, you gain complete control over the
memory garbage of Eclipse. Install them via Help > Software Updates
> Find and install – Search for new features to install and choose a
new remote site. Enter http://www.kyrsoft.com/updates/ as the URL.

Improving performance of Eclipse/FlexBuilder

May 13th, 2008 . by polygeek

I’m working on a Flex project that is just kicking Eclipse in the ass. It takes forever to build and I keep getting out of memory errors.
Finally, I complained about the issue on Twitter and @tomcornilliac was
nice enough to twit back that I needed to give Eclipse a bigger heap by
editing the eclipse.ini file.

Simple enough. My eclipse.ini file is in the root folder of the Eclipse installation and looks like this:

-showsplash
org.eclipse.platform
–launcher.XXMaxPermSize
256M
-vmargs
-Dosgi.requiredJavaVersion=1.5
-Xms40m
-Xmx256m

-Djava.net.preferIPv4Stack=true
-Djava.net.preferIPv4Stack=true

I changed the two bolded lines to:

-Xms256m
-Xmx512m

And everything runs much faster and I haven’t gotten any of those pesky errors since.

You can also go Window > Preferences > General > Show heap
status to get a display of how much RAM Eclipse has to work with and
how much it’s actually using. Very handy to turn that on to see if you
need to increase your RAM allowance.

Thanks Polygeek! ;)





Real time Monitoring of Apache Error Log

25 09 2008

Log in via SSH to your Web server. Now run

tail -f /var/log/httpd/error_log

Now you can have that window monitoring your server





Static Keyword in C and Java

9 07 2008

This is a beginner programming concept but since I tend to switch from C to Java and vice versa over long periods of time, I tend to forget it, so here it is.

from http://www.java-samples.com/showtutorial.php?tutorialid=285

There will be times when you will want to define a class member that will be used independently of any object of that class. Normally a class member must be accessed only in conjunction with an object of its class. However, it is possible to create a member that can be used by itself, without reference to a specific instance. To create such a member, precede its declaration with the keyword static. When a member is declared static, it can be accessed before any objects of its class are created, and without reference to any object. You can declare both methods and variables to be static. The most common example of a static member is main( ). main( ) is declared as static
because it must be called before any objects exist.Instance variables declared as static are, essentially, global variables. When objects of its class are declared, no copy of a static variable is made. Instead, all instances of the class share the same static variable.

Methods declared as static have several restrictions:

  • They can only call other static methods.
  • They must only access static data.
  • They cannot refer to this or super in any way. (The keyword super relates to
    inheritance.)

If you need to do computation in order to initialize your static variables, you can declare a static block which gets executed exactly once, when the class is first loaded. The following example shows a class that has a static method, some static variables, and a static initialization block:

// Demonstrate static variables, methods, and blocks.
class UseStatic {
static int a = 3;
static int b;
static void meth(int x) {
System.out.println(“x = ” + x);
System.out.println(“a = ” + a);
System.out.println(“b = ” + b);
}
static {
System.out.println(“Static block initialized.”);
b = a * 4;
}
public static void main(String args[]) {
meth(42);
}
}

As soon as the UseStatic class is loaded, all of the static statements are run. First, a is set to 3, then the static block executes (printing a message), and finally, b is initialized to a * 4 or 12. Then main( ) is called, which calls meth( ), passing 42 to x. The three println( ) statements refer to the two static variables a and b, as well as to the local variable x.

Note It is illegal to refer to any instance variables inside of a static method. Here is the output of the program:

Static block initialized.
x = 42
a = 3
b = 12

Outside of the class in which they are defined, static methods and variables can be used independently of any object. To do so, you need only specify the name of their class followed by the dot operator. For example, if you wish to call a static method from outside its class, you can do so using the following general form:

classname.method( )

Here, classname is the name of the class in which the static method is declared. As you can see, this format is similar to that used to call non-static methods through object reference variables. A static variable can be accessed in the same way—by use of the dot operator on the name of the class. This is how Java implements a controlled version of global functions and global variables.
Here is an example. Inside main( ), the static method callme( ) and the static variable b are accessed outside of their class.

class StaticDemo {
static int a = 42;
static int b = 99;
static void callme() {
System.out.println(“a = ” + a);
}
}
class StaticByName {
public static void main(String args[]) {
StaticDemo.callme();
System.out.println(“b = ” + StaticDemo.b);
}
}
Here is the output of this program:
a = 42
b = 99

In C however it serves the purpose of preserving a function ’s member value beetween calls to that function. Pretty much like instantiating an “object” containing that variable, upon calling the function.





Flex ColumnWise Datagrid

31 05 2008

Original Blog Article on http://vipuljhawar.wordpress.com/2008/03/27/comparable-datagrid-in-flex/

Using a datagrid in Flex seems very easy, but it has the inherent problem as ready to eat meal. It may not allow you to do all the modifications and may not allow you to present it in a view you desire.

A few months back i had a requirement to create a datagrid, which displayed data column wise instead row wise i.e. the datagrid was suppose to be used for comparing and viewing data across columns rather than rows. So, how do we deal with such a problem in Flex. If you are working on HTML, its easy as you can just alter the logic in the for loop printing the rows. The whole point is using multi dimension arrays.

After finding no easy way to do it in Flex, i had to use to the same programming talent to display data column wise.

As datagrid expects the dataprovider to be in the form of an Array or ArrayCollection of objects and then it iterates over these objects to display a property of these objects in each column when you use the dataField property or you can reformat your test using the labelFunction property for the column. I used a combination of programming logic and labelFunction to display the list.

Lets say we intend to display Person objects columnWise, as displayed below.comparable-table.png

Now we would receive person object from the server to the client and there is no way that you can use labelfield property or the lablefunction straight away to create such a table.

The wrokaround is to keep the person array aside and create an array of indexes equal to the number of rows that each column would have or the max. number of rows that a column could have in the whole table. So we will create an array with numbers {1,2,3,4…} each number denoting a particular row in the column. Now, iterate through the person object array and keep on adding DataGridColumn objects to the datagrid for as many Person object. So, the dataprovider to the datagrid is an array of indexes and the number of columns is equal to the number of Person objects. Assign a labelFunction to each column such that

public function getCompareLabel(item : Object, column : DataGridColumn) : String {
var cIndex : int = int(Number(column.dataField)); //this will give you the column for which you have to get data.
if (cIndex == 0)
return getRowLabel(item, column); //Now in getRowLabel just write a switch function which will give label’s for each row, such as “First”, “Last” etc. This gives the first column.
var person : PersonDAO = personArray[cIndex-1] as PersonDAO;
//Now from second column onwards we will get the particular person object from the dataArray and display data for a particular field accordingly.
switch(item) {
case 1 : return getCmpStr(person.firstName);
case 2 : return getCmpStr(person.lastName);
case 3 : return getCmpStr(person.age);
….

…..

}

The output will be a table like above. Strange, isn’t it Flex is suppose to make things easier but i had to swing around the whole place to get this is in place.





26 05 2008

This allows us to access application memebers from within a comp based on container. Not very OOP

super.parentApplication