Binary Literals

In Java SE 7, the integral types (byteshortint, and long) can also be expressed using the binary number system. To specify a binary literal, add the prefix 0b or 0B to the number. The following examples show binary literals:

// An 8-bit 'byte' value:
byte aByte = (byte)0b00100001;
// A 16-bit 'short' value:
short aShort = (short)0b1010000101000101;
// Some 32-bit 'int' values:
int anInt1 = 0b10100001010001011010000101000101;
int anInt2 = 0b101;
int anInt3 = 0B101; // The B can be upper or lower case.
// A 64-bit 'long' value. Note the "L" suffix:
long aLong = 0b1010000101000101101000010100010110100001010001011010000101000101L;</pre>

Obtain your Lost Java source codes from executable jar or classes

This post describes how you can have your lost source codes from the Jar.

For this we need to decompile all the classes which are present inside the jar to obtain your lost source codes.

A software called “JD-GUI” does this. You just need to open it and drag your executable jar to it and it will show you the decompiled source codes.

You can download the decompiler from The page contain all relevant information you will need to decompile.

Note : Make sure you don’t use it for illegal purpose. If the codes are obfuscated then decompiler won’t be able to fully decompile the jar.

Java TCP Chat – Multiple Client

INFO : These programs work as following

  • server must be running first
  • any number of clients can be run then
  • server randomly take request from any client and respond to it
  • to respond client server maintains that many number of threads
  • each thread share the same object, which object’s method will respond to client, thus synchronization is achieved
  • client program runs until client enters ‘EXIT’


public class TCPMultiServer {

public static void main(String argv[]) throws Exception {

ServerSocket welcomeSocket = new ServerSocket(6789);

Responder h = new Responder();
 // server runs for infinite time and
 // wait for clients to connect
 while (true) {
 // waiting..
 Socket connectionSocket = welcomeSocket.accept();

// on connection establishment start a new thread for each client
 // each thread shares a common responder object
 // which will be used to respond every client request
 // need to synchronize method of common object not to have unexpected behaviour
 Thread t = new Thread(new MyServer(h, connectionSocket));

// start thread


class MyServer implements Runnable {

Responder h;
 Socket connectionSocket;

public MyServer(Responder h, Socket connectionSocket) {
 this.h = h;
 this.connectionSocket = connectionSocket;

 public void run() {

while (h.responderMethod(connectionSocket)) {
 try {
 // once an conversation with one client done,
 // give chance to other threads
 // so make this thread sleep
 } catch (InterruptedException ex) {

try {
 } catch (IOException ex) {
 Logger.getLogger(MyServer.class.getName()).log(Level.SEVERE, null, ex);



class Responder {

String serverSentence;
 BufferedReader br = new BufferedReader(new InputStreamReader(;

// on client process termination or
 // client sends EXIT then to return false to close connection
 // else return true to keep connection alive
 // and continue conversation
 synchronized public boolean responderMethod(Socket connectionSocket) {
 try {

BufferedReader inFromClient =
 new BufferedReader(
 new InputStreamReader(

DataOutputStream outToClient =
 new DataOutputStream(

String clientSentence = inFromClient.readLine();

// if client process terminates it get null, so close connection
 if (clientSentence == null || clientSentence.equals("EXIT")) {
 return false;

if (clientSentence != null) {
 System.out.println("client : " + clientSentence);
 serverSentence = br.readLine() + "\n";


return true;

} catch (SocketException e) {
 return false;
 } catch (Exception e) {
 return false;


public class TCPMultiClient {

public static void main(String argv[]) throws Exception {
 String sentence;
 String modifiedSentence;

BufferedReader inFromUser =
 new BufferedReader(
 new InputStreamReader(;

Socket clientSocket = new Socket("localhost", 6789);

while (true) {
 DataOutputStream outToServer =
 new DataOutputStream(

BufferedReader inFromServer =
 new BufferedReader(
 new InputStreamReader(

sentence = inFromUser.readLine();

outToServer.writeBytes(sentence + '\n');

if (sentence.equals("EXIT")) {

modifiedSentence = inFromServer.readLine();

System.out.println("FROM SERVER: " + modifiedSentence);


JSF Features

JSF is rich featured that make it much popular than the existing frameworks. Some of the JSF features are :

I JSF is standard web user interface framework for Java. 
II Built on top of Servlet API.
III JSF is a component framework
IV UI components are stored on the server.
V Easy use of third party components.
VI Event driven programming model.
VII Events generated by user are handled on the server.
VIII Navigation handling.
IX It can automatically synchronize UI components.

X JSF supports multiple client devices.
XI JSF has extensible architecture.
XII International language support.
XIII Extensive tool support (Sun, Oracle, IBM etc.).
XIV Rapid application development approach.

What is differences between JVM, JDK, JRE

Java Development Kit (JDK)

The JDK is a superset of the JRE, and contains everything that is in the JRE, plus tools such as the compilers and debuggers necessary for developing applets and applications.

Java Runtime Environment (JRE)

The Java Runtime Environment (JRE) provides the libraries, the Java Virtual Machine, and other components to run applets and applications written in the Java programming language. In addition, two key deployment technologies are part of the JRE: Java Plug-in, which enables applets to run in popular browsers; and Java Web Start, which deploys standalone applications over a network. It is also the foundation for the technologies in the Java 2 Platform, Enterprise Edition (J2EE) for enterprise software development and deployment. The JRE does not contain tools and utilities such as compilers or debuggers for developing applets and applications.

Java Virtual Machine

The Java Virtual Machine is responsible for the hardware- and operating system-independence of the Java SE platform, the small size of compiled code (bytecodes), and platform security.










Reference : Oracle

Does Java Use Pass-By-Value Semantics?

If Java passes objects by passing the reference variable instead, does that mean Java uses pass-by-reference for objects? Not exactly, although you’ll often hear and read that it does. Java is actually pass-by-value for all variables running within a single VM. Pass-by-value means pass-by-variable-value. And that means, pass-by-copy-of-the-variable! (There’s that word copy again!)

It makes no difference if you’re passing primitive or reference variables, you are always passing a copy of the bits in the variable. So for a primitive variable, you’re passing a copy of the bits representing the value. For example, if you pass an int variable with the value of 3, you’re passing a copy of the bits representing 3. The called method then gets its own copy of the value, to do with it what it likes.

And if you’re passing an object reference variable, you’re passing a copy of the bits representing the reference to an object. The called method then gets its own copy of the reference variable, to do with it what it likes. But because two identical reference variables refer to the exact same object, if the called method modifies the object (by invoking setter methods, for example), the caller will see that the object the caller’s original variable refers to has also been changed.

The bottom line on pass-by-value: the called method can’t change the caller’s variable, although for object reference variables, the called method can change the object the variable referred to. What’s the difference between changing the variable and changing the object? For object references, it means the called method can’t reassign the caller’s original reference variable and make it refer to a different object, or null. For example, in the following code fragment,
                          void bar() {
                                Foo f = new Foo();
                           void doStuff(Foo g) {
                                 g = new Foo();
reassigning g does not reassign f! At the end of the bar() method, two Foo objects have been created, one referenced by the local variable f and one referenced by the local (argument) variable g. Because the doStuff() method has a copy of the reference variable, it has a way to get to the original Foo object, for instance to call the setName() method. But, the doStuff() method does not have a way to get to the f reference variable. So doStuff() can change values within the object f refers to, but doStuff() can’t change the actual contents (bit pattern) of f. In other words, doStuff() can change the state of the object that f refers to, but it can’t make f refer to a different object! 

Latest News

Java 8

Java SE 8 Developer preview
Java SE 8 Early Access is provided to the community so that they can get feedback on the ongoing progress of the project. Download it at Please try it out and report bugs

NetBeans IDE 7.3 Released

NetBeans IDE 7.3 empowers developers to create and debug rich web and mobile applications using the latest HTML5, JavaScript, and CSS3 standards. Developers can expect state of the art rich web development experience with a page inspector and CSS style editor, completely revamped JavaScript editor, new JavaScript debugger, and more. Additional highlights available in 7.3 include continued enhancements to the IDE’s support for Groovy, PHP, JavaFX and C/C++.