IT Community - Software Programming, Web Development and Technical Support

simple example for the java concepts

This is a discussion on simple example for the java concepts within the Java Programming forums, part of the Software Development category; can anyone ca give the simple example for multi threading,multi tasking,multi programming in java for the beginners...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Software Development > Java Programming

Register FAQ Members List Calendar Mark Forums Read
  #1  
Old 07-19-2007, 03:58 AM
lavanya lavanya is offline
D-Web Trainee
 
Join Date: Jul 2007
Posts: 24
lavanya is on a distinguished road
Question simple example for the java concepts

can anyone ca give the simple example for multi threading,multi tasking,multi programming in java for the beginners
__________________
Thanks,

Lavanya.J
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2  
Old 07-20-2007, 05:47 AM
oxygen oxygen is offline
D-Web Architect
 
Join Date: Jun 2007
Posts: 632
oxygen is on a distinguished road
Default Re: simple example for the java concepts

Hi.....lavanya..

I have explained multithreading with example.....

i hope this will help u....



MULTITHREADING IN JAVA

Executable part of an application is called as thread. We often interact with threads while using many applications. For example, if we use MS-word application then we see that a thread (spell checker) runs continuously as we continue typing. It continuously checks the spelling of words we type, from its dictionary. Java provides a way to create these threads. There are two ways for creating threads in java. One is by extending THREAD class and other is by implementing EUNNABLE interface. We will see an example of creating thread. As we know that the main program is itself a thread so therefore we will see a sample program of main program.

Class test
{
public static void main(String arg[])
{
Thread t=Thread.currentThread();
System.out.println(t);
t.setName("test thread");
System.out.println(t)
}
}
the output of this program will give the thread's name that is "main", its priority that is 5 and its representation. The priorities of thread are between 1 and 10 the normal priority is
5. Now we will see how we create threads from extending thread class.
Class newthread extends Thread
{
newthread()
{
super("demo thread");
System.out.println("child thread:"+this);
Start();
}
public void run()
{
try
{
for(int i=5;i>0;i--)
{
System.out.println("child thread:"=i);
Thread.sleep(500);
}
catch(InterruptedException e)
{
System.out.println("child interrupted");
}
System.out.println("exiting child thread");
}
}
class demo
{
public static void main(String arg[])
{
new Newthread();
try
{
for(int i=5;i>0i--)
{
System.out.println("main thread:"+i);
Thread.sleep(1000);
}
catch(InterruptedException e)
{
System.out.println("main thread interrupted")
}
System.out.println("main thread exiting");
}
}
in java threads can be prioritized. They can be given priorities between 1 and 10. there are several methods for thread for example isAlive() and join(). There is possibility that one thread can communicate with another. For example one thread may want to know whether another thread is alive or dead. This is done by isAlive() method. If you want to know that a thread is finished or not, you can call isAlive() method defined by thread class. Its general form is:
final Boolean isAlive()
if it returns true then it means thread is running. If it returns false then thread has stooped. While isAlive() is occasionally useful, the method that you will commonly use to wait for a thread to finish is called join().
Final void join()throws InterruptedExcepption
This method waits until the thread on which it is called terminates. Its name comes from the concept of the calling thread until the specified thread joins it. Additional forms of join() allow you to specify a maximum amount of time that you want to wait for specified thread to terminate.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3  
Old 07-20-2007, 05:48 AM
oxygen oxygen is offline
D-Web Architect
 
Join Date: Jun 2007
Posts: 632
oxygen is on a distinguished road
Thumbs up Re: simple example for the java concepts

just give some description for MultiTasking....


Concept of MultiTasking
Multitasking is performing two or more tasks at the same time. Nearly all operating systems are capable of multitasking by using one of two multitasking techniques: process-based multitasking and thread-based multitasking.
Process-based multitasking is running two programs concurrently. Programmers refer to a program as a process. Therefore, you could say that process-based multitasking is program-based multitasking.
Thread-based multitasking is having a program perform two tasks at the same time. For example, a word processing program can check the spelling of words in a document while you write the document. This is thread-based multitasking.
A good way to remember the difference between process-based multitasking and thread-based multitasking is to think of process-based as working with multiple programs and thread-based as working with parts of one program.
The objective of multitasking is to utilize the idle time of the CPU. Think of the CPU as the engine of your car. Your engine keeps running regardless of whether the car is moving. Your objective is to keep your car moving as much as possible so you can get the most miles from a gallon of gas. An idling engine wastes gas.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
QTP Blog for Certification and Concepts expertqtp Testing Tools 0 07-22-2008 03:19 AM
Redesigning to accommodate Custom design concepts Jiminez48 Web Design Help 0 01-29-2008 12:14 AM
Concepts on the Software Life Cycle vadivelanvaidyanathan Software Testing 2 03-23-2007 02:16 AM
Concepts of the Cookie testing vadivelanvaidyanathan Software Testing 0 03-20-2007 04:53 AM
CMM concepts vadivelanvaidyanathan Quality Engineering and Methodologies 0 03-14-2007 04:54 AM


All times are GMT -7. The time now is 11:05 AM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.
Our Partners
One Way Moving Companies | Stamford Dentist | Euro Millions Lottery | Home Loans| Furniture

SEO by vBSEO 3.0.0