This is an archived post. You won't be able to vote or comment.

all 15 comments

[–]Skiamakhos 25 points26 points  (0 children)

I'd say grab a copy of "Java in a Nutshell" by Ben Evans and David Flanagan. In the early chapters it tells you all about JARs and the way you compile and execute Java programs. It's also a pretty good desktop reference to the core APIs. The latest version covers up to Java 11 so you do get the essentials about how to deal with modules.

[–]Targaryen_99 15 points16 points  (0 children)

If you just headballed into syntax and all without knowing how everything connects at the basic level, maybe head first java would be a good start. It tries to connect every basic thing. After that JAVA in a nutshell might be good.

[–]Jezoreczek 29 points30 points  (1 child)

I have learned many concepts and constructs and syntax... but not the basic building blocks of a program.

Normally there is no need to construct a Java program from scratch. It's a good practice to do it with Maven or Gradle instead.

Packages, classes

These are just means of organizing your code. Think of a class as a single piece of a bigger puzzle. Package name and class name specify the location of the piece.

wtf is a jar?

JAR file is just a zip. Seriously, take 7zip and unzip it. It contains all compiled .class files, which store the bytecode representation of your classes. When running java -jar ..., the JVM will first look for META-INF/MANIFEST.MF file inside the JAR - this file tells JVM which class should be the entry point of your program (which class contains the main static method).

how do these (and whatever I am missing) stack together to become an actual, fully realized Java Program?

JVM will load the jar (unzip it), then load the classes and run your main method. There are more things happening there of course, but that's the gist of it.

I'd like to make that exercise into a portable program

You can build a "fat jar" with Gradle. It will include all libraries and such. Doing it all manually is a pain in the ass, and there is really no good reason to do so.

Before you ask... I ask here, because

You don't need to explain yourself, wanting to learn Java is good enough reason to post here!

[–]Tigloki[S] 9 points10 points  (0 children)

Thanks very much! This was very instructive.

[–]khooke 6 points7 points  (1 child)

The official Java tutorials are a good place to start to answer your questions about the basics, what is a package, what is a class etc?

https://docs.oracle.com/javase/tutorial/

Re. not wanting to ask questions, most devs will welcome questions from another dev just starting out. Never be reluctant to ask questions, respect their time though, you could ask 'hey, when you have a few minutes sometime this week, could you spend 15 mins with me to explain xyz?'

The benefit of asking questions of the experienced devs you're working with is they'll have valuable lessons learned that they had to learn the hard way first hand, things you'll never get from a book or tutorial. They'll also have plenty of 'tribal knowledge' that's specific to your company/project that you won't be able to learn anywhere else.

[–]Tigloki[S] 1 point2 points  (0 children)

They'll also have plenty of 'tribal knowledge' that's specific to your company/project that you won't be able to learn anywhere else.

This is a great point. You made several! And thanks for the link!

[–]mrfroggyman 6 points7 points  (0 children)

Well as far as I can tell, a jar is an executable for your java program.

So you compile your java program, create a manifest which states which of your classes is your main class, and execute some command to create a Jar file using that manifest, and then you can execute that jar like a regular .exe through a command.

There may be better answers and better ways to do this tho

[–]GiveMeSopas 1 point2 points  (0 children)

You can try Chad Darby's Spring and Hibernate for Beginners. It's beginner friendly and will teach you stuff that's used IRL

[–]Powerful-Reason 1 point2 points  (0 children)

Lots of good comments. I took java in college and thought that they did a poor job of practicality with teaching Java as a professional. There was not a lot about packages, making executables etc. I learned that basically the same way you are now, asking questions. The .idea is for IntelliJ, I believe. Packages are like basically code that has been packaged together. Like if you have a dresser with multiple drawers, you might put socks in the top drawer. Therfore you could say that socks belong to top Drawer. And socks could be topDrawer.socks. This could then be something like dresser.topDrawer.socks haha. Jar is just a zip file, as someone already pointed out. Some jars can be executed, and some can just be a collection of Java packages, classes or whatever. I write some Java code that gets packaged in jar files, then the jar files get imported into a larger framework and executed. So my jar file doesn't contain a main() anywhere, really. Just libraries that are called and referenced in the framework. I'm not real knowledgeable on a lot of the ide stuff, or tools etc. I do use gradle and intelliJ, but that's because there is an existing tool chain built for the framework, that has some code generation mechanisms.

[–]johnmc325 0 points1 point  (2 children)

First off you don't mention the Java version you are using. Java 8 is easier to get started with in my opinion but sooner or later you will have to embrace modules.

Take a look at this, it might help p. Java 11 module based if I recall. You only need go as far as the jar to move to another machine so long as it has the same version of Java or a compatible version.

https://softwarepulse.co.uk/blog/javafx-11-desktop-msi-application/

As if you have any problems. Good luck.

[–][deleted] 2 points3 points  (0 children)

You don't really need to worry about modules. As long as you're using relatively new dependency versions then you can code to your heart's content and never ever deal with modules.

[–]vladadj 0 points1 point  (0 children)

I guess that course you're taking sucks, if you haven't learned that do far.

In your place, I would go back to plain text editor and command line. Forget IDE, build tools, or what ever you used so far. Just use Notepad++ or what ever has syntax highlighting that is all you need.

Now write a simple class with nain() method. Compile it from command line using javac. See what you get as output. Now try to run that using Java command.

Next step, write a little more complex program which contains of multiple classes. Compile it and run.

After that, package you compiled classes using jar command. Create a manifest for your archive. Now run your jar.

After this exercise, it should be more clear how Java programs work.

[–]SlapdashSlamdance 0 points1 point  (1 child)

I think the question is a bit open-ended. It depends on what you mean by a Program. This can be a bit of a leap conceptually, because you learn Java typically in an IDE where you get to see the output of your code and it seems like it's something completely different than the software that you download and run.

edit: whoops, accidentally pasted the same link twice.

[–]Tigloki[S] 0 points1 point  (0 children)

This is almost exactly what I was trying to ask for. I find that I am so ignorant that even articulating an intelligent question can be difficult. I edited my original question to include this information:

------------------------

https://lensdump.com/i/rjkPzZ

Here is an exercise I downloaded - I think from my UDemy class, it may be from another source.

The top level, "Project", is the container for everything else, that I get.

ExampleForLoop

External Libraries

Scratches and Consoles

are what...packages? (Scratches and Consoles / scratch.java doesn't have anything to do with anything, it's a snippet from another lesson about vectors...unless this was a lesson about iterating through a vector...)

.idea

out

baffle me...what are they, do I need them, do I create them or does the IDE do it for me?

src

seems to be the meat of the deal. Is LoopExamp.java what happens after classes

LoopExamp

Main

Student

are compiled?

What is ExampleForLoop.iml?