This week's book giveaway is in the NodeJS forum.
We're giving away four copies of Serverless Applications with Node.js and have Slobodan Stojanovic & Aleksandar Simovic on-line!
See this thread for details.
Win a copy of Serverless Applications with Node.js this week in the NodeJS forum!

Oleg Shubin

Ranch Hand
+ Follow
since Jun 25, 2015
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Oleg Shubin

I have a library that wants me to use if I want it to send its HTTP/HTTPS requests through a proxy that requires a username and a password. However, that library will be used to implement a small feature in a huge application (that I did not write myself) that may use Authenticators for its own needs already. I can ensure that my Authenticator is set last but I do not want the previous Authenticators to cease functionality - they might be needed still. So naturally I try to do the following: set my Auth; when asked for PasswordAuthentication decide whether I should handle the request; if yes, give my credentials; if no, forward the request to whatever the previous authenticator was.
So I hacked this together:

I suppose that the code is terrible but I cannot see why yet. Please explain to me why this is not the way to do it.

Thank you

I have recently stumbled upon the following problem when writing my library:
I have class A, which is supposed to be extended in the final application. For convenience of use the Collection that holds references to the objects of this class is defined in a generic way (Collection<T extends A>). I have also found it necessary to keep a reference to that Collection in every instance of A. (I took precautions to avoid memory leaks.) What type do I assign to that reference?

To be more specific, here's a tl;dr:
A Server object keeps references to all of its clients. Clients are represented by class ServerClient that is supposed to be extended when in use. In order to avoid tons of casting to address application-specific methods of ServerClient subclasses, I decided to make Server objects generic (Server<C extends ServerClient>), so that Server.getClients() returns an appropriate Collection. At the same time, while the client is connected to the server, I need to address the Server's fireDisconnectEvent(C client) (as an example) object from inside the ServerClient class or its subclasses, so I want to keep a reference to it. Here's where the problem lies: if I make the field of type Server<?>, it results in a ton of unsafe (from compiler's PoV) casting, as the input type becomes "?" otherwise. The ideal way to do it would be to make the type of the field something like Server<this.getClass()>, but it is obviously impossible.

Any ideas? Is it possible at all or is it easier to do the casting and complain about Java's generics? Maybe there is something I'm overseeing?
Thank you in advance.

P.S. The subject is a bit confusing, I guess. Just as the situation as a whole.
1 year ago
Uups! I've accidently posted this on the wrong forum! Can a mod move this to General Java? Please?
2 years ago
Hello everyone,

I have a problem with program-to-program communication. I have an old 16-bit application (written in QBasic in 1991, no sources left), that was designed for manual operation only. As a part of my current project I need to access this program from a Java application (without human interaction, of course). Basically the idea is to create a web interface for that 16-bit program; Java program should send requests to the application and read its output. However, I have run into problems.
First of all, I need to use a 16-bit emulator (DOSBox is currently in mind) to run the app. Next, the app itself has a text user interface and it only responds to raw keyboard events, so I cannot really use input redirection. To give a bit more detail, the UI requires the user to either press a key and confirm his desicion with enter, or choose an option with arrow keys and enter. I don't know the proper way to interact with such an application.
Having that said, here is an unnecessarily complicated way to make Java <-> 16-bit interaction possible that came into my head: have OS send fake keyboard events to the 16-bit emulator. It should look the following way: Java calls some OS (I plan to use Windows Server 2008) library, OS "tells" the emulator that it has received a key press, emulator passes the event to the program. I was going to post a question asking "Wehre can i haz lib 4 winodws keybroad eventz emulation" but quickly realized I'm obviously overcomplicating here.

My final questions are: 1) Is there a way to send OS-level keyboard events to a specific application in Java or in C/C++? Can anybody recommend something? 2) Is there an easier or alternative way to solve the problem that you know?

Thank you in advance
2 years ago
Thank you for your awnser, I think what you've meant to say is that even having several hashes of a password does not make it much easier to "crack".
2 years ago
Which algorithms are better for password hashing then? Anyway, I was asking my question about a general case with generic hashing algorithms.
2 years ago
Knowing only one digest of a password (i.e. MD5) it is almost impossible to get the original String. How much easier is it to get the original in case two digests are known (i.e. MD5 and SHA-1)?
2 years ago
I am trying to design a game engine that would be able to run on desktop, as an applet and as an Android application. I know I cannot have the exactly same file in all three cases due to different formats (e.g. Android's Dalvik VM requires DEX files not supported by Oracle's JVM) but I can at least try to make code that, if compiled properly, could do the trick.

