Welcome, Guest: Join Nairaland / LOGIN! / Trending / Recent / New
Stats: 2,347,252 members, 5,206,405 topics. Date: Monday, 14 October 2019 at 12:16 AM

Java Programming For Dummies - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Java Programming For Dummies (36862 Views) (2) (3) (4)

(1) (2) (3) (4) (5) (6) (7) (8) (9) (10) (Reply) (Go Down)

Java Programming For Dummies by gbengaijot(m): 9:45am On Feb 14, 2006
For those of us who programming has made us look like incompetent fools.
Does anyone knows basics of programming using java?, can u please give us tutorials??, I av no knowledge in programming but willing to get my hands wet.

SBUcareer, are you there?, layi, seun, coder, waiting for you guys.
dish it out to us plzzzzzz
Re: Java Programming For Dummies by sbucareer(f): 6:27pm On Feb 14, 2006

Thank you for opening this thread. I will be giving a tutorial on Java and C++. I will start with Java and progress through C++.

I will be using a reference material, basically a book by Professor Fintan Culwin, a Head of Software Engineering at the school of Computer Information Systems and Mathematic at London South Bank University. The book is called A Java Foundation Classes Primer, ISBN 0-333-77339-X

The book discuses Software Engineer rather to Software programming, which is what I will be teaching. I have to start making you think like a software Engineer rather than programming. The truth is that you can learn software programming in little as two to three weeks, but it will take you years to learn software Engineer/Development.

The C++ I will use this book as a reference by Deitel & Deitel, Third Edition, How to Program C++. It has a UML for Software Engineers. ISBN 0-13-089571-7


Re: Java Programming For Dummies by sbucareer(f): 6:37pm On Feb 14, 2006
[size=24pt][center]Learning Java - from a system approach[/size][/center]


I will not bore you with the history of programming and why Java was introduced. But if you want to learn the reasons behind java, which it may also be, you can read this

There is no point teaching students a language without telling them how or where to use it and all the tools they need for it.

To learn java you will need these tools

1. IDE
2.Java 1.5 Compiler
3.Set the environment for your system.

Emr,  I will be teaching this on windows, but if you are reading this from a unix web browser (Probably Firefox) let me know I will write-up examples of installing these tools and setting up your environment for you.

Re: Java Programming For Dummies by sbucareer(f): 7:02pm On Feb 14, 2006


Download and install textpad, I used it because it is shareware but allows you unlimited access to the IDE, but there is some annoying glitches, you will soon find out. I'd introduced you to a more complex IDE but it will take time to configure and it will forfeit the idea of the tutorial, as unnecessary time will be wasted learning IDE.

If you are confident or want to do extra learning as most student do, you can try the Netbeans or Eclipse

The configuration of the above IDE is out of the context of this tutorial.

Download java 1.5 and install it into your system following the installation wizard.  Java 1.5 will install in your windows directory i.e. C:\Program Files\Java\jdk1.5.0_06, don't bother yourself with _o6 this is for stability version. We are not developing critical system yet so we will not bother about stable version.

Go to your system control panel and double click on your systems, select the advance tab and click on environment variables, this is on windows XP Prof.

For other windows platform, locate you systems from control panel and find environment variables it looks like this.

You have two components there, user Variables and System Variables. You will need the system variables, and do this.

From the system variable click new and edit as follows

Variable name: JAVA_HOME
Variable value: C:\Program Files\Java\jdk1.5.0_06


Click ok to come off the screen. Find in the system variable, a variable called path and click the edit button. Leave the Variable name: path and add this to your, NOTE do not delete anything just add ; at the end of the variable and add your JAVA_HOME like this ;%JAVA_HOME%\bin  Here is how my path looks like

Variable value: C:\Program Files\Microsoft.NET\FrameworkSDK\Bin\;C:\Program Files\Microsoft Visual Studio .NET\Common7\IDE\;C:\WINDOWS\Microsoft.NET\Framework\v1.0.3705\;C:\Program Files\Microsoft Visual Studio .NET\Vc7\bin\;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%JAVA_HOME%\bin;%CATALINA_HOME%\bin;C:\Program Files\MySQL\MySQL Server 4.1\bin;c:\Program Files\Microsoft SQL Server\90\Tools\binn\

You can see where I added my JAVA_HOME highlighten in blue.  Once you have done this fire up your texpad and write this program and compile it. If it works you have completed tutorial one if not PM [email=valentine.obih@gmail.com?subject=Help with installing java from Nairaland.com]my email[/email]
Re: Java Programming For Dummies by sbucareer(f): 7:09pm On Feb 14, 2006
This is how the system property looks like from your window control panel

