Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,150,848 members, 7,810,268 topics. Date: Saturday, 27 April 2024 at 04:00 AM

Java Programming For Dummies - Programming (7) - Nairaland

Nairaland Forum / Science/Technology / Programming / Java Programming For Dummies (40464 Views)

Programming For Dummies. / Vb.net For Dummies: / Vb.net For Dummies: (2) (3) (4)

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

Re: Java Programming For Dummies by sbucareer(f): 1:47pm On Sep 13, 2006

@clocky

I always advocate for hard framework and programming practices, the reason for this is that, IMHO is that if you learn the hard way to learn the easy way is very rewarding and straight forward.

JSF and JSTL are the first framework introduced by Sun and was Incorporated into J2EE and other web technology. No doubt, today framework has become easier and snazzy i.e spring, hibernate, even complete enterprise application development has been introduced i.e. Ruby on Rails.

My point is that if you can learn hard framework, your learning curve is completed. To move over to new framework will require you just hours to get acquainted. It works for me and that is why I am advocating it.

Remember that all this new frameworks are practically the same with the older ones just that some configuration is taken care of by the application parser or the development environment by the application itself.

Re: Java Programming For Dummies by Bossman(m): 9:35pm On Sep 13, 2006
Struts is another popular frameworks. It also requires a lot of configuration entries though. It's actually structured after the Model-View-Controller (MVC) pattern. I guess you can consider another abstraction layer on top of the MVC pattern. And, it is heavily configuration driven.

clocky:

@sbucareer

Why JSF ? why not struts or spring mvc . JSF is a freaking cumbersome framework to work with. The xml configurations are very horrible and things just don't gel together easily at all.
Re: Java Programming For Dummies by Taysay(m): 11:37am On Nov 14, 2006
@Sbucareer,
Yeah this is really really cool, thread. I just want to know if you have a soft copy of the book," A Java Foundation Classes Primer, ISBN 0-333-77339-X", pls if you do , can u pls upload it for me, so that I can do a download. I will really appreciate this Tanx. wishing u well in al your endeavours. have a wonderful day.
Re: Java Programming For Dummies by sbucareer(f): 1:03pm On Nov 14, 2006
[size=18pt]
Taysay, click on this link and bookmark it. I have the book but not the soft copy. The book do not come with softcopy. It was recommended by Prof Fintan as he was our lecturer then. Also remember people in the academic acumen has criticized his method of teaching software development. Most of the methods he used was invented and developed by him, like the Class diagram, Object diagram JSP (Jackson Structural Programming), instance diagram.

I find his teaching method adequate for undergraduate. His teaching may have become abate as he is more into research and publications now. The only thing that I think that make his teaching formidable is his coding style. But go through the link(s) I posted above and follow is teaching, it will certainly help you. Do not hesitate to ask question if you do not understand any pointers.

[/size]
Re: Java Programming For Dummies by Taysay(m): 6:47pm On Nov 14, 2006
@Sbucareer,
Just to let u know u are great a broda, pls keep on keepin on. I will get back to u afta downloading the files. tanx have a good one
Re: Java Programming For Dummies by gbengaijot(m): 9:47am On Nov 15, 2006
@SBU career, i am beggining to understand some of the post on this thread which i did not understand when this thread was very active. I will email my class diagram for the temperature thingy very soon.
Re: Java Programming For Dummies by sbucareer(f): 11:33am On Nov 15, 2006

Good that you are beginning to understand the programming concept, I will look forward to receiving your classes
Re: Java Programming For Dummies by gbengaijot(m): 2:23pm On Nov 15, 2006
Ok, What do you think about this class diagram. I want you to access it first before i start writing the codes,

Its was the first assignment on temperature

Re: Java Programming For Dummies by sbucareer(f): 2:36pm On Nov 15, 2006

Good, well done Gbenga, where were your brain all these time? Now you having beginning to understand the notion of

1. Attributes
2. Methods (Private, Public and Protected)
3. Constructor

The diagram have only one minor mistake the bottom right hand should be public not private. Your methods should depict what they accept or return i.e.
-------------> celsius:int
<------------ celsius: int


Now, can you tell me why the isTemperatureWorking method is protected? And why the constructor takes two arguments?

