Naruto Shippuden

Naruto Discussion Forum
Who should win? Be sure to nominate who will reign supreme for this month's Member of the Month!

Go Back   Naruto Discussion Forum > The Bath House > Off-Topic

Off-Topic For anything under the sun that won't fit elsewhere!

Reply
 
Thread Tools
Old 08-03-2012, 04:56 AM   #1
Ultimate combatant
Special Jonin Candidate
 
Ultimate combatant's Avatar
 
Join Date: Mar 2010
Posts: 3,167
Rep Power: 14
Ultimate combatant completed an S-Rank mission on the way to the bathroom.Ultimate combatant completed an S-Rank mission on the way to the bathroom.Ultimate combatant completed an S-Rank mission on the way to the bathroom.Ultimate combatant completed an S-Rank mission on the way to the bathroom.Ultimate combatant completed an S-Rank mission on the way to the bathroom.Ultimate combatant completed an S-Rank mission on the way to the bathroom.Ultimate combatant completed an S-Rank mission on the way to the bathroom.Ultimate combatant completed an S-Rank mission on the way to the bathroom.Ultimate combatant completed an S-Rank mission on the way to the bathroom.Ultimate combatant completed an S-Rank mission on the way to the bathroom.Ultimate combatant completed an S-Rank mission on the way to the bathroom.Ultimate combatant completed an S-Rank mission on the way to the bathroom.Ultimate combatant completed an S-Rank mission on the way to the bathroom.Ultimate combatant completed an S-Rank mission on the way to the bathroom.
Default Java programming tutorial #1

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:
public class Hello{
public static void main(String[] args){

//Two slashes left of this sentence indicate the rest of the line is used for commenting.
//It does not do anything, it only helps programmer to understand the program better.

/* This has the same function but there is a difference. Unlike two slashes, this way
your comment can be as long as you wish. You end this comment by writing down:
*/

//Excluding the comments, this is the basic structure. Of course there are many other forms.
//Forms that I do not intend to show to you. At least not in this tutorial.

//Hello is the class in which main method can be found.

//If you go to Save As, you can save this file as Hello.java

//You do not like name Hello?
//Change the name of class to Awesome
//and save file as Awesome.java
//The first letter of class name should be a capital letter. A instead of a, B instead of b,...

//But if we want our program to do anything, we have to put some code:

System.out.print("Hello World!!!");

/* What does the code above do, you ask? Simple, it will write down:

Hello World!!!

*/


}
}


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:
public class Tobi{
public static void main(String[] args){

System.out.println("Deidara-senpai!!");

for (int i=0; i<3; i++){
System.out.print(i+1);
if (i<2){
System.out.print(", ");
}
}

System.out.print(" and I am Tobi!!");

}
}




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.
Ultimate combatant is offline   Reply With Quote
Old 08-03-2012, 04:58 AM   #2
Schnarf
Childish Gambino Lover
 
Schnarf's Avatar
 
Join Date: Nov 2011
Posts: 1,476
Rep Power: 9
Schnarf strikes fear and awe in the fragile hearts of Genins.Schnarf strikes fear and awe in the fragile hearts of Genins.Schnarf strikes fear and awe in the fragile hearts of Genins.Schnarf strikes fear and awe in the fragile hearts of Genins.Schnarf strikes fear and awe in the fragile hearts of Genins.Schnarf strikes fear and awe in the fragile hearts of Genins.Schnarf strikes fear and awe in the fragile hearts of Genins.Schnarf strikes fear and awe in the fragile hearts of Genins.Schnarf strikes fear and awe in the fragile hearts of Genins.Schnarf strikes fear and awe in the fragile hearts of Genins.Schnarf strikes fear and awe in the fragile hearts of Genins.Schnarf strikes fear and awe in the fragile hearts of Genins.
Send a message via Skype™ to Schnarf
Default Re: Java programming tutorial #1

tl;dr.
__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

The Strokes
Schnarf is online now   Reply With Quote
Old 08-03-2012, 06:17 AM   #3
megabbaut
Debby Downer
 
megabbaut's Avatar
 
Join Date: Nov 2010
Location: Dish town...filled with fish
Posts: 8,591
Rep Power: 18
megabbaut just might be Kage someday.
megabbaut just might be Kage someday.megabbaut just might be Kage someday.megabbaut just might be Kage someday.megabbaut just might be Kage someday.megabbaut just might be Kage someday.megabbaut just might be Kage someday.megabbaut just might be Kage someday.megabbaut just might be Kage someday.megabbaut just might be Kage someday.
Default Re: Java programming tutorial #1

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:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
src="
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
type="application/x-shockwave-flash" width="425" height="350">
My Battle Theme:
YouTube:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
src="
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
type="application/x-shockwave-flash" width="425" height="350">
GT & PSN: VesicantDegree1
megabbaut is offline   Reply With Quote
Old 08-03-2012, 06:22 AM   #4
Maruko
MotM Winner: March
Winter is Coming
 
Maruko's Avatar
 
Join Date: Sep 2011
Posts: 12,283
Rep Power: 33
Maruko is the subject of legends and tales that shall be passed on for generations to come.Maruko is the subject of legends and tales that shall be passed on for generations to come.Maruko is the subject of legends and tales that shall be passed on for generations to come.
Maruko is the subject of legends and tales that shall be passed on for generations to come.Maruko is the subject of legends and tales that shall be passed on for generations to come.Maruko is the subject of legends and tales that shall be passed on for generations to come.Maruko is the subject of legends and tales that shall be passed on for generations to come.Maruko is the subject of legends and tales that shall be passed on for generations to come.Maruko is the subject of legends and tales that shall be passed on for generations to come.
Default Re: Java programming tutorial #1

Nice, dude.
__________________

Maruko is offline   Reply With Quote
Old 08-03-2012, 06:34 AM   #5
Ultimate combatant
Special Jonin Candidate
 
Ultimate combatant's Avatar
 
Join Date: Mar 2010
Posts: 3,167
Rep Power: 14
Ultimate combatant completed an S-Rank mission on the way to the bathroom.Ultimate combatant completed an S-Rank mission on the way to the bathroom.Ultimate combatant completed an S-Rank mission on the way to the bathroom.Ultimate combatant completed an S-Rank mission on the way to the bathroom.Ultimate combatant completed an S-Rank mission on the way to the bathroom.Ultimate combatant completed an S-Rank mission on the way to the bathroom.Ultimate combatant completed an S-Rank mission on the way to the bathroom.Ultimate combatant completed an S-Rank mission on the way to the bathroom.Ultimate combatant completed an S-Rank mission on the way to the bathroom.Ultimate combatant completed an S-Rank mission on the way to the bathroom.Ultimate combatant completed an S-Rank mission on the way to the bathroom.Ultimate combatant completed an S-Rank mission on the way to the bathroom.Ultimate combatant completed an S-Rank mission on the way to the bathroom.Ultimate combatant completed an S-Rank mission on the way to the bathroom.
Default Re: Java programming tutorial #1

Quote:
Originally Posted by megabbaut View Post
That wasn't tooo hard to follow.

btw does this have to do with the encrypted message?
Yep, I encrypted the code with the help of Java. Over time, if people will be happy with the tutorials and if I made more of them we might come to that part.

Either way, the riddle is not too hard!!!
Ultimate combatant is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 07:20 PM.


Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.