• Post Reply Bookmark Topic Watch Topic
  • New Topic

Java My Interview Question  RSS feed

 
Rubendren Ruben
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey, guys i need some help from you guys. I went for and interview today this is the uestion that they give me to do, so i did but dont know whether its correct or not. I need you guys to help me so that it will be eazy abit for my second interview. Please do help me guys. Hope some one out there to help me to solve this question out. Your kind hearted is much appreciate. Thank You guys.



1. Is there any part not correct in the Java code below?







2. “A web server is listening at port 80 waiting for requests from clients. If there is a client connected to this server, the server will setup connection with it, then response request from client. Until finish all service with the current client, the server can setup connection and provide service for the next client”

Is the above description right? Justify your answer?


3. A server spawns a new process for each client connected to it, and this process is dedicated to provide service to this client. What is the main possible problem for this approach?



4. Consider the following figure,




Figure 1 Process Communication

a) What are the source and destination port numbers in the segments flowing from the server back to the client’s process?



b) What are the IP addresses in the network layer datagram carrying the transport-layer segments?



5. Briefly describe the FOUR (4) steps to create a TCP client, and give sample code of each step.

6. Consider the following incomplete program of a UDP echo server.


 
Campbell Ritchie
Marshal
Posts: 56525
172
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

We do not operate like that. We expect you to tell us what you thought, and we shall see whether we agree. Please tell us what answers you gave.
you should always use the code button in your posts; I have gone back and you can see how much better your post looks now
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rubendren Ruben wrote:1. Is there any part not correct in the Java code below?


If the interview is asking if it's syntactically correct--that is, if it's legal Java--then the answer can easily be found by compiling it. Of course, you should first try to figure out on your own what you think the result will be.

If he's asking if it's semantically correct--that is, if it will produce the desired behavior--then the question cannot be answered without first knowing what the desired behavior is.
 
Rubendren Ruben
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:Welcome to the Ranch

We do not operate like that. We expect you to tell us what you thought, and we shall see whether we agree. Please tell us what answers you gave.
You should always use the code button in your posts; I have gone back and you can see how much better your post looks now


Okay what should i do now guys??
 
Campbell Ritchie
Marshal
Posts: 56525
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should tell us what you thought the answers were.
 
Rubendren Ruben
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, guys this what i think the answers are. Please do help me if i'm wrong. Thank You.

Question 1:
Class Foo has not been imported in to call AProgram.

Question 2:
No correct, the server will create a new connection on a different port and wait for the next client to connect.

Question 3:
The total number of concurrent users may cause the server to reach the maximum connections allowed, any new connections will not be created and service will be disrupted

Question 5:
I do not know about TCP Client programming
 
Ivan Jozsef Balazs
Rancher
Posts: 999
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> A server spawns a new process for each client connected to it, and this process is dedicated to provide service to this client. What is the main possible problem for this approach?

Creating a new process needs more resources than creating a new thread let alone than picking a thread from a pool.
 
Rubendren Ruben
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ivan Jozsef Balazs wrote:> A server spawns a new process for each client connected to it, and this process is dedicated to provide service to this client. What is the main possible problem for this approach?

Creating a new process needs more resources than creating a new thread let alone than picking a thread from a pool.



Thank You so much for your kind help Mr. Ivan Jozsef Balazs.
 
Stuart A. Burkett
Ranch Hand
Posts: 679
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rubendren Ruben wrote:Question 1:
Class Foo has not been imported in to call AProgram.

No. There is no package statement in either class, so we must assume they are both in the same package, so no import statement is required.
Hint : Look at how method1 and method2 are being called in the AProgram class and then look at how their definitions differ.
 
Rubendren Ruben
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply guys. Is this the answer for question 1 No.

1)There is no package statement in either class, so we must assume they are both in the same package, so no import statement is required.
Hint : Look at how method1 and method2 are being called in the AProgram class and then look at how their definitions differ.

 
Mansukhdeep Thind
Ranch Hand
Posts: 1163
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rubendren Ruben wrote: Thanks for the reply guys. Is this the answer for question 1 No.


So, for case 1, are you saying that the code is correct? What is your reason?
 
Rubendren Ruben
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mansukhdeep Thind wrote:
Rubendren Ruben wrote: Thanks for the reply guys. Is this the answer for question 1 No.


So, for case 1, are you saying that the code is correct? What is your reason?



Im not really confirm with the answer, so can you assist me in this please, question 1 answer.
 
Campbell Ritchie
Marshal
Posts: 56525
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rubendren Ruben wrote:Hi, guys this what i think the answers are. Please do help me if i'm wrong. Thank You.

Question 1:
Class Foo has not been imported in to call AProgram. . . .
I believe that is incorrect. I would think that both classes are in the unnamed package. Which line will really produce a compiler error? (Assuming you complete the constructor.)
 
Mansukhdeep Thind
Ranch Hand
Posts: 1163
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rubendren Ruben wrote:
Mansukhdeep Thind wrote:
Rubendren Ruben wrote: Thanks for the reply guys. Is this the answer for question 1 No.


So, for case 1, are you saying that the code is correct? What is your reason?



I'm not really confirm with the answer, so can you assist me in this please, question 1 answer.


Base your answer on concrete reasoning, not guessing. Read about class and instance members. Then tell us the correct answer for 1. And if you still don't understand, try compiling them on the command prompt. Observe the result.
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rubendren Ruben wrote:Im not really confirm with the answer, so can you assist me in this please, question 1 answer.


You don't need us for that. As I already pointed out, after you try to figure it out, just compile it and see what happens. If it's legal Java syntax, it will compile successfully; if it's not, you'll get one or more errors from the compiler, and they'll tell you what's wrong with it.
 
Rubendren Ruben
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys i need a help again for this question:

4. Consider the following figure,




