![]() |
|
|||||||
| Active Topics | Register | Forum Rules | FAQ | Forum Rules | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Off-Topic For anything under the sun that won't fit elsewhere! |
![]() |
|
|
Thread Tools |
|
|
#1 |
|
Special Jonin Candidate
Join Date: Mar 2010
Posts: 3,167
Rep Power: 14 ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
Hi. So, I thought to myself why not to make a small Java programming tutorial. After all, I assume at least some of you don't know much about it.
Tutorial will cover some parts of Java language. Some confuse Java for JavaScript but this is not the same. There may be some similar elements, overall they are completely different. This tutorial will not include GUI. If you already have knowledge of this, simply don't read and the problem is solved. Hopefully, at least some of you will learn something new from this. This will be a one short introduction to some basics. If it turns out successful, I might make more. So, here we go!!! You can write Java program in text editor such as notepad or gedit. Of course, there are other environments made especially for programming but for the simple introduction, you don't need those. Here is the basic structure for creating simple program (I will use term program to avoid confusion): Spoiler:
If you have Java installed and you environment variables are properly set, you can go to cmd. Go to the folder file you created is. Than type: javac Hello.java After that, type java Hello In the cmd, "Hello World!!!" should be written. Of course, you can change the message. But it is smart to use only english letters. But if we want to do something else? Perhaps we want it to calculate sum of two numbers? Delete the line where "System.out.print("Hello World!!!");" is written. We want sum of two different numbers. We could simply write: System.out.print(5+7); And it would work. You can try it. But what if we want to store the value? We will initiate a variable and we will assign it a value. What shall we call it? We could use numerous names but make sure it doesn't start with a number or a capital letter. We will call it: num The other number we will call num2. To initiate a variable, you write down its type, than name and value; There are numerous types, for whole numbers, we use int, if we wanted to calculate with decimal numbers, we could use type double. So: int num=25; int num2=73; System.out.print(num+num2); Keep in mind that number (or the result) must not be bigger than (2^31)-1. Because that is the limitation of int type. As you might have guessed +, -, *, / are the most basic operations. If statement. Some times you want your program to do something only if some conditions are fulfilled. int a=0; if (a<7){ a=15; } System.out.print(a); If a is smaller than 7, only then will value assigned to a be equal to 15. Since 0 is smaller than 7, a<7 will be true and a will be assigned value 15. Otherwise, it would remain 0. How about now? int a=10; if (a<7){ a=15; } else{ a=5; } System.out.print(a); Since 10 is not smaller than 7, a=5 part will happen. Value 5 will be written out. Now comes the for loop. for (int i=0; i<5; i++){ System.out.print("Hi."); } You wonder what it does? int i=0 ~ It creates variable with name i. It assigns it value 0. i<5 ~ The content within the for loop will repeat itself as long as i is smaller than 5. i++ ~ Once everything within for loop is done variable i will be increased by number one. So, "Hi." will be written 5 times, then i will be equal to 5. At that point what is inside for loop will not repeat itself. Why? Because 5 is not smaller than 5. Here is a small program, can you guess what it does? Spoiler:
This would be all for today. What do you think? Give me your feedback. Was it too simple, too complicated, obvious, unclear, monotone, misleading or incorrect... Thank you!!! Last edited by Ultimate combatant; 08-03-2012 at 06:48 AM. |
|
|
|
|
|
#2 |
|
Childish Gambino Lover
|
tl;dr.
__________________
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. The Strokes |
|
|
|
|
|
#3 |
|
Debby Downer
Join Date: Nov 2010
Location: Dish town...filled with fish
Posts: 8,591
Rep Power: 18 ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
That wasn't tooo hard to follow.
btw does this have to do with the encrypted message?
__________________
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. My theme: YouTube:
YouTube:
|
|
|
|
|
|
#4 |
|
Winter is Coming Join Date: Sep 2011
Posts: 12,283
Rep Power: 33 ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
Nice, dude.
__________________
|
|
|
|
|
|
#5 | |
|
Special Jonin Candidate
Join Date: Mar 2010
Posts: 3,167
Rep Power: 14 ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
Quote:
Either way, the riddle is not too hard!!! |
|
|
|
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
|
|