Java

Distributed Programming Homeworks

Posted by Strainu on February 23, 2008
Java, Software / No Comments

Distributed Programming Homeworks from the Automatics and Computer Science Faculty, UPB, 5th year, prof. Corina Stratan. Themes: Transactional Distributed Object DataBase Management System, RMI (Remote Method Invocation), Plane ticket reservation web service, SSH access using a web interface with JSP/servlets.
Continue reading…

Share and Enjoy:
  • Facebook
  • Twitter
  • Identi.ca
  • LinkedIn
  • Reddit
  • Add to favorites

Tags: , ,

Network Programming Homeworks

Posted by Strainu on February 23, 2008
C, Java, Software / No Comments

Network Programming Homeworks from the Automatics and Computer Science Faculty, UPB, 5th year, prof. Valentin Cristea. The archive contains a homework made in Java. Themes: RPC (Remote Procedure Call), Sorting trees using MPI, Secure chat server in JAVA, Bidding system using CORBA.
Continue reading…

Share and Enjoy:
  • Facebook
  • Twitter
  • Identi.ca
  • LinkedIn
  • Reddit
  • Add to favorites

Tags: , ,

Parallel Algorithms Homeworks

Posted by Strainu on February 23, 2008
C, Java, Software / No Comments

Parallel Algorithms Homeworks from the Automatics and Computer Science Faculty, UPB, 5th year, prof. Valentin Cristea. The archive contains a homework made in Java. Themes: Parallel Game of Life with OpenMP, Sudoku with Replicated Workers, image manipulation (filters, Huffman coding), routing tables.
Continue reading…

Share and Enjoy:
  • Facebook
  • Twitter
  • Identi.ca
  • LinkedIn
  • Reddit
  • Add to favorites

Tags: , ,

Using Serialization with non-blocking sockets

Posted by Strainu on November 11, 2007
Java / 2 Comments

The most common way to make a server in Java is to create a thread pool and associate each request with a thread. Java5 offers a special class called Executor that can help you with the task. However, if you ever needed to make a server which can handle thousands of connections, you know this solution doesn’t scale very well. Most processors can’t handle more than a few hundreds of threads.
The solution is to use non-blocking sockets, a feature introduced in java 1.4 (the java.nio package). However, this has an important drawback: you can’t use the getInputStream(), getOutputStream() functions from the Socket class to serialize objects. The reason is simple: with non-blocking sockets, there is no way the system can guarantee that the whole object has been sent/received.
You can however “trick” the virtual machine by using explicit Streams. You have a simple example below. We try to send an object with the Message type.

The code works if you receive the whole object or more than one object (the readObject() function reads exactly one object). However, I had some issues with reconstructing the object if it arrived in multiple pieces. Any suggestions on that part would be useful.
Here are some resources that I found useful: a discussion at forum.java.sun.com and another discution about the subject.

Share and Enjoy:
  • Facebook
  • Twitter
  • Identi.ca
  • LinkedIn
  • Reddit
  • Add to favorites

Call by sharing

Posted by Strainu on June 15, 2007
Functional Programming, Java, Python / No Comments

In a previous article, I was saying trying to convince you that Java passes its parameters by value. Although this is the most widely-spread name for the action of passing references to objects, some experts have a different opinion. They name this parameter-passing technique “call by object” or “call by sharing“.

The only programming language that openly uses that name is CLU, however one must note that languages like LISP, Scheme, Python or Java use the same technique. You can find a short study on the subject in the python mailing list archives.

Share and Enjoy:
  • Facebook
  • Twitter
  • Identi.ca
  • LinkedIn
  • Reddit
  • Add to favorites

Why Java sends the parameters by value

Posted by Strainu on May 02, 2007
Java / 1 Comment

Some students learn that parameter passing in Java is done by reference. In fact, Java only sends parameters by value, and those parameters are either primitive types or references, never actual objects. If you define a variable in Java which is not in a primitive type, you actually define a reference. So, when you write

Object a = new Object();

what happens is that a is a reference and its value is actually the address of the heap area containing the object.

Now, let’s say you have something like:

void aFunction(Object b)
{
    b = "blah";
}
....................................................
Object a = new Object();//we define a as a new object
aFunction(a);//we call the function
System.out.println(a.toString());//NOT "blah"

What happens here is that the function aFunction receives a as an actual parameter, it copies the parameter’s value (which is an address, NOT the object you created with new) and then modifies the copy. Of course, a still has the unchanged value when aFunction returns.

Some people argue that this is passing by reference, because the object that a points to can be changed. This is true, however, as we’ve seen, the object is not passed as a parameter.

You can find a formal analysis of this subject here.

Share and Enjoy:
  • Facebook
  • Twitter
  • Identi.ca
  • LinkedIn
  • Reddit
  • Add to favorites

Quotes (Java)

Posted by Strainu on March 26, 2006
Java, Software, SQL / No Comments

Preview

Aforisme (Java) A program that demonstrates the communication between Java (I have used the NetBeans IDE) and the MySQL server. To run the program, you need the MySQL server and the “quotes” table(use the quotes.sql file).
Continue reading…

Share and Enjoy:
  • Facebook
  • Twitter
  • Identi.ca
  • LinkedIn
  • Reddit
  • Add to favorites

Tags: , , ,

Algorithm Analysis Project

Posted by Strainu on March 26, 2006
Java, Software / No Comments

Preview

Algorithm Analysis Project 3rd year, Computer Science Faculty, UPB, Bucharest. It’s about contour tracing (Square Tracing Algorithm, Moore-Neighbor Tracing, Radial Sweep, Theo Pavlidis’ Algorithm). To see the applets, just choose the algorithm, then click on “Program”.
Continue reading…

Share and Enjoy:
  • Facebook
  • Twitter
  • Identi.ca
  • LinkedIn
  • Reddit
  • Add to favorites

Tags: , , ,

OOP Labs

Posted by Strainu on March 26, 2006
Java, Software / No Comments

OOP Labs OOP labs, Automatics and Computer Science Faculty, UPB, 2nd year, prof. Florian Moraru. Continue reading…

Share and Enjoy:
  • Facebook
  • Twitter
  • Identi.ca
  • LinkedIn
  • Reddit
  • Add to favorites

Tags: , , ,