Overriding the equals() method

I was looking for any best practices related to overriding the equals() method in objects and came across javapractices.com, which has a section devoted to the equals() method: Implementing equals. This article doesn’t really answer the question of “when” you override the method, although from other reading I can surmise that you do so whenever you think you or someone else may need to use the object as a key in a hashtable. Any other opinions as to the “when” of overriding the equals() method?

Application settings when using servlets

I posted some notes a couple weeks ago about .NET configuration files, came across the code for doing the same thing in a servlet container tonight. Basically, you get a ServletConfig object using the getServletConfig() method of the Servlet interface and then call getInitParameter(String initParamName) on that. For example, let’s say that I put a global database connection string in my web.xml deployment descriptor:

<web-app>
  <servlet>
   <servlet-name>myservlet</servlet-name>
   <servlet-class>MyServlet</servlet-class>
    <init-param>
     <param-name>connection_string</param-name>
     <param-value>user id=sa;password=mypassword;initial catalog=mydb;data source=mydbserver;Connect Timeout=30</param-value>
    </init-param>
  </servlet>
</web-app>

Then, in my servlet code init() method, I could write this:

ServletConfig sc = getServletConfig();
String connection_string = sc.getInitParameter(“connection_string”);

After retrieving the value from the ServletConfig object, you’ll probably want to store it for later use in the ServletContext object:

ServletContext c = getServletContext();
c.setAttribute(“connection_string”, connection_string);

Now I can get the connection string in a JSP or a servlet later using this short snippet:

String myCS = (String)getServletContext().getAttribute(“connection_string”);

user level security in apache

I needed to lock down a couple directories on this server using Basic Authentication in Apache… in case you’ve ever wanted too, or someday will need too:

1) Add the username to the password file using the htpasswd module:

# htpasswd /etc/httpd/users username

where ‘/etc/httpd/users’ is the name of the file you want your users/passwords stored and ‘username’ is the username you want to add. It’ll ask you for the password, and then again before adding the user to the file. If the file doesn’t exist, usr the -c flag to create the file:

# htpasswd -c /etc/httpd/users username

2) Then add a .htaccess file in the directory you wan to secure that contains this:

AuthName “username”
AuthType Basic
AuthUserFile /etc/httpd/users
require user username

where ‘/etc/httpd/users/’ is the name your passwd file and ‘username’ is the name of the user you want to allow in this directory.

Gandhi’s Truth

I finished “Gandhi’s Truth: On The Origins of Militant Nonviolence” this morning. I won’t try to summarize what Erik Erikson wrote over 450 pages, but here are a couple quotes I found worth remembering:

… I must reduce myself to zero. So long as a man does not of his own free will put himself last mong his fellow creatures, there is no salvation for him. Ahimsa is the farthest limit of humility.” [pg 59]

… I will not forget the consternation which I caused in some of Gandhi’s odl friends when I asked them to stand up and show me how tall he was as compared with them. It became clear that, while in fact small, he seemed immeasurable. The passing of such a pervasive light leaves the dark even darker and the once-enlightened suddenly forlorn. For the numinous person has the strange power to make the participant feel part of him and yet also feel augmented in himself; and both of these augmentations are apt to wane when the great moment is over.” [pg 63]

Heinrich Zimmer summarizes the meaning of dharma as: “The correct manner of dealing with every life problem that arises, therefore, is indicated by the laws (dharma) of the caste (varna) to which one belongs, and of the particular stage of life (asrama) that is proper to one’s age. One is not free to choose; one belongs to a species — a family, guild, and craft, a group, a denomination. And since this circumstance not only determines to the last detail the regulations for one’s public and private conduct, but also represents (according to this all inclusive and pervasive, unyielding pattern of integration) the real ideal of one’s present natural character, one’s concern as a judging and acting entity must be only to meet every life problem in a manner befitting the role one plays…” [pg 75-76]

.. In all of Gandhi’s utterances … two themes stood out, new in the independence movement: never start what you have not clearly circumscribed in your own mind or what you are not ready to suffer for to the very end.” [pg 89]

In regards to the desire Gandhi had to be untainted and unsmudged: “Mere character could be, as it were, a cold chimney, nothing more than an encasement. A fireplace is not worth more than the fire it can hold and warmth it can generate; and a man like Gandhi, I would surmise, early knew that he had to contain a superior energy of destructive, as well as benevolent, forces..” [pg 101]

On the difference between Indians and Westerners: “… the very qualities of Indians count for defects in South Africa. The Indians are disliked in South Africa for their simplicity, patience, perseverance, frugality, and otherworldliness. Westerners are enterprising, impatient, engrossed in multiplying their material wants and in satisfying them, fond of good cheer, anxious to save physical labor and prodigal in habits.” [pg 190]

An illuminating quote in relation to the chaos that enveloped Baghdad in the days following the initial US occupation: “The point is that excess and riot follow repression and suppression when the moral restraints are lifted, precisely because of the autocratic and blind nature of those restraints…. nonviolence, inward and outward, can become a true force only where ethics replaces moralism. And ethics, to me, is marked by an insightful assent to human values, whereas moralism is blind obedience; and ethics is transmitted with informed persuasion, rather than enforced with with absolute interdicts.” [pg 251]

On our identities, who we are: “For membership in a nation, in a class, or in a caste is one of those elements of an individual’s identity which at the very minimum comprise what one is never not, as does membership in one of the two sexes or in a given race. What one is never not establishes the life space within which one may hope to become uniquely and affirmatively what one is — and then to transcend that uniqueness by way of a more inclusive humanity.” [pg 266]