I am trying to open Motorola BLE API library for Android. I am not too familiar with Java so I am not sure if it is even possible.
When I try to open .class file from the library with notepad++ it contains something like:
Êþº¾ and black squares.
Is there a way to open them properly?
You can use the tool javap to disassemble .class files (= compiled Java code) but that won't tell you much.
Try to find the official documentation or the source (= .java files) by googling for the class name instead.
You will need to de-compiler to read the .class files. There are various available in the market, which are open source and free. Here is one
A .class file means that the library has already been compiled into Java's version of machine code, so you won't be able to view it in notepad. There are programs for decompiling class files back into source, but you need to make sure that a) you have the rights to do so, and b) that the particular decompiler supports the class file's particular version of Java.
For more information on decompilers, see this question:
How do I decompile Java class files?
If there source code (.java files) are provided , better use those. If not, then you have to use one of the de-compiler program. But even then if the code is obfuscated , even de-compiler would not be of any use. You have to use just the API documentation for any work.
Java is a compiled language where the source is compiled into machine readable bytecode. You have to disassemble/decompile the bytecode to get it into an even semi-readable form.
Also note that the license of the library very probably forbids you from disassembling it.
If you are really using to use the api in your application then here is the way:
See the documentation of the api that is provided.
Also import the classes in with the import statement. For eg put the classes in a new folder as "api" in current folder and the import statement would be as follows:
import api.*;
Then in the application logic make use of documentation on how to access the library.
Documentation here might help: https://developer.motorola.com/docs/bluetooth-low-energy-gatt-framework-api/
Related
I downloaded class files and jar files. I want to know is there any way to I can certainly get java code of these?
You cane make use of JAD for code de-compilation. Download jad from here.
There are some ways you can do that by using tools like dex2jar. But that will be generated code for the class. if you can, just ask the owner directly about it.
you can use java decompiler too link
Was given a couple of .class files but the .java files weren't sent with and I was hoping to find a way to get the .java files using the .class files. Thanks
You can use a decompiler to do so. One of the most major ones is JD-GUI.
JD-Core is a library that reconstructs Java source code from one or more “.class” files. JD-Core may be used to recover lost source code and explore the source of Java runtime libraries. New features of Java 5, such as annotations, generics or type “enum”, are supported. JD-GUI and JD-Eclipse include JD-Core library.
EDIT (2018-02-23): It seems that JD-GUI is incapable of decompiling bytecode compatible with Java 8+ JREs. This, obviously, changes the utility of my answer.
EDIT (2018-05-24): For replacing JD-GUI, I would recommend Luyten, which can be found here. It's very similar to JD-GUI, but supports Java 8 byte code, itself being based on Procyon.
You can use any of the java decompiler utility for this. There are a couple of few good utilities available over the internet, e.g., JD decompiler, you can also look for the eclipse plugin as well for the same.
To view java content from .class files many decompilers are available.
I'm using JD compiler which is very good.
http://jd.benow.ca/
If you want it for edit/ update puropse, one way is copy + paste from decompilers. Other solutions i'm not aware of.
You can use Jadclipse which is basically a Java Decompiler. It can be used with eclipse integration..
You can use decompiler to get .java files from a jar file or a .class file
I have a jar that I want to take out a class file and add a few lines of code to it. I got class editor, but you can't actually change any code, you can change constants and that is all. I have a program that you can read the source code from a .class but you can't change anything on it. Is there a program or eclipse plugin that you can read and EDIT the source code from a .class file?
Have a look at decompilers. They'll transform the java-bytecode back to source code. One example of such a compiler would be JD: http://jd.benow.ca/
After editing the source code you would have to compile the code again and pack it in the respective .jar file.
If your file is an old enough version, you can use jasper to disassemble it into bytecode, edit the bytecode and reassemble it using jasmin. Unfortunately these tools have not been updated in some time.
They do not produce Java code; you'll have to learn Java bytecode. But it is more reliable than the so-called "decompiler" methods.
As Java .class files are in byte-code format, you cannot modify them the way you would edit a .java source file. Bytecode is a low level language closer to the machine language rather than Java itself.
If you need to modify the source, one option is to use a decompiler, e.g. JAD (Java Decompiler), to get a source file and then change it and recompile to .class using javac. Make sure you figure out which version of Java language (1.4, 5, 6, 7, 8) has been used for the original jar file.
What you need for this is a java de-compiler. This will take the bytecode out of your class file and convert it back to its source. From there you will need to recompile the .java files that the de-compiler produces.
Here are some java de-compilers that I have seen:
http://dcompiler.sourceforge.net/
http://jd.benow.ca
I've been provided some external JAR libraries for a project I'm doing. I can access the compiled code but I can't really understand it as its not in the form I'm used to seeing. Any tips on how to 'de-code' and understand what's going on?
Thanks
Search the net for Java Decompilers (e.g. JAD). What you see in a jar is Java-Classes, i.e. the result of compiling .java files.
There are decomiplers you can use them to de-compile .class to .java. We are using JD Java decompiler.
NOTE: I think De-compilation (or) modifying de-compiled code is illegal in some countries. Be aware of it.
You could use a decompiler like JAD to decompile from .class file to .java files, but in my experience its use is quite limited
Try Java Decompiler (Yet another Fast Java decompiler) : http://java.decompiler.free.fr/ .
It can decompile your compiled library.
JAD is only supported up to 1.3.
There should be a documentation and/or source jar that you can attach to your IDE, which will allow you to access the documentation.
If not, you have to decompile it.
Keep in mind that it might be ok to treat this jar as a black box.
Does anyone know if it's possible to convert a String/file into java source which can be compiled at run time using something like JavaCompiler. It looks like this is possible with Java 6, but I haven't seen anyone say that JavaCompiler is available in Android.
Basically my main goal is to turn a String or file text into source code in Android. Does anyone know how that can be done?
Thanks!
Android runs Dalvik not Java 6. JavaCompiler is not included in standard Dalvik distribution, so you cannot use it. Dalvik runtime is designed for embedded system as such it is less dynamic, compiling code on the fly is one of the things that it is not supposed to do.
Try what Hyangelo suggested, or Google for other scripting libraries. Clojure for example. ;)
You could do something advanced and setup a web service to compile source for you. This service would accept java source, compile it into a dalvik compiled class and return it as a binary.
This binary could then be added to a custom class loader as described here: http://android-developers.blogspot.com/2011/07/custom-class-loading-in-dalvik.html
Although you are not compiling on the phone, this would be compiled during runtime and, once inserted into your classloader, available for execution.
Technically possible, but not easy. If you look at Terminal IDE they package in all the tools to compile Android byte code from source on the device. You could take a similar approach by writing out the string to a file on disk, compiling it, and then use DexClassLoader to load the classes from the compiled JAR file or APK.