|
|
I tried to use that, but that exception is thrown if the server is offline but also when it didn't responded to .connect(...) in time.
|
|
|
|
|
Did the exceptions include any message text to explain what was the underlying cause? When I run my Java client against an offline server I get:
Exception in thread "main" java.net.ConnectException: Connection refused: connect
There may be some more useful information at Java Network Programming FAQ[^].
|
|
|
|
|
|
Check inetaddress.isReachable.
It is similar to ping
|
|
|
|
|
In my app I'm using JNI, and because of that I have to add into User/System Path the location to jvm.dll from JRE\bin\server . To add a variable in User Path it doesn't require administrator rights, so I'm taking this approach. To add it I'm using REG ADD from CMD with the following functions. The problem that I have is that after I'm adding the variable into Path, the software still doesn't see it and returns the error "jvm.dll not found", but if I restart the computer, then it runs fine and sees the variable. Also after I'm adding it, if I manually go into User Path and double click to edit the variable, and simply press enter without changing anything, then it doesn't require the restart. Does it have something to do with the code/way I'm adding the variable? What should I do to get past this and to get it working without the user/client having to restart the computer before it is working?
Function to run CMD:
std::string executeCMD(const char* cmd) {
std::string result;
std::array<char, 128> buffer;
std::unique_ptr<FILE, decltype(&_pclose)> pipe(_popen(cmd, "r"), _pclose);
if (!pipe) {
return "ErrorCMD";
}
while (fgets(buffer.data(), buffer.size(), pipe.get()) != nullptr) {
result += buffer.data();
}
return result;
}
Use of the function:
resultCMD.insert(0, "reg add \"HKEY_CURRENT_USER\\Environment\" /v PATH /t REG_EXPAND_SZ /d \"");
resultCMD.append("\" /f");
executeCMD(resultCMD.c_str());
resultCMD is a std::string which contains the values that were in Path and also the value that I'm adding under the following format with "C:\Program Files\Eclipse Adoptium\jre-18.0.1.10-hotspot\bin\server" being added after I use the function from above:
C:\Program Files\Eclipse Adoptium\jre-18.0.1.10-hotspot\bin\server;D:\Program Files (x86)\VMware\VMware Player\bin\;D:\Program Files\Python\Python310\Scripts\;D:\Program Files\Python\Python310\;C:\Windows\system32;C:\Windows; ...and the rest of the variables, this was as an example, after each variable they have a ;
|
|
|
|
|
I ended up switching to use RegOpenKeyExA, RegQueryValueExA, RegCreateKeyEx, RegSetValueExA to get and add the values into Path, that way I can use SendNotifyMessage(HWND_BROADCAST, WM_SETTINGCHANGE, 0, (LPARAM)TEXT("Environment")); to get past the need for a system restart/logout.
|
|
|
|
|
There is also the “setx” command that can help with that.
I ran into similar problems setting info into the registry directly.
|
|
|
|
|
If I'm planning to distribute some software that uses Java, can I simply add in it's folder structure jre-8u333-windows-x64.exe (or other versions, this was the latest) for those that don't have it and prompt them to install it? Or beside that I need to add a file with Oracle license and have the user tick a box that they agree? Or do I have to buy something from Oracle?
The software will be free but it contains microtransactions for profit.
|
|
|
|
|
If you're bundling Oracle software, then you go with what the Oracle license says.
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
|
|
|
|
|
|
I'm using jdk1.8.0_333 / jre1.8.0_333. Do you know if this is a problem or not? Or I need to try to switch to a new version to be free? I'm not really going to make money from my first release, so I would like to try to keep it free.
Also I've seen that there is another source for Java: OpenJDK[^] / OpenJDK JDK 18.0.1.1 GA Release[^]. Is this one free, while the one from Oracle you need a subscription but contains some more advanced features/libraries?
|
|
|
|
|
For the definitive answer that's going to deal with money, the ONLY people you should be asking this question of is Oracle Support.
|
|
|
|
|
Because this is a issue that can lead to financial/law problems I took a look at JDK's and I found Adoptium[^]. Do you know if this is free for commercial use? I see that they have JDK and JRE. I will try to contact them as well, but for sure it will take quite a long time before they respond.
|
|
|
|
|
I don't do Java.
The only reason I know about the licensing is because of the licensing requirements at work.
|
|
|
|
|
public class student{
private int ID;
private String Name;
Student class constructor
student(int id, String name){
this.ID = id;
this.Name = name;}
public int getid(){
return this.ID;}
public String Getname(){
return this.Name;}
public void SETid(int i){
this.ID = i;}
public void sETNAme(String n){
this.Name=n;}
method to display data
public void display() {
System.out.println("Student id is: " + id + " "
+ "and Student name is: "
+ Name;);
System.out.println();
}}
|
|
|
|
|
No.
Even if you'd asked nicely, you haven't bothered to tell us what "the error" is.
Dumping your code without explanation and demanding that someone "solve the error" is a great way to alienate people, and ensure nobody wants to help you.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Let's start by formatting the code and adding ;line numbers so it is actually readable. You can now clearly see that at the very least you have invalid lines at lines numbers 5 and 22. I assume these are supposed to be comment lines so require a "//" at the beginning. You also have mixed capitalisation on your setters and getters.
So start by fixing those and see what happens.
1 public class student{
2 private int ID;
3 private String Name;
4
5 Student class constructor
6 student(int id, String name){
7 this.ID = id;
8 this.Name = name;
9 }
10 public int getid(){
11 return this.ID;
12 }
13 public String Getname(){
14 return this.Name;
15 }
16 public void SETid(int i){
17 this.ID = i;
18 }
19 public void sETNAme(String n){
20 this.Name=n;
21 }
22 method to display data
23 public void display() {
24 System.out.println("Student id is: " + id + " "
25 + "and Student name is: "
26 + Name;
27 );
28 System.out.println();
29 }
30 }
|
|
|
|
|
You forget to add // on commenting lines that is in line number 5 and 22
public class student{
private int ID;
private String Name;
student(int id, String name){
this.ID = id;
this.Name = name;
}
public int getid(){
return this.ID;
}
public String Getname(){
return this.Name;
}
public void SETid(int i){
this.ID = i;
}
public void sETNAme(String n){
this.Name=n;
}
public void display() {
System.out.println("Student id is: " + id + " "
+ "and Student name is: "
+ Name;
);
System.out.println();
}
}
|
|
|
|
|
See my answer of 9th June above.
|
|
|
|
|
He already did, when he cut'n'pasted it
Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012
|
|
|
|
|
Hello. I'm new to Java -- I want to learn, and am going through HFJ. I know it's an old book, but there are no later editions, so I may be behind the times.
I'm not a professional programmer, but I'm on a few programming forums, and I can't seem to get an answer to a question I have regarding the Runnable interface. I'm in chap 15 of the book re: threading, and I came across this statement in regards to starting a new thread:
public class MyRunnable implements Runnable
Runnable threadJob = new MyRunnable ()
What I don't understand is how can you make a new object with an interface, but use the class MyRunnable. Shouldn't it be MyRunnable thread = new MyRunnable ()?
I'm just confused. Runnable isn't a class, so what's going on?
|
|
|
|
|
|
Any class can be "cast" to an interface that it implements; or it can be cast to any object it is "derived" from (e.g. "object").
In your example, a new MyRunnable is created and implicitly "down cast" to Runnable.
The interface acts like a proxy for all (different) classes that implement that interface; allowing only access to the properties / methods identified via the interface.
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
|
|
|
|
|
In C++ terms, a Java interface is a pure abstract class that only has member functions. No fields.
Fields on interfaces are always “constants”. (This is an older Java rule)
It is closer to the COM interface concept.
It could also be called an API contract.
An object can implement multiple interfaces.
This is an easy way to create delayed binding. The thread library was written decades ago, but you can create an Object today that will be usable by this old library as long as you honor the contract defined by the library. For Runnable, you must provide the run() method. The live Thread object will then invoke your run() method when you get your plumbing code correct.
|
|
|
|