netlogo in java - java

I need to create a large library to determine turtles' behaviour and need an interface to show the results after they completed their behaviours. Is it possible to run Netlogo in Netbeans ? If possible , does it create problems after a while such as limited reaching to codes ,slows down or anything else?

Actually, you can use the "HeadlessWorkspace" functionality to run NetLogo programs from within a Java program (or unit test). So, using this, you can definitely step through responses from a model within a NetBeans debugging session (e.g. querying reporters).
Please see the following page for the projects' description of this functionality:
https://github.com/NetLogo/NetLogo/wiki/Controlling-API

NetLogo is a Java program which implements both an IDE (Integrated Development Environment) for the NetLogo programming language, as well as a NetLogo interpreter. NetBeans is an IDE for Java (and other languages, but not NetLogo).
So, no, you cannot run NetLogo programs in Netbeans. Netlogo programs only run in the Netlogo IDE.
You are also asking about speed. Yes, a NetLogo program probably runs slower than an equivalent program written in Java. It depends on the specific program.

Related

calling python from java

I need to call some Python code from Java.
I am aware though that Jython exists or that Java has its own Python interpreter.
Thing is, said Python code uses some native (C) compiled code, even runs something on GPU.
So I can divide this into two questions:
Does Jython or Java's Python interpreter support this? That is, the Python code (when called from Java) would run with all the C and GPU parts, thus will run roughly as fast as it would on its own.
If neither of the above mentioned ways support this, is there any other way to do this?
P.S. If that helps, although I suppose it's irrelevant, the code I need to run are highly GPU/C optimized neural networks from Keras (with TensorFlow underneath). I absolutely can't afford to run the only-Python interpreted version.
Currently jython does not support native compiled python modules. In order to run native modules you will need access to a native python(cpython) interpreter from java. There are several open source projects that use JNI to access a cpython interpreter. Three projects that you can look into are JEP, JPY, and JyNI. In regards to GPU access, I only have experience with JEP which I have used with PyCUDA to execute code on the GPU. While I don't have personal experience with tensorflow, I know there are posts on the JEP mailing list regarding using JEP and tensorflow so I believe there are other projects using this combination successfully.

Can you use gems, when you execute a Ruby script in embedded JRuby?

It so happened that I need to unit-test this Ruby script. It's a Sinatra-based web application that uses several gems.
I have more experience in Java than in Ruby, time is very important (and elegance isn't), and so I thought I may be faster, if I execute that script in a JUnit class and mock all subsystems it depends on (web server, database). That way I could use my Java skills to test a Ruby system. It looks like you can embed Ruby in a Java program.
Question: Can I use gems in embedded Ruby, i. e. create a Java program that could execute the tests on any machine (Windows, Linux, Mac) and wouldn't require that I install several gems on it manually? If yes, how?
Note: They need to be real gems, mocks are fine.
Update 1 (25.01.2017 13:14): One obvious solution is to extract the logic of that script into a separate Ruby file without dependencies. That probably would be 80 % of the code. Then I could test that logic file even without having the gems.
I am assuming you are using JRuby. Check this and this out. With this maybe you can do the opposite and use Junit from within Jruby itself.

How does Java differ on different platforms?

I am currently in high school. I was recently browsing the internet looking for what employees in the software industry usually want and what the job requirements are like.
I came accros a job description and one of the requirement is:
Strong, object-oriented design and coding skills (C/C++ and/or Java
preferably on a UNIX or Linux platform)
Note the last part: Java preferably on a UNIX or Linux platform.
I don't understand this. Isn't Java run inside a virtual environment/machine? Why would it matter what OS it is running on since Java cannot directly interact with the OS?
A developer job description may require experience with some OS for several reasons:
First, as you noticed already, there are languages that talk directly to the OS and the code needs to be aware of the underlying OS (like C/C++, which are listed in your job description).
Secondly, even if the programming language abstracts away anything that's OS-specific from you (including the file-system / path separators), you are still going to deploy / configure / run / monitor your applications on top of some OS and you need to know (at least) the basics in order to do that.
For a Java job description, If UNIX/Linux "is a plus", it usually means you're going to run your code on a UNIX/Linux system and you should know how to start a process (your own java app or some application server), how to deploy an application in a container, how to read log files and so on...
While Java the language runs on a virtual machine, the Java library must abstract access to facilities available on the host platform. Ideally, these abstractions are cross-platform, but the devil is in the details—hence the preference for experience on a particular target platform.
Develop once debug everywhere
While conceptually it shouldn't make any difference on what target platform the java code is executed on unfortunately in practice it isn't always that simple but a rather tedious task to get the code running on any platform.
Beginning from easy to circumvent mistakes e.g. using / or \ instead of java.io.File.separatorChar or : / ; instead of or java.io.File.pathSeparatorChar
there are most often problems including methods implemented in native code that often aren't that compatible across different platforms.
It might be even possible your employer is looking for someone to implement native java methods using JNI.
First, you're right in that Java runs inside of a virtual machine - it doesn't directly expose the inner workings of the system to you. However, that doesn't mean that each system doesn't differ in some way under the covers - different flavors of operating systems have different kernels, different ways they think about scheduling, different ways to handle threading, and different interrupt chains (Linux has quite a few signals, whereas Windows has a handful).
As far as Java (the language) is concerned, it runs the same everywhere. How it's actually accomplished is dependent on the native JVM that it's running on.
For this job posting, though, I wouldn't read too much into the UNIX/Linux portion. This is more or less gauging how comfortable someone would be working in a UNIX or Linux environment while programming Java. The majority of IDEs available for Java are cross-platform, but that shop may be using Mac or some flavor of *nix (RHEL, Debian, Ubuntu, etc). It'd also be important to make use of the command line/shell script, since a lot of the convenience of working with UNIX/Linux is on the command line.
Not every shop uses Windows machines to develop on. Just a heads-up.
Java does not differ on different platforms. That is the most highlighting feature of Java ( portability ). The JVM abstracts the underlying platform.
However, platform matters when it comes to a software development, which involves not just the coding part. Mostly in industries, devs work on Linux platform by logging into a terminal. You don't get a GUI as in Windows and a good IDE like NetBeans. So in that case, you should know how to compile and run a java program from terminal.
Example, In linux, In order to create a package, you create a directory ( folder ), say myJava/. You go into it (cd myJava) and write the SomeThing.java file and compile using javac SomeThing.java and you get a SomeThing.class file ( inside myJava ). Now in order to execute this, you need to use the java command. Prior using it, you need to move to the parent directory containing this package. Then execute as java myJava.SomeThing. You wouldn't be knowing this unless you play around in Linux platform. Other things like setting up the classpath etc are also matters of concern

how can we run python script(which uses nltk and scrapy) from java

I have written python scripts that use scrapy,nltk and simplejson in my project but i need to run them from java as my mentor wants to deploy them on a server and i have very less time to do this.I took a glance at runtime.exec() in java and jython, needless to say that running system commands from java doesn't look simple either.
So I would like to know if running the python scripts from java as system command -'python example.py ' using runtime.exec() or alternatively using jython would be more simpler and actually feasible or whether there is a simpler workaround .It would also be great to know if anyone had run python code that uses nltk from java using Jython and whether they encountered any problems.Please help me as I have to do this as asap.Any thoughts and suggestions regarding this are welcome.
Thanking in advance!!
The Jepp project lets you call python scripts from Java. It provides an easy mechanism to pass variables into a script and extract values back. I've used on a few projects with good success

Is there any Python-like interactive console for Java?

I spent a lot of time programming in Java recently, and one thing I miss from scripting languages was the ability to test them in a console.
To quickly test a java program, I have to edit a file, then turn it to bytecode and execute it. Even using an IDE, it loses its fun after the 372 th time.
I would like to know if there is a product out there that features anything like an interactive console (I bet you need a JIT compiler) and some autocompletion (with relexivity, I suppose it's possible).
Maybe that's something very common that I just don't know about or something completely impossible, but its worst asking :-)
Yes; jshell, and before that some close approximations are Groovy, Clojure, Scala, and the Bean Shell.
Funnily enough, you get an interactive console with Jython ! You don't get much more Python-like.
Java REPL
http://www.javarepl.com/term.html
with an intellij plugin:
http://plugins.jetbrains.com/plugin/7215?pr=
Try Dr Java's "Interaction Pane".
JShell is now standard in Java 9.
JShell introduction
An approach that I have used to some degree of success is to debug in Eclipse and use the display view. What the display view gives you is the ability to manipulate the code currently running in the JVM through executing Java statements. Any object available at the particular break point you are stopped at is in scope within the display view. While this isn't exactly what you are looking for it does provide some of the features that a REPL provides for other programming environments. See Debugging with the Eclipse Platform for more information.
You can execute Scala interactive interpreter too.
You may be interested in Groovy.
You can use BeanShell to run arbitrary Java code. If you want Eclipse integration, EclipseShell has BeanShell support.
Jgrasp IDE have a interactive console where you can test in,
i use it a lot, and there is alos a debug view showing variabel etc
efter you have deklare them.
It is opensoruce and you can get a copy att
http://www.jgrasp.org/
// Anders
I've occasionally run into the same problem and have a partial solution. I keep around a file (as Charlie Martin said, Java needs its class contexts) that is little more than a test program. In a second window - a console - I have a script that I run that just checks the modification time of the source file every second or two. When it sees the source change, it re-compiles it (I'm usually fiddling in C, but I've done this with Java, as well) and executes the result.
It's not a great solution, but its a fast one-off and I've found it to be very useful.

Categories

Resources