When do new things get added to the Java API - java

I have been wondering about this for a while and I can’t really find a clear answer. You see the standard Java API is really big and it includes a lot of different libraries and classes for you to use from GUI design to sending data over the Internet to basic things like sending a String to the console.
It also includes things like reading MIDI generating secure random Strings, things that seem really specific. But at the same time there doesn’t seem to be any standard JSON libraries available while JSON is an universal way of sending data between systems.
So what I want to know is: When does something get added to the Java API? What does something need to be considered to be added to the API?

There is a "framework" that drives how new features "get" into java; to manifest themselves later on as new language elements or libraries.
Enter ... the Java Community Process!
Meaning: this is a forum where people make suggestions; which then get discussed; and at some point are either "added to Java somehow"; or rejected.
And for starters: the JSON-P project about a JSON processing API was/is driven by the jcp, see entry 374.
Finally: but you are correct, not everything that shows up in the "standard library" should be there; whereas other important parts take way too long before people can agree on a proposal. And of course, there is also a long history of evolution.
So: when you could restart Java from scratch; you would organize things in a different way (and to a certain degree, that is what Java9 is trying to enable with the new module concept).

Related

How to load a .java file into a variable? [duplicate]

This question already has answers here:
What is a Java ClassLoader?
(8 answers)
Closed 5 months ago.
I'm still fairly new to java and currently working on a text-based adventure game as a practice project.
The engine loads scenes to play that are all child-classes from a "Scene" superclass and appear as for eg. "dungeon.java". Now I want the game to be expandable.
The ideas is that a user can drop new scenes as .java-files into a "Scenes" folder and everytime the game is launched it reads all files in that folder and safes them into a "Scene"-class array.
My problem is that I don't know how to code this. I googled a lot and tried various phrasings but all I can find are tutorials for reading lines from txt-files or similar.
Is it even possible to read a complete file into a variable without serialzation?
I already tried the following code, but didn't get around to test it yet.
private static void buildScenePool() {
File scenesFolder = new File("/scenes");
\\ setup filter for .java files
FilenameFilter javafilter = (dir, name) -> name.endsWith(".java");
File[] sceneList = scenesFolder.listFiles(javafilter);
\\ create new arry large enough for all scenes
allScenes = new Scene[sceneList.length];
try{
FileInputStream fileIn = new FileInputStream(scenesFolder);
ObjectInputStream objectIn = new ObjectInputStream(fileIn);
\\ iterate trough the list array and safe files to array
for (int x = 0; x < allScenes.length; x++) {
allScenes[x] = objectIn.readObject( (Scene)sceneList[x] );
}
objectIn.close;
} catch (IOException e) {
System.err.println(e.toString());
}
}
This is rather very complicated. java code is normally compiled, and thus, that means you'd have to scan for a new java file, compile it (which is its own complicated ordeal, as that also means setting up the classpath and the like properly so that the compiler knows what to do), then load in the class file the compiler produced, and then call the appropriate methods in there.
You can do that. It's just, quite complicated. Your standard JVM doesn't necessarily even ship with a compiler; this is solvable too (either demand that this runs only on one that does, and the modern deployment rules for java involve you getting a JVM on your user's machines, so you thus pick one that does include a compiler – or you can just ship the compiler as dependency with your app, javac is itself a java app and runs on any JVM).
However, the more usual approach is to not actually use java for this. Instead, use something java-like, but not java: Scripting languages, like groovy, or javascript (okay, that is not particularly java-like perhaps).
That is its own sort of complication. There are no easy answers to any of this.
I think it's time to first think broad strokes and determine how you want the user's experience (that is, a user that wants to add a scene) should be, and then ask a new SO question about your specific choice.
You write em, they install em
In this model, users simply download or pick a 'scene' impl that someone else wrote (a 'real' programmer with a full fork of the entire source code, an IDE, a build tool, the works). Don't knock it - programming is hard, and saying: "Oh, look, anybody can customize a scene, it's easy, just open notepad.exe, write something like this (example java file here), and dump it in the Scene folder and off you go!", but this is not at all easy. To us programmers that seems familiar at least, but to your average user you're asking them to just rattle off a poem in ancient sumerian - normal people don't program. And if they do program, they're programmers. They would much rather get instructions about how to fork a project and set it up in an IDE than some bizarreness about tossing raw java files someplace.
Scripting
This is what Processing (for programming arduinos) does, more or less what webbrowsers did (which explains why javascript is so weird), and most 'plugin systems' for pseudo-smart editors like TextMate and Emacs do: You script them. As in, you fully buy into the idea that the custom stuff written by the user is extremely simple and highly targeted (really only makes sense to run within the confines of your app, not as standalone stuff - and dependencies don't generally come up), and pick a language that fits that model, and java certainly is not that.
Obvious options are javascript and groovy. This is certainly possible but not at all easy. Still, if you're interested, search the web for tutorials on how to run javascript or groovy inside a JVM, and you'll get plenty of hits.
Java code, and you compile it
That's what your question is positing as only option. I don't recommend it, but you can do this if you must. Be aware that it seems to me, based on the way you worded your question and your example code which makes various newbie mistakes (such as print-and-continue exception handling, which is always wrong, using obsolete APIs, and messing with built-in serialization) that this is a few ballparks beyond your current skillset. A challenge is always cool, so, if you want to go for it, you should! Just be aware it'll be the most difficult thing you've ever written and it'll take a few fully dedicated weeks, with a lot of reading and experimenting.
Just definitions, really
The central tenet so far has been that you can actually program. Instructions that make the machine act in certain ways. Possibly you don't need any of that. If a Scene is really just a background colour and a few widgets displayed here and there, should it even be code at all? Maybe you just want a declarative setup: The plugin/scene writer just declares certain properties and that's all they get to do, you just 'run' such a declarative definition. In which case the 'language' of the declaration can be in JSON, XML, YAML, TOML, or any other format designed for configuration files and such, and you can forego the hairy business of attempting to compile/run user-provided code in the first place.
In order to load the Java classes into your application, you need to compile them. You could do this from Java by invoking the javac executable. See Starting a process in Java? for instructions on how you could do that. Once compiled, you'd then need to load the classes into the JVM using a class loader, e.g. by invoking ClassLoader.defineClass. You probably want to configure a protection domain as well, to prevent user provided classes from misbehaving.
However, Java might not be the best approach for extending your application. You could consider using a scripting language instead, like JavaScript. See Nashorn (an open source script engine that was included in previous versions of Java, and that can now be downloaded separately) and the Java Scripting Programmer's Guide for more information.

Evernote: Get a list of all edits

I am trying to develop a simple statistics tool to analyse various behaviours of collaborators within an Evernote Notebook using the Evernote Java API.
I need the informations which user edited which note and when.
Even though the documentation is quite good, I am still unable to find the required functionality inside the api.
(TLDR:)
Is there a way to access a list of edits of a evernote note using the API?
I am not bound to using the Java SDK so if there is a way, which is limited to using another language, it would be no problem to switch.
Andreas - Did you look into these methods in the API?
NoteStore.GetNote and NoteStore.getNoteApplicationData
It sounds like this would be a decent place to start at the very least. I cannot say for certain if this will return everything you are looking for though.
I hope this helps!
I'm not exactly sure what you are looking for but NoteStore#listNoteVersions might be the one you want. You can get a list of NoteVersionId and then use another API called NoteStore#getNoteVersion to get metadata to see which note is updated when.
Note that the API is probably only for premium accounts.

Java; Runtime Interpretation; Strategies To Add Plugins

I'm beginning to start on my first large project. It will be a program very similar to Rosetta Stone. It will be a program, used for learning a foreign language, written in Java using Swing. In my program I plan on the user being able to select downloaded courses to learn from. I will be able to create an English course since I am a native English speaker. However, I want people who speak other languages to be able to write courses for users to use as well (this is an essential part for my program to work).
Since I want the users to be able to download courses of languages they want, having it hard-coded into the program is out of the question. The courses needed to be interpreted during the runtime. Also since I want others to collaborate with my work (ie make courses), I need to make it easy for them to do so.
What would be the best way to go about doing this?
The idea I have come up with is having a strict empty course outline (hard-coded) with a simple xml file which details the text and sounds to be used. The drawback to this is that it extremely limits the author. Different languages may need to start out with learning different parts.
Any advice on the problem at hand as well as the project as a whole will be greatly appreciated. Any links to any relevant resources or information would also be greatly appreciated.
Think you for your time and effort,
Joseph Pond
Simply, you should base your program on a system such as Eclipse RCP, or the Netbeans Platform. Both of these systems already deal with exactly this problem, and both are perfectly adequate for this task. They're not just for IDEs.
It's a larger first step as you will need to learn one of these platforms beyond simply just Swing.
But, they solve the problem, and their overall organization and technique will serve your program well anyway.
Don't reinvent this wheel, just learn one of these instead.
If you are set on doing this from scratch (Will's idea isn't bad), What I would do is first lay down the file format that would be easiest to create your language course in. It could be XML, plaintext or some other format you come up with yourself.
You will probably need some flexibility in the language format because you will want to actually be able to specify things like questions and answers. XML is a pain because of all the extra terminators, but it gives a good amount of meta-data. If you like XML for that, you may consider defining your language file in YML, it gives you the data of XML but uses whitespace delineators instead of angle brackets.
You probably also want to define your file in the language it's created for, so you might or might not want to require english words as keys. If you don't want any english, you may have to skip both XML and YML and come up with your own file format--possibly where the layout and/or special symbols define the flow and "functionality".
Once you have defined the file format, you won't have to worry about hard-coding anything... you won't be able to because it will already be in the file.
Plug-in functionality would be nice as well... This is where your definition file also contains information that tells you what class to instantiate (reflectively) and use to parse/display the data. In that way you could add new types of questions just by delivering a new jar file.
If this is confusing, sorry, this is difficult in a one-way forum because I can't look at your face and see if you're following me or if I'm even going in the right direction. If you think I'm on the right track and want more details (I've done a bit of this stuff before) feel free to leave a follow-up question (or an email address) in a comment and I'd be glad to discuss it with you further.
If I was doing this, I'd seriously consider using Eclipse EMF to model the "language" for defining courses. EMF is rather daunting to start with, but it gives you:
A high-level model that can be entered/edited in a variety of ways.
An automatic mechanism for serializing "instances" (i.e. courses) to XML. (And you can tinker with the serialization if you choose.)
Automatically generated Java classes for in-memory representations of your instances. These provide APIs that are tuned to your model, an generic ones that are the EMF equivalent of Java reflection ... but based on EMF model classes rather than Java classes.
An automatically generated tree editor for your "instances".
Hooks for implementing your own constraints / validation rules to say what is a valid "course".
Related Eclipse plugins offer:
Mappings to text-based languages with generation of parsers/unparsers
Mappings to graphical languages; e.g. notations using boxes / arrows / etc
Various more advanced persistence mechanisms
Comparisons/differencing, model-to-model transformations, constraints in OCL, etc
I've used EMF in a couple of largish projects, and the main point that keeps me coming back for more is ease of model evolution ... compared with building everything at a lower level of abstraction. If my model (language) needs to be extended / changed, I can make the necessary changes using the EMF Model editor, regenerate the code, extend my custom code to do the right stuff with the extensions, and I'm pretty much done (modulo conversion of stored instances).

Using noweb on a large Java project

Has anyone used the noweb literate programming tool on a large Java project, where several source code files must be generated in different subdirectories? How did you manage this with noweb? Are there any resources and/or best practices out there?
Noweb will dump out files relative to the current working directory, or at the absolute path you specify. Just don't use * at the end of your filename (to avoid inserting the # preprocessor directives). I would recommend using %def with # to show where you define and use names.
<</path/to/file.java>>=
reallyImportantVariable += 1;
# %def reallyImportantVariable
noweb lets you reorder and (the real win) reuse snippets of code, which I don't think javac would understand.
I'd agree that since most people expect that you'll use javadoc, you're probably swimming against the stream to use noweb.
Literate Programming works its best if the generated intermediate code can point back to the original source file to allow debugging, and analyzing compiler errors. This usually means pre processor support, which Java doesn't support.
Additionally Literate Programming is really not necessary for Java, as the original need for a strict sequential order - which was what prompted Knuth to write a tool to put snippets together in the appropriate sequence - is not present. The final benefit of literate programming, namely being able to write prose about the code, is also available as Javadoc which allow you to put everything in as comments.
To me, there is no benefit in literate programming for Java, and only troubles (just imagine getting IDE support).
Any particular reason you are considering it?

Java SWIFT Library

I'm looking for a Java library for SWIFT messages. I want to
parse SWIFT messages into an object model
validate SWIFT messages (including SWIFT network validation rules)
build / change SWIFT messages by using an object model
Theoretically, I need to support all SWIFT message types. But at the moment I need MT103+, MT199, MT502, MT509, MT515 and MT535.
So far I've looked at two libraries
AnaSys Message Objects (link text)
Datamation SWIFT Message Suite (link text)
Both libraries allow to accomplish the tasks mentioned above but in both cases I'm not really happy.
AnaSys uses a internal XML representation for all SWIFT messages which you need to know in order to access the fields of a message. And you need to operate on the DOM of the XML representation, there is no way to say "get the contents of field '50K' of the SWIFT message".
And the Datamation library seems to have the nicer API but does not find all errors.
So does anyone know other SWIFT libraries to use?
Have you looked at WIFE? We use that in our application which translates SWIFT messages to an internal XML format and back again. We haven't had any problems with it. Also, it's licensed under the LGPL, so you can hack it up if you need to. Check it out.
SWIFT is releasing a "Standards Developer Kit" which includes an "MT/XML Schema Library".
From the doc:
"The MT/XML Schema Library is a complete set of XML schema definitions for MT messages, and software which shows how to convert messages from an MT format to an MT XML representation and back. This approach allows XML integration between applications while the MT (FIN) format will continue to be transported over the SWIFT network."
Java source code will also be made available, again from the doc:
"Working sample Java source code that converts a message in MT format to an XML instance and from an XML instance to a message in MT format."
See: http://www.swift.com/support/drc/develop/standards.page
This can be a great aid in dealing with FIN messages in XML syntax.
You can combine the open source implementation WIFE with the commercial validation component from http://www.prowidesoftware.com. It validates that the messages you create with the model or XML representation are good through SWIFT network validation rules.
There is a product call Volanté that make a great job. Their solution is certified by SWIFT and the integration is easy ( I sound like I'm working for them ... I'm not). I've been using it since a couple of month .
IBM is also offering a solution (cannot remember to name right now) but then you are committed to the big blue.
If your company is not comfortable with the LGPL license, You might want to check Progress Sonic ESB, or ArtixDS (recently acquired), TIBCO ActiveWhatever or Oracle/BEA Aqualogic. Chances are you are already using something from these companies and you can get decent discount.
Along with jodonnell, we also use WIFE. It works very well. I'm not sure if it does the network validation rules (#2 on your list) though.
paymentcomponents (http://www.paymentcomponents.com/) parser was easy to use and found all errors. Their site definitely needs work but if u look there, u'll find what u r looking for
I can not really help you out with a Java implementation. Microsoft of course, have their own Biztalk adapter for ISO15022 and 20022. And they will actually do the validation fairly well. But as you say you are actually looking for a java solution.
You might find, as I did when I researched this 6 years ago, that mapping FIN messages to XML and then to into objects, a standard library will only get you partly to your goal. You will have to integrate this with your backend application and whatever market practices you face in the particular messages you need to support.
I finally ended up writing a generic FIN parser /150022 class library in c++.
Anyway, good luck. An idea is to be more specific in your question. What types of messages do you need to support?
Datamation's libraries have evolved since then. If you need a corresponding solution in 2021, you can check FINaplo by PaymentComponents (formerly called Datamation), a multi-purpose implementation for financial messages.
It provides online validation/parse/translation/envelope services, Java SDKs, as well as REST solutions, all including error specifications. I am actually one of the authors.
A demo for a SWIFT MT Java library can be found in this GitHub link.

Categories