I'm trying to get the username on Windows
public class Foo {
public static void main(String[] args) {
System.out.println(System.getProperty("user.name"));
}
}
It works with normal users, but when I do it with system account,
The value was different from the output of whoami command
Any ideas? I need to get the correct name with Java, and it's best without dependency jars
P.S I'm running CMD on a Windows 2008 R2 box
Related
After programming on Mac for a while I tried to program on windows for a change. I started to program but soon realised, what ever I put, the result will not show. I tried the most basic code on netbeans which is,
public class NewClass {
public static void main(String[] args) {
System.out.println("Hello");
}
}
On my Macbook it would give me "Hello" but on my Windows it would give me,
"run: BUILD SUCCESSFUL (total time: 0 seconds)" with no Hello what
soever...
Is it still possible to use Java in Classic ASP (IIS 7.* / Windows) via Java Moniker as is demonstrated at http://cephas.net/blog/2004/03/15/scripting-in-asp-with-java/? (and http://thrysoee.dk/InsideCOM+/ch11f.htm and https://hq.lojcomm.com.br/java/Interop.class.asp).
I cannot make it work from IIS 8.5 (or from dektop VbScript) in my Windows 10 with Java 1.8.0_131 installed in C:\Program Files\Java.
I get all the time: error'800401e4' with no other clarifications in the first line:
set Java_Date = getObject("java:java.util.Date")
response.write( Java_Date.toString() )
and the same error comes if I try to use NetBeans-compiled custom class:
set Java_Greeter = getObject("java:omatestit.Hello")
public class Hello
{
public static void main(String[] args)
{
//do nothing - this will keep us from getting a compile error
}
public String SayHello()
{
return "Hello Geek";
}
}
which locates in:
"C:\Program Files\Java\jdk1.8.0_131\include\win32\TrustLib\omatestit\Hello.class"
Can anyone figure out what is wrong with previous settings?
What I've tried:
class TempDir {
public static void main (String[] args) {
System.out.println(System.getProperty("java.io.tempdir"));
}
}
I need to keep a script consistent with Windows and Linux, windows returns temp directory however, ubuntu returns null, I'm not sure why?
System.out.println(System.getProperty("java.io.tmpdir"));
Prints /tmp on my Ubuntu system, so it looks like you mispelled the property name.
I have the following class in Java which prints "Hello World" in portuguese:
public class PrintUnicode {
public static void main(String[] args) {
System.out.println("Olá Mundo!");
}
}
I am using Eclipse, so I exported the project to a Runnable Jar File. After that, I went to cmd (Windows 7) and ran the generated jar file.
The result was:
Olß Mundo!
Is there an easy way to avoid this error?
Found the solution. Just change to:
public class PrintUnicode {
public static void main(String[] args) {
System.console().printf("Olá Mundo!");
}
}
The error with System.out happens because:
By default, Java encodes Strings sent
to System.out in the default code
page. On Windows XP, this means a
lossy conversion to an "ANSI" code
page. This is unfortunate, because the
Windows Command Prompt (cmd.exe) can
read and write Unicode characters. (source here)
This is my first post on the forum, hope all of you guys are well.
I've got a issue using JiST/SWANS, the ad hoc simulator in java within eclipse.
I managed to load the API, (as an external JAR ofcourse) but Im basically having a problem integrating the runtime of JiST within eclipse.
After running the hello world im usually getting a stackoverflowerror exception, since it may need modifications within the runtime.
import jist.runtime.JistAPI;
public class hello implements JistAPI.Entity {
/**
* #param args
*/
public static void main(String[] args) {
System.out.println("simulation start");
hello t = new hello();
t.myEvent();
}
public void myEvent()
{
JistAPI.sleep(1);
myEvent();
System.out.println("hello world, t=" + JistAPI.getTime());
}
}
the website is: http://jist.ece.cornell.edu/index.html
Thank you in advance!
Actually you need to run Main.java within jist.runtime. But before rigth click Main.java, properties, Run/Debug settings, New,Arguments and type your class name (plain name no .java needed) in Progam arguments. This will tell the jist interface to translate your code using the rewriter and run it.
Examples:
To run hello.java type "hello"
To run aodvsim.java type: "jist.swans.Main driver.aodvsim"
If there are arguments needed type them after the clas name like: "jist.swans.Main driver.aodvsim -n 25 -f 2000x2000 -a grid:5x5 -t 10,600,60"
Wilmer Arellano
How well does SWANS work? Given that the documentation and code date back to 2005, I am not sure if this is the best platform to use.