Note
-----------
Your constructor is wrong, constructor can NEVER return and argument.  If you can understand why it takes two arguments in the Temperature class, you would see that it does not need to return them back, hence

<--------------- celsius:int
<-------------- fahrenheit:int

Constructor MUST have the same name of the Class. Here is a constructor signature of a Temperature class public  Temperature(int celsius, int fahrenheit) You see, it does not say void or stipulate to return anything.


A constructor help to initialize an instance of a class to an object that has initial state, aggregate values, behavior and well formed attribute. If you can understand this line you can answer my question above. I do not claim that this is the proper definition of a constructor nor do I agree to support your argument in any event that it challenges the academic acumen. It is only an indication of a meaning, hence constructor.

Here is examples

Temperature cold = new Temperature (-2, 10);

Now cold is and object
It has an initial state (which could be cold or hot)
It has aggregate values ( -2 + 10 = 8 )
It has a behavior (getTemperature) Remember without state, getTemperature will not behave, thus return null;
Its attributes are formed by our construtor

Hence we can get the current temperature
String theCold = cold.getTemperature();

Re: Java Programming For Dummies by gbengaijot(m): 2:52pm On Nov 15, 2006
why is the bottom right hand corner public and not private?,


Tricky question, hang on, i'll try to answer it in a bit, brb
Re: Java Programming For Dummies by gbengaijot(m): 4:27pm On Nov 15, 2006
DOnt mind me SBU, God knws where my brain went to initially. Ok, here is the crack to your qquestionsd, lol


* You are right, the bottom right hand side is meant to be "Public" and not private since its class can be accessed/called by any object.

* The temperature method is protected because it is meant to be accessed by objects of its class or subclass( i.e subclass "Celsius' and Fahrenheit". am i right?, )



Ok, you are right that a constructor does not return a value( I didnt realise that before, just read it on google). But i know that a constructor bears the Name of the class anyway.

