Language - Java macOS Javac: Difference between revisions

From Phidgets Support
No edit summary
(Redirected page to Language - Java)
 
(6 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{NoTitle}}
#REDIRECT [[Language - Java]]
{{Language_-_Java_Dev_Environment_Table}}
{|
|style="vertical-align:middle; width: 60%;"|
<font size=6>'''Language - Java'''
 
'''MacOS with javac'''</font>
 
Welcome to using Phidgets with Java! By using Java, you will have access to the complete Phidget22 API, including events.
 
javac is a command line-based compiler for java programs that compiles java code into bytecode class files.
|{{TOC limit|2}}
|}
 
{{Language_-_Java_Intro|macOS|javac}}
#You will need a copy of [{{SERVER}}/downloads/phidget22/libraries/any/Phidget22Java.zip phidget22.jar]
 
==Use Our Examples==
One of the best ways to start programming with Phidgets is to use our example code as a guide. Before we get started, make sure you have [[#Install Phidget Drivers for macOS | installed the Phidget drivers]].
 
 
Next, select an example that will work with your Phidget:
*{{SampleCode|Java|Java Examples}}
 
 
Place both the example file and the phidget22.jar file in the same location. Your folder should now look something like this:
[[Image:Java_mac_javac_folder.png|link=|center]]
 
 
Open the terminal at the folder location. Next, enter the following command:
 
<syntaxhighlight lang="java">
javac -classpath .:phidget22.jar example.java
</syntaxhighlight>
 
 
Finally, enter the following command to run the program:
 
<syntaxhighlight lang="java">
java -classpath .:phidget22.jar example
</syntaxhighlight>
 
 
[[Image:Java_mac_javac_run.png|link=|center|850px]]
 
 
{{Edit_the_Examples}}
 
==Editing the Examples==
{{Language_-_Java_Editing_the_Examples}}
 
==Write Code==
{{Language_-_Java_Write_Code}}
 
==Setting up a New Project==
When you are building a project from scratch, or adding Phidget functionality to an existing project, you'll need to configure your development environment to properly link the Phidget Java library.
 
Create your new project folder and java file, and place phidget22.jar in the same folder as your new project file. Your folder should look something like this:
 
[[Image:Java_mac_javac_newproject_folder.png|link=|center]]
 
To use the Phidget Java library in your program, add the following import to your code:
<syntaxhighlight lang="java">
import com.phidget22.*;
</syntaxhighlight>
 
Once you are ready to run your program, open the terminal at the folder location. Next, enter the following command in the command prompt:
 
<syntaxhighlight lang="java">
javac -classpath .:phidget22.jar example.java
</syntaxhighlight>
 
Finally, enter the following command to run the program:
<syntaxhighlight lang="java">
java -classpath .:phidget22.jar example
</syntaxhighlight>
 
[[Image:Java_mac_javac_newproject_run.png|link=|center]]
 
The project now has access to Phidgets.
 
==Further Reading==
{{Language_-_Java_Further_Reading}}

Latest revision as of 16:38, 15 March 2021

Redirect to: