Every thread in Java needs a Runnable. To make a runnable, you must first create a class which implements the Runnable interface. Runnable interface has a method called run() which gets called by the Thread. Your class will need to have this method. Put your code in this run() method. Your Runnable class should look similar to:
//do some work..
Now, you can create a thread in multiple ways but the most appropriate way is to pass the runnable object in its constructor.
Make sure that you say thread1.start() and not thread1.run(). thread1.run() simply calls the run method within the runnable while thread1.start() runs the run method in separate thread.
That’s it! Now you know the basics of threading in Java!
Double click it. It should open as any other normal application.
If it doesn’t open as expected or opens WinRAR/WinZIP/7-Zip or any other archiving software, follow here:
Right click the file and point to Open With.
Click on Select Default Program.
Java should be here in the list of programs. If it isn’t then click browse and locate your java installation. It should be in C:Program FilesJavajre7binjava.exe
If you dont have any folder called Java in Program files, then go to www.java.com and download and install it first.
Once Java is installed, follow step 2.
Click OK. Follow step 2.
Click on ‘Add File’ button to add files to it. A dialog box will be presented.
Locate your source code files. You can select more than one file by selecting one file and then holding the ‘Ctrl’ key and selecting other files. Alternatively, if you wish to select all files, you can press ‘Ctrl + A’ to select all files in the directory you are in.
Make sure that you do not select any executable files. This may cause an error.
You should see list of files in the list above ‘Add File’ button. If you wish to add more files, follow step 3.
Once you are done, click Start. It will start counting lines in the files you have selected.
You’re done! The table will display number of code lines in each file and below the table you’ll find total line count and line density.
I hope you like it. Feel free to shout out any suggestions/feedback you have regarding this small application. Have fun!
If statements are important in any programming language. I had a bit of hard time while doing if statements in linux since they are different than those in a conventional programming language. First of all, an if statement to compare whether a value in a variable val1 is equal to 5 is like: val1=5 if [ $val1 -eq 5 ] then Code here to do some stuff else If above condition is false, then code here gets executed fi
Note that spaces are important when defining condition. $val1 refers to the variable and -eq simply implies equal to operator to compare if the $val1 is equal to 5.
Seems pretty easy? It is. Other conditional operators are:
Not equal to
Now, if I want to compare strings, for instance, if variable answer is equal to “yes” then the code will be as follows: if [ "$val" = "yes" ] then Code here to do some stuff fi
Again, spaces are important here.
In here, ‘=’ can easily be replaced by conventional conditional operators like ‘>’ or ‘<‘ or ‘!=’ etc.
Well, this has been a bit tricky for me so I decided to put it on my blog so that it can be helpful to you guys.
First of all, How to define a variable?
There! I’ve just defined a variable count with 0 as its initial value.
Now, How do you print value of a variable?
Next. How do you perform calculations on a variable?
Okay. So assume that you have two variables called val1 and val2 with values 3 and 4 respectively. Now, you want val3 to have the addition of val1 and val2. So,
val1=3 val2=4 val3=expr $val1 + $val2
Similarly, to do subtraction:
val4=expr $val1 - $val2
Note that spaces are very important here.
Now, if you wish to assign value returned by a command to a variable, then it works by doing:
wcount=wc -w myfile.txt
anything between and will be executed as linux command and the value returned by that command will be assigned back to the variable to left.