Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Application Programming › Simple (for you, not me) Java help
New Posts  All Forums:Forum Nav:

Simple (for you, not me) Java help

post #1 of 2
Thread Starter 
Firstly, I should introduce myself. I'm a week into an online degree in creative computing. I expect I'll be in this section of OCN a lot

Currently trying to begin Oracle's "get started" tutorial and, as is so often the case when you have a minute amount of knowledge, getting very confused.


PROBLEM 1

So, I've installed the JDK as it said. The file path is

c: > program files > java

and the two folders contained inside are

jdk1.7.0_01

and

jre7

The installation instructions then say

Quote:
To set the PATH variable permanently, add the full path of the jdk1.7.0\\bin directory to the PATH variable. Typically, this full path looks something like C:\\Program Files\\Java\\jdk1.7.0\\bin. Set the PATH variable as follows on Microsoft Windows:

Click Start, then Control Panel, then System.

Click Advanced, then Environment Variables.

Add the location of the bin folder of the JDK installation for the PATH variable in System Variables. The following is a typical value for the PATH variable:

C:\\WINDOWS\\system32;C:\\WINDOWS;C:\\Program Files\\Java\\jdk1.7.0\\bin
I get to the screenshot below (using Win 7 64bit - in case it makes a difference) and that's where I get stuck.



What / where do I do what it's asking me?

PROBLEM 2

One seemingly good tut. that I've found uses the code

Code:
class myfirstjavaprog
{  
        public static void main(String args[])
        {
           System.out.println("Hello World!");
        }
}
It says to save the notepad file as ExampleProgram.java

Then

Quote:
"Compiling the Program

A program has to be converted to a form the Java VM can understand so any computer with a Java VM can interpret and run the program. Compiling a Java program means taking the programmer-readable text in your program file (also called source code) and converting it to bytecodes, which are platform-independent instructions for the Java VM.

The Java compiler is invoked at the command line on Unix and DOS shell operating systems as follows:

javac ExampleProgram.java

Note: Part of the configuration process for setting up the Java platform is setting the class path. The class path can be set using either the -classpath option with the javac compiler command and java interpreter command, or by setting the CLASSPATH environment variable. You need to set the class path to point to the directory where the ExampleProgram class is so the compiler and interpreter commands can find it. See Java 2 SDK Tools for more information.

Interpreting and Running the Program

Once your program successfully compiles into Java bytecodes, you can interpret and run applications on any Java VM, or interpret and run applets in any Web browser with a Java VM built in such as Netscape or Internet Explorer. Interpreting and running a Java program means invoking the Java VM byte code interpreter, which converts the Java byte codes to platform-dependent machine codes so your computer can understand and run the program.

The Java interpreter is invoked at the command line on Unix and DOS shell operating systems as follows:

java ExampleProgram
At the command line, you should see:

I'm a Simple Program
Here is how the entire sequence looks in a terminal window:

"
I kind of understand what I need to do, but the instructions are gobbledy-gook to me!

Where do I save that simple code that they've given me? How do I tell the cmd prompt where it is so that it can be compiled?


ADVICE

The prof told us all to experiment with java and get to understand it before doing any more in depth reading. I hoped that following the begginner tutorial would help. I'm certainly someone that learns through experimenting. If I can get the code to work then I can start changing it (obviously learning what different code will do) but I'm getting very frustrated with turning text into, um, 'software' (if that's the right word).

Does anyone know of a tutorial or guide that will explain, in n00b terms, how to make super-simple code work, from typing in notepad to hitting the final 'enter' in a command prompt?

Do you all think that I'm trying to learn in the right way? As I said, it really is my first hour or two looking around? Would you suggest a different approach?


Thanks as always for a) answers b) reading such a long post.



tl;dr

how can I make the simple code run?
My do-it-all rig
(17 items)
 
  
CPUMotherboardGraphicsGraphics
AMD K15 970A-D3P NVIDIA GeForce GTX 660  NVIDIA GeForce GTX 460 
RAMRAMHard DriveOptical Drive
Kingston  Kingston  Crucial M4 64Gb, 4x 1Tb, 1x 500Gb WD Caviar Black LG LiteScribe GH24 
OSMonitorKeyboardPower
Win 10 x64 LG E2350 23" 1920x1080 / Samsung 19.5" 1366x768 Razer Lycosa (Mirror Edition) Corsair HX850w 
CaseMouseMouse PadAudio
CoolerMaster 690 Razer Mamba 2012 Razer Goliath XL Logitech X-530 speakers 
Audio
Creative SupremeFX X-Fi sound card 
  hide details  
