Archiverse Internet Archive
投稿のみ 投稿と返信
前のページ(最近)
1 2 3 4 5 6 7 8
次のページ(過去)
返信[12]
親投稿
Andres TanookiOcarina
When writing a method, you must ALWAYS place a pair of opening and closing parenthesis next to the method name. The stuff that goes inside the parenthesis is called the "parameter" or "argument." You can have more than one argument when defining a method. The argument for main is: String[] args Once again, we'll find out what this piece of code means later.
1そうだね
未プレイ
返信[11]
親投稿
Andres TanookiOcarina
But what does static mean? What does void mean? If you can bear with me here, I'll explain those other keywords when we go over methods in a later tutorial. This line of code that we have just wrote creates, or "defines", a method called main. EVERY Java program MUST contain a main method. The method name goes right before that opening parenthesis, and everything before it is all keywords.
1そうだね
未プレイ
返信[10]
親投稿
Andres TanookiOcarina
Alright, now on the second line, type this line in: public static void main(String[] args) You probably have no idea what this line of code means, but do you see something familiar? Yes, the keyword public! This special piece of code can be accessed by other programs.
1そうだね
未プレイ
返信[9]
親投稿
Andres TanookiOcarina
It will go to the next line, but you'll notice that it has an indent. Why is this? This special indent is called "whitespace." The purpose of whitespace is to make your code easier to read and to make it more organized. If you've seen other people's programs, you will probably see some examples of whitespace. Feel free to start at the left margin, though. It won't mess up the program.
1そうだね
未プレイ
返信[8]
親投稿
Andres TanookiOcarina
The programs are written between those two curly brackets, which I'll refer to as braces from now on. IMPORTANT: You must always have an opening brace to begin the program and a closing brace to end it, or else you will get an error. {: Opening brace. }: Closing brace. Alright, now click on the right side of the opening brace and press Enter.
1そうだね
未プレイ
返信[7]
親投稿
Andres TanookiOcarina
So if you were to change public to protected in our newly made class: protected class HelloWorld { } Then only programs within src can access it. Cool, huh? And finally, let's go over those curly brackets.
1そうだね
未プレイ
返信[6]
親投稿
Andres TanookiOcarina
The keyword public basically means that the program can be accessed by other programs outside of the class. If you'd like, it can be private, which means that it can't be accessed by outsiders, or protected, which means it can only be accessed by programs in the same "package." The package in our MiiverseTutorial project is called src, and it looks like a brown box. Continued...
1そうだね
未プレイ
返信[5]
親投稿
Andres TanookiOcarina
Java programs MUST ALWAYS be written inside of a class. Our class HelloWorld is the class we will be using to write our code...for now. However, we won't be creating any special objects in this class.
1そうだね
未プレイ
返信[4]
親投稿
Andres TanookiOcarina
For example, let's say there is a class named Shape. Circle, square, and triangle are all objects of the Shape class. Or, how about a Cat class? The Cat class can contain objects such as catnip or whiskers, but can also have "actions" such as purr and rip your couch apart. These actions are known as "methods" in Java. I'll talk about objects and methods later in this course.
1そうだね
未プレイ
返信[3]
親投稿
Andres TanookiOcarina
Hooray! We can now TRULY begin to write our code! In the editor, you'll see something like this: public class HelloWorld { } If you have absolutely no idea what this means, have no fear. I will explain it all right now. A class is a blueprint from which objects are created. It could be considered as a category, which I'll explain in the next comment.
1そうだね
未プレイ
返信[2]
親投稿
Andres TanookiOcarina
I recommend that you save it into a folder which you can use to store your programs. Try making a new folder in your hard drive, like this: C:\MyPrograms. After you have created your project, it will show in the Package Explorer on the left. If you click on it, you'll see something called src. Right-click on src, scroll over New, and select Class. Name your class "HelloWorld", and click finish.
1そうだね
未プレイ
返信[1]
親投稿
Andres TanookiOcarina
In order for you to go on, you must have your IDE (preferably Eclipse) and the JDK all set up. Now, we can begin coding! Open up Eclipse. Once it has opened, go to the top left corner of the screen, and click on File. Then scroll over New, and select Java Project. You can name your Java project whatever you like, but I'll choose to go with MiiverseTutorial. Continued...
1そうだね
未プレイ
トピック
Andres TanookiOcarina

Java tutorial #1

In this post I will demonstrate how to write a simple Hello World program in Java.
2そうだね
未プレイ
返信[15]
親投稿
Andres TanookiOcarina
This post was made as an introduction to Java and setting up. In the next post, I will demonstrate how to write a Hello World program! See you there, Miiverse!
0そうだね
未プレイ
返信[14]
親投稿
Andres TanookiOcarina
Here are the links for Eclipse and the JDK. Just a reminder that you can download any other IDE that you feel is right for you, but in my opinion, Eclipse is the best choice. Eclipse: eclipse[DOT]org/downloads/packages/eclipse-ide-java-developers/lunasr2 JDK: oracle[DOT]com/technetwork/java/javase/downloads/jdk8-downloads-2133151[DOT]html
0そうだね
未プレイ
返信[13]
親投稿
Andres TanookiOcarina
Under the Advanced tab, click on "Environment Variables" on the bottom. When the window pops up, click on any of the two New buttons. Another window will now ask for the variable name and value. Set the name as PATH or Path, and paste the bin address into the value box. Now close all the windows by clicking OK. Whew! And that's how you set up the JDK!
0そうだね
未プレイ
返信[12]
親投稿
Andres TanookiOcarina
Click on that bin folder, and once inside, click on the address bar. Copy the address that is already in the address bar. Then, if you're on Windows, go back to System in the Control Panel. On the left side of the page you'll see something called: "Advanced System Settings." Click on that. Continued...
0そうだね
未プレイ
返信[11]
親投稿
Andres TanookiOcarina
Continued from directions... A wizard will pop up once the download has completed. Make sure you install the JDK into a folder where you know it is in there. Complete the requirements that the installation wizard will give you. After you complete the wizard, go to the folder in which you installed JDK. Inside the folder, you'll see another folder called bin. Continued...
0そうだね
未プレイ
返信[10]
親投稿
Andres TanookiOcarina
The IDE is the software in which you write your code. I really don't have a good explanation on what the JDK is for, but you can go to its Wikipedia page to find out? Nevertheless, they are both vital to Java programming.
2そうだね
未プレイ
返信[7]
親投稿
Andres TanookiOcarina
For example, if your Windows computer has an x64-based processor, then you download the x64 version. If you're on Windows, you can find out what type of processor you have by going to Control Panel --> System and Security --> System. Unfortunately, I don't have Solaris, Mac OS, or Linux, so you have to find out where you can locate your processor details if you have one of those OSs. Continued...
2そうだね
未プレイ