-5

I am completely new to Java and I just learned some very basic stuff, such as

boolean isRaining = true; // true or false
if (isRaining) {
    System.out.println("Windshield wipers on.");
}

When I save this on my computer (I have notepad++), I save it as a .java, and when I click on it, it asked me what to open it with, so I close notepad++.

How do I see the result of a java program? (yes, I have java 8 installed on my computer)

Kedar Mhaswade
  • 4,237
  • 2
  • 23
  • 29
FlipFloop
  • 1,143
  • 1
  • 12
  • 22
  • 5
    You should really read a basic book/[tutorial](https://docs.oracle.com/javase/tutorial/getStarted/cupojava/netbeans.html) about programming with Java. – pzaenger Mar 07 '17 at 16:34
  • Do you have the Java **compiler** installed? (not the runtime) – AntonH Mar 07 '17 at 16:34
  • 2
    You should also look into using an IDE, such as Eclipse or NetBeans. It's full of tools to help with writing and debugging your code. – David Mar 07 '17 at 16:35
  • 4
    I'd recommend going through at least [lesson 1 of the Oracle Java tutorial](https://docs.oracle.com/javase/tutorial/getStarted/cupojava/index.html) - it covers compiling your first Java program. – wkl Mar 07 '17 at 16:35
  • Start out with the Oracle tutorials. It will walk you through your first program including compilation and running. https://docs.oracle.com/javase/tutorial/getStarted/ Being new is 1 thing, but you need to learn how to find the basic information on the tasks you are trying to complete. – scrappedcola Mar 07 '17 at 16:36
  • There are tons of tutorials out there in the net. Here is the official one: [The Java™ Tutorials](https://docs.oracle.com/javase/tutorial/). Look for the getting started section. – vanje Mar 07 '17 at 16:37
  • I propose you download jdk+netbeans from Oracle, it's free and professional and easy to get started. – Erich Kitzmueller Mar 07 '17 at 16:38
  • Possible duplicate of [How to run Java Programs](http://stackoverflow.com/questions/2096309/how-to-run-java-programs) – Abdelsalam Shahlol Mar 07 '17 at 16:44
  • @scrappedcola does my java program have to be in the same drive as JAVA? – FlipFloop Mar 07 '17 at 16:51
  • @FlipFloop did you follow the instructions in the getStarted tutorial that we've all pretty much posted? – scrappedcola Mar 07 '17 at 16:53
  • @scrappedcola yes, but I saved .java program on my `D:` and downloaded java on `c:` – FlipFloop Mar 07 '17 at 16:58
  • If you are just trying to figure out how to program java code, might I suggest starting with "Groovy". Groovy understands/runs java code but without some complications. It also has shell to get you going right away (groovysh) and an app (groovyConsole) that lets you type your code in and run. These will allow you to try out java code without worrying about saving/compiling/class definitons/method definitions--just type in the code like you did in your question. – Bill K Mar 07 '17 at 17:17
  • @FlipFloop if the compiler and runtime are in your path it shouldn't matter what drive you run it on. – scrappedcola Mar 07 '17 at 17:21
  • @scrappedcola I got it to work (thx to you) but i'm having trouble setting up a permanent path (to be quick). My file is in c:\jdk..... and I set a permanent path to that, how d i use this path in cmd?? – FlipFloop Mar 07 '17 at 21:16
  • if it's in the system PATH you won't need the folder path but should just be able to use javac and java independent. http://stackoverflow.com/questions/1672281/environment-variables-for-java-installation – scrappedcola Mar 07 '17 at 21:23

2 Answers2

2

Great start on picking up a little Java - you have the right idea but you're missing a few intricacies of the Java language. From what you have wrote, I'm guessing you have a little web dev experience?

I really recommend following through this site: http://www.learnjavaonline.org/en/Hello,_World! which will get you going with your first app. You can find the offical docs here: https://docs.oracle.com/javase/tutorial/

Java is hard to get going with but very powerful once you get going.

Good luck!

Programatt
  • 776
  • 4
  • 10
  • 21
2

If you have java compiler installed then goto command prompt and try
Compile: javac filename.java
Run: java filename
Learn java from tutorialspoint

ihsahs
  • 58
  • 8