Wednesday, March 17, 2004

Static

 

1 exerting force by reason of weight alone without motion

2 showing little change

  • An early frustration in learning Java is the error:   non-static method foo( ) cannot be referenced from a static context
  • Perhaps you are trying to call a simple method of your class from the main() method.  The main method is a static context.  The quick solution is to instatiate your object with MyObject mo = new MyObject right inside your main method.  now you have an instance of MyObject  
  • A static variable or method is going to persist across all the objects instantiated.
  • Static means that you lose the use of the 'this' keyword because the use of 'this' implies that you have an instantiation of an object.
  • Static means that it doesn't depend on the instantiation of an instance of the object. It still exists and can be called from an instance of the object, but it can also be called without creating the object.
  • The main() method is static because you have to call it to start a java program. That is, you call it before any objects are instantiated.
  • Consider the following class: 
    public class AddMe{
    	
    	static int num = 100
    	
    	static int add(int i){
    		int sum = i+2;
    		return sum;
    	}
    }
    
  • When I want to access the variable num, I can just say, myNum = AddMe.num and get the number 100.
  • I can also instantiate AddMe am = new AddMe() and then call myNum = am.num with the same effect.
  • Same with the add method. myNum = AddMe.add(2) sets myNum to 4 and so does myNum = am.add(2)
  • During my one week java class from Sun, I completed an exercise by using all static methods. I could then call the methods just like I made function calls in PHP or VB. My solution was used as an example of bending Java to act like a procedural language. Which, in case you need to be told, was frowned upon. It avoids all the Object Oriented concepts of Java. You don't even ever need to instantiate a class!

6:55:17 PM    comment []
 


Scary Story:

A co-worker of mine was playing basketball at the Downtown St. Paul YMCA one evening last week. The guys leave their kids in the corner of the gym, somewhat separated from the court, but still in view. One of the guys had to stop playing because he couldn't see his child ( age 3 ). The group split up to look and they still couldn't find him. Then, screams were heard coming from the spiral staircase leading up from the courts. The basketball players ran up the stairs, saw a guy dragging a child by the shirt, shouted at him, causing him to drop the child and escape.

They told the front desk who said, "he's gone, we can't do anything and kids aren't allowed there anyway".

It scares me to think that this guy, who has lost touch with reality to the extent that he would try to abduct a child from under the noses of 10 large guys playing basketball, is still running around downtown in a skyway system that is connected to the Children's museum, the science museum, the civic center, any number of day cares, restaurants, a library, and public eating areas.
2:42:04 PM    comment []

 


That didn't hurt too bad. Today was the first day of driving a displaced bus rider to work. She has a 10-week gig in downtown St. Paul and doesn't expect the strike to end in the next month.
12:40:04 PM    comment []
 


Weiqi Gao ( http://www.weiqigao.com/blog/2004/01/24/1074956131000.html ) points out that IDEA 4.0 supports tab groups with which you can split the editor window and edit two files at once. This fixes a small headache I was having over IDEA 3.x

Just right-click on the tab of a file you have open and select "Split tab group horizontally" and the file you have chosen will appear on the other side of the newly split editor window. Right-click again and click "Move to opposite tab group" to put it back.

Now I would like to find out how to remove the tabs altogether.
12:29:55 PM    comment []