How to setup Princeton cos 126 development environment? - java

I followed all of the steps for setting up the development environment from the following website:
enter link description here
However, when I compile/run code (from the terminal) I have to use a different syntax than what I see in the textbook.
Example:
My Code:
`
javac -classpath ".\path\to\library.jar;" MyCode.java
java -classpath ".\path\to\library.jar;" MyCode`
Textbook Code:
The issue arises when I have to write code with the StdLib lilbrary. I can get the code to run, but only with a long complicated --classpath option at the end. I don't know what I've installed wrong but, it's really bothering me that I can't figure this out. Any help would be appreciated.
Thank you.

Related

Javac will not run despite Java being installed

While I have some experience in Python and JavaScript, I am new to Java and am trying it out for the first time. To get started, I went to http://www.java.com, downloaded the dmg there, and then used the package it gave me to install Java. After doing so, I received confirmation that Java had been installed successfully and I closed and trashed the dmg and package. Afterwards, I hopped on my terminal (I am using a Mac running on MacOS Monterey) and tried to use javac on a script I wrote. I received the following error message:
The operation couldn’t be completed. Unable to locate a Java Runtime that supports javac.
Please visit http://www.java.com for information on installing Java.
I went online and did some typical troubleshooting searches. First, I found a site suggesting that I create an environment variable $JAVA_HOME and set it equal to $(/usr/libexec/java_home) in .zshenv (yes, I use zsh not bash). I followed this instruction and when I run echo $JAVA_HOME I get /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home. However, running javac still did not work.
Once more, I went online and this time, I found the suggestion of adding javac to $PATH. So I went into .zshenv and added usr/bin/javac to $PATH (the $PATH export line now looks like this: export PATH="/Users/[redacted]/Library/Python/3.8/bin:/usr/bin/javac:$PATH"). This alteration was confirmed when I exited an reentered terminal and ran echo $PATH. However, once again, running javac yielded the same error.
I feel as if I am facing what must be a pretty common and easily fixable issue, but yet, I haven't yet been able to find a solution that works despite perusal of several other StackOverflow posts and tech articles. Still, I know I'm probably missing something simple, and if this is a duplicate of another question, please link that question in a comment, and I'll take this one down.
Thanks!

Visual Studio Code: Java code does not run at all

I am new to this world of programming.
I started like one week ago so I am a complete noob.
I have written some very basic java code but every time I press "run code" it spits out an error message.
It says "The command "javac" is either typed wrong or could not be found".
"exited with code=1 in 0.015 seconds"
What exactly is the problem and how do I solve it?
My code is free of typos and nothing is shown as wrong or incomplete.
I have tried to correct the java path in settings but that did not change anything at all.
The message is clear: VS code does not find javac.
It needs javac to compile your java source code.
As a start, see if you can do that manually: open a console, "cd" into the directory with the source code, and run javac WhateverClassYouHave.java to see if that works.
You might have for example only installed a JRE, not a JDK. Then you have java (the Java virtual machine), but not javac, the java compiler.

How can I run an example in cloudsimSDN?

I can't run the CloudSimSDN via cmd (Command Prompt) and I can't run that via eclipse, too.
I installed eclipse 4.6.0, JDK 1.8.0. The cloudSimSDN needs CloudSim-3.0.3, apache Commons Math, json-simple-1.1.1 and guava-17.0.
I have given below the errors. Could you tell me know what needs to be done?
When I try to execute the example using the following command:
java -cp ./*:. org/cloudbus/cloudsim/sdn/example/SDNExample MFF dataset-energy/energy-physical.json dataset-energy/energy-virtual.json dataset-energy/energy-workload.csv > results.out
java -cp ./*:.This code needs to be write in special directory? Or -cp ./*:. is a special switch in java?(please explain about it. I am beginner in cloudsim, Help me please.
Below are the error codes:
Could not find or load main class org.cloudbus.cloudsim.sdn.example.SDNExample.
My reference of source code: CloudSimSDN
please go through steps mentioned here at tantrabhavan.blogspot.com. It worked for me!!!!

Running a java program using -cp

so I've checked many posts here and tried everything people suggested and I'm still getting "Could not find or load main class" error, and my professor wasn't very helpful in his answer when I asked for help.
This is what my professor said is supposed to work (he is using OSX).
java -cp classes:lib/json.jar cst420.jsonrpc.client.GroupServerJavaStub http://127.0.0.1:8080
After reading some other posts on this site, I also tried:
java -cp classes:"lib/json.jar" cst420.jsonrpc.client.GroupServerJavaStub http://127.0.0.1:8080
java -cp "lib/json.jar" cst420.jsonrpc.client.GroupServerJavaStub http://127.0.0.1:8080
Still nothing works. I'm in the base directory in a bash prompt ~\GroupJsonRPC and the class file that is in ~\GroupJsonRPC\classes\cst420\jsonrpc\client\GroupServerJavaStub.class exists and is ready for running. The same goes for ~\GroupJsonRPC\lib\json.jar. Any insight into how to get this darn thing running would be greatly appreciated!
PS: I'm using Windows.
The proper command is:
java -cp "classes;lib/json.jar" cst420.jsonrpc.client.GroupServerJavaStub http://127.0.0.1:8080
You need to be sure to include the directory of your class files as well as the jar file(s) with ';' separators, and don't use the -jar option. It invalidates the -cp option.

JDBC classpath issue

I don't like to post a question when so many suggestions pop up when I type the question title in but looking through them all and seeing no solution is somewhat distressing. I've been following a tutorial for java->postgres connections and I am constantly getting slaughtered by
"Could not find or load main class Seb"
error messages.
I've tried using
SET CLASSPATH=%CLASSPATH%:<path to work directory>;<path to jdbc jar>
compiling like so:-
javac -cp .:jdbc.jar Seb.java
and executing like so:-
java -cp .:jdbc.jar Seb
and can't see through the light -_-
The thing is, following the tutorial down to the letter (and watching the demonstration video) doesn't seem to work for me.
I'm simply using notepad and cmd.exe on Windows 8 for development as it's only a learning opportunity, not a big project - but I'm baffled as to why I can't get the thing to run!
JDBC postgres files are in the same directory as .java file.
Code is available if needed as is any other information I can provide.
Thanks in advance for any help,
-Tim!
Use a semi-colon classpath separator for Windows
java -cp .;jdbc.jar Seb
^
Read: PATH and CLASSPATH

Categories