Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old May 22nd, 2006, 6:20 PM   #1
ReggaetonKing
Pro
 
ReggaetonKing's Avatar
 
Join Date: Nov 2005
Location: NJ
Posts: 894
Rep Power: 13 ReggaetonKing is on a distinguished road
Send a message via AIM to ReggaetonKing
Programming with Java: Tutorial

Programming with Java
------------------------------------
"Intro to Java"
First I would like to say Java is a great programming language. Its flexible
and a lot can be done with it. While other high level language are translated into native
code or machine code.Java is translated "Java Bytecode", which is read by the a small Java
program itself called the JVM(Java Virtual Machine). The JVM is considered an interpreter.
There are many reasons Javauses it's own Virtual Machine and not compile like
other programming languages. One needs to understand this before going on and writing program
using Java. Using Java Bytecode makes Java very popular in industries who needs a independent
program to "Run Anywhere". The J.D.K (Java Development Kit) are the tools used to create and
develop Java programs.

You can download Java, JVM, and JDK via Sun Microsystems's Web Site.
http://java.sun.com/j2se/1.5.0/download.jsp

It's necessary to have the lastest JRE and JDK in order to write Java
programs. In order to run any Java program on your computer, you need the
JRE. Only if web sites have Java Applets embemmed. This is an type of
Java program which is specially used for Web Pages. Examples of
Applets are on a lot of popular web sites like www.yahoo.com and others.
------------------------------------
"Data Types"
There are a range of data types in the programming language of Java. Here
are just some of the data types that are available.
char - a character like a,b,c, etc.
String -- a group of characters or words.
int -- Integer, a number ranging from -2147483648 to 2147483647.
float -- a Integer but with a longer range of numbers than int, -9223372036854775808 to 9223372036854775807.
single -- a number with a decimals.
double -- also a number with a decimals but with a longer range.
I am not going to cover much on Java's data types but you should have the
basics on which one can do what.
------------------------------------
"How to Write A Program in Java"
You only need a text editor like Notepad or Vim to write Java programs. You
can compile and run Java program you've written through the command line once you've installed
Java and the JDK. You can also use IDE (Integrated Development Enviroment) such as Eclipse,
Bluejay, and JEdit. I consider IDEs to be great. But I recommend a new user to use the command
line to run and compile their programs. Its good practice and you will appreciate it more! :-)!

Let's get start by opening your editor or IDE, which ever you prefer.
Start by creating a new Java file also called a Java Class. Java uses the
extension ".java" and it's compiled buddy's extension is ".class". Remember
that what ever you name you file, that has to be the name of your main class.
Now lets get into the writing part. Lets create a file called Welcome.java
and inside that file we are going to write...
[PHP]
public class Welcome
{
public static void main(String args[])
{
System.out.println("Welcome World!");
}
}
[/PHP]

Now we are going to discussion what all of these words actually mean.
[PHP]
public class Welcome
{
//methods go here....
}
[/PHP]
It is a class. All Java program is made up of classes. The class "Welcome"
is declared "public". We are not going to go
into what else we can do because this is just a a short tutorial on
Programming with Java.
[PHP]
public static void main(String args[])
{
//statements of code go here...
}
[/PHP]
This is what every Java program needs in order to run a program, A "main
method". For those who have experience in other programming languages methods
are just re-named functions. A method something that carries out a specific task
that is wanted to be done by the programmer. The Java API is full of classes
with methods just specifly designed to carry out something.

Here's an example of using the Math class located in
The java.lang package.
[PHP]
public class Welcome
{
public static void main(String args[])
{
int x;
int y;
int sum;
x = (int) (Math.random() * 10) + 1;
y = (int) (Math.random() * 10) + 1;
sum = y + x;
System.out.println("The sum of x and y is " + sum);
}
}
[/PHP]
What I've used is the "Math.random()" statement to generate a random number
1 thru 10. Because the Math.random() generates a floating-number, I made it
an integer number so that things can be easier. Also, Math.random()
generates a number that is more or equal to zero but less than one,
"0 <= Math.random() < 1". That's why it is necessary to multiply it by
10 and add 1. So that the number 1 thru 10 can be generated. Play around
with the example and see what you can come up with. The "Math.random()"
method's task is only to create a random number not anything more, not
anything less. For this section, start creating your own methods
instead of having your main method do everything else. Methods make
programming a lot easier and it is easier to debug a program when a
program is broken down into parts. It will not matter now when creating
< 20 line program, when you want to create your own Media Player or
something else that will be large, you will see it's a must to have
different methods. No one can write a large program perfectly in one shot.
__________________
I would love to change the world, but they won't give me the source code!
ReggaetonKing is offline   Reply With Quote
Old May 22nd, 2006, 6:24 PM   #2
Jimbo
Battle Programmer
 
Jimbo's Avatar
 
Join Date: Feb 2006
Location: Bellevue, WA, USA
Posts: 887
Rep Power: 12 Jimbo is on a distinguished road
might I suggest the tutorial section? :p
Jimbo is offline   Reply With Quote
Old May 22nd, 2006, 6:25 PM   #3
ReggaetonKing
Pro
 
ReggaetonKing's Avatar
 
Join Date: Nov 2005
Location: NJ
Posts: 894
Rep Power: 13 ReggaetonKing is on a distinguished road
Send a message via AIM to ReggaetonKing
yeah I didn't have the rights to post this in there so maybe Big K would do it for me.
__________________
I would love to change the world, but they won't give me the source code!
ReggaetonKing is offline   Reply With Quote
Old May 22nd, 2006, 6:48 PM   #4
Jimbo
Battle Programmer
 
Jimbo's Avatar
 
Join Date: Feb 2006
Location: Bellevue, WA, USA
Posts: 887
Rep Power: 12 Jimbo is on a distinguished road
You might to get your information correct... I read as far as data types and then cracked up so hard I stopped reading...
Jimbo is offline   Reply With Quote
Old May 22nd, 2006, 6:53 PM   #5
andro
Professional Programmer
 
Join Date: Oct 2005
Location: California
Posts: 364
Rep Power: 13 andro is on a distinguished road
Send a message via AIM to andro
Float's aren't integers, long's are (which you forgot to mention). There's no such thing as a single. You forgot short, byte and boolean. Also, String isn't a data type, it's a class.

I don't think you should be writing a tutorial quite yet.
andro is offline   Reply With Quote
Old May 20th, 2008, 2:17 AM   #6
rakesh_kpn
Newbie
 
Join Date: May 2008
Posts: 2
Rep Power: 0 rakesh_kpn is on a distinguished road
Re: Programming with Java: Tutorial

q
rakesh_kpn is offline   Reply With Quote
Old May 20th, 2008, 3:37 AM   #7
Jabo
Not a user?
 
Join Date: Sep 2007
Posts: 330
Rep Power: 11 Jabo is on a distinguished road
Re: Programming with Java: Tutorial

I would suggest doing a spell-check and a grammar check too before submitting it.
Jabo is offline   Reply With Quote
Old May 20th, 2008, 11:58 AM   #8
Jimbo
Battle Programmer
 
Jimbo's Avatar
 
Join Date: Feb 2006
Location: Bellevue, WA, USA
Posts: 887
Rep Power: 12 Jimbo is on a distinguished road
Re: Programming with Java: Tutorial

old thread
</discussion>
__________________
<insert disclaimer here>
Jimbo is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

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

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




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 6:16 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC