What is the java equivalent for Perl's require command? [closed] - java

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I am completely new to cgi concepts.
I'm given a task to convert a Perl cgi script to Java program.
I understood that the require 'file.ext' command in Perl includes the file available for code in the Perl script.
Because of the very limited resources and improper documentation I couldn't find any proper info.
Is there any Java equivalent to do the same action that require in Perl does?

The paradigms do not map at all. In Perl, require simply reads a file and runs the code in it, and everything else happens as side effects of that. In Java, your code must be compiled, and classes are included automatically when you compile your program. See Extend a java class from one file in another java file for more answers on this topic.

Related

Can I code a Java program that will call a program in another language (Rust) to do some calculations? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I'd like to make a simulation, but I'd like to write the code to display the state of the simulation and the user interaction (frontend?) in Java (Kotlin actually, but I don't think it is relevant here) for the JVM, and I'd like to write the actual code of the simulation (backend?) in Rust. Mostly because I think it would be neat and that I would learn something.
Can I achieve this, and if yes, how? It might be relevant that the data that needs to be exchanged between the two programs is just a fixed-size array of floats.
Thank you for your help.
A Rust program compiles to native code (executable or shared library). To call native code from Java you have to use JNI: https://www.baeldung.com/jni.
You may find the jni crate useful for the Rust side of the project: https://docs.rs/jni/0.16.0/jni/

How to apply Java patches? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
Basically, I'm looking to find out how to apply Java patch files using Java. So, to sum that up, I need Java code to apply a patch file to a java source file.
Cheers!
There are many ways to extend functionality of the already developed Java application.
You can for example use external non-runnable *.jar files with some extra classes. To do so, you have to first implement proper "uploading" functions in your app, e.g. by using custom ClassPath objects, which is nicely described here, or you can try to use multi URLClassLoaders, which is described here.
There is also another approach, which allows you to call external methods in form of a String, but I haven't tested it yet, altough you can read about it here.

How to execute a .bat file with java program? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
How to execute a .bat file with java program?
Thanks in advance
bat files cannot be converted directly to jar files.
But you can implement bat file logic in a java application, using, for instance Apache Commons Exec and when it is compiled, package it as a jar file.
Do you know the rationale behind the question, the reason why they want you to do it ? Creating a jar requires development in java.
I think you need more information how the final application will be deployed. They probably have additional requirements which made them decide it could no longer be developed in a shell scripting language but requires a real programming language.
Make sure you understand the 'why?' before thinking about the 'how?'.
good luck

How to put normal java code into a website [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
is there any way to put normal java code into a website? i have made a game with DrJava and i would like to put that somehow onto a website, is there a way to do such a thing? like would I have to convert java to javascript or what? this is not an applet and is just written in normal java, and i am no expert in coding. please help
You could always run the Java program from an applet. You might need to sign the applet and take care of permissions if you need filesystem or socket access.
Java has applets. However, like SLaks said Java's not meant for the browser Sun tried early on to make Java the programming language of choice for the web client-side and failed.

Executing Java programs through Python [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
How do I do this?
You can execute anything you want from Python with the os.system() function.
os.system(command)
Execute the command
(a string) in a subshell. This is
implemented by calling the Standard C
function system, and has the same
limitations. Changes to os.environ,
sys.stdin, etc. are not reflected in
the environment of the executed
command.
For more power and flexibility you will want to look at the subprocess module:
The subprocess module allows you to
spawn new processes, connect to their
input/output/error pipes, and obtain
their return codes.
Of course, Jython allows you to use Java classes from within Python. It's an alternate way of looking at it that would allow much tighter integration of the Java code.

Categories

Resources