Monthly Archives: December 2012

Public, protected, default and private in Java

Here is some simple rules to memorize these access modifiers : private: class scope. default (or package-private): package scope protected: package scope + child (like pakage, but we can subclass it from different pakages). The protected modifier always keeps the … Continue reading

Posted in Java | Tagged | Leave a comment

Get URL Base / Hostname of the servlet

Here is a simple method for getting hostname of the current servlet: public String getUrlBase(HttpServletRequest request) throws MalformedURLException { URL requestUrl = new URL(request.getRequestURL().toString()); String portString = requestUrl.getPort() == -1 ? “” : “:” + requestUrl.getPort(); return requestUrl.getProtocol() + “://” … Continue reading

Posted in Java | Tagged , | 2 Comments

Work with IO Stream in Java

In java, one can divide streams into two main types: Connection streams, which Java use to directly connect to the source data (File on external memory, Network stream…): – FileInputStream/ FileOutStream is used to read binary file – FileReader/FileWriter is … Continue reading

Posted in Java | Tagged | Leave a comment