Reply
My do-it-all rig
(17 items)
 
  
CPUMotherboardGraphicsGraphics
AMD K15 970A-D3P NVIDIA GeForce GTX 660  NVIDIA GeForce GTX 460 
RAMRAMHard DriveOptical Drive
Kingston  Kingston  Crucial M4 64Gb, 4x 1Tb, 1x 500Gb WD Caviar Black LG LiteScribe GH24 
OSMonitorKeyboardPower
Win 10 x64 LG E2350 23" 1920x1080 / Samsung 19.5" 1366x768 Razer Lycosa (Mirror Edition) Corsair HX850w 
CaseMouseMouse PadAudio
CoolerMaster 690 Razer Mamba 2012 Razer Goliath XL Logitech X-530 speakers 
Audio
Creative SupremeFX X-Fi sound card 
  hide details  
Reply
post #2 of 2
First of all, Hi AGAIN! tongue.gif

You want to type code in notepad and then save it so that you can run it. Right?

The thing you described in problem 1 (setting environmental variables) is not necessary to be able to run code but it will surely make it easier for you to run java code without typing in a command to set the path every time you want to run a program.

Firstly, Java code can be written in any text editor and then saved as file with the extension ".java". To be able to run the ".java" file, you need to compile it (convert it into a form which the computer can read) so that the instructions in it can be executed. This is the part when you need the jdk files (which you happen to have downloaded). The jdk files know how to convert the instructions we give in the form of code to something the computer can understand.

Suppose you make a .java file and save it on the desktop. To run it, do the following steps.

1. Open up Command Prompt.
2. Type in "cd desktop" to change your current directory to the desktop (where the .java file is saved).
3. Now you want CMD PROMPT to know where to look up the jdk files from so that it can use them on the .java file you made.
To do this, type in (without quotes): "set path="C:\\Program Files\\Java\\jdk1.7.0\\bin"" or to the bin folder wherever you have saved the jdk files and press enter Now the command prompt has access to the jdk files.
4. Let's say your file's name is "X.java". To compile this file, type in "javac X.java ". This uses those jdk files to convert your .java file to code which can then be used to run the actual program. (You will see an X.class file appear on your desktop).
5. Now type in "java X". This will execute the .class file produced from your .java file.
You will now see any output or and error if there is a problem in your code.

YOU HAVE REACHED YOUR GOAL OF EXECUTING A JAVA PROGRAM!!!!!

Now, let's go back to your Problem1.
You will notice that whenever you need to execute a program from CMD(if you have closed it and opened it again), you will need to type in the set path command again and again which becomes tedious and boring eventually.
To save yourself from this, you can specify this path in your environment variables option so that CMD will always automatically know where to look for the jdk files and you won't have to type this command every time you run a program.

There in the VARIABLE NAME field, type in "Path".
And in the PATH field, type in "C:\\Program Files\\Java\\jdk1.7.0\\bin" (or wherever you have saved the JDK files).
This will save you from that hassle but remember this is not necessary to run a java program through command prompt.

Hope I helped.
MacBook Pro 13"
(6 items)
 
 
Desktop
(13 items)
 
CPUGraphicsRAMHard Drive
Intel i5 3210 @ 2.5 GHz Intel HD4000 4 GB DDR3 @ 1600 MHz 500 GB @ 5400 RPM 
OSMonitor
OSX Mountain Lion 13.3" @ 1280 x 800 
CPUGraphicsRAMHard Drive
Intel i5 480m@2.67GHz AMD Radeon Mobility 5650 4GB DDR3 500GB 
OSMonitor
Windows 7 64bit HP 15.6" 1366x768 
CPUMotherboardGraphicsRAM
E7500 Intel...:( MSI GTS250 1GB 2GB 
Hard DriveOSMonitorPower
250GB Windows XP 17" LG CRT 1280x768@85hz 400W 
  hide details  
Reply
MacBook Pro 13"
(6 items)
 
 
Desktop
(13 items)
 
CPUGraphicsRAMHard Drive
Intel i5 3210 @ 2.5 GHz Intel HD4000 4 GB DDR3 @ 1600 MHz 500 GB @ 5400 RPM 
OSMonitor
OSX Mountain Lion 13.3" @ 1280 x 800 
CPUGraphicsRAMHard Drive
Intel i5 480m@2.67GHz AMD Radeon Mobility 5650 4GB DDR3 500GB 
OSMonitor
Windows 7 64bit HP 15.6" 1366x768 
CPUMotherboardGraphicsRAM
E7500 Intel...:( MSI GTS250 1GB 2GB 
Hard DriveOSMonitorPower
250GB Windows XP 17" LG CRT 1280x768@85hz 400W 
  hide details  
Reply
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Application Programming
Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Application Programming › Simple (for you, not me) Java help