However, I am afraid that some libraries might not be available on all three platforms. Thus I plan to define interfaces in my engine and only use them in further development and make different platform-specific implementations of those interfaces. When the application is launched, the interface is hooked to a correct implementation, e.g. the graphics interface would have Swing, OpenGL and Android OpenGL implementations. However, according to this thread Android may not fully implement all of Java API packages.
What other packages may not be available on Android or in applet environment? What packages are guaranteed to be fully supported in all three cases?

Thanks in advance
2 years ago
Norm Radder, thank you for your awnser. I checked manifest file specification and realized that out of all those attributes I only need Class-Path and Main-Class attributes to launch main method. It is then not my responsability to process all manifest data.
So I will try creating a ClassLoader with the subject JAR and all Class-Path entries as code sources, then loading class specified by Main-Class attribute and finally invoking its main() method with desired "console" arguments.
2 years ago
Thank you for your awnser, but I am afraid that is not exactly an option.
I personally could modify my main server's JAR file to include an agent class, but I also want to publish this application later for others to use, and your solution would cause a couple of problems:
a) modifying a JAR file is often a violation of application's license, thus it would be illegal to inject an agent class into a JAR;
b) in many cases (including mine) JVM arguments cannot be changed, thus making Command-Line Interface unreliable and useless.
2 years ago
In my Java program, I need to launch another JAR file (respecting its MANIFEST.MF) without creating a new instance of Java Virtual Machine. How can that be done?

Why I need this: I am currently writing a "wrapping" program for an application run on a remote hosting so I can have better control over the server via TCP. There, hosting software would run the file specified by me (the wrapping program), and the program has to open its own TCP server and then launch the main server. Although I know I could create a new process and have my application control it via its standart IO streams (, System.out, System.err), that would limit my possibilities while also probably violating hosting terms. So I tried manually invoking server's main class. However, manifest file may specify data required by the server (such as Class-Path property or application-dependant properties) that I may not know about.

Thanks in advance
2 years ago
Thank you! It is indeed a very useful tool.

It turned out that I was right, and the example in the original post is indeed the case, values 42 and 6 are present in bytecode. Looks like constant expressions are always evaluated.
3 years ago
As I know, the Java bytecode compiler, javac, does some small optimization. I'd like to have a better idea on what and how does javac optimize.

E.g. after some research I found out that loop unrolling is not javac's task (JIT takes care of that), so the following code is going to stay intact in bytecode:

Programming techniques suggest using named constants to make code clearer, and I suppose javac is going to substitute constants with their values (if they are available at compile time, of course). So, is the following code:

...going to compile as the next one?

Thanks for helping.
3 years ago

Paul Clapham wrote:There are problems which arise when you mix Swing and AWT components in the same application, most of which involve components not displaying correctly. Looks like you might be encountering that. Just use the Swing components already.

Well, that turned out to be the problem. However, that's strange: as I know, Swing is based on AWT, moreover, it is actually just a bunch of (complex) utilities added to AWT; shouldn't it be backwards-compatible, especially if, IMHO, I do not use any of those utilities?

Anyway, thank you for helping. I'll be more careful with mixing libraries next time.
3 years ago
** Uups, looks like I've posted on the wrong forum! Needs to be in Swing / AWT / SWT **

Although that might seem to be a beginner's problem I'm having it in quite an unusual context.

I've got a JFrame (Swing component) all of whose children are AWT Components. Those Components (Canvas, in fact) are displaying buffered images that are concurrently updated by other threads. A java.util.Timer is repainting the frame at fixed rate. Although I see that the all the components are being painted over and over (a message is printed from one of the component's paint() method) the JFrame itself does not change visually until OS requests repainting (e.g. I change the size of the window).

All the Swing-related activities are performed from the AWT event dispatching thread; JFrame is repainted using frame.repaint().

Unfortunatly I cannot provide the actual code here because it is linked to my entire project, so here is a simplified version:

Why do I only use Swing for the frame? Well, at first I wanted to make an AWT application (less useless (in my case) processing, amiright?) but it turned out I needed double bufferisation in order to reduce artifacts on screen updates.

Thanks in advance
3 years ago