Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

New to programming  RSS feed

 
T Voort
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, I need urgent help.

I really, really want to learn programming. But for some reason, it is impossible to write a book about it that works. I just picked up "head first java", since everywhere online they keep saying it is such a great beginner's book.. Well.. it doesn't even explain how to GET java...


So... I came here in the hope that somebody could explain me, STEP FOR STEP, like I am completely retarded, how to actually start programming, and make sure that it actually functions.

What I have done so far:

1. Went to http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
2. Downloaded Java SE Development Kit 8u65
3. Ran the .exe

4. Went to http://www.oracle.com/technetwork/java/javase/documentation/jdk8-doc-downloads-2133158.html
5. Downloaded Java SE Development Kit 8u65 Documentation
6. Extracted it to This PC > Downloads > jdk-8u65-docs-all

6. Then it said in the book that I needed to change the PATH. On this website it also said I should do that, so I did. (NOT with a HOME_JAVA variable, I simply added the path to the beginning of the path file).
7. My PATH variable now says: C:\Program Files (x86)\Java\jdk1.7.0_55\bin;C:\Program Files (x86)\ActiveState Komodo Edit 9\;C:\ProgramData\Oracle\Java\javapath;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;C:\Program Files\Intel\DMIX;C:\Program Files (x86)\ATI Technologies\ATI.ACE\Core-Static;C:\Program Files (x86)\QuickTime\QTSystem\;%USERPROFILE%\.dnx\bin;C:\Program Files\Microsoft DNX\Dnvm\;C:\Program Files\Microsoft SQL Server\120\Tools\Binn\;C:\Program Files (x86)\Windows Kits\10\Windows Performance Toolkit\;C:\Program Files (x86)\nodejs\;C:\Program Files (x86)\Skype\Phone\

8. Made a folder C:\java
9. Stored MyFirstApp.java there

10. Ran C:\java\MyFirstApp.java in the cmd.

Now I have a problem
The first time I ran this, another file appeared in this directory, named MyFirstApp.class

If I type C:\java\MyFirstApp.java again, It opens codeblocks. I do not know what to do next. Nowhere does it say what to do next.

If I type any variation of what the tutorial on this website tells me to type, I get an error saying "is not recognized as internal or external command".

MY QUESTIONS:


1. How do I get rid of it opening codeblocks? I don't want this and wrote the MyFirstApp.java in Notepad++
2. What do I have to type next to actually run the MyFirstApp.java or MyFirstApp.class (whichever one I need to run)
3. Do I really have to type all these console commands just to get something working? Can't I get a program. Type the Java code, press play and get it to simply run? If not, WHY not?


Extra question:

I have before all this, downloaded a program called "processing", which is apparently something you should be able to code Java in.

when I type

""

Which is a simple hello world program... I get the error message: illegal modifier for the local class HelloWorld; only abstract or final is permitted.
What does this mean, why do I get it, and most of all:


WHY CAN'T I JUST TYPE CODE AND GET A PROGRAM TO WORK?

Thanks a lot. I really hope you can give me a STEP by STEP explanation of what to do.
don't assume I know things.

If I have to type something, please show me LITERALLY what I have to type, because apparently I am too retarded to make things work any other way.

Thanks again.
 
Mike. J. Thompson
Bartender
Posts: 689
17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So when you're creating a program there are three basic stages.

1) Write the .java files. You seem to have managed this ok. Notepad++ is a good choice for a beginner, and should give you basic syntax highlighting. This means it knows which keywords have special meaning in java and will colour them differently, making it easier to read.

2) Compile the .java files. You appear to have got the hang of this, because the output of the compiler is one or more .class files. However you don't compile the .java files by running them directly. The java compiler is called javac.

javac MyFirstJavaApp.java

might produce

MyFirstJavaApp.class.

But the exact files it produces will depend on the contents of the .java file.

3) Run the compiled code. To run your program your code needs to have an entry point. The entry point is a method called main, with a very specific signature (meaning a specific return type and parameter types). Don't worry about why right now.

So I will assume that the MyFirstJavaApp.java file has a class called MyFirstJavaApp which has this entry point.



To run this program you use the java program. Make sure you are in the same directory as the MyFirstJavaApp.class file and run it as follows:

java MyFirstJavaApp

Notice that you give java the name of the class, not the name of the file. Don't put .class on the end.
 
T Voort
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay. I have a folder named java, in C:\java.

In that folder are two files:

MyFirstApp (java source file)
MyFirstApp.class (CLASS file)

What do I have to type in?

Because you say:

" To run this program you use the java program. Make sure you are in the same directory as the MyFirstJavaApp.class file and run it as follows:

java MyFirstJavaApp "

So WHAT do I type EXACTLY in cmd to get that?

Because if I try to go to c:\java

it says "is not recognized as internal or external command, operable program..."

 
Tapas Chand
Ranch Hand
Posts: 614
9
BSD Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
open command prompt.
Type Hit Enter

Type Hit Enter
Thats it.
 
T Voort
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are a livesaver! Thanks a bunch
 
Campbell Ritchie
Marshal
Posts: 55672
161
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
T Voort wrote:. . . "is not recognized as internal or external command, operable program..."
Welcome to the Ranch

The reason for that is that you did not correctly set a System PATH when you installed Java®. Read our FAQ and scroll down to where it tells you about the PATH.
 
Ryan Gabriel
Greenhorn
Posts: 20
Android Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
May be you in installed codeblocks willingly or unwillingly, you can uninstall it like any other program from your computer.
As you are learning java, codeblocks could be a bit hard for you.
You should go for IntelliJ IDEA or Eclipse But practicing in command is the best option for beginners.
this is a good reference to teach you about command.
 
Campbell Ritchie
Marshal
Posts: 55672
161
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ryan Gabriel wrote:May be you in installed codeblocks willingly or unwillingly, you can uninstall it like any other program from your computer.
As you are learning java, codeblocks could be a bit hard for you.
Good point If that program is causing problems you should uninstall it.

You should go for IntelliJ IDEA or Eclipse But practicing in command is the best option for beginners.
this is a good reference to teach you about command.
I have seen better tutorials that that. Look at our FAQ which I gave a link to yesterday, or here. Avoid using NetBeans Eclipse IntelliJ and other IDEs at this stage. There is a risk that they will simply confuse you.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!