Create a program that is usable in Windows

-1

I am a student of programming, still in the first year of my course. So far I have studied Java , C , Haskell and Script Shell . I am fairly functional in Java and C .

I know how to write code, compile and execute on a terminal of Linux , but suppose I want to create an application that runs on Windows . I write my code - in Java , for example - by creating a simple calculator.

After having the code, how do I create an application that can be run in Windows, a so-called "program"?

If it is a very complex process for my degree of competences, please say so soon.

From now on thanks to anyone who tries to help me:)

    
asked by anonymous 23.05.2018 / 18:24

2 answers

2
  

Based on a fairly simple example: create a calculator. After having the code, how do I create an application that can be run in Windows, a so-called "program"?

Assuming you are in Windows and your calculator's classes are located in a src folder, with the com.example.Calculadora class being the main class, you can do this to compile your program into a calculadora.jar file % (assuming your JDK is properly installed):

cd src
dir /s /B *.java > ../sources.txt
cd ..
javac -encoding utf8 -d bin @sources.txt
jar -cfe calculadora.jar com.example.Calculadora -C bin .

If you want to compile in unix / linux, even if you go (or not) use the JAR produced in windows, you can do so (changing only the second line):

cd src
find -name "*.java" > ../sources.txt
cd ..
javac -encoding utf8 -d bin @sources.txt
jar -cfe calculadora.jar com.example.Calculadora -C bin .

To run it in an environment (unix / linux or windows) where a compatible JVM is installed properly , you can double-click on the file calculadora.jar or do this:

java -jar calculadora.jar
    
23.05.2018 / 20:08
4

Programs created in the Java language run on the Virtual Java machine, so they are not stand-alone, they depend on the user having JavaVM installed, it is impossible to run a program written in Java without this.

Compiling a program in C, C ++, etc, will be compiled based on the compiler used, there is no way to run in Windows something that was compiled for Linux, just like it does not have to run something that was compiled for Mac OS X v10.1 run on Mac OS X v10.13 , this is due to the architecture used by both operating systems.

Compiling in Windows generally has compatibility between Windows systems, but depends heavily on the compiler you used and the APIs used to write the code.

So to summarize, if it's Java will run on multiple systems as long as it has JavaVM installed, if C is going to have to compile in architecture by architecture you want to run the program.

Linux generally does not have compatibility between different Linux distros, so some applications are usually distributed in sources and you have to compile with GCC (or other compiler that the distro and / or repositories have), of course there are no guarantees of depends on who wrote the code.

    
23.05.2018 / 18:40