We are here with you hands in hands to facilitate your learning & don't appreciate the idea of copying or replicating solutions. Read More>>

Looking For Something at vustudents.ning.com? Click Here to Search

www.bit.ly/vucodes

+ Link For Assignments, GDBs & Online Quizzes Solution

www.bit.ly/papersvu

+ Link For Past Papers, Solved MCQs, Short Notes & More

Assignment Questions

 

Question # 1                                                                                                                               Marks 5     

 

How can we avoid Aliasing Problems in Java, provide a code example. Keep your answer to the point.

 

Question # 2                                                                                                                              Marks 10     

 

You will write a simple Java code that will demonstrate working of threads. You will write two classes, one CS508.java and 2nd one will be SimpleThread.java.

 

SimpleThead.java will extend the thread class. In run method, your thread will display its name and number of milliseconds (0 to 5000) it will sleep for. And then it will sleep randomly for 1 to 5000 milliseconds. Once thread has finished it will display its name and message that it has finished. One thread will sleep 5 times before ending.

 

In CS508.java, you will create 3 threads of SimpleThread  and will run them. Name of the first thread will be your name, name of second thread will be your VU student id, and name of 3rd thread will be VU.

 

Here is the sample output of the code that you will write

 

 

Note:

1) No need to send the java/class files, put code in word file along with answer of the first question.

2) For question number one you can search over the internet. But do not copy paste the contents as it is , use your own words.

 

+ Click Here To Join also Our facebook study Group.

+ How to Join Subject Study Groups & Get Helping Material?

+ How to become Top Reputation, Angels, Intellectual, Featured Members & Moderators?


See Your Saved Posts Timeline

Views: 2156

.

+ http://bit.ly/vucodes (Link for Assignments, GDBs & Online Quizzes Solution)

+ http://bit.ly/papersvu (Link for Past Papers, Solved MCQs, Short Notes & More)

+ Click Here to Search (Looking For something at vustudents.ning.com?)

Attachments:

Replies to This Discussion

how to start working in netbeans?

Aliasing means that more than one reference is tied to the same object, as in the preceding example. The problem with aliasing occurs when someonewrites to that object. If the owners of the other references aren’t expecting that object to change, they’ll be surprised. This can be demonstrated with a simple example:

//: appendixa:Alias1.java
// Aliasing two references to one object.
import com.bruceeckel.simpletest.*;
 
public class Alias1 {
  private static Test monitor = new Test();
  private int i;
  public Alias1(int ii) { i = ii; }
  public static void main(String[] args) {
    Alias1 x = new Alias1(7);
    Alias1 y = x; // Assign the reference
    System.out.println("x: " + x.i);
    System.out.println("y: " + y.i);
    System.out.println("Incrementing x");
    x.i++;
    System.out.println("x: " + x.i);
    System.out.println("y: " + y.i);
    monitor.expect(new String[] {
      "x: 7",
      "y: 7",
      "Incrementing x",
      "x: 8",
      "y: 8"
    });
  }
} ///:~

 

In the line:

Alias1 y = x; // Assign the reference

 

a new Alias1 reference is created, but instead of being assigned to a fresh object created with new, it’s assigned to an existing reference. So the contents of reference x, which is the address of the object x is pointing to, is assigned to y, and thus both x and y are attached to the same object. So when x’s i is incremented in the statement:

x.i++;

 

y’s i will be affected as well. This can be seen in the output:

x: 7
y: 7
Incrementing x
x: 8
y: 8

mehr pateesa gud keep it up & thanks for sharing 

Attention Students: You don’t need to go any other site for this assignment/GDB/Online Quiz solution, Because All discussed data of our members in this discussion are going from here to other sites (Other sites Admins posted with fake IDs at their sites :p ). You can judge this at other sites yourself. So don’t waste your precious time with different links.

THanks Mehr Pateesa for shearing 

Please Discuss here about this assignment.Thanks

Our main purpose here discussion not just Solution

We are here with you hands in hands to facilitate your learning and do not appreciate the idea of copying or replicating solutions.

Here is the Answer 

thats are .java Files execute it and tell me is it right or not?

Attachments:

kindly upload on mediafire..
can't download from this site.

// CS508

import java.lang.Thread;

public class CS508
{
public static void main( String[] args )
{
System.out.println();

// create each thread with a new targeted runnable
Thread thread1 = new Thread( new PrintTask( "pc130200019" ) );
Thread thread2 = new Thread( new PrintTask( "H. M. Imran" ) );
Thread thread3 = new Thread( new PrintTask( "Student1" ) );
Thread thread4 = new Thread( new PrintTask( "Student2" ) );
Thread thread5 = new Thread( new PrintTask( "Student3" ) );
Thread thread6 = new Thread( new PrintTask( "Student4" ) );
Thread thread7 = new Thread( new PrintTask( "Student5" ) );

System.out.println();

// start threads and place in runnable state
thread1.start(); // invokes run method
thread2.start(); // invokes run method
thread3.start(); // invokes run method
thread4.start(); // invokes run method
thread5.start(); // invokes run method
thread6.start(); // invokes run method
thread7.start(); // invokes run method

System.out.println();
} // end main
} // end class CS508

______________________________________

// SimpleThread class sleeps for a random time from 0 to 5 seconds
import java.util.Random;

public class SimpleThread implements Runnable
{
private final int sleepTime; // random sleep time for thread
private final String taskName; // name of task
private final static Random generator = new Random();

public SimpleThread( String name )
{
taskName = name; // set task name

// pick random sleep time between 0 and 5 seconds
sleepTime = generator.nextInt( 5000 ); // milliseconds
} // end SimpleThread constructor

// method run contains the code that a thread will execute
public void run()
{
try // put thread to sleep for sleepTime amount of time
{
System.out.printf( "%s will sleep for %d Milliseconds.\n",
taskName, sleepTime );
Thread.sleep( sleepTime ); // put thread to sleep
} // end try
catch ( InterruptedException exception )
{
System.out.printf( "%s %s\n", taskName,
"terminated prematurely due to interruption" );
} // end catch

// print task name
System.out.printf( "%s thread has finished\n", taskName );
} // end method run
} // end class SimpleThread

Attachments:

not compiling.
saying cs508 should be public class,while it is already ,what can i do.?

which software will be used to run the program??

net beans.
but u can run java files from cmd too..
just set ur JDK environment variable.

RSS

© 2019   Created by + M.Tariq Malik.   Powered by

Promote Us  |  Report an Issue  |  Privacy Policy  |  Terms of Service