Will i be right to say that When a class is created, it is created with consrtuctor in a way that if another instance of the class((an object) is created, it straightaway inherit the values of that class?,


If i am wrong, then i think i need a little bit of more explanation. Please do break it down





N:B: Please be patient with me, if i am too naive. I am just picking this things bit by bits,
Re: Java Programming For Dummies by sbucareer(f): 3:28am On Nov 16, 2006
[size=18pt]
Remember that Java is OOP (Object Oriented Programming) so objects has to be encapsulated within a class. Thus, all the attributes and methods of a class are encapsulated within the object.

Furthermore, any inferring object could access all the contents of an object. Sun tried to limit the access to their inference by protecting the attributes and methods by using private, public and protected keywords.

Look at it this way that if I transmite and object through a network i.e. from one Pc to another Pc and some clever person is able to get hold of the object, he would never be able to access the private and protected information of the object.

The isTemperatureWorking method is protected because it does not return any of our private attribute. Remember we had

private int celsius;
private int fahrenheit;


You cannot do this

Temperature cold = new Temperature(-3, 8 );
int theCold = cold.fahrenheit;

But you can do this

private int celsius;
public int fahrenheit;

Temperature cold = new Temperature(-3, 8 );
int theCold = cold.fahrenheit;

Because you cannot access private attributes from an instance object, we use a public keyword to deceive the program to return fahrenheit i.e.

public int getFahrenheit(){return fahrenheit;}

We do not want anyone to access the isTemperatureWorking() because it does not return any attributes, just a boolean testing. If someone ever get hold of our program in the form of object he would find it very difficult to understand what we are doing because we do not expose the isTemperatureWorking(), hence he would not be able to see it. If the object is accompanied by another instance object within the same package, and we used isTemperatureWorking() in a public method, that person could figure out what the method is doing by looking at the algorithm.

If we wanted to make it very difficult to read we will declare isTemperatureWorking() as a private method. Every private attributes or method cannot been seen by other instance object, even you the programmer.
[/size]
Re: Java Programming For Dummies by sbucareer(f): 3:53am On Nov 16, 2006


public class Testing{
  public static int age = 3;

  public static void main (String[] args){
             System.out.println( age);
  }
}


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


public class Testing{
  public int age = 3;

  public static void main (String[] args){
             System.out.println( age);
  }
}

Can you tell me why the second class failed at compile time and how would you fix it by making age an instance variable?

This small exercises will make you to understand very important fundamentals with java
Re: Java Programming For Dummies by Taysay(m): 1:22pm On Nov 16, 2006
@Sbucareer,
Good day how is the going? Pls I just want to let you know that the chapter 5 is not accessible. Then I wanted to know what’s happening to your proposed thread. “WEB DEVELOPMENT USING JAVA”. Tanx Have a wonderful day
Re: Java Programming For Dummies by parosky(m): 2:01pm On Nov 16, 2006
Don't suppose you are teaching Gbenga alone.

The second class will fail because age was declared to be an instance variable and an instance of the class has not been created. A static method apply to every object of a class( it is called shared member in VB)

This should work?

public class Testing{

public Testing{
public int age = 3;
}

public static void main (String[] args){
System.out.println( age);
}
}
Re: Java Programming For Dummies by sbucareer(f): 3:29am On Nov 17, 2006

parosky, your code will not compile. You also failed to understand the nature of instance variable.  You got it right that the first class was a class wide variable, thus it belongs to the class.

The second class however do not belong to the class varibale, rather it requires and instance of the class, hence instance varible.


public class Testing{
 
public Testing{ //What are you doing here? Is it a constructor or something else
public int age = 3; //Even if it was a constructor a public keyword would not be used here
}

  public static void main (String[] args){
             System.out.println( age); //age is still not an instance variable
  }
}

Do you mean

public class Testing{
 
public Testing(){
int age = 3;
}

  public static void main (String[] args){
             System.out.println( age);
  }
}

Still it will not compile. You seem to know what you are doing Parosky but think hard, putting age inside the constructor do not make it an instance varibale.


@Taysay
Do you know Java enough for me to start WEB DEVELOPMENT USING JAVA. The prerequisite for WEB DEVELOPMENT USING JAVA is Java.

If you do know Java, download Tomcat 5.x or Netbeans 5.5, it comes with tomcat. Configure and set all the necessary classpath i.e.

SET JAVA_HOME=c:\<java_directory>\
SET TOMCAT_HOME=c:\CATALINA_HOME\

SET PATH=%PATH%;%JAVA_HOME%\bin;%TOMCAT_HOME%\bin

CLASSPATH=%CLASSPATH%;%TOMCAT_HOME%\common\lib\servlet.jar

Show others how you managed to setup your environment by posting it to the forum so that other that are interested in the thread will follow, then I can begin to teach you WEB DEVELOPMENT.

Re: Java Programming For Dummies by gbengaijot(m): 9:27am On Nov 17, 2006
am still trying to assimilate oooooooo, bear wiv me.
Re: Java Programming For Dummies by Gaxton(m): 10:30am On Nov 17, 2006
Hi Every1,
I just started this Java thing a few weeks ago and em I'll say I really need help,
I have read some books like "Learn Java in 21 days "and some others and I think I grabbed some concepts but what i want really some one good to tell me is about kind the programs or
their first software dev project and how they went about,
Ok ! let me say U can give a challenge maybe something close to the first challenge you faced or first application u wrote on your own.
Thank you very much
Gaxton
contact me thru Pimpgaxton@yahoo.com or by fone 08032901183
Re: Java Programming For Dummies by Gaxton(m): 10:43am On Nov 17, 2006
Hi Every1,
I just started this Java thing a few weeks ago and em I'll say I really need help,
I have read some books like "Learn Java in 21 days "and some others and I think I grabbed some concepts but what i want really some one good to tell me is about kind the programs or
their first software dev project and how they went about,
Ok ! let me say U can give a challenge maybe something close to the first challenge you faced or first application u wrote on your own.
Thank you very much
Gaxton
contact me thru Pimpgaxton@yahoo.com or by fone 08032901183
Re: Java Programming For Dummies by sbucareer(f): 12:26pm On Nov 17, 2006
[size=18pt]
@Gaxton, follow the thread from the beginning. This thread is a very good starting point into learning Java. It does not only teach you some Java, it also teaches you Software Development, which I think is the best way to teach Java.

To learn Java syntax, you do not require anyone to teach you what is:

1. Variables
2. Class variables
3. Instance variable
4. function
5. Constructor
6. Setter and getter
7. Primitive types
8. Objects
9. Reserved keywords
10. Conditional loops
11. Data structures like arrays etc
12. Sequence, Selection, iteration
13. Exceptions
14. etc.

We can help you with these things but it is up to you to grasp the concept to begin applying them within your programming logic. It is really not hard to understand. If java is too strong for you, start with a procedural language like Modula2, or Pascal. I don't know where to download there compiler but if you do google search you may come up with links to their compiler.

But learning programming with these old language will teach you bad programming habits and you will never forgive me. I will recommend to stay with java and give it a hard try for three solid months. Like 8 hours every day for three months, you will not come out of it without gain.

Let me let everyone into a secret that I use and you know what, it works for me.

If you want your computer to process data quickly, shutdown every process within that computer and run you application uninterrupted till it terminates, it will have more processing power to solve the problem quicker.

I have taken that analogy to human. My Pastor said any man that do not dream when sleeping is a dead man anyway. He is right, we MUST dream. I have used this dreaming as a tool to solve most of my problems. You know when you are sleeping most of you body functions is shutdown i.e. walking, talking, smelling, vision, etc. if you commit a task to your brain it would be solved quicker at night.

Try it, it works for me. But the difficult bit is, how do you commit a task to your brain when sleeping. It takes time to learn it but what I do is to start thinking of the problem whilst laying on bed, make sure that you think of nothing apart from the problem till you fall asleep. You brain will only recognize that input before committing itself to sleep. It will try and process it and come up with answer when you wake.

Think of Java before you sleep, believe me when you wake up most of the issues will be solved for you, it is amazing phenomenon and it works for me. You should give it a try.

[/size]
Re: Java Programming For Dummies by gbengaijot(m): 1:44pm On Nov 17, 2006
Worrrrrrrrrddddddd, @SBU.

i am gonna do more analysis of your questions on saturday as i am very busy till 11pm tonight. And i have saturday to myself and am dedicating it to java.

Be rite back on saturday.
Re: Java Programming For Dummies by sbucareer(f): 2:50pm On Nov 17, 2006
gbenga:
Will i be right to say that When a class is created, it is created with consrtuctor in a way that if another instance of the class((an object) is created, it straightaway inherit the values of that class?,

A new class is created by the help of constructor. You are right there gbenga. But it does not inherit the values of the class. A class is a default template with out value, state or identity. But object has identity, values and state. i.e.

Temperature warm = new Temperature(90, 170);

warm is the object, it has values (90 and 170), identity is warm, state it is a warm weather. You can query the object warm by using its methods to get the states and values.

Remember constructor helps us to set Temperature class to this states i.e.



public class Temperature{
  private int celsius; //See it does not have state, just template. This could be refered to with using this.celsius

  private int fahrenheit; //See it does not have state

      public Temperature(int celsius, int fahrenheit){
             this.celsius = celsius; //See the constructor is helping us to set celsius to a state, thus the object will have a state
             this.fahrenheit = fahrenheit;
       }
}
Re: Java Programming For Dummies by sbucareer(f): 3:12pm On Nov 17, 2006

Look at this

Re: Java Programming For Dummies by Taysay(m): 6:03pm On Nov 18, 2006
@parosky,
whats just to let you know that the second class will not COMPILE, because you can make reference of a non static variable in a static block

public class Testing{
public static int age = 3;

public static void main (String[] args){
System.out.println( age);
}
}


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


public class Testing{
public int age = 3;

public static void main (String[] args){
System.out.println( age);
}
}

in the first class the variable was declared to be static so it could be referenced from a static block , where as in the second instance the variable isnt static so cannot be access from a static block .
Re: Java Programming For Dummies by Taysay(m): 6:07pm On Nov 18, 2006
@ Sbucareer,
Good day Sir, just to let you know that I already have netBeans 5.0 running on my system, and its bundled with tomcat. So do I still need to set the class cariable as mentioned? I was also going to ask you how to remove depracation warnings in netBeans. tanx have a good one.
Re: Java Programming For Dummies by Taysay(m): 6:11pm On Nov 18, 2006
@Parosky,
I just want to correct the typos in the my previous post.
whats up just to let you know that the second class will not COMPILE, because you "cant" make reference of a non static variable in a static block

public class Testing{
public static int age = 3;

public static void main (String[] args){
System.out.println( age);
}
}


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


public class Testing{
public int age = 3;

public static void main (String[] args){
System.out.println( age);
}
}

in the first class the variable was declared to be static so it could be referenced from a static block , where as in the second instance the variable isnt static so cannot
Re: Java Programming For Dummies by sbucareer(f): 10:08pm On Nov 18, 2006

Use javac option -deprecation or modify your ant script within your Netbeans like this


<!-- =================================================================== -->
  <!-- Compiles the source code                                            -->
  <!-- =================================================================== -->
  <target name="compile" depends="prepare">
    <javac srcdir="${src.dir}"
   destdir="${build.classes.dir}"
   debug="on"
   deprecation="OFF"
   optimize="off"
         fork="java$$javac.exe"
         source="1.5" 
   includes="**">
    <classpath refid="classpath"/>
    </javac>
  </target>
Re: Java Programming For Dummies by mimohmi(m): 3:25am On Nov 21, 2006
@Taysay

Hey ma guy, please never turn off deprecation warning. It's a valuable feed back
mechanism that inform you of a new implementation in the library. If it because of
the 1.4 exams, i will advice you go for the 5.0 version. There are a number of materials
available for the exams. If not, you will have to go for upgrade later. That means more
bucks and effort.


To the hot static puzzle, let's play with it a bit

@subcarrer

public class Testing{
public static int age = 3; //class variable, created before the class object (b4 constructor get called)

public static void main (String[] args){
System.out.println( age); //age is already created and intialized so can be used.
} // the funniest part is it can only be called from a static method
} // because the method also belong to the class, ie it is not tied to
// any instance of the class.
@2

public class Testing{
public int age = 3; // instance variable, initalized after the constructor is called
//not availabe until the new class operator.
public static void main (String[] args){
System.out.println( age); //screeching by compiler, age is an instance variable
} //method is class method
}

@3
What of this
public class Testing{
public static int age = 3;

public static void main (String[] args){
System.out.println( age); //prints 3

Testing test = new Testing();
System.out.println(test.age); //prints 3
}
}

May be like this
public class Testing{
public static int age = 3;

public Testing(){
age = age + 1;
}
public static void main (String[] args){
System.out.println( age); // prints 3

Testing test = new Testing();
System.out.println(test.age); // prints 4 ---
}
}
Re: Java Programming For Dummies by gbengaijot(m): 1:52pm On Nov 22, 2006
@mimohmi and SBU, i have been a very slow java learner, but at least i am not stading sstill nor moving backward. I was trying to check my local library for java books and the only ones i saw was for web application. I am more interested in standalone application(at least for now) than web application. can i still learn java with those books?,

or should i just make use of resources i find on the web.
Re: Java Programming For Dummies by Gaxton(m): 11:59am On Nov 23, 2006
Hello SBucarreer!
Just wanna say thank you for your advice,
I really do want to stick with JAVA, cos I think it has future prospect, I really do hope learn more from you, at least now that you have broken down JAVA into subtopics. I think I will have a good starting point.
Thanks once more and God bless you!
Re: Java Programming For Dummies by Bossman(m): 4:22pm On Nov 23, 2006
Any good beginners Java book should be able to teach you the fundamentals of Java. So, if the ones you are seeing are not doing that, there are a number of books on-line that you can try to download. As I posted somewhere in the thread. One of the best books out there that is free is Bruce Eckels Thinking in Java. I have been doing Java for a while and I still consult this book regularly. You can download both the HTML and word version of this excellent book at the link below. There may even be a PDF version out there. Personally, I use the HTML version.

http://www.mindviewinc.com/

gbengaijot:

@mimohmi and SBU, i have been a very slow java learner, but at least i am not stading sstill nor moving backward. I was trying to check my local library for java books and the only ones i saw was for web application. I am more interested in standalone application(at least for now) than web application. can i still learn java with those books?,

or should i just make use of resources i find on the web.
Re: Java Programming For Dummies by Gaxton(m): 11:42am On Nov 27, 2006
Hello SBU! just wanna say thank u for ur consistency in the Java Tutorials, My radiodemonstration worked i.e. after building and running it, it gave out message "false" like 4 times, pls I want 2 know if that' s the expected result. i 'm using Netbeans 5.5. Thank u very much!

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

Nigerian Software Engineer given test to prove he is an engineer at JFK Airport / Facebook Is Suing Me For This / Learning To Program With Java by the Fulaman

(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 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 84
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.