Learning Java...

Discuss how to write good code, break bad code, your current pet projects, or the best way to approach novel problems

Learning Java...

Post by Pagerops on Mon Mar 01, 2010 6:35 pm
([msg=35951]see Learning Java...[/msg])

Hello HTS,

This is my first post, but this is not a blind shot at a answer. I recently ran into the need to code some Java, but i don't know how to read or write Java I asked my local public library for a recommendation on a book and they had me check out. Java & XML: Written by Brett D. & Justin Edelson, it is a O'Reilly publication. I have tried to read it but could only get 3 chapter in before i found myself completely lost. I looked back into my notes (I do take notes) but found that even they made no sense to me. Would someone please in simple terms explain as simply as they/you can, what java is, dose, and why its needed.(ill probably have more questions) I am sure its in the book but i just can't understand that, with the way this book reads. (like instructions for a Japanese Stereo BTW)


Thank you,
Pager


P.S. a simple example of basic code, explained would be nice as well but if it is too much trouble don't bother.
User avatar
Pagerops
New User
New User
 
Posts: 21
Joined: Wed Jul 09, 2008 2:29 pm
Blog: View Blog (0)


Re: Learning Java...

Post by sanddbox on Mon Mar 01, 2010 7:08 pm
([msg=35954]see Re: Learning Java...[/msg])

Java is a high-level programming language. That means it looks more like English than it does the ones and zeroes computers understand.

When you create java code, you run it through a compiler that converts Java into byte code. Java code can then be executed (by running it through the java virtual machine).

Java is very portable, meaning it can be run on many machines (for instance, many phones are programmed in Java). The reason it is portable is because it is run through a Java virtual machine. You can think of this as a second, virtual computer inside your computer that runs the code.

To make the coding process easy, you can download Netbeans or Eclipse. (For Netbeans, you only need the SE package).

An IDE, or integrated development environment, is just a program that makes the coding task simpler. It can autocomplete methods/variable names, give you code suggestions, spot errors, etc; but it is most useful for the fact that it compiles it and runs it for you.

Before I give any code examples, have you ever programmed in a different language?
Image

HTS User Composition:
95% Male
4.98% Female
.01% Monica
.01% Goat
User avatar
sanddbox
Expert
Expert
 
Posts: 2344
Joined: Sat Jul 04, 2009 5:20 pm
Blog: View Blog (0)


Re: Learning Java...

Post by Pagerops on Sat Mar 06, 2010 2:06 pm
([msg=36199]see Re: Learning Java...[/msg])

Thank you, and only HTML,
User avatar
Pagerops
New User
New User
 
Posts: 21
Joined: Wed Jul 09, 2008 2:29 pm
Blog: View Blog (0)


Re: Learning Java...

Post by darksniper8542 on Sat Mar 06, 2010 7:34 pm
([msg=36213]see Re: Learning Java...[/msg])

I've had a little learning in Java.

As said above, Java is a programming language, and it looks a lot like English.

For example:

if(data=5)
{
return "happy";
}
else(return "sad")

That would mean that if the number saved in "data" is 5, to return the word happy., otherwise, return the word sad.

Java is easy to learn, but the problem is how to use it. There are loops, ifs, different data types, heck, you can even draw with it.

If you need help with coding, i can give you tips here and there. But the best thing will probably be that book. use the index. A LOT.

P.S. im not sure if the else statement is right, tell me please?
darksniper8542
New User
New User
 
Posts: 3
Joined: Wed Mar 03, 2010 9:53 pm
Blog: View Blog (0)


Re: Learning Java...

Post by sanddbox on Sat Mar 06, 2010 8:02 pm
([msg=36215]see Re: Learning Java...[/msg])

The else statement is incorrect. Here's an example: (By the way: In Java (and many other languages), you precede comments with a // so that the compiler knows they're not actual code)

Code: Select all
boolean happy = true;

if (happy) //this is the equivalent of saying "if happy is true..."
{
System.out.println("I am happy!"); //This will say 'I am happy!'
}
else //otherwise...
{
System.out.println("I am sad."); //This will say 'I am sad.'
}
Image

HTS User Composition:
95% Male
4.98% Female
.01% Monica
.01% Goat
User avatar
sanddbox
Expert
Expert
 
Posts: 2344
Joined: Sat Jul 04, 2009 5:20 pm
Blog: View Blog (0)


Re: Learning Java...

Post by tgoe on Sat Mar 06, 2010 9:50 pm
([msg=36223]see Re: Learning Java...[/msg])

The if is probably wrong too.

Compare
Code: Select all
if(data=5)

Code: Select all
if(data==5)


As far as learning java goes... this is an easy start: http://www.mindview.net/Books/TIJ/
but nothing beats the source http://java.sun.com/new2java/
User avatar
tgoe
Contributor
Contributor
 
Posts: 718
Joined: Sun Sep 28, 2008 2:33 pm
Location: q3dm7
Blog: View Blog (0)


Re: Learning Java...

Post by sanddbox on Sat Mar 06, 2010 9:58 pm
([msg=36224]see Re: Learning Java...[/msg])

Woops, missed that. tgeo is correct- you compare with the == operator. His code would set the variable data to 5.
Image

HTS User Composition:
95% Male
4.98% Female
.01% Monica
.01% Goat
User avatar
sanddbox
Expert
Expert
 
Posts: 2344
Joined: Sat Jul 04, 2009 5:20 pm
Blog: View Blog (0)


Re: Learning Java...

Post by darksniper8542 on Sat Mar 06, 2010 10:05 pm
([msg=36225]see Re: Learning Java...[/msg])

a year away from java really killed me
darksniper8542
New User
New User
 
Posts: 3
Joined: Wed Mar 03, 2010 9:53 pm
Blog: View Blog (0)


Re: Learning Java...

Post by eljonto on Sun Mar 07, 2010 3:41 am
([msg=36244]see Re: Learning Java...[/msg])

darksniper8542 wrote:a year away from java really killed me


It's not really Java as opposed to the fundamentals of many programming languages. Statements in braces, parameters in parentheses and knowing the difference between assignment and equality operators.
-Quis custodiet ipsos custodes?, Juvenal
_________________________________________________________________
User avatar
eljonto
Poster
Poster
 
Posts: 373
Joined: Thu Apr 17, 2008 1:16 am
Location: Australia
Blog: View Blog (0)


Re: Learning Java...

Post by Pagerops on Sun Mar 07, 2010 3:44 am
([msg=36246]see Re: Learning Java...[/msg])

So its like C with the If/then but it If/else ( :!: if that make sense :!: )
User avatar
Pagerops
New User
New User
 
Posts: 21
Joined: Wed Jul 09, 2008 2:29 pm
Blog: View Blog (0)


Next

Return to Programming

Who is online

Users browsing this forum: No registered users and 0 guests