Help - Search - Members - Calendar
Full Version: Help With Java Code
Sal's RuneScape Forum > Everything... Not RuneScape > Tech Talk > Programming & Web Development
Nashy19
I've got this Java code which I want to turn into a program but I've never done it before and got stuck with the compiling

CODE
/**
*
* Copyright 2003-2004 The Apache Software Foundation
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*     http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*/

package org.apache.geronimo.common;

import java.io.Serializable;

/**
* A long integer counter class.
*
* @version $Revision: 1.3 $ $Date: 2004/03/10 09:58:25 $
*/
public class LongCounter
    extends CloneableObject
    implements Serializable
{
    /** The current count */
    private long count;
    
    /**
     * Construct a LongCounter with a starting value.
     *
     * @param count   Starting value for counter.
     */
    public LongCounter(final long count) {
        this.count = count;
    }
    
    /**
     * Construct a LongCounter.
     */
    public LongCounter() {}
    
    /**
     * Increment the counter. (Optional operation)
     *
     * @return  The incremented value of the counter.
     */
    public long increment() {
        return ++count;
    }
    
    /**
     * Decrement the counter. (Optional operation)
     *
     * @return  The decremented value of the counter.
     */
    public long decrement() {
        return --count;
    }
    
    /**
     * Return the current value of the counter.
     *
     * @return  The current value of the counter.
     */
    public long getCount() {
        return count;
    }
    
    /**
     * Reset the counter to zero. (Optional operation)
     */
    public void reset() {
        this.count = 0;
    }
    
    /**
     * Check if the given object is equal to this.
     *
     * @param obj  Object to test equality with.
     * @return     True if object is equal to this.
     */
    public boolean equals(final Object obj) {
        if (obj == this) return true;
        
        if (obj != null && obj.getClass() == getClass()) {
            return ((LongCounter)obj).count == count;
        }
        
        return false;
    }
    
    /**
     * Return a string representation of this.
     *
     * @return  A string representation of this.
     */
    public String toString() {
        return String.valueOf(count);
    }


    /////////////////////////////////////////////////////////////////////////
    //                                Wrappers                             //
    /////////////////////////////////////////////////////////////////////////

    /**
     * Base wrapper class for other wrappers.
     */
    private static class Wrapper
        extends LongCounter
    {
        /** The wrapped counter */
        protected final LongCounter counter;
        
        public Wrapper(final LongCounter counter) {
            this.counter = counter;
        }
        
        public long increment() {
            return counter.increment();
        }
        
        public long decrement() {
            return counter.decrement();
        }
        
        public long getCount() {
            return counter.getCount();
        }
        
        public void reset() {
            counter.reset();
        }
        
        public boolean equals(final Object obj) {
            return counter.equals(obj);
        }
        
        public String toString() {
            return counter.toString();
        }
        
        public Object clone() {
            return counter.clone();
        }
    }
    
    /**
     * Return a synchronized counter.
     *
     * @param counter    LongCounter to synchronize.
     * @return           Synchronized counter.
     */
    public static LongCounter makeSynchronized(final LongCounter counter)
    {
        return new Wrapper(counter) {
            public synchronized long increment() {
                return this.counter.increment();
            }

            public synchronized long decrement() {
                return this.counter.decrement();
            }

            public synchronized long getCount() {
                return this.counter.getCount();
            }

            public synchronized void reset() {
                this.counter.reset();
            }

            public synchronized int hashCode() {
                return this.counter.hashCode();
            }

            public synchronized boolean equals(final Object obj) {
                return this.counter.equals(obj);
            }

            public synchronized String toString() {
                return this.counter.toString();
            }

            public synchronized Object clone() {
                return this.counter.clone();
            }
        };
    }

    /**
     * Returns a directional counter.
     *
     * @param counter       LongCounter to make directional.
     * @param increasing    True to create an increasing only
     *                      or false to create a decreasing only.
     * @return              A directional counter.
     */
    public static LongCounter makeDirectional(final LongCounter counter,
                                              final boolean increasing)
    {
        LongCounter temp;
        if (increasing) {
            temp = new Wrapper(counter) {
                public long decrement() {
                    throw new UnsupportedOperationException();
                }
                
                public void reset() {
                    throw new UnsupportedOperationException();
                }
            };
        }
        else {
            temp = new Wrapper(counter) {
                public long increment() {
                    throw new Unsupporte                }
            };
        }
        
        return temp;
    }
}


Can somebody tell me what I need to do?
cjgone
File only contains the classes if I correctly matched up curly brackets... You have to create the object, but I have no idea wtf this program is even supposed to do.
Nashy19
It's just an up and down counter, I want to make it into an .exe or something I can use.
Kaibamanjrs
QUOTE (Nashy19 @ Oct 28 2009, 05:39 AM) *
It's just an up and down counter, I want to make it into an .exe or something I can use.

lol java into exe?

anyways, what you have here is a bunch of classes. if you run this, it will do nothing. Create a class with a main method and use that to create a LongCounter object.
cjgone
QUOTE (Nashy19 @ Oct 28 2009, 07:39 AM) *
It's just an up and down counter, I want to make it into an .exe or something I can use.



I've never seen a so complicated counter, I can't imagine how this is only a counter... It has the most worthless functions attached to it and some really out-there ones.

like wtf : import java.io.Serializable;
???

What kind of counter is this.
Kaibamanjrs
QUOTE (cjgone @ Oct 28 2009, 07:31 PM) *
QUOTE (Nashy19 @ Oct 28 2009, 07:39 AM) *
It's just an up and down counter, I want to make it into an .exe or something I can use.



I've never seen a so complicated counter, I can't imagine how this is only a counter... It has the most worthless functions attached to it and some really out-there ones.

like wtf : import java.io.Serializable;
???

What kind of counter is this.

http://www.j2ee.me/developer/technicalArti.../serialization/

i think hes doing something he doesnt need.
Arctic Wolf
QUOTE (Kaibamanjrs @ Oct 29 2009, 03:56 AM) *
QUOTE (Nashy19 @ Oct 28 2009, 05:39 AM) *
It's just an up and down counter, I want to make it into an .exe or something I can use.

lol java into exe?

anyways, what you have here is a bunch of classes. if you run this, it will do nothing. Create a class with a main method and use that to create a LongCounter object.


Yes java to exe is quite possible.
http://en.wikipedia.org/wiki/AOT_compiler
cjgone
QUOTE (Arctic Wolf @ Nov 4 2009, 03:25 AM) *
QUOTE (Kaibamanjrs @ Oct 29 2009, 03:56 AM) *
QUOTE (Nashy19 @ Oct 28 2009, 05:39 AM) *
It's just an up and down counter, I want to make it into an .exe or something I can use.

lol java into exe?

anyways, what you have here is a bunch of classes. if you run this, it will do nothing. Create a class with a main method and use that to create a LongCounter object.


Yes java to exe is quite possible.
http://en.wikipedia.org/wiki/AOT_compiler

I'm pretty sure compiling Java into binary as an executable would negate its purpose of cross platform compatiblity. The code needs to be compiled down to binary from bytecode to run, but you don't turn Java into an executable, it's done by the Java Virtual Machine from the bytecode.
Arctic Wolf
QUOTE (cjgone @ Nov 6 2009, 01:25 PM) *
QUOTE (Arctic Wolf @ Nov 4 2009, 03:25 AM) *
QUOTE (Kaibamanjrs @ Oct 29 2009, 03:56 AM) *
QUOTE (Nashy19 @ Oct 28 2009, 05:39 AM) *
It's just an up and down counter, I want to make it into an .exe or something I can use.

lol java into exe?

anyways, what you have here is a bunch of classes. if you run this, it will do nothing. Create a class with a main method and use that to create a LongCounter object.


Yes java to exe is quite possible.
http://en.wikipedia.org/wiki/AOT_compiler

I'm pretty sure compiling Java into binary as an executable would negate its purpose of cross platform compatiblity. The code needs to be compiled down to binary from bytecode to run, but you don't turn Java into an executable, it's done by the Java Virtual Machine from the bytecode.


Having it as an executable means it isn't interpreted and run without the need of a jre. It does negate cross platform but it does have uses. It can't be decompiled as easy as jar files and runs faster on start up etc. You can compile it straight into executable by the way.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.