PDA

View Full Version : Java tutorial - Basic things.


tom b
05-06-2009, 01:01 AM
Hey im not really the best tutorial writer or the best person with grammar but i try my best ;)

--------------------------------------

Okay so to get started we need to go over a basic helloworld. Helloworld is a starting well an introduction to java ( Used in many other programming languages).


class Helloworld
{
public static void main(String args[])
{
System.out.println("Hello World!");
}
}


Okay so im going to break this down for you.

class Helloworld
{

This represents the name of the .class file

for e.g if the .class was meow it'd be class Meow {

-----

public static void main(String args[])
{

This is the java main method, you will come across this alot!
-----
System.out.println("Hello World!");
}
This command out prints the words Helloworld. like a send message in a server but diffrent.
----

Okay so now you have understood the Helloworld basic java app we can move on the putting this into action with new vocab.

Int - Int means interger it holds numeretic values. ONLY numbers! e.g int x = 1;
system.out.println("message"): - like a send message on a server but diffrent!
if ( - An if statement.
while ( - While statement
++ - Can be used with an int's value to stop loops.
----
So heres something i will explain using Java.


class Yourname//name of your .class
{
public static void main(String args[])//Java main method
{
int tom = 1;//interger! NUMBERS ONLY

if ( tom > 2 ) { // if tom is greater than 2 which it isnt (int)
system.out.println("Tom isn't bigger than 2.");// if toms bigger than to says that
}
}
}

(' // ' tells java to ignore the code thats in it )

there are also varios types of java comment blocks.
---
I don't really want to go into Java coding conventions maybe i will in my next tutorial.
---

Java questions!:

I felt like doing this as an add because many people ask theese questions!

What does a compiler do? - A compiled turns the .java into .class. .class are java byte codes ( What java reads to run the program)

why does a compiler get errors? - I know this is stupid but some bright sparks still confused with it. A compiler gets an error when you have programmed incorrectly causing the Javac ( The java compiler) to reture errors.

Why do i get 100 errors when i edit .class files - Because .class files are java byte codes and if you edited them the compiler can't compile the things that have alredy been compiled + the java byte codes are like juberish so trying to add some java in there is quite pointless.

------


So yeh im sorry for any bad grammar and ile look forward to my next tut.

- Tom

Acid Pillow
05-06-2009, 01:02 AM
I did a rip-check, and it all seems to be yours.
I wish I could do this stuff, but I've never had to nack for it. :(

tom b
05-06-2009, 01:04 AM
I did a rip-check, and it all seems to be yours.
I wish I could do this stuff, but I've never had to nack for it. :(


Just use google and watch java tuts + Java sun tuts and youle be epic in no time! + This is really basic my next tut will be on arrays and saving data.

liljon9090
05-06-2009, 01:06 AM
I'm guessing this will help me a little bit.Nevertheless great work.

tom b
05-06-2009, 01:09 AM
I'm guessing this will help me a little bit.Nevertheless great work.

Thanks. Hope it helped ;)

P403
05-06-2009, 01:19 AM
:rabbit::rabbit:Nice Bro.:rabbit::rabbit: (http://www.youtube.com/watch?v=oWH8SlJze-w)

~Aaron~

Fhillip
05-29-2009, 02:19 PM
rog3r add my msn i need to ask you something deff need to ask you something if your from the moparscape fourms..

Configure
05-29-2009, 02:24 PM
Thanks, helped me a bit.

Fvgbak
05-29-2009, 03:30 PM
Your second code wont work.



class Yourname//name of your .class
{
public static void main(String args[])//Java main method
{
int tom = 1;//interger! NUMBERS ONLY

if ( tom > 2 ) { // if tom is greater than 2 which it isnt (int)
system.out.println("Tom isn't bigger than 2.");// if toms bigger than to says that
}
}
}


Should be

class Yourname//name of your .class
{
public static void main(String args[])//Java main method
{
int tom = 1;//interger! NUMBERS ONLY

if ( tom > 2 ) { // if tom is greater than 2 which it isnt (int)
System.out.println("Tom isn't bigger than 2.");// if toms bigger than to says that
}
}
}


You could try this.


class Yourname//name of your .class
{
public static void main(String args[])//Java main method
{
int tom;//interger! NUMBERS ONLY
int userInput;


System.out.println("Please Input the Value that Tom equals.");
userInput = input.nextInt();
input.close();


if ( tom = 1 ) {
System.out.println("Tom isn't bigger than 2.");
} else {
System.out.print("Tom is bigger than 2.");
}
}
}

Newb
06-04-2009, 03:37 AM
You didn't even explain most of it.

tom b
08-24-2009, 01:45 PM
nm double post >.<

This tutorial is HelloWorld, if you want to get clever then go ahead.


Stop going of topic and posting your crap.


It doesn't make you look clever, so if you want to get smart add my msn.