I'm learning to code Java...
I just installed the Java runtime environment and Visual Studio Code, and wrote this:
public class IterationDemo
{
public static void main(String[] args)
{
System.out.println('x');
}
}
However, I don't see any output, both under output or terminal. Only kind of a rectangle (▯) under terminal.
I've tried to find a solution googling, stack and so on but no answer yet...
what can I do?
Thanks!
OK; got solved on its own - I ended up clearing the cache and then the output came :)
Thanks myself!
Related
I'm trying to implement a training task and output chess pieces to the console, but no matter how I change the encoding, the console still shows question marks instead of a chess piece. I will be grateful for your help! i'm using Intelij Idea
public class Chess {
public static void main(String[] args) {
System.out.println("♝");
}
}
and in console i see : ? insread of ♝
Im trying UTF - 8, and many others Encodings, but nothig does work. I'm om 8.1 windows
I'm using intellij communicated version and also add checkstyle plugin
how ever, i made simple java file just say hello
public class hello {
public static void main(string[] final args)
{
system.out.println("hello, world");
}
}
it's simply run. however checkstyle tell me there is problem at the last line.
he told me
Got an exception-expecting EOF, Found '}' error
I don't know what is the problem. block is correctly close.
is there something i need to add or fix that ?
This problem became a real issue in the checkstyle project. Basically it was related with the use of lambdas, yet the problem exposed herebefore is clarely not related to Java 8 lambdas. You can check the issue here. You can solve it by specifying a valid version. In gradle it would be:
apply plugin: 'checkstyle'
checkstyle {
toolVersion = "6.1.1"
}
Try formatting it like
public class Hello
{
public static void main(String[] args)
{
System.out.println("hello, world");
}
}
and the "s" in system.out.println and string[], should be capital
Checkstyle is a tool which is used to find flaws in formatting and coding conventions followed if any exists in the code. The rules are set using by configuring the checkstyle. And if any part of your code does not abide by them, it will throw an exception. In most of the cases exceptions will be self explanatory. You can use google depending on the exception you get.
I am trying to use Google Caliper to benchmark some simple code. I am using the examples from their websites. Here's what I've done so far:
Downloaded the Caliper JAR and added it to my Netbeans project
After having difficulties, I downloaded JUnit.jar and hamcrest.jar. Still not working.
Here's my code:
import com.google.caliper.Benchmark;
public class Benchmark1 extends Benchmark {
public void timeNanoTime(int reps) {
for (int i = 0; i < reps; i++) {
System.nanoTime();
}
}
}
I am extending Benchmark because when I try to extend "SimpleBenchmark" like on their website it tells me it cannot find SimpleBenchmark. I then, in my main method, create a new Benchmark1() hoping something will happen. Nothing does. This is the code inside my main class.
Benchmark1 test = new Benchmark1();
test.timeNanoTime(10);
I know this is no doubt a simple error but I cannot, despite much Googling, figure out where I'm going wrong. The code compiles but does not run.
EDIT: I should say I'm running Netbeans on Windows 7 with Caliper 1.0
It's true; the documentation is woefully outdated and incomplete. I'm working on it. In the meantime, here's what will get your benchmark running.
Your main method should delegate to CaliperMain, not directly to the benchmark. Try
public static void main(String[] args) {
CaliperMain.main(Benchmark1.class, args);
}
Windows will be a problem. Particularly, issue 215 will be the biggest blocker.
You could switch over to Perfidix http://perfidix.org/
Perfidix has eclipse Integration and can be used like JUnit.
Another option would be JUnitbenchmarks http://labs.carrotsearch.com/junit-benchmarks.html
It's a really great framework for Junit 4+. It can even build html charts to compare results.
I want to find out how to open any exe in Windows using Java code. I have searched Google before and they only show me part of the code that they use, I think, because it doesn't seem to compile.
I have downloaded JDK 7 to compile. I don't use Eclipse at the moment and also explaining what I had to do to get it to work in detail would help a lot.
to what Sri Harsha Chilakapati said: would i need to create a class for the code?
Thanks to those who answered but i didn't quite get what you meant but i did however manage to find a website which had what i was after:
http://www.rgagnon.com/javadetails/java-0014.html
public class Test {
public static void main(String[] args) throws Exception {
Process p = Runtime.getRuntime().exec(
"\"c:/program files/windows/notepad.exe\"");
p.waitFor();
}
}
the above was what i was after but thanks again anyway to the people who answered.
Try this.
String myExe = "C:\\MyExe.exe";
String args = "";
Runtime.getRuntime().exec(myExe + " " + args);
Hope this helps.
I would recommend the ProcessBuilder, especially for additional arguments.
How can I reproduce EXCEPTION_STACK_OVERFLOW error in Java.
PS: I am not talking of StackOverflowError Error in Java which gracefully shuts the JVM. I am talking of EXCEPTION_STACK_OVERFLOW in error.log which cause JVM to crash.
Most EXCEPTION_STACK_OVERFLOW errors I found so far happen in native code outside the JVM. A crash inside the JVM is worth a bug report and will be fixed. Or are you in need of an (unknown) exploit?
So the easist and most reliable way would be to write a native library with some code that causes the JVM to crash and call that with JNI.
(general answer, I actually don't know how to do it exactly. Can't be done with java code only ;) )
public static void stackoverflow()
{
stackoverflow();
}
Call it, and enjoy :D
Blow stack:
public static void main(String[] args) {
main(null);
}
Blow heap:
public static void main(String[] args) {
List<String> list = new ArrayList<String>();
while(true) list.add(new String("boom"));
}