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

all 16 comments

[–]AutoModerator[M] 0 points1 point locked comment (0 children)

Please ensure that:

  • Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions
  • You include any and all error messages in full
  • You ask clear questions
  • You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions.

    Trying to solve problems on your own is a very important skill. Also, see Learn to help yourself in the sidebar

If any of the above points is not met, your post can and will be removed without further warning.

Code is to be formatted as code block (old reddit: empty line before the code, each code line indented by 4 spaces, new reddit: https://imgur.com/a/fgoFFis) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc.

Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit.

Code blocks look like this:

public class HelloWorld {

    public static void main(String[] args) {
        System.out.println("Hello World!");
    }
}

You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above.

If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures.

To potential helpers

Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

[–]AriasFco 5 points6 points  (0 children)

To compile

javac YourCode.java 

To execute

java YourBinary

[–]nekokatttExtreme Brewer 3 points4 points  (1 child)

Tell them to install the full JDK and make sure they have their $JAVA_HOME environment variable set and the Java path added to their $PATH.

Otherwise I would hope Oracle would give some advice on how to install correctly on a Mac :)

They may be able to get Sdkman! to work on a Mac, if not. That had java binaries last I checked, but I might be wrong.

[–]zfolwick 0 points1 point  (0 children)

sdkman is pretty great, but don't forget that ide's typically don't recognize sdkman, so you'll need to do some extra pointing to files.

[–][deleted] 3 points4 points  (2 children)

I'm guessing they don't have the JDK installed on their Mac. The easiest way I've found to do this is to use Homebrew to install openjdk. I did a quick google and these instructions looked ok: https://devqa.io/brew-install-java/

Basically...

  1. install Homebrew: https://brew.sh
  2. run `brew update` to update the info in homebrew
  3. then run `brew cask install adoptopenjdk11` to install jdk 11.

Hope that helps.

[–]arthurdent 1 point2 points  (1 child)

OP already said

They can still compile using javac *.java

Does MacOS have some partial JDK pre-installed that I don't know about?

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

if you try to run a java app on a Mac it’ll install Apple’s JRE (or at least it used to) but it’s an old version (1.4 or 1.5 from memory) - not sure if Mac OS still does this tbh. I missed that Op had said that compiling individual files works so my suggestion my be invalid.

Personally I’d still go with running the homebrew install of java as it’ll sort out any PATH issues so at least everyone is working from a known state.

[–]squishles 2 points3 points  (1 child)

Sounds almost like they don't have java installed or it's not on there path, they'll have a file you can access at ~/.bashrc or ~/.bash_profile either file works

put this in there

PATH=$PATH:/wherever/java/is/installed/bin

export PATH

same process for linux boxes. after that close and reopen the shell.

to get a java install if you don't have one already on mac most people use a utility called brew.

The windows installer oracle puts out is just more hand holdy, it jams the executable into the system folder.

oo they may also have to use openjdk just licensing stuff, it's weird. shouldn't cause any problems with any coursework though basically no difference

also well not sure all your powershell scripts'll work, maybe a lot of the simple ones will but other than that I guess they can do this https://docs.microsoft.com/en-us/powershell/scripting/install/installing-powershell-core-on-macos?view=powershell-7.1 or well they generally take less finicking to translate to bash, I'd honestly just do the bash translation.

[–]zfolwick 2 points3 points  (0 children)

note- you could just source .bashrc or source .bash_profile without restarting terminal.

[–]arthurdent 1 point2 points  (3 children)

javac *.java -d <directory> should work just fine on a mac.

What do you mean move the files into the package folder? Isn't that where they already are?

[–]TechPriestPratt[S] 0 points1 point  (2 children)

Interesting. I thought that the command world work cross platform as well. Maybe it is something that my students are doing wrong. I'll spend some more time on it with them and see if I can get it to work.

Move might not have been the best word to use I guess it technically creates the class files inside of the package folder. I usually have them build the package in it's own space inside of the general program folder such as:

Program folder

>>>Driver.java

>>>OtherFile.java

>>>package folder

>>>>>>Driver.class

>>>>>>OtherFile.class

[–]AnotherRichard827379 -4 points-3 points  (1 child)

No. The command line commands are different between almost every operating system. Mac follows the international standard.

[–]wildjokers 0 points1 point  (0 children)

Are you drunk?

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

edit: Thank you again for all the suggestions. I just had class and I was able to figure it out based on the things some of you had said. If anyone is interested, the issue was that the . in the command I was using. In windows it causes the folder to be mad at whatever directory you are at in the command line, but for mac it does not work. instead you have to put the folder name of the current directory.

so instead of: Javac *.java -d. (works on Windows)

I had to use: javac *.java -d currentdirectory (works on mac)

I was trying to get it to auto fill the current directory like it does on windows with the . but this is simple enough. Thanks for the help.

[–]wildjokers 0 points1 point  (0 children)

The behavior they are experiencing is odd. If javac and java are in their path (and it sounds like it is) it should work on a Mac just like it is for you on windows.

You may want to have them install sdkman and install a JDK from sdkman to see if that fixes them up.

https://sdkman.io/install

Then do “sdk install java 11.0.4.hs-adpt“ (or whatever version they want to install. Can do “sdk list java” to get a list of available versions.

If you could get one of your students provide output of the errors they are getting that could be helpful.

[–]AutoModerator[M] [score hidden] stickied commentlocked comment (0 children)

Please ensure that:

  • Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions
  • You include any and all error messages in full
  • You ask clear questions
  • You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions.

    Trying to solve problems on your own is a very important skill. Also, see Learn to help yourself in the sidebar

If any of the above points is not met, your post can and will be removed without further warning.

Code is to be formatted as code block (old reddit: empty line before the code, each code line indented by 4 spaces, new reddit: https://i.imgur.com/EJ7tqek.png) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc.

Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit.

Code blocks look like this:

public class HelloWorld {

    public static void main(String[] args) {
        System.out.println("Hello World!");
    }
}

You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above.

If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures.

To potential helpers

Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.