Damon McNeill

Ranch Hand
+ Follow
since Apr 06, 2010
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
4
Received in last 30 days
0
Total given
2
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Damon McNeill

TL;DR: I'd like to implement a .class file plugin architecture?
1 year ago
Maybe I should give some context to the problem.

I've got an implementation of a programming language interpreter written in Java, and I'd like to have others be able to extend its functionality in Java. The interpreter is packaged into an executable JAR, and I've exposed a public API from my package so others can import my package and write arbitrary Java code using my API. When the interpreter is invoked, I'd like to be able to dynamically load those .class files that have been built based on my API. They should implement a certain interface, which I will use to load their functionality into the interpreter at runtime.

I hope that all makes sense!
1 year ago

Folks,

Question regarding dynamic class loading. I'd like to dynamically load a given ".class" file into an instance of a specific public interface that I define, and which the class is expected to implement. Right now I'm just trying to get a Class instance, given the file name.

This code works:



However, when I use this same code in my application I get a ClassNotFoundException. My application is packaged as an executable JAR file, and the path of the ".class" file is passed as a parameter into the command line. So it's something like



How would something like this be implemented? I looked at the defineClass() methods in ClassLoader, and also into the idea of implementing something like MyCustomFileClassLoader extends ClassLoader.

Thanks in advance!

1 year ago

Junilu Lacar wrote:Your statements about casting to Test and about wierdness indicate that you don't fully understand how casting works.

A cast does not change an object's type. A cast is merely a reassurance to the compiler that the thing you are casting is indeed compatible to the type that you're casting it to. It's like you guaranteeing to a creditor that your friend can indeed pay his loan off. The cast basically tells the compiler, "Trust me on this, I know you only know that this other thing is an Object but I've checked it out and can assure you it's actually an instance of Test."



Yes, but if you try to cast an object to a type which it is not a member of, then you get the dreaded ClassCastException.
2 years ago
Instead of a dialog box, create a new window (whose parent is your main interface). Dialog box is limited to a simple choice like "OK", "RETRY", "CANCEL", but you can do anything you like in a new window.
2 years ago
Options are generally done via a menu on the GUI interface, not a Dialog box. Most users, I think would agree, that dialog boxes suck.
2 years ago

Beware of getting tangled in the weeds before you even have a chance to survey the general lay of the land around you.



That's as good a quote as I've seen regarding premature optimization.
2 years ago
You need to read the full header, and only then, send it to the server for a response.

Hope it helps.


2 years ago
For example, given the HTTP header as

GET / HTTP/1.0
Host: google.com
Connection: close
Header: Value



your code is sending each line of this as a full request, which is not what is needed.
2 years ago


The code here seems to assume that a "request" is fully contained in one line; however, an HTTP request may contain multiple newlines. This is not a simple problem. I think to get a correct solution, would require you to write a HTTP request parser, and a generator, according to the formal grammar of HTTP. It would be sort of similar to writing a JSON parser,  but HTTP is a lot simpler than JSON.
2 years ago
It's not dumb. I'm sure there's a context-free grammar that specifies what a valid HTTP header look like. Your problem is to generate valid instances of that grammar.

2 years ago
I don't know about this version of "try" syntax that's you're using.. But I posted an example of a simplistic "copy" program, maybe try running that on your test input, and see if that works. If it does, then the problem is somewhere else in your code?
2 years ago
2 years ago

My understanding :Buffered input streams read data from  buffer, the native input API is called only when the buffer is empty. Similarly, buffered output streams write data to a buffer, and the native output API is called only when the buffer is full. Even though there is no need to flush on each iteration, if we still do it that adds some extra overhead at each iteration and hence slowing down the code execution .



Yes, that's correct. However, there's no need to flush() on EVERY iteration, just the final one. Basically, flush() is called internally by write() when then buffer is full. If it's not full, no flush is done.
2 years ago

then again, I'm a Taurus so that makes me a little bit more cautious and circumspect than most people when it comes to these kind of things.  



I'm an Aries, so I tend to jump into  things quickly... lol
2 years ago