Topic:   [Java] The Various Basics   (Read 37241 times)


0 Members and 3 Guests are viewing this topic.

Gan


  • Administrator

  • ^ This guy is amazing.

  • *****


  • Posts: 4411
[Java] The Various Basics
« on: May 12, 2009, 07:34:18 AM »
This post will be filled with many small pieces of code that are of great importance in the Java world. Even though these may seem incredibly basic, most people have the hardest time wrapping their mind around the most simplistic pieces. That's where this post comes in, it will help you get your feet off the ground.

Variables:
Variables store data for you, like boxes when you have too much crap lying around the house. Variables are set up as so:
Code: [Select]
[Object Type] [Object Name] [Optional =] [Optional Data];
Examples:
Code: [Select]
//Initialize an Integer
int i = 0;

//Initialize a String
String message = "Hello World.";

//Initialize a Char
char letter = 'A';

If-Statements:
If statements are what makes your program... a program. It allows you to actually do stuff depending on variables.
Code: [Select]
if (i == 1) {i = 0;}
For Loop:
Code: [Select]
for (int i = 0; i <n; i++) 
{
//code goes here
}
While Loop:
Code: [Select]
While (true) {i += 1;}
Print Line:
Code: [Select]
System.out.println("Hello World.");


-Gandolf
P.S. If you guys just post your random Java code, I will insert them in a category. I'll also add definitions under the pieces of code a little later.
« Last Edit: May 12, 2009, 05:09:11 PM by Gandolf »

WarHampster


  • GMG Extraordinaire

  • ***


  • Posts: 1501

  • The People's Moderator
    • Arcade of the Absurd
Re: [Java] The Various Basics
« Reply #1 on: May 12, 2009, 07:55:46 AM »
For loop


Code: [Select]
for (int i = 0; i <n; i++)
{
//code goes here
}

Gnome


  • GMG Extraordinaire

  • ***


  • Posts: 1073
Re: [Java] The Various Basics
« Reply #2 on: May 12, 2009, 04:30:50 PM »
wow  :o

stiff i prefer Obj-C maybe its my way of programing that makes it easier for me

This Cannot be, NOOOOOOOO!!!!

-Gnomes Cry when the McRib was discontinued again.

GMG Tim


  • Administrator

  • GMG-er

  • *****


  • Posts: 465
Re: [Java] The Various Basics
« Reply #3 on: May 12, 2009, 05:02:44 PM »
Quote
wow  :o

stiff i prefer Obj-C maybe its my way of programing that makes it easier for me


Most of this code would work with Objective-C, because Obj-C accepts C/C++ syntax. The for loops, while loops, variable declarations are all identical in Obj-C.

Ghost

Gan


  • Administrator

  • ^ This guy is amazing.

  • *****


  • Posts: 4411
Re: [Java] The Various Basics
« Reply #4 on: May 16, 2009, 03:47:52 PM »
Hey guys, I'm going to follow up on Gnomes idea which is where Gm syntax is compared to Java so learners can understand and get the hang of it.

I don't have too much knowledge of Gm code, so if you guys could post snippets, tasks, or even extremely small apps which you would like to see how they would work in Java; that would be wonderful.


-Gandolf

Gnome


  • GMG Extraordinaire

  • ***


  • Posts: 1073
Re: [Java] The Various Basics
« Reply #5 on: May 18, 2009, 10:16:22 AM »
Quote
Hey guys, I'm going to follow up on Gnomes idea which is where Gm syntax is compared to Java so learners can understand and get the hang of it.

I don't have too much knowledge of Gm code, so if you guys could post snippets, tasks, or even extremely small apps which you would like to see how they would work in Java; that would be wonderful.


-Gandolf


we will call it the G-NOME system :D
This Cannot be, NOOOOOOOO!!!!

-Gnomes Cry when the McRib was discontinued again.