Create a Java program WITHOUT some fancy IDE

How to create a JAVA application WITHOUT the use of a Commercial IDE

Recently I decided I was bored and needed to learn something new. So I decide to try JAVA seeing as that was the Language that many others on this forum had chosen.

But unlike everyone else here. I wanted to learn from the ground up, and not rely on some fancy IDE.
Or I wanted to learn ‘Long Division’ before buying a calculator.

It took me hours of research, and consultations with both Norman and Thorsten. Before I was able to ferret out a series of steps the worked. So here is ONE approach. If anyone has alternative syntax or steps feel free to let me know.

NOTE : These steps are specific to macOS, but should be “mostly” the same for Window/Linux

Step 01
Decide on the NAME for you application [we will use ‘FOO’ here]
you should of course select a name that is appropriate for your project

Step 02
Create an empty directory structure with the name of your application [FOO]

Step 03
write your java source using your favorite Text Editor
[IMPORTANT… each file MUST use ‘.java’ as the extension]
store these files in the FOO directory
Note : the hows and whys of the actual Java programming language syntax can be found elsewhere

Step 04
execute TERMINAL
navigate to the FOO directory you created above
compile your Java Source using this command

javac -classpath . *.java

This tells java to compile ALL *.java files located in the current directory [-classpath .]

use javac --help if you want to see more compiler options

Step 05
in your favorite text editor create a file named ‘MANIFEST.MF
Edit this file and insert the following lines

IMPORTANT! this file must contain no addtional whitespace, there are no spaces BEFORE the “:” and only ONE after it, and the file MUST end with a Linefeed

Main-Class: XXXXX

Replace XXXX with the class name from one of your .java files that is “main”, see example below

Step 06
create a JAR file from everything… a JAR is a Java ARchive

jar -cmvf MANIFEST.MF foo *.class

Step 07
Execute your new Java program using

java -jar foo

Example :

Create a Directory named “OldMac”
copy these 3 files

File #1 - name OldMacDriver.java

 public class OldMacDriver {
      public static void main( String[] args ) {
           OldMacCow maudine = new OldMacCow();
           OldMacCow pauline = new OldMacCow();
           maudine.moo();
           pauline.moo();
  
           OldMacDuck ferdinand = new OldMacDuck();
           ferdinand.quack();
      }
 }

File #2 - name OldMacCow.java

public class OldMacCow {
   public void moo() {
      System.out.println("Cow still says moo.");
   }
}

File #3 - name OldMacDuck.java

public class OldMacDuck {
   public void quack() {
      System.out.println("Duck still says quack.");
   }
}

here are our “steps”
Step 01 - name of our App is “OldMac”

Step 02 - we created our directory

Step 03 - we added 3 .java source code files

Step 04 - go to terminal, CD to “OldMac” and execute
javac -classpath . *.java
this will create a .class version of each .java file

Step 05 - create a file called 'MANIFEST.MF" with the contents

Manifest-Version: 1.0
Main-Class: OldMacDriver

NOTE : ‘OldMacDriver’ is the class named in our 1st Java file above

Step 06 - create a JAR file using

jar -cmvf MANIFEST.MF OldMac *.class

Step 07 - Run it

java -jar oldmac

Output should be

Cow still says moo.
Cow still says moo.
Duck still says quack.

Note… this is a SIMPLE example… and I’ll be honest , if there are issues, I may or may not be able to help… I myself have just started to learn all of this

But I hope this helps

6 Likes

Very cool “getting under the hood” … so to speak. Thank you for sharing! :slight_smile:

What will the Goat say ? :grin:

Nothing while something he needed to eat when programming the example…

I don’t see any goat

Bah !
:stuck_out_tongue:

Uuuups :slight_smile:

I No!
Dave is way too smart to fall in to my not so cunning trap.

But my question does highlight the programers problem of spelling the difference between Goat and Sheep sounds.
:innocent:

or Goal ?

The difference is 1 character… (or the small horizontal crossing…

The only question I have: why should I do it without IDE when all IDE`s are for free entirely (IntelliJIdea CE, Netbeans, Eclipse)??? I did not get the goal of it.

The goal is EDUCATION. learn to add and subtract before you buy a calculator.

Besides… If and IDE were meant to be the ONLY way to do things, why does this other way even exist?

Just because you are an expert in Java with all the fancy tools, doesn’t mean that everyone wants to do it YOUR way.

At the end of the day… I prefer Swift, you prefer Java… my way isn’t the only way, nor is yours,

Freedom of choice, Freedom to learn things using alternative methods.

:man_facepalming:

I give up!

That isn’t an answer. I know that I can edit Java even with text editor and compile with JavaC. The Goal of the IDE is helping the programmer with code completion, JavaHelp and so on. I always thought and saw that learning Java was less painful using the IDE with switched on Java doc showing within Coding. It is, you are completely right, possible and if you prefer it, also your way of doing it. But I do not know and I can’t decide anyhow if that is the deeper way of learning.

For IOS I prefere also XCODE where I was building a complete infrastructure around my Java Solutions to have native compiled applications made by Xcode Compiler. And I believe that is the best way doing that.

While you prefere Swift you are writing almost only native for Mac. I have not even the chance doing that cause the most Apps I am writing have to be available for IOS and Android, the Desktop-Apps have always to be available at least for Desktop and Mac. So I even have no chance of using Swift what is really nice Solution in my eyes. Yes, you’re right.

@thorstenstueker , yes it IS an answer… because that is EXACTLY why I wrote this. You don’t have to agree… and this post wasn’t directed to people like you. It was directed to others like myself, you like to know WHY/HOW things work. So you continue using Java in the most productive whay you know, and give others the chance to start at the beginning and DECIDE FOR THEMSELVES…

1 Like

Exactly that chance I leave everybody. The only thing I was mentioning is, that starting with IDE and JavaDocs showed within coding live can be possibly especially for a beginner easier than without. It is everybody’s own choice what and how and where to start and to learn. Yours is that: okay. But I was telling exactly because of this that possibly the IDE could help. Not more. Not less.

When things work correctly, the IDE way is an easier way to learn the language. But in a lot of Java examples, something often doesn’t work quite like it should and it won’t compile. I don’t know if it’s a version thing, a helper app thing, or what…but then I’m completely out of luck because I don’t know what all the IDE was shielding me from. It’s not the language I’m having a problem with, it’s everything else. I appreciate the “from scratch” method for this, and plan to go through it over the holiday break.

I tested in IntelliJIdea 2021.3, Netbeans 12.6 and Eclipse:

I get all Errormessages I get using command line or VSCode. So I am to stupid to get.

No.

You simply Think Different

Emile, I have no Idea. My thinking is that learning is on it’s best way when using an IDE which gives me in all cases an advice where my error is and which contains also within the coding all the documentation. That has nothing to do with fancy. Nobody would come to the conclusion that Swift UI or Xcode should be made without IDE. Java is not that simple and especially using Stuffs like Maven are really complex to do without IDE. But, like I said: maybe I am to stupid to get what is better on not using an IDE.

1 Like

When my now-grown daughter was a toddler, I taught her well. After going through the standard menagerie, one could ask her “What does the Robot say?” At which she would thrash her arms and shout “Danger,Danger!”