Latest Activity In Study Groups

Join Your Study Groups

VU Past Papers, MCQs and More

We non-commercial site working hard since 2009 to facilitate learning Read More. We can't keep up without your support. Donate.


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.

 

Views: 2337

Attachments:

Replies to This Discussion

1st question was 2 times already shared in this thread.

fellows at least read first.

Little Chef thanks 

Little Chef plz share Q#I here again.......................bohat maharbani ho gi  aur abi b ye errors aya rahay hain plz help me ......

sir ni ho rahi tab b run plzzzzzzzzzzzzzzzzzzz time kam ha help me

ma nay type kia ha    javac CS5081.java  phr ma nay type kia ha javac CS508.java  aur phr javac CS508 lakin error aya rahay hain

you are right same error mairy pass b aa raha ha

sir os nay kaha hoa ha Question may How can we avoid Aliasing Problems in Java lakin yahan aap  use of Aliasing bata rahay hain is code may

questio

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

copied from " http://www.linuxtopia.org/online_books/programming_books/thinking_i... " 

and still i am not able to write a reason that how could we avoid aliasing problem in java and ... :/

sir os nay kaha hoa ha Question may How can we avoid Aliasing Problems in Java lakin yahan aap  use of Aliasing bata rahay hain is code may


sny2ksa plzzzzzzzzzzzzzzzzzzz agar aap nay bana li ha tu help me .... mari last 2 may be zero hain.....i am really sad ...

RSS

Looking For Something? Search Below

VIP Member Badge & Others

How to Get This Badge at Your Profile DP

------------------------------------

Management: Admins ::: Moderators

Other Awards Badges List Moderators Group

Latest Activity

Ammara Sabir posted a discussion
14 minutes ago
Ammara Sabir liked 刀のの尺's discussion سامنے ہین ہم مگر! نظر آئین کس کو
23 minutes ago
Ammara Sabir liked 刀のの尺's discussion سامنے ہین ہم مگر! نظر آئین کس کو
24 minutes ago
Mani Siddiqui posted a status
"عین ممکن ہے کہ مجھ ہی میں کمی ہو لیکن سامنے آئے....محبت جسے راس آئی ہے"
27 minutes ago
Mani Siddiqui posted a status
"اُڑتے اُڑتے دُور اُفق میں آس کا پنچھی ڈوب گیا روتے روتے بیٹھ گئی آواز کسی سودائی کی"
28 minutes ago
Mani Siddiqui posted a status
"خوش دعوتِ یاراں بھی ہے ۔۔۔ یلغارِ عدو بھی کیا کیجیے دل کا ۔۔۔ جو کم آمیز بہت ہے"
28 minutes ago
Mani Siddiqui posted a status
"جس مصور کی نہیں بکتی کوئی بھی تصویر میری تصویر بنائے گا تو چھا جائے گا"
30 minutes ago
Mani Siddiqui posted a status
"کوٸی دشمن کو یوں نہ دیکھے گا جیسے قسمت کو دیکھتا ہوں میں"
33 minutes ago

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

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