Figure 1 Process Communication

a) What are the source and destination port numbers in the segments flowing from the server back to the client’s process?



b) What are the IP addresses in the network layer datagram carrying the transport-layer segments?



5. Briefly describe the FOUR (4) steps to create a TCP client, and give sample code of each step.
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rubendren Ruben wrote:Hi guys i need a help again for this question:

4. Consider the following figure,


What figure?



Figure 1 Process Communication

a) What are the source and destination port numbers in the segments flowing from the server back to the client’s process?



b) What are the IP addresses in the network layer datagram carrying the transport-layer segments?



5. Briefly describe the FOUR (4) steps to create a TCP client, and give sample code of each step.


You previously said you don't know anything about TCP client programming. So you need to study that to the point where you feel you can answer those questions. It is not reasonable to expect somebody hear to tell you all you need to know about TCP/IP. It is also not reasonable to expect somebody to just give you the answer, and even if they did, it wouldn't mean anything to you until you take the time to study networking anyway.
 
Rubendren Ruben
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is what i did. Correct me if im wrong.

4. Consider the following figure,




Figure 1 Process Communication

a) What are the source and destination port numbers in the segments flowing from the server back to the client’s process?
(3 Marks)
P1 (ip: A, port: 9157) accesses to server (ip: C, port: 80)
P2 (ip:B port: 5775) accesses to server (ip: C, port: 80)
P3 (ip: A, port: 9157) accesses to server (ip: C, port: 80)


b) What are the IP addresses in the network layer datagram carrying the transport-layer segments?
(2 Mark
Answer :
SP=80 SP=9157
DP=9157 D‐IP=B
D‐IP=A S‐IP=C
S‐IP=C DP=80

DP=80
SP=5775
D‐IP=B
S‐IP=C




5. Briefly describe the FOUR (4) steps to create a TCP client, and give sample code of each step.
(4 Marks)
1. Establish a connection to the server.
We create a Socket object, supplying its constructor with the following two arguments:
 the server's IP address (of type InetAddress);
 the appropriate port number for the service.
Socket link = new Socket(InetAddress.getLocalHost(), 1234);
2. Set up input and output streams.
These are set up in exactly the same way as the server streams were set up (by calling methods getInputStream and getOutputStream of the Socket object that was created in step 2, and warp them to Scanner and PrintWriter).
Scanner input = new Scanner(socket.getInputStream());
PrintWriter output = new PrintWriter(socket.getOutputStream(), true);
3. Send and receive data.
The Scanner object at the client end will receive messages sent by the PrintWriter object at the server end, while the PrintWriter object at the client end will send messages that are received by the Scanner object at the server end (using methods nextLine and println respectively).
sendMsg = consoleInput.nextLine();
output.println(sendMsg);
rcvMsg = input.nextLine();
System.out.println(rcvMsg);
4. Close the connection.
This is exactly the same as for the server process (using method close of class Socket).
socket.close();


 
Rubendren Ruben
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, Mr. Jeff Verdegan, acctually im trying out to do the question after reading some book regarding TCP and i hope what i did was correct. Correct me if i made any mistake so that i will learn from the mistake that i have done.
 
Campbell Ritchie
Marshal
Posts: 56525
172
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you ever work out whether the first code snippet would run correctly?
 
Rubendren Ruben
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yup but its not working. Guess i made some mistake but i cannot find out where it went wrong.
 
Mansukhdeep Thind
Ranch Hand
Posts: 1163
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Go one step at a time. Tell us what is the problem with the first snippet. What were the errors when you tried compiling those?
 
Rubendren Ruben
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, guys atlast I have completed my assignment and have submitted today. Thanks alot guys for those who help me completing this assignment. Without you guys I will be not able to complete this assignment. Thanks alot guys for the kind guidance.
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome!
 
Rubendren Ruben
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, guys is there any one who can develop a remote access system in jawa.
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rubendren Ruben wrote:Hi, guys is there any one who can develop a remote access system in jawa.


Assuming you mean "Java", not "jawa", and assuming you were to provide details on what you mean by a "remote access system," then, yes, there are plenty of people here who could develop it. But that's not how this site works. We're not here to write people's code for them. If you want to hire somebody to do some work, then there's a Jobs Offered forum on this site that's the appropriate place to post. Given the rest of this thread, though, that question sounds like you want somebody to write something so you can take credit for it in a job interview. That ain't gonna happen.

So, what are you really trying to ask?
 
Rubendren Ruben
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, Mr. Jeff Verdegan actually i'm very new to this page. Earlier I have told you guys that if i've made any mistake means do assist me. I understand because of some typo mistake "java" I wrote it as "jawa". You should understand something first im asking regarding the VNC remote access to buy if any one have done the project perivously. I understand nothing can get for free, so if you have any contact you should let me know and not to talk rude as how you was. If can please take some time to learn how to respect people and respond in a good manner if some one needed help.
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rubendren Ruben wrote:im asking regarding the VNC remote access to buy if any one have done the project perivously.


You want to create a VNC-like product in Java? It's not possible in pure Java, since it needs access to low-level OS calls. And even if you did it--in Java or some other language--you'll have a hard time getting anyone to buy it, since there are already several free ones on the market, and Windows comes with RDP built right in.

I understand nothing can get for free, so if you have any contact you should let me know and not to talk rude as how you was. If can please take some time to learn how to respect people and respond in a good manner if some one needed help.


First, I don't owe you anything. Nobody here does. Second, I don't think I was rude to you, but if you feel that I was, then report my post using the Report button that's right there in the post, or contact the moderator who's responsible for this forum. A link to his or her profile should be above the topic list somewhere.
 
Rubendren Ruben
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, Mr. Jeff Verdegan no worries on what ever has past. Anyways, thanks for your kind help.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!