Re: Java Programming For Dummies by sbucareer(f): 7:17pm On Feb 14, 2006
Test your IDE and Java installation plus environment setting by running a simple HelloWorld program


public class HelloWorld extends Object{
  public static void main (String args[]){
         System.out.println("Hellow World"wink;
   }//End main
}//End program HelloWorld


Don't worry about any of the above code, just copy/type it into your IDE, compile and run it. I will explain what is happening in a later tutorial.


Re: Java Programming For Dummies by sbucareer(f): 8:02pm On Feb 14, 2006


I will start by explaining what is OOP. OOP is defined as Object Oriented Programming. You will ask yourself what the heck is OOP; I know I asked myself the same question when I started learning OOP.  Well let’s take a simple example of OOP from a different point of view.

Let say someone is sick and he go and visits the doctor and the doctor said you have cold, hence high temperature, and headache. Listen cold, temperature and headache, three things at the same time. I am not a doctor but I will think the doctor will give the patient three pills to help and solve each problem. But wait, wouldn’t it be nice if the doctor had given him just one pill that contains all the medicine for the three type of problem he had? Well, I know I will like it, as I hate taking medicine.

What does that means, in computer world OOP means a revolutionary concept that changed the rules in computer program development, object-oriented programming (OOP) is organised around "objects" rather than "actions," data rather than logic.

Like our pill scenario, we can put more that one thing in a container, that container is called Object. We can access the Object and get other information it contains. If an Object contains headache medicine or temperature medicine we can ask for these information.

Remember that Object belong to a data type i.e Integer, Char, String, Boolean, and Object. There is some thing we call Poloymorphysim, we will discuss about that later on, basically it is a way to change an object to another data type. It helps in managing the class and less coupling in program. I will also discuss about coupling at a later stage.


Re: Java Programming For Dummies by sbucareer(f): 8:17pm On Feb 14, 2006


Remember that every class you create is an object. That class can contain lots of information relating to itself and other classes. An Object is an instance of some class, which has aggregate values, attributes and identity. There are several difinition of Object. You can do a google search or pick up a very known Java book and compare Object definition in correlation to computer programming.

Class is basically an Object. Let say that a class is one file named HelloWorld.java, when we instantiate the class it becomes an Object and we can have many insatances of a class. There is no limit to the amount of instances we can have out of a class.

I will show you how to instantiate a class at later tutorial

Re: Java Programming For Dummies by sbucareer(f): 8:49pm On Feb 14, 2006


Here is a Class diagram I want to introduce. It helps when you are building your class. You will noticed that the digram is divided into three cross sections namely;

1. Private
2. Public
3. Protected

What this means it that each section has a strict rule enforcing it to become what each section is depicting. If a variable or method is on any section it automatically inherit the rule of that section.

Let me explain what this Class diagram does. The rectangular shape at the top depicting radio means that, this class name would be called Radio. The rectangles on the right hand side are methods except the first one that shares the same name with the class Radio. It is called constructor. A constructor help initialize the class to initial values and provide an identity for the Object. Remember I told you that a class is the same as Object only that you can have as many objects you want.

The rectangle at the middle is the attributes of the class, in some other language called variables. You can see that the variables are private. It means that no Object can see it attributes.

The last one if the rectangle at the left with protected attributes. It is a method that return whether the Radio is working or not. The Objects that can access this is the objects within it package. Don't worry too much about package, private, protected and public I will talk about it later in the tutorial. Don't worry it will all make sense soonest, I promise.

Re: Java Programming For Dummies by sbucareer(f): 9:51pm On Feb 14, 2006

Let me write the above class and we can see what it does. Remember I am NOT teaching programming, I am teaching software development. As you can see we have already start thinking of developing a Radio application.

In Java we have libraries like any other language. Why is library good for programmers?

1. It help in developing application fast
2. It has been tested, hence reduce bugs
3. It promotes reuseable code
4. It make life easier for you.

All these and many more are the reasons for using libraries. You can develop your libraries if you want, but it will take time to develop a simple application. In java we use the reserved keyword import to add libraries that we want to use. Another key factor to learning java is getting familiar with API (Application Programming Language), really what this means are libraries.

We are going to use a Class called Object and we will import it from java.lang.Object. See API

import java.lang.Object;

public class Radio extends Object{

private int frequency = 0;
private int volume = 0;
protected boolean working = false;

public Radio (int theFrequency, int theVolume){

   frequency = theFrequency;
   volume        = theVolume;
   working = true;
}//End constructor

public int getFrequency( ){
   return frequency;
}//End getFrequency

public void setFrequency (int toSet){
   frequency = toSet;
}//End setFrequency

public int getVolume( ){
  return volume;
}//End getVolume

public void setVolume (int toSet){
   volume = toSet;
}//End setVolume

protected boolean isRadioWorking(){
   return working;
}//End isRadioWorking
}//End Class Radio



This is the actual code that the class diagram above depict. As you can see it has a class name, attributes (I forgot to add working in the above class diagram), every attributes the class has, it have it getter and setter methods.

A getter and setter methods are Java specification for developing beans. The class above could be refer as bean but for now let call it a class. For every variable name you must have a way to change it value(behaviour), hence set and get it.  All you do is put get/set in front of the attributes name

Re: Java Programming For Dummies by skima(m): 10:04pm On Feb 14, 2006
This is cool, hope ur compiling it on a single document ,
Re: Java Programming For Dummies by sbucareer(f): 10:18pm On Feb 14, 2006


Here is the implementation class. The class that will run the above class. We are going to called it RadioDemonstration class

import java.lang.Object;

public class RadioDemonstration extends Object{

//We are going to create Object(s) of class Radio
static private Radio firstObject = null;
static private Radio secondObject = null;

public static void main (String args[]){

//We are going to instantiate two objects we created above
firstObject = new Radio (12, 3);
secondObject = new Radio (4, 7);

//Testing the new Objects or querying their attributes
System.out.println (firstObject.getFrequency());
System.out.println(secondObject.getFrequency());

//Changing the identity of the objects we create above, hence assigning new values to their attribute.
firstObject.setFrequency(3);
secondObject.setFrequency(10);

//Testing the new Objects or querying their attributes
System.out.println (firstObject.getFrequency());
System.out.println(secondObject.getFrequency());
}//End main
}//End RadioDemonstration class


What the above class is doing is instantiating the objects of Radio class and accessing there attributes through getter and setter methods. 

Here is an assignment for you.

1. Draw a class diagram of temperature
2. Determine the attributes it will have and methods (Setter and getter)
3. Provide a class for temperature and also provide a suitable demonstration class called TemperatureDemonstration.
4. Print out the attributes by accessing its appropriate method (Setter and getter)

Post your solution here. Don't send it to my email.  When I recieve a reasonable solution I will go to next tutorial.

Thanks for reading

Re: Java Programming For Dummies by gbengaijot(m): 10:26pm On Feb 14, 2006
Mmmmmmmmmmmmmmmmmmmmmm, grin SBU, please hang on oooooo, it seems loads for me to leanr. can u give me like 2 days to assimilate this, lol. U r really a teacher.
Re: Java Programming For Dummies by sbucareer(f): 10:57pm On Feb 14, 2006

Every assignment I post here will be a week from the day of post. Example if I post an assignment today Tuesday, I will like to see the answer next week Tuesday. It does not matter if you get it right or wrong and please don't be ashame we are all learning it will help somebody in the future who may want to use this forum as a guide to learning Java/C++ programming to see that the road it not easy.

Besides I can monitor your progress from the public eyes.

Re: Java Programming For Dummies by gbengaijot(m): 11:46pm On Feb 14, 2006
U said we should download the java compiler. i can see download java 1.4, is that it really? There is a download wich includes netbeans and there is another which is j2EE1.4SDK with a JDK5.0 included.

WHich one exactly. should i donwload.( please i knw am a dummy)
Re: Java Programming For Dummies by sbucareer(f): 12:25am On Feb 15, 2006

Download JDK5.0 only. Don't download with Netbeans or J2EE. if you know how to use Netbean you can download JDK 5.0 with Netbean else just download the Java Development Kit 5.0 only.

J2EE, will be when you have learned Java very well, That version is for distributed application, comes with HTTP server and JDBC, JDNI, Web Enterprise, Enterprise Application, Web services and Enterprise Java Beans. You are not ready for this yet. But after this tutorials I bet you would be.

Re: Java Programming For Dummies by gbengaijot(m): 12:53am On Feb 15, 2006
I am downloading it now( i clicked the red logo from this link) http://java.sun.com/j2se/1.5.0/download.jsp. U r my man, av been waiting for a tutor like this. all those books seems like jargons to me. i will install it 2morow nite when i come back from Thomson prometric in salford quays( Thats my workplace).
Re: Java Programming For Dummies by mochafella(m): 12:57am On Feb 15, 2006
sbucareer:

import java.io.Object;

um sbu, shouldn't that be java.lang.Object? Let me know if you need help with anything.
Re: Java Programming For Dummies by sbucareer(f): 1:21am On Feb 15, 2006

Thanks for that mochafella, I am typing straight into the forum, I think I will need to use IDE so all these little mistakes would be corrected for me. mochafella you are welcome to contribute you thoughts.

Correction please. import java.lang.Object, thanks mochafella
Re: Java Programming For Dummies by Fdeveloper(m): 2:54pm On Feb 15, 2006
@sbucareer, Great work! I'm sure many people will find your tutorial very informative.
Re: Java Programming For Dummies by kenniy(m): 3:40pm On Feb 15, 2006
wonderful!, keep that up bro! i'll try and be attempting the assignments
Re: Java Programming For Dummies by olat(m): 7:18pm On Feb 15, 2006
sbucareer, I am also one of those eager to learn the Java. I have always been 'in' and 'out' of it. With this your system approach, I am more than ready to face it. I have also started attempting those exercise.
Please, do not relent, this is one way of empowering somebody, I like ur spirit.
Re: Java Programming For Dummies by sbucareer(f): 8:02pm On Feb 15, 2006
[size=24pt][center]
Help with tutorial
[/size][/center]


I have Identified some attributes and methods for the tutorial above.

Attributes
[list]
[li] celsius[/li]
[li] fahrenheit[/li]
[/list]

Methods
[list]
[li]getCelsius[/li]
[li] setCelsius [/li]
[li] getFahrenheit [/li]
[li] setFahrenheit [/li]
[/list]


Wicked, to draw the Object diagram will be peace of cake now. Remember as a developer you should have a way to allow your system to give feedback.  Remember in previous artifact, we had a boolean method to tells us if the radio is working or not i.e. isRadioWorking().  There is no different to thhis software. We have to provide a method to query the Software, is the temperation software working or not? I will leave that to you to figure out.

Remember to optimize you graphic upload. Don't make it too big. I use fireworks and save as .gif. Gif is a good digital optimization package.

A common graphics format that can be displayed on almost all web browsers. GIFs typically display in 256 colors and have built-in compression. Static or animated GIF images are the most common form of banner creative.


Re: Java Programming For Dummies by Zule(m): 8:13pm On Feb 15, 2006
sbucareer
I must comment on what your doing on this forum in fact it is not easy to do such a work, I mean lecturing some one online (F.O.C) Great!!!! Kudos
Re: Java Programming For Dummies by sbucareer(f): 8:25pm On Feb 15, 2006

Thanks, Zule.
Re: Java Programming For Dummies by kenniy(m): 12:12am On Feb 16, 2006
hmm, embarassed how do i run?
Re: Java Programming For Dummies by mochafella(m): 12:16am On Feb 16, 2006
kenniy:

hmm, embarassed how do i run?
run what?
Re: Java Programming For Dummies by kenniy(m): 12:18am On Feb 16, 2006
the java code
Re: Java Programming For Dummies by mochafella(m): 12:22am On Feb 16, 2006
gbengaijot:

http://java.sun.com/j2se/1.5.0/download.jsp.
Do you have the sdk installed?
Are you using an IDE? What is it?
Re: Java Programming For Dummies by kenniy(m): 12:51am On Feb 16, 2006
yeah, IDE too
i just dont know the very basics, my bad i guess
Re: Java Programming For Dummies by sbucareer(f): 1:02am On Feb 16, 2006


Kenniy, have you looked at tutorial on installing the required software? If you want me to teach you eclipse, open another thread for eclipse. It is one of the most powerful IDE for Java, C/C++ etc. initially developed by IBM and given to open source community

Rather than starting a new thread I have found useful article at IBM website on how to use eclipse

It cost IBM $40 million to developing Eclipse and releasing it as an open source project, to the Eclipse.org Consortium, so you are working with a powerful IDE. If you know how to use eclipse, you can even plugin your application into eclipse. Like microsoft browser that allows you to plugin shockwaves, flash movies etc.

This is one of the easiest IDE for student, install and use no configuration required Ready to program. If you have a problem with ready PM.
Re: Java Programming For Dummies by kenniy(m): 1:20am On Feb 16, 2006
thanks all lot y'all. i'll check that up tomorrow, kind off sleepy now.
i'll join the class tomorrow.

(1) (2) (3) (4) (5) (6) (7) (8) (9) (10) (Reply)

Programming For Dummies. / Vb.net For Dummies: / Vb.net For Dummies:

Nigerian Software Engineer given test to prove he is an engineer at JFK Airport / A Thread For Tutorial On Python Programming / What Are The Best Laptops For Programmers And Hackers?!

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2019 Oluwaseun Osewa. All rights reserved. See How To Advertise. 167
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.