Recent Notes

Displaying keyword search results 61 - 70
Created by jinx on April 25, 2011 12:43:40    Last update: April 25, 2011 12:43:40
Use the PHP function method_exists to check if the class or object has a certain method. It returns TRUE if the method exists (even when the value of the property is NULL), FALSE if the method does not exist. Example: <?php class A { var $p = 'A property'; ... Outputs: Class A has method f1: bool(true) Object $a has... Also note that C++-like method overloading does not exist in PHP. Thus there's no ambiguity about which version of the method exists, i.e., with no argument, with one argument... etc. The following code generates Fatal error: <?php class A { var $p = 'A property'; ...
Created by freyo on April 21, 2011 10:59:37    Last update: April 21, 2011 10:59:37
The class android.content.Context (of which android.app.Activity is a subclass) provides the method getPackageName() which returns the name of this application's package. Sample code: public void onCreate(Bundle savedInstanceState) ...
Created by jk34 on April 20, 2011 11:18:22    Last update: April 20, 2011 11:18:22
java.lang.CharSequence is an interface, which java.lang.String implements. So a String is a CharSequence (so are StringBuffer and StringBuilder ). But how do you convert a CharSequence to String ? Unsurprisingly, the method is toString() : String s = "a string"; CharSequence cs = ne...
Created by Dr. Xi on April 19, 2011 16:02:55    Last update: April 19, 2011 16:03:24
Method Description object.__getattr__(self,name) Called when an attribute lookup has not found the attribute in the usual places (i.e. it is not an instance attribute nor is it found in the class tree for self ). object.__setattr__(self,name,value) Called when an attribute assignment is attempted. This is called instead of the normal mechanism (i.e. store the value in the instance dictionary). If __setattr__() wants to assign to an instance attribute, it should not simply execute self.name = value — this would cause a recursive call to itself. Instead, for new style classes, it should call the base class method with the same name, for example, object.__setattr__(self, name, value) . For classic classes, it should insert the value in the dictionary of instance attributes, e.g., self.__dict__ [name] =...
Created by Dr. Xi on April 18, 2011 12:10:37    Last update: April 18, 2011 12:14:24
Python defines a long list of special methods to customize class behavior. This is a short list for the Basic Customizations . Method Description object.__new__(cls[, ...]) Called to create a new instance of class cls. __new__() is a static method (special-cased so you need not declare it as such) that takes the class of which an instance was requested as its first argument. __new__() is intended mainly to allow subclasses of immutable types (like int, str, or tuple) to customize instance creation. It is also commonly overridden in custom metaclasses in order to customize class creation. object.__init__(self[,...]) Called when the instance is created. The arguments are those passed to the class constructor expression. If a base class has an __init__() method, the derived class’s __init__()...
Created by alfa on April 11, 2011 21:17:11    Last update: April 11, 2011 21:17:11
Some methods to create an array in Java: With literal initialization. // array of strings String[] dogs = { "Chihuah... With array constructor (array allocated by not the elements). // create a byte array byte[] buffer = new byte... Anonymous array to be used as a parameter in method invocation String.format("Hello %s, %s, %s!", new Object[] { ...
Created by alfa on April 11, 2011 20:55:35    Last update: April 11, 2011 20:55:35
There are two methods to create a temporary file in Java: File.createTempFile(String prefix, String suffix) : Creates an empty file in the default temporary-file directory, using the given prefix and suffix to generate its name. The default temporary-file directory is specified by the system property java.io.tmpdir . File.createTempFile(String prefix, String suffix, File directory) Creates a new empty file in the specified directory, using the given prefix and suffix strings to generate its name. If no exception is thrown, then: The file denoted by the returned abstract pathname did not exist before this method was invoked, and Neither this method nor any of its variants will return the same abstract pathname again in the current invocation of the virtual machine. Call File.deleteOnExit() to arrange for the...
Created by alfa on April 06, 2011 13:13:34    Last update: April 06, 2011 13:13:34
This error happens when the class exists but it does not match the package name. In the screen capture below, the class Nothing exists but it doesn't reside in the com.demo.io package. $ java com.demo.io.Nothing Exception in thread ... A much shorter error message displays if the class does not exist at all: $ java com.demo.io.Nothing2 Exception in thread...
Created by Dr. Xi on April 05, 2011 08:34:17    Last update: April 05, 2011 08:35:06
The Java servlet API does not provide a getStatus method for HttpServletResponse until version 3.0. This is a wrapper that provides getStatus for servlet API 2.5 and older. You have to override 4 methods because sendError etc. does not call setStatus . import javax.servlet.*; import javax.servlet.ht... You can plug it in a servlet filter like this: public void doFilter(ServletRequest req, ...
Created by Dr. Xi on April 01, 2011 12:59:10    Last update: April 04, 2011 14:14:17
To configure Tomcat HTTP Basic Authentication with SSL: Configure web app for basic authentication (add these in web.xml ): <security-constraint> <web-resource-collec... Three elements are needed for this to work: security-constraint with the url-pattern to protect, login-config for the type of authentication method to use, and security-role for the role name(s) used in the security-constraint . Add login info to conf/tomcat-users.xml : <tomcat-users> <role rolename="testUserRole... Turn on SSL in conf/server.xml : <Connector port="8443" protocol="HTTP/1.1" SSLEnab... For default keystore file ${user.home}/.keystore , the keystoreFile attribute can be omitted. Otherwise, add keystoreFile="/path/to/keystore/file" . The setup is different if you are using APR .
Previous  2 3 4 5 6 7 8 9 10 11 Next