Strainu onLine
Blogul unui automatist
If you came here searching articole.strainu.ro or blog.strainu.ro, you're in the right place - all those sites were integrated in the main site.
23rd
FEB
Distributed Programming Homeworks
Posted by Strainu | Filed under Java, Software
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.
(more…)
23rd
Network Programming Homeworks
Posted by Strainu | Filed under C, Java, Software
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.
(more…)
23rd
Parallel Algorithms Homeworks
Posted by Strainu | Filed under C, Java, Software
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.
(more…)
11th
NOV
Using Serialization with non-blocking sockets
Posted by Strainu | Filed under Java
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 sending end
Message outgoingMessage;
SocketChannel socketChannel;
//we open the channel and connect
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
ObjectOutputStream objectOutputStream = new ObjectOutputStream(byteArrayOutputStream);
objectOutputStream.writeObject(outgoingMessage);
objectOutputStream.flush();
socketChannel.write(ByteBuffer.wrap(byteArrayOutputStream.toByteArray())); - The receiving end
SocketChannel socketChannel;
ByteBuffer data;
//we open the channel and connect
socketChannel.read(data);
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(data.array());
ObjectInputStream objectInputStream = new ObjectInputStream(byteArrayInputStream);
Message message = (Message)objectInputStream.readObject();
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.
15th
JUN
Call by sharing
Posted by Strainu | Filed under Functional Programming, Java, Python
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.
2nd
MAY
Why Java sends the parameters by value
Posted by Strainu | Filed under Java
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
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:
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.
26th
MAR
Quotes (Java)
Posted by Strainu | Filed under Java, SQL, Software

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).
(more…)
26th
Algorithm Analysis Project
Posted by Strainu | Filed under Java, Software

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”.
(more…)
Tags: Contour tracing, Java, Poli, Software
26th
OOP Labs
Posted by Strainu | Filed under Java, Software
OOP Labs OOP labs, Automatics and Computer Science Faculty, UPB, 2nd year, prof. Florian Moraru. (more…)
Recent Posts:
- 10 Mar MP – Dezvoltarea un...
- 10 Mar MIP – Analiza infor...
- 09 Mar MFP – Analiza perfo...
- 09 Mar MCP – Analiza calit...
- 05 Mar Wikipedia e mai prietenoa...
- 04 Mar Strainu.eu
- 03 Mar IP – Deschiderea un...
- 03 Mar ACP – Achiziționar...
- 30 Jan Danese Cooper is the new ...
- 11 Dec Planeta Wikimedia is up!