Posts

Java Conversion Types and Conversion Contexts

Image
When an expression evaluated in Java programing language it either produce a result or nothing. An expression denotes nothing if and only if it is a method invocation. An expression produce a result has a type that can be deduced at compile time from the structure of the expression, the types of the literals, variables, and methods mentioned in the expression. The expression that produce a result will always evaluated in some context and it must be compatible with a type expected in that context; this type is called the target type. The compatibility of expression with it's surrounding context type is determined as  The expression the deduced type can be influenced by the target type After the type of the expression has been deduced, an implicit conversion from the type of the expression to the target type can be performed If neither of the above strategy is able to produce the appropriate type, a compile-time error occurs. In some cases context is able to accept a expression type

Puzzle: The throws clause on a constructor declaration

Image
Although it is common to see a throws clause on a method declaration, it is less common to see one on a constructor declaration. The following program has such a declaration. What does it print? public class Test { private Test instance = new Test() ; public Test () throws Exception { throw new Exception( "Runtime Exception" ) ; } public static void main (String[] args) { try { Test b = new Test() ; System. out .println( "Surprise!" ) ; } catch (Exception ex) { System. out .println( "Exception throw by constructor" ) ; } } } The main method invokes the constructor of Test class, which throws an exception. You might expect the catch clause to catch this exception and print "Exception throw by constructor". But if you tried running it, you found that it does not print anything : It throws a StackOverflowError . Why? if you have a closer look at the program the

Continuous Integration with Jenkins

Image
Continuous integration Continuous integration (CI) is the practice, in software engineering, of merging all developer working copies to a shared mainline several times a day. It was first named and proposed by Grady Booch in his 1991. although Booch did not advocate integrating several times a day. The main aim of CI is to prevent integration problems, referred to as "integration hell" in early descriptions of XP. CI isn't universally accepted as an improvement over frequent integration, so it is important to distinguish between the two as there is disagreement about the virtues of each. In XP, CI was intended to be used in combination with automated unit tests written through the practices of test-driven development. Continuous integration (CI) is an integral part of an agile software development setup. Sprint after sprint, teams strive to "not break the build" while delivering incremental features. But when developers focus completely on adding features, code

Load Balancing usign HAProxy for Openfire

Image
Introduction HAProxy, which stands for High Availability Proxy, is a popular open source software TCP/HTTP Load Balancer and proxying solution. Its most common use is to improve the performance and reliability of a server environment by distributing the workload across multiple servers (e.g. web, application, database). Installing HAProxy $ apt-get install haproxy We need to enable HAProxy to be started by the init script. $ nano /etc/default/haproxy Set the ENABLED option to 1 ENABLED=1 Configuring HAProxy HAProxy's configuration process involves 3 major sources of parameters the arguments from the command-line, which always take precedence the "global" section, which sets process-wide parameters the proxies sections which can further divide as defaults listen frontend backend The configuration file syntax consists in lines beginning with a keyword referenced in this manual, optionally followed by one or several parameters delimited by spaces. 1

Enable Clustering in Openfire

Image
Clustering Clustering is a technique used to "scale up" a single XMPP domain. The server members within a cluster share an identical configuration. Each member allows any user within the domain to connect, authenticate, and exchange stanzas. Clustered server shares a single database, and also required to be resident within the same LAN-based (low latency) network infrastructure. This type of deployment is suitable to provide runtime redundancy and will support a larger number of users and connections (within a single domain) than a single server. How to Cluster Openfire To create an Openfire cluster, you should have at least two Openfire servers, and each server must have the Hazelcast plugin installed. Install hazelcast plugin The Hazelcast plugin version corresponding to the Openfire release (3.9.3) is 1.2.0 Edit the config file of hazelcast in plugins/hazelcast/classes directory $nano openfire/plugins/hazelcast/classes/hazelcast-cache-config.xml By de

Enable JMX Port in Tomcat with authentication

What is JMX ? Java provides a technology called JMX that supplies tools for monitoring and managing applications, system objects, devices and service-oriented networks. Those resources are represented by objects called Managed Bean (MBeans) Enable JMX port in Tomcat To monitor Heap Memory, Threads, CPU Usage, Classes, and configure various MBeans at remote we need to enable a JMX port in tomcat. Step 1: Go to path where you have Tomcat installed $ cd /usr/share/tomcat7/bin Step 2: Make setenv.sh file and give it the read, execute and access permission $ chmod 755 setevn.sh Step 3: Edit the setenv .sh file and paste the following lines export JAVA_OPTS="-Dcom.sun.management.jmxremote=true \ -Dcom.sun.management.jmxremote.port=9999\ -Dcom.sun.management.jmxremote.authenticate=false\ -Dcom.sun.management.jmxremote.ssl=false \ -Djava.rmi.server.hostname=192.168.x.x"   1. enables jmxremote   2 . specifies the port  3. says that we don’t need to use ssl  4. says to leave

Tomcat SSL/TLS Configuration | Run tomcat over HTTPS

Image
HTTPS HTTPS (also called HTTP over TLS, HTTP over SSL and HTTP Secure) is a protocol for secure communication over a computer network which is widely used on the Internet. HTTPS consists of communication over Hypertext Transfer Protocol (HTTP) within a connection encrypted by Transport Layer Security or its predecessor, Secure Sockets Layer. The main motivation for HTTPS is authentication of the visited website and protection of the privacy and integrity of the exchanged data. SSL SSL (Secure Sockets Layer) is the standard security technology for establishing an encrypted link between a web server and a browser. This link ensures that all data passed between the web server and browsers remain private and integral. SSL is a security protocol. Protocols describe how algorithms should be used. TLS Transport Layer Security (TLS) and its predecessor, Secure Sockets Layer (SSL), both of which are frequently referred to as 'SSL', are cryptographic protocols designed to provide communi