Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 7 years ago.
Improve this question
I have an app written in Scala and some of my team members want a Java version of it. It is a demo app to use another API written in Scala, and they want a Java version of the app to be able to use the API from Java. However, the app is somewhat large and I don't want to manually rewerite in Java (and they don't want to learn Scala). Is there any tool that will automatically generate (readable) Java code from the Scala code?
they want a Java version of the app to be able to use the API from Java
Scala classes are usable from Java (since it's all JVM bytecode in the end). Can you just package a jar with your classes for them to use?
I don't think it's possible to convert from scala back to standard java since Scala does some pretty low-level byte-code manipulation. I'm 90% sure they do some things that can't exactly be translated back into normal Java code.
No, there is no such tool.
Scala in some sense is a coffescript of Java.
Look how all that funky classes in coffescript are translated to javascript. The same* would be with scala.
I don't think that there is a lot features that can't be translated to Java in any way, but most of the features will be translated to extremely cluttered code, even if the human will do that work.
But there is java to scala translators.
* not saying literally about classes
You have to decompile the .class files to java source files, beware that scala produces many more .class files
You can use javap from oracle included in the sdk or jad decompiler
for detailed explanation read the following article:
Link scala class to java source
Not sure if this would work, but you could run the class files through a java decompiler.
If it works at all the result is bound to be ugly as hell.
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 5 years ago.
Improve this question
Ive been searching for a while and can't seem to find what im looking for. What I want to do is write a python script to report problems and enforce code standards in Java code. Everything I have found so far has been things to translate java into python or python into java and that isn't really what I want. Im looking for a python library that can parse a multi-thousand class project and present the source itself in python in such a way where I can write rules something like
every class must have class level javadoc
every class must have a #primaryContactName tag in class level javadoc
every class must have a #primaryContactEmail tag in class level javadoc
the authorized 3rd party library list is {1,2,3,4,5} are any libraries other than this
list used
all lists and maps fully type safe.
bla bla bla
I reallize that I can get a great deal of this info from javac with very little effort, and I may investigate using javac to make version work, but im looking to do something a bit more advanced where I can build in real analytics
I have done similar with XDoclet in the past, but that was primarily used to mantain metadata in the source code about what systems it was accessing and such, nothing really to this analytics level im looking for now.
Anyone come across a python library that would help out with this? I would consider other languages (java, c, etc) its simply in my current situation, python is easier to work with than anything else.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 4 years ago.
Improve this question
I saw the http://vmkit.llvm.org/ project but it's not quite what I'm looking for. Don't want my code to run on yet another VM but on .NET's and Java's VM.
Are there any compiler backends for LLVM that generate .NET CIL and/or Java Bytecode?
LLVM is on a much lower level than CIL and Java byte code. This means that it is difficult to map the LLVM instructions on to CIL and Java instructions, and nobody has really needed it yet so the work has not been done completely.
Some of the work has been done though. See http://llvm.1065342.n5.nabble.com/JVM-Backend-tp41356.html to see if it is useful to you.
EDIT 2020-09-03: Since this answer was written, WebAssembly has been defined which is essentially a cross platform machine language definition which runs in all major browsers and hopefully soon also natively on Linux and others. I would think that the future would be that everything distributes in this format and then is run on the appropriate virtual machine. This will most likely end the CPU wars.
C++ can be compiled to CIL (with visual C++/CLI compiler), so why not a CIL backend for LLVM?
I don't think it would be so complicated as far as the not .NET specific CIL instruction set
is quite small/simple. Compiling C++ to Java is much more complicated because there are no pointer instructions in Java's bytecode, so a Java's bytecode LLVM backend would be much more complicated.
I guess guys from MONO LLVM backend have already worked on something similar, but it seems they exploited LLVM in a different way because MONO is a C# compiler not a C++ compiler.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 3 years ago.
Improve this question
I am developing for Android under Eclipse. I have some c++ (.h and .cpp) files that I wish to use in my Android application. I have read Programmming in C/C++ with the Java Native Interface and now I know how to make .so file and import it to Android. But the main problem is that:
Is there any tool that converts c++ (.h and .cpp) file to java style files which I can compile and create .so library ? I have heard about JNI - javah and javac can that tools help me and if they can so HOW ?
Edited:
javah is a useful tool that creates a C-style header file from a given class. The resulting header file describes the class file in C terms. Although it is possible to manually create the header file, this is almost always a bad idea. javah knows exactly how Java types and objects map into C types. For example, an int in Java maps to a long in C, and a long in Java maps to a 64-bit value, _int64, in native code. How to use this javah?
Anybody have expiarance of how to use functions that are implemented in .so library in android application ? If anybody have code examples or useful articles links please give.
Thanks in advance !
You don't "convert C++ file to java style". You need to create a JNI wrapper around your existing C++ code. This JNI wrapper is actually C++ code that can be called by Java.
By wrapper I mean that you shouldn't have to modify your existing C++ code base. This wrapper, or better said this binding should generally be very thin. The wrapper code is only meant to expose existing functionalities, not to implement them. It is better to leave the implementation in the (portable) C++ code base.
If the code base isn't too large, then I recommend that you write this wrapper by hand, as explained in The JavaTM Native
Interface
Programmer's Guide and Specification
Now, if you are trying to bind a large library, it may be problematic. So, in regard to tools, I haven't used that, but have a look at SWIG, and the relevant SWIG Java documentation.
According to the homepage description, it's what you're asking for:
SWIG is typically used to parse C/C++
interfaces and generate the 'glue
code' required for [Java, Python, PHP,
...] to call into the C/C++ code.
javah can be useful in certain cases, but it's not what you ask for. It extracts JNI boiler plate code out of native declarations found in Java classes. Regarding javac, it's the Java compiler, that's irrelevant.
When developing for Android you are not limited to using the Java language. Why not use C++ directly? See e.g. the Android NDK.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 7 years ago.
Improve this question
Theoretically this seems possible to me. So can Any one confirm this to me, if it's possible? and if there is such a software that does this?(like Java to C++ or C#)
And in general would it be possible to transfer languages like Java to server-side programing language like PHP?
Translating the syntactical elements of one language and producing another is not trivial but it's not impossible. A good parser can build syntax trees in one language and then emit another. The difficulty of porting code outside the context of simple "Hello World" type applications is twofold:
The libraries of one language will probably differ (e.g. WinForms vs Swing)
Some language features will have to be catered for: (lambda expressions, anonymous methods, different inheritance implementations etc).
It is possible, but the major problem is that Java has a very large runtime library which needs to be made available in the target language in order to be able to do a fully automatic conversion.
For the special case of Java -> .NET, you can use J# from Microsoft to compile it into a .NET assembly which can then be used. Also ikvm.net allows for running a JVM inside .NET.
For PHP I do not believe such a solution exist. You MAY be able to use gcj to create a native library which can be linked in, but I do not believe it is a feasible soultion.
What functionality do you need in PHP?
Visual Studio ships with a Java to C# translator, and even tough it does a pretty decent job, there's still a lot to clean up afterwards.
In my experience you really have to ask yourself if it makes sense to translate code from one language to another. What is the gain? Will the translated code be maintainable? If the answers to these questions point in the wrong direction, translating is probably not the right approach.
Google Web Toolkit does conversion from Java to JavaScript:
http://code.google.com/webtoolkit/overview.html
to answer your question, yup, theoretically this is indeed possible and practically such technology is used every day :)
The interesting thing, in my opinion, is that the Java converters typically convert by taking the bytecode, not the source code. Then it's, say, bytecode-to-ObjectiveC source code. For some converters (at least one opensource one) it's bytecode-to-XML then XML-to-target-language.
For example, the Uniwar application for the iPhone, which has been acclaimed by all and made its way to the appStore's top ten, as been written in Java (JME) and automatically converted from the Java bytecode. Reaching the top ten, even for a few days, means that this is deployed on a lot of machines ;)
In the Real-World [TM], Cobol-Java and, weirdly, Java-Cobol are not unheard of.
For all this to work that said you need a really good converter :)
Theoretically it is possible. But as others pointed out the main problem is to translate libraries.
Some time ago I made Java to Tcl(XOTcl) and Java to Python translators to evaluate the translation posibility. Search by java2tcl and yava2python.
They convert syntax but do not make relevant constructions translations (e.g. Java file operations to Python ones). That would require more development time.
In general my opinion is what such a translation may be possible. But only if your translator covers classes/libraries of the converted project.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 8 years ago.
Improve this question
I use vim as my editor but I would like to get some of the same power of the IDE's for java when it comes to refactoring. Are there any commandline tools for refactoring java? I could probably hack something together using perl or vim scripting but if there is something already out there I'd rather use that.
You could try Eclim. The goal of Eclim is to expose the functionality of Eclipse within Vim. In particular, there are a few commands for refactoring that are supported.
Check out jrefactory, and its command line option.
Code refactoring is a very context-sensitive and interaction-heavy process which doesn't lend itself very well to command-line interfaces. There can be dozens of types of refactorings you could do to a particular file (or set of files) and coming up with a vim interface to integrate all of this would be a major challenge.
If you want IDE functionality, why not use an IDE? Especially with Java, which lends itself so well to automatic refactoring by a complex piece of software like Eclipse.
I would strongly advise you to use VIM within an IDE (e.g. VIMPlugin and Eclipse - this is the combination I use and it works very well).
I used to be a VIM diehard. However the refactoring and code analysis within a modern IDE will far surpass any capabilities that VIM will provide (with plugins etc.).
Don't get me wrong. I love VIM and still use it for all sorts of stuff. Modern IDEs are the most productive route forward, however.
I know this is an older question, but I was asking myself this question a bit back and decided to write one. It's new and it not "super awesome yet" but it's written in GOLANG and it's open source. DISCLAIMER, this is my project but I am not self promoting. I just thought I'd share with others that care about something of this nature.
https://github.com/asharif/ref