Sunday, December 9, 2012

java.net.BindException: Address already in use: JVM_Bind:8080

There are many ways to come out of this Tomcat port address problem.....some say kill the port...some say change the port number by going to server.xml and giving a different port number.....and etc....

But I would say just exit from eclipse and start again this way you would get back that port address again....
and another thing I observed was in your Tomcat Manager once you go to your application there would be options like start stop etc...dont press the stop or other links (buttons) as it would in my understanding just stop the session and would not kill it...and hence the Tomcat port will be left hanging

Saturday, December 8, 2012

System.out.println


public class Sysout_class {
   
    public static void main(String[] args) {

    System.out.println("Hello");
    //As you can see from the Oracle Spec the following lines are written
    /*
    * %W% %E%
    *
    * Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
    * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
    */

    //(A) In System Class it calls the PrintStream class
    /*       
    System is a final class defined in java.lang.*
       
    public final class System {
    }

    * The "standard" output stream. This stream is already
    * open and ready to accept output data. Typically this stream
    * corresponds to display output or another output destination
    * specified by the host environment or user.
    * <p>
    * For simple stand-alone Java applications, a typical way to write
    * a line of output data is:
    * <blockquote><pre>
    *     System.out.println(data)
    * </pre></blockquote>
    * <p>
    * See the <code>println</code> methods in class <code>PrintStream</code>.
    *
    * @see     java.io.PrintStream#println()
    * @see     java.io.PrintStream#println(boolean)
    * @see     java.io.PrintStream#println(char)
    * @see     java.io.PrintStream#println(char[])
    * @see     java.io.PrintStream#println(double)
    * @see     java.io.PrintStream#println(float)
    * @see     java.io.PrintStream#println(int)
    * @see     java.io.PrintStream#println(long)
    * @see     java.io.PrintStream#println(java.lang.Object)
    * @see     java.io.PrintStream#println(java.lang.String)
   
    public final static PrintStream out = nullPrintStream();
   
    private static PrintStream nullPrintStream() throws NullPointerException {
    if (currentTimeMillis() > 0) {
        return null;
    }
    throw new NullPointerException();
    }
   
               
    (B)It goes to the PrintStream class
    public void println(String x) {
    synchronized (this) {
        print(x);
        newLine();
    }
    }
   
    (B1)
    public void print(String s) {
    if (s == null) {
        s = "null";
    }
    write(s);
    }
   
    (B2)
    private void write(String s) {
    try {
        synchronized (this) {
        ensureOpen();
        textOut.write(s);
        textOut.flushBuffer();
        charOut.flushBuffer();
        if (autoFlush && (s.indexOf('\n') >= 0))
            out.flush();
        }
    }
    catch (InterruptedIOException x) {
        Thread.currentThread().interrupt();
    }
    catch (IOException x) {
        trouble = true;
    }
    }   
   
    public void write(String str) throws IOException {
    write(str, 0, str.length());
    }
   
    (B3)
    public void write(String str) throws IOException {
    write(str, 0, str.length());
    }
   
    (C)   
    private BufferedWriter textOut;
   
    BufferedWriter's Super class is Writer Class and in that class it calls the write method
    print(x) finally goes to private BufferedWriter textOut;
 
    public void write(String str) throws IOException {
    write(str, 0, str.length());
    }
   
    (D)
    Similarly for newLine() from PrintStream class (B) the same procedures as (B1), (B2), (B3) and (C) follows;
    */
    }
}

Clone

(a)

public class CloneFirst implements Cloneable{
   
    int a;
    String b;
    //As you can see from the Oracle Spec the following lines are written
    public CloneFirst cloneMethod() throws CloneNotSupportedException{
       
        /*
         * %W% %E%
         *
         * Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
         * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
        */       
        /**
         * Creates and returns a copy of this object.  The precise meaning
         * of "copy" may depend on the class of the object. The general
         * intent is that, for any object <tt>x</tt>, the expression:
         * <blockquote>
         * <pre>
         * x.clone() != x</pre></blockquote>
         * will be true, and that the expression:
         * <blockquote>
         * <pre>
         * x.clone().getClass() == x.getClass()</pre></blockquote>
         * will be <tt>true</tt>, but these are not absolute requirements.
         * While it is typically the case that:
         * <blockquote>
         * <pre>
         * x.clone().equals(x)</pre></blockquote>
         * will be <tt>true</tt>, this is not an absolute requirement.
         * <p>
         * By convention, the returned object should be obtained by calling
         * <tt>super.clone</tt>.  If a class and all of its superclasses (except
         * <tt>Object</tt>) obey this convention, it will be the case that
         * <tt>x.clone().getClass() == x.getClass()</tt>.
         * <p>
         * By convention, the object returned by this method should be independent
         * of this object (which is being cloned).  To achieve this independence,
         * it may be necessary to modify one or more fields of the object returned
         * by <tt>super.clone</tt> before returning it.  Typically, this means
         * copying any mutable objects that comprise the internal "deep structure"
         * of the object being cloned and replacing the references to these
         * objects with references to the copies.  If a class contains only
         * primitive fields or references to immutable objects, then it is usually
         * the case that no fields in the object returned by <tt>super.clone</tt>
         * need to be modified.
         * <p>
         * The method <tt>clone</tt> for class <tt>Object</tt> performs a
         * specific cloning operation. First, if the class of this object does
         * not implement the interface <tt>Cloneable</tt>, then a
         * <tt>CloneNotSupportedException</tt> is thrown. Note that all arrays
         * are considered to implement the interface <tt>Cloneable</tt>.
         * Otherwise, this method creates a new instance of the class of this
         * object and initializes all its fields with exactly the contents of
         * the corresponding fields of this object, as if by assignment; the
         * contents of the fields are not themselves cloned. Thus, this method
         * performs a "shallow copy" of this object, not a "deep copy" operation.
         * <p>
         * The class <tt>Object</tt> does not itself implement the interface
         * <tt>Cloneable</tt>, so calling the <tt>clone</tt> method on an object
         * whose class is <tt>Object</tt> will result in throwing an
         * exception at run time.
         *
         * @return     a clone of this instance.
         * @exception  CloneNotSupportedException  if the object's class does not
         *               support the <code>Cloneable</code> interface. Subclasses
         *               that override the <code>clone</code> method can also
         *               throw this exception to indicate that an instance cannot
         *               be cloned.
         * @see java.lang.Cloneable
         */
        return (CloneFirst)super.clone();
       
    }
}

(b)

public class CloneCallingFirst extends CloneFirst{

    public static void main(String[] args) throws CloneNotSupportedException {
      
        CloneFirst cf1 = new CloneFirst();
        cf1.a=10;
        cf1.b="Ten";
        CloneFirst cf2;
        cf2 = cf1.cloneMethod();
      
        System.out.println("The Answer for a is " + cf2.a);
        System.out.println("The Answer for b is " + cf2.b);
      
    }