top of page

Java Coding

NOTE: void run() function will not return a value


Multi-Threading

To pass a values from a thread constructor to the main function.

Create to second function within the thread constructor

 public class Foo implements Runnable {
     private volatile int value;

     @Overridepublic void run() {
        value = 2;
     }

     public int getValue() {
         return value;
     }
 } 

In the main function that calls the thread constructor.

Call the start() and join() from the thread constructor, this will execute both together.

Foo foo = new Foo();
Thread thread = new Thread(foo);
thread.start();
thread.join();
int value = foo.getValue();

If Statements

Use the variable.equals for checking values within if statements instead of "==".

if (Password.equals("a"))

For Loops

Iteration of for each loop that will run.

inti=0;
for (Thread t : Thread.getAllStackTraces().keySet()) {
    consumer.accept(i, item);         
    i++;     
}

 
 
 

Recent Posts

See All
Harbor Install & Setup

1. Go to the Harbor releases page & Download either the online or offline installer for the version you want to install. 2. Use tar to...

 
 
 

Comments


Contact Me

Tel: 678-642-8051

cspeed@jcsassoc.com

  • Google+ Long Shadow
  • LinkedIn Long Shadow
  • Facebook Social Icon
  • Twitter Long Shadow

© 2005 by Christopher Speed

Your details were sent successfully!

bottom of page