Opening and operating programs in java on a mac

In summary, the conversation discusses the use of Java on a Mac and the possibility of opening other programs like TextEdit or the Terminal from a Java program. The Runtime class has exec functions that can be used for this purpose, and there are multiple ways to run external programs from Java. However, the issue of permission denied may arise, which could be due to the operating system rather than the Java Virtual Machine.
  • #1
Yoyo_Guru
33
0
I started taking a java course at my school and we are required to use macs. I looked for how to open other programs like text edit or the terminal but the code segments I found only worked for java. Is it possible to have a java program open other programs like text edit or the terminal on a mac? And if so how?
 
Technology news on Phys.org
  • #2
Yoyo_Guru said:
I started taking a java course at my school and we are required to use macs. I looked for how to open other programs like text edit or the terminal but the code segments I found only worked for java. Is it possible to have a java program open other programs like text edit or the terminal on a mac? And if so how?

I'm not entirely sure what you're asking here. You mean you want to launch some external program from Java code?

If so, the Runtime class has exec functions that can do that:

http://download.oracle.com/javase/6/docs/api/index.html

There's so many ways of doing it. And exec isn't always the best way, but it might be what you're looking for.

I found a page with a rather large number of different ways to run external programs from Java:

http://www.rgagnon.com/javadetails/java-0014.html

Not sure why you want to do that in this case, but that's up to you. :smile:
 
  • #3
ok, thanks. I got a little farther but everytime I run it I get an error saying permission denied. Do you know how to get around this? Also some of the terms used on the site confused me so I kinda had to guess. Here is what I wrote, maybe I just wrote something wrong.

Process p = new ProcessBuilder("/Applications/Skype.app", "myArg").start();
 
  • #4
Yoyo_Guru said:
ok, thanks. I got a little farther but everytime I run it I get an error saying permission denied. Do you know how to get around this? Also some of the terms used on the site confused me so I kinda had to guess. Here is what I wrote, maybe I just wrote something wrong.

Process p = new ProcessBuilder("/Applications/Skype.app", "myArg").start();
Keep in mind that the "myArg" means you're passing the application an argument of "myArg". That was just a placeholder in the example in the docs. Unless you're trying to pass that as a parameter (don't see why), you can just remove it.

As for the permission problem, I'm not entirely sure. I assume you caught an IOException? I would guess that it's your operating system and not the Java Virtual Machine (but I could be wrong). As for how to fix it, I'm not totally sure. Someone who knows Macs will have to chime in here. There's probably some way of giving the application permission to launch Skype, but I personally have no clue how to do it on a Mac and would be reaching.
 
  • #5
Alright, thanks a lot.
 

1. How do I open a Java program on my Mac?

To open a Java program on your Mac, you can either double click on the program's icon or right click on the program and select "Open". You can also use the terminal to navigate to the program's directory and use the "java" command to run the program.

2. Can I run multiple Java programs at the same time on my Mac?

Yes, you can run multiple Java programs at the same time on your Mac. However, the performance of each program may be affected depending on the resources available on your computer.

3. How do I check which version of Java is installed on my Mac?

To check the version of Java installed on your Mac, go to "System Preferences" and click on "Java". Then, click on the "General" tab and select "About". The Java version will be displayed in the pop-up window.

4. Do I need to install any additional software to run Java programs on my Mac?

No, Mac computers come with Java pre-installed. However, if you want to develop Java programs, you may need to install the Java Development Kit (JDK) from the official Java website.

5. How do I close a Java program on my Mac?

To close a Java program on your Mac, you can either click on the "X" button on the program's window or use the "Command + Q" shortcut. You can also use the terminal to find the program's process and use the "kill" command to terminate it.

Similar threads

  • Programming and Computer Science
Replies
9
Views
1K
Replies
3
Views
222
  • Programming and Computer Science
Replies
1
Views
321
  • Programming and Computer Science
Replies
6
Views
1K
  • Programming and Computer Science
Replies
2
Views
1K
  • Programming and Computer Science
Replies
8
Views
3K
  • Programming and Computer Science
Replies
19
Views
3K
  • Programming and Computer Science
Replies
7
Views
659
  • Programming and Computer Science
Replies
15
Views
1K
  • Programming and Computer Science
Replies
1
Views
1K
Back
Top