Jul 20, 2008

Java Lab 01 - My first installment of Java tutorials

Free Web Hosting, No Ads > CONTRIBUTE > Computers > Programming Languages > Java, Java Servlets, Java Script, & JSP

free web hosting

Java Lab 01 - My first installment of Java tutorials

dyknight
I have decided to come up with a series of Java tutorials teaching simple Java. This is my first chapter.

For this chapter, I will be showing how to write a simple program that:
1. Pops up a JOptionPane,
2. Shows a message on the pane.

Classes, Objects
Java, as some of you might already know, is a/an (almost) completely object-orientated programming language (OOP). Some of the experts out there may argue that Java is fully object-orientated, but I don't think that is absolute. Some programmers consider Ruby to be fully OOP and Java to be almost fully OOP because Java still uses primitive data types. (I don't know much on this, but if you do, please PM me. I love to learn.)

Object-orientated means that the program works with objects. An object is something that contains data and methods. A class defines the object, specifying what information the object should hold and what methods can be called. (methods are also known as functions)

An analogy:
"Humans" can be considered to be a class. Objects of this class should have a name, an age, a gender, and a bloodtype. The objects should be able to talk, sleep, eat, and see. "John" is an object. His name is John, age 18, male, bloodtype O. Like all humans, he talks, sleeps, eats, and sees.

Human -> Class
John -> Object
name, an age, a gender, and a bloodtype -> information
talk, sleep, eat, and see -> methods

The Code
To start coding, you need Java 2 Standard Edition Runtime Environment and Development Kit (J2RE and JDK, which can be downloaded from java.sun.com) and a compiler. I recommend Dr. Java, which can be downloaded from drjava.org.

In Java, everything is held within a class. Even the main method is enclosed within a class. So we start by typing this in:

CODE
/*
   Lab 1:

   File: Lab01.java
*/



public class Lab01 {



Now, we need to DECLARE the objects we need (e.g. we need to declare a human "john"):

CODE
javax.swing.JFrame window;
java.awt.Point position;


The above declares a window object and a point object, from the javax.swing package and the java.awt package.

Next, we need to CREATE the objects we need (e.g. creating John's body):

CODE
window = new javax.swing.JFrame ();
position = new java.awt.Point(200,500);


Then we give the characteristics:

CODE
window.setSize(300,300);
window.setTitle("My First Java Program in Lab");
window.setLocation(position);


Finally, we make it visible:

CODE
window.setVisible(true);


The final code looks like this:

CODE
/*
   Lab 1:

   File: Lab01.java
*/



public class Lab01 {

    public static void main (String [] args) {
          
    javax.swing.JFrame window;

        window = new javax.swing.JFrame ();

        window.setSize(300,300);
        window.setTitle("My First Java Program in Lab");

        java.awt.Point position;

    position = new java.awt.Point(200,500);

        window.setLocation(position);
    window.setVisible(true);
    }
}


Type the above into Dr Java, compile and hit F2 to run. There you go!. Do leave a message to ask for help if you need.

 

 

 


Reply

beeseven
First of all, I see no JOptionPane. JFrames aren't the same thing. Second, why don't you import anything? It makes it less messy and you don't have to type the whole package tree every time you want to do something. You didn't setDefaultCloseOperation either, which can cause some problems.

Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.
Confirm Code:

Similar Topics

Keywords : java, lab, 01, installment, java, tutorials

  1. I Need Help With Setting Up My Site, Made Using Java
    any help would be appreciated (5)
  2. N00b Programmer
    Need Tutorials (1)
    Hi, I am trying to learn C++ as I have been interested in mods and making games forever. I have been
    unsecsessful in my search for good tutorials, guide or any kind of documentation on how to learn the
    language and utilize it and program. any reccomendations or help would be very appreciated!
    Thanks!....
  3. Java Game
    (2)
    Hi, I'm interested in game creation on websites. The game should be playable via web browser.
    I'm not new in programing, I know C++, C# and OpenGL api. But I'm new on Java. So I have
    some questions I want to ask You: Will I'l be able to create simple 2d game with java which
    would be playable via web browser? Simple 2d game means: timers, images, animated sprites, in game
    font. Will I'l be able to use OpenGL? Or I should use something different? Does Trap17 suports
    java graphics features I want? Thank You for Your time and answers.....
  4. Learn Java Programming Language Online Step By Step
    (0)
    I had found this site >> http://learnjava.awardspace.com This website is for people who want
    to learn Java Programming Language step by step. This website also includes JAVA lessons from the
    beginning to advanced level. So this site appropriates for the beginner of Java programmer language
    or non-basic Java Programming Language. The lessons are easy to follow and understand starting
    from how to get your PC JAVA ready, the fundamental programming concept and creating the real
    application. Moreover, the working examples are also included. Please enjoy the les....
  5. Java Object[][] Help
    (2)
    I'm having some issues with working with objects . I get an index out of bounds ex.
    Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 0 heres how
    I'm using it ---------------------------- Object contestants = new Object {}; contestants
    = "test"; any ideas appreciated. Do I need to specify the initial size on creation or something?
    It seems I answered my own question I gave it an inital size then I was able to add things. But is
    there a way I can add to it on the fly without knowing its require maximum size?....
  6. Free Java Hosting?
    (2)
    Hii.. just want to know if Trap17 provides the java(jdk)/jdbc/mysql as free hosting?? In case, it
    doesn't provide these. Can anyone guide me to a free java host? Thanks. Manu....
  7. Java Vs Javascript
    (11)
    I thought they were completely different things. Surely javascript should be seperated from the rest....
  8. Apache Tomcat And Java
    Will they run on package1/2 (0)
    Hi, Ive made a couple of Java servlets for a website and was wondering if it is possible to use them
    w/ the free hosting package is an application environment such as Tomcat? Dunk....
  9. Java Or C++
    (2)
    Many having tell me to make my MMORPG in java leads me to agree, But I'm not sure truly is it
    not yet easier, but yet the outcome of programming an MMORPG in java will make it fail or succeed
    more then one in C+= I've learned a lot of variables in javascript, and I don't think that
    java would be too bad either. My true question is, is those who use these languages, which seems
    to give better outcome, and which seems to be more in ease. Regards -PCessna....
  10. Full Web Building Tutorials
    finding the sites that help allot with webdesign (2)
    I have been using the site http://www.w3schools.com/ for quit some time now, and i really really
    like it it helps allot if your a beginner and has allot to offer if you have some webdesign
    knowledge. At W3Schools you will find all the Web-building tutorials you need, from basic HTML and
    XHTML to advanced XML, SQL, Database, Multimedia and WAP W3 publishes a series of tutorials, though
    most web developers are unaware of it. Mainly, though, W3C's site houses a collection of
    proposals, drafts, and Recommendations, written by geeks for geeks. And when I say geeks, I d....
  11. Budding Java Game Developers?
    Ever wanted to make your own java web-based game, but not had the time (8)
    Right, this is the first post of hopefully many in this thread. Basically the idea is to get many
    developers together to share ideas and knowledge to create our very own game. First we'll be
    asking for is any ideas of what kind of game everybody would like to make, and then we'll set
    about assigning tasks depending on everybodies skills. We will need programmers, artists,
    web-designers, even admin and marketing. This will be freeware, but the experience will be great.
    So, ideas anyone?....
  12. Java Applet Query
    (1)
    Hey there, I have made an applet that shows images moving about the screen. I have pause/resume
    buttons that work. But i've noticed that when the applet is interuppted by something i.e moving
    another window over it, it will automatically repaint. My question is how can I stop this? How can
    I make it so that the only time that paint is called is when I want it to be called? Thanks in
    advance!....
  13. Wysiwyg Jscript Editor
    I need a good Java Script Editor (3)
    Can any of you guys give me a good Java Script Editor. I really need one badly. I make Java Script
    goodies as an addon for my web site but it really takes a lot of my time to type all those similar
    code blocks over & over again, Could any one please provide me such an editor as Microsoft Visual
    Basic or Visual C++. I mean the IDE shold have similar features. ****Above all it should be a free
    one**** Thanks in adv. Dave....
  14. Know Of Any Good Php Tutorials?
    (9)
    Hi all this well be my first posting so hopefully I can get some good advise here. Can anyone tell
    me were there is a very good tutorial for php. I am good at self teaching from tutorials but i do
    hear php can be difficult so if anyone can lead me to a php tutorial that is as basic as possible i
    would be very pleased. p.s hopefully this post is in the right area :/....
  15. Tom Clancy's Rainbow 6: Vegas
    New installment to next-gen shooter (1)
    Ubisoft and Red Storm Entertainment are about to release the latest installment in the Award-winning
    Rainbow Six series: Rainbow Six: Vegas 2. Terrorists once again storm Las Vegas, and only Team
    Rainbow can stop them. Armed with new technology and new weapons like the M468 (An advanced version
    of the M16A2/M4A1 rifle) and the SR-25 sniper rifle, Team Rainbow raises the stakes in this action
    shooter. Featuring an intense single player campaign and new multiplayer maps and modes, R6: Vegas
    2 is guaranteed to be on of this year’s most anticipated games. R6: Vegas 2 hits ....
  16. Php Calculator That Calculates Genetic Percentages?
    I need help finding sites or tutorials. (2)
    Okay, I have created, looked, and generally studied simple PHP calculators. However, I can not seem
    to find any tutorials on how to create a genetic calculator. One that calculates genetic percentages
    similar to that of Punnette Squares. I have seen plenty of websites that have these types of
    calculators, but I have yet to see any websites offer tutorials on how to create these types of
    calculators. So.. does anyone know of any tutorials I can find or sites that might have the tutorial
    I am looking for? Maybe even a tutorial here? Reason for asking: I am creating a webs....
  17. Java Updates On My Machine
    I have several versions (3)
    As per the following image, I have several java updates stored on my machine, and I wondered if the
    older ones could be deleted and have the java runtime perform okay? I'm simply trying to
    clean out a bunch of junk on my machine... make some HDD space.....
  18. Circular Movment/animation In Java?
    (6)
    Hey there guys! How would i go about making an object move about a fixed point for a java
    applet? Thanks in advance guys! Regards, Rod....
  19. Soldier Of Fortune: Payback
    Latest installment from the infamous blood-and-guts FPS (1)
    Soldier of Fortune: Payback, the third installment of Activision and Cauldron HQ’s Soldier of
    Fortune first person shooter franchise just hit stores. And GameTrailers.com has posted a recent
    review of the game, released for the PC, Playstation 3, and XBOX 360. In this installment, you play
    a gun for hire that is double-crossed while protecting a valuable target. You travel to the world’s
    most deadly hotspots to stop an extremist plot while dispatch various enemies. This budget-priced
    game, as in all other first person shooters, features a linear single-player campaign....
  20. Irc On Your Java Enabled Mobile!
    A breif tutorial describing how to access IRC on a Java enabled mobile (1)
    Before we go on please make sure that you have the following: Data Subscription on your Network
    with Support for Data Access from Java Apps. This could either be a GPRS Connection or a Wap
    connection. Whatever, it is, it is better to have a Traffic based Subscription rather than a Time
    based Subscription as chatting involves less traffic & more time. Generally, GPRS is billed Traffic
    wise whilst Wap is billed Time wise. Contact your Service Provider for more information. A phone
    with Java MIDP Support with Data Service Access & OTA Java App Installation & a max ja....
  21. Beginning Java
    where to start (10)
    does anyone know of any good websites with free java tutorials for people without a lot of prior
    coding experience? i've read some tutorials, but every one i read starts making references to C
    and C++... well i don't know either of those so it gets really really confusing really really
    fast. ive downloaded the sdk but that is it.... i know a pretty good amount of php and a tiny bit of
    perl but those are procedural languages so i dont know if they even helpe me at all with an OOP
    language like java.....
  22. Jsp Or Java Chat Script Like Mig33
    (4)
    so most of you guys know mig33. its a wap application,probaly java.most kindly to be java. does
    anyone have java knowlege or knows where i can get a chat script like mig33? i also know this server
    supports jsp so im planing to use it for my application. i was hosted here last year but moved
    because i found a better host. now im back just to use the jsp on this server. Im planing to run
    chat applictions so if any one wants to help me in my project let me know.....
  23. The Power Of Java
    the best application that shows java features (14)
    Java technology has various usage from mobile applications to Enterprise applications. I think the
    power of Java technology in web applications and applets is showed in "meez.com" where u can create
    your own 3d avatars. /rolleyes.gif" style="vertical-align:middle" emoid=":rolleyes:" border="0"
    alt="rolleyes.gif" />....
  24. Java Helpdesk
    All your queries regarding Java Programming goes here. (8)
    Hellow friends, I am creating this thread for all queries and suggestions related to java coding. If
    you face any problem, post it here, and others who have a solution can post the reply here. Hope it
    helps the users.....
  25. Hotspot Virtual Machine Exception_access_violation
    conflict between Sun Java and Windows (4)
    i was just messing around as usual on the net, and when i was closing everything down, i noticed
    this file on my desktop 'hs_err_pid3672' its a text file, i have no idea what it is and cant
    understand anything in it, but its kinda freakin me out, so i would appreciate anything you guys
    have to say about it CODE # # An unexpected error has been detected by HotSpot Virtual
    Machine: # #  EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x7c9010f3, pid=3672,
    tid=1928 # # Java VM: Java HotSpot(TM) Client VM (1.5.0_06-b05 mixed mode, shar....
  26. Java Basic Program Guidance
    (6)
    aving some problems taking in the Java at Uni, Was wondering if anyone could shine some light on it
    for me. My task is to write a program that will ask you to enter 2 words. the program will then
    print out both words on one line. However the words will be seperated by dots that will make the
    total length of the line 40. so if your first word was turtle and the second was abc, the output
    would be turtle...............................abc The program should check for certain conditions:
    1. a word can not be longer than 37 characters; 2. there must always be atlest 2 do....
  27. How To Create Java Button Or Frame
    to be customized (12)
    hi to all!!!! just like to ask if it would be possible if i could make a custom
    button or frame in java. i got tired of using the build infeatures in java. i would like to create
    my own dessign of button or frame.. can it be possible!!! /biggrin.gif' border='0'
    style='vertical-align:middle' alt='biggrin.gif' /> thank!!!! /laugh.gif'
    border='0' style='vertical-align:middle' alt='laugh.gif' /> New Help In! is NOT a descriptive
    topic title. Next time you decide not to follow the posting rules, you will be issued a w....
  28. [help] Java Script: Window.open
    Works with Firefox, not IE (8)
    CODE <HEAD> var popUpWin=0; function popUpWindow(URLStr) {
     if(popUpWin)  {    if(!popUpWin.closed) popUpWin.close();  }
     popUpWin = open(URLStr, 'GunBound Tactics: Screenshots',
    'width=820,height=550,menubar=no,resizable=yes,scrollbars=yes,toolbar=no,top=90,left=90')
    ;; } </HEAD> <BODY> <a
    href="javascript:popUpWindow('/f11/clipped.php');"><b>Clips&
    #60;/b></a> This is a script for opening a new window. It works ....
  29. Java Script Drop Down Menu With Css
    - a full code for a dynamic drop down (2)
    Introduction This is a code that I use to dynamically create the drop down menus. First, you have
    to edit the following code and put it in your Javascript. Notice : /*** SET BUTTON'S FOLDER HERE
    ***/. Edit that to your folder. Also, the /*** SET BUTTONS' FILENAMES HERE ***/. This creates a
    mouseover when the drop down is activated. Put all your onmouseover images under: oversources = new
    array; and your onmouseout images under : upsources. Be sure to set your on and out images above
    each other. CODE /*** SET BUTTON'S FOLDER HERE ***/ var buttonFold....
  30. Auto Run Java Program
    Run Java program on double click (11)
    Some of the installables in java comes in form of .jar file, one has to just double click or type
    "java -jar file.jar", and it starts executing. The reason for this is a line appended in the
    MANIFEST.MF file of that jar file. For writing a similar jar file of your own, just write your java
    file, then compile the same and create a jar file. Create a MANIFEST.MF file and the content should
    have the followings: CODE Manifest-Version: 1.0 Created-By: xyz Main-Class:
    xyz.MainClass Here xyz.MainClass is the main class. Now create a jar file with the man....

    1. Looking for java, lab, 01, installment, java, tutorials

Searching Video's for java, lab, 01, installment, java, tutorials
Similar
I Need Help
With Setting
Up My Site,
Made Using
Java - any
help would
be
appreciated
N00b
Programmer -
Need
Tutorials
Java Game
Learn Java
Programming
Language
Online Step
By Step
Java
Object[][]
Help
Free Java
Hosting?
Java Vs
Javascript
Apache
Tomcat And
Java - Will
they run on
package1/2
Java Or C++
Full Web
Building
Tutorials -
finding the
sites that
help allot
with
webdesign
Budding Java
Game
Developers?
- Ever
wanted to
make your
own java
web-based
game, but
not had the
time
Java Applet
Query
Wysiwyg
Jscript
Editor - I
need a good
Java Script
Editor
Know Of Any
Good Php
Tutorials?
Tom
Clancy's
Rainbow 6:
Vegas - New
installment
to next-gen
shooter
Php
Calculator
That
Calculates
Genetic
Percentages?
- I need
help finding
sites or
tutorials.
Java Updates
On My
Machine - I
have several
versions
Circular
Movment/anim
ation In
Java?
Soldier Of
Fortune:
Payback -
Latest
installment
from the
infamous
blood-and-gu
ts FPS
Irc On Your
Java Enabled
Mobile!
- A breif
tutorial
describing
how to
access IRC
on a Java
enabled
mobile
Beginning
Java - where
to start
Jsp Or Java
Chat Script
Like Mig33
The Power Of
Java - the
best
application
that shows
java
features
Java
Helpdesk -
All your
queries
regarding
Java
Programming
goes here.
Hotspot
Virtual
Machine
Exception_ac
cess_violati
on -
conflict
between Sun
Java and
Windows
Java Basic
Program
Guidance
How To
Create Java
Button Or
Frame - to
be
customized
[help] Java
Script:
Window.open
- Works with
Firefox, not
IE
Java Script
Drop Down
Menu With
Css - - a
full code
for a
dynamic drop
down
Auto Run
Java Program
- Run Java
program on
double click
advertisement



Java Lab 01 - My first installment of Java tutorials



 

 

 

 

ADD REPLY / Got an Opinion! Remove these ADs! RAPID SEARCH! Free Web Hosting [X]
Express your Opinions, Thoughts or Contribute more info. to help others.
Ask your Doubts & Queries to get answers, So that "Together We can help others!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE