Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,153,824 members, 7,820,892 topics. Date: Wednesday, 08 May 2024 at 12:53 AM

Java Programming For Dummies - Programming (6) - Nairaland

Nairaland Forum / Science/Technology / Programming / Java Programming For Dummies (40488 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 parosky(m): 3:41pm On Jun 22, 2006
Has sbucareer abandoned this thread? Let's know where we can read your contributions. But then continue this forum. This could not be all there is to java.
Re: Java Programming For Dummies by sbucareer(f): 9:11am On Jun 23, 2006

I did not abandon the thread, the fact that no one is trying to do the assessment apart from skima was enough to discourage me to continue.

Also, I have been really busy at work on a government project we had, and as the project manager I was left with little time to do other things, which includes responding to the forum.

I am off for three weeks because we are ahead of the project. Good system analyst and developers need time off from work or else the software will be over budget.

Anyway, the little time I have within this three weeks I will contribute and hope reader really try and do some of the assignment. It really helps me to assess myself or my teaching.

See you soon.

Re: Java Programming For Dummies by parosky(m): 2:11pm On Jun 23, 2006
sbucareer:


I did not abandon the thread, the fact that no one is trying to do the assessment apart from skima was enough to discourage me to continue.


You don't need to be discouraged. Just know some people are keenly reading even if not giving feed back. I'd have been trying the assignment out myself but for time. I am a medical practitioner write java and vb but stronger in vb. So i found time to read you at work but soon I'll be trying your assignment out and getting back to you. Pls don't stop.

I think you really deserve the rest. Welcome back
Re: Java Programming For Dummies by sbucareer(f): 2:37pm On Jun 23, 2006

Ok! Parosky, thanks for your encouragement and recommendation. I would like to continue this thread. But I would like to say this, would you like to continue with Swing development or would you like web application development using Jakarta or J2EE blueprints?

Swing is a component development i.e. desktop development or standalone development, while web application development is combinations of different technologies i.e. html, jsp, servlet, jsfl, xml, soap, jni/jdni, database, testing by writing Test case using JUnit, refactoring by using Eclipse or Netbeans.

Let me know the one you are particular interested in. Prerequisite, you must be familiar with java. To learn Java think of everything you see in life as Object, even your girlfriend is an Object because they can change with the help of money and makeups Haha!!!

I need your answer?
Re: Java Programming For Dummies by sbucareer(f): 3:11pm On Jun 23, 2006

The rest of the tutorial material would be posted on this site, bookmark it if you are interested on following this thread.

Any problems please contact me at [email=valentine.obih@gmail.com?sbuject=Jakarta+and+J2EE+blueprint+tutorial]this email[/email]
Re: Java Programming For Dummies by skima(m): 10:55pm On Jun 23, 2006
Actually,  I attempted the assignment. After all the coding,  the stuff failed to compile. I was stucked! lipsrsealed But i came online for help no response.

So I tried to restart the assignment  to enable me see where i went wrong.

But thats no excuse for me.

I am working with java now using Netbeans. ( Thanks to Mimoh who gave me the CD) Though am also engaged in alot of project "stockbrokerage web app","Mini-ecommerce", Elearning site and a government e-tax solution which i was developing with PHP( delta state) wish i had to complete with same time.

I'd to split my time,

But am back with java. Now i learns alone.
Re: Java Programming For Dummies by kingfemi(m): 3:32pm On Jul 07, 2006
Did u have any reference site where i can learn JAVA from scratch.
Re: Java Programming For Dummies by sbucareer(f): 11:16am On Jul 08, 2006

Use this Java site.

Re: Java Programming For Dummies by h4rdc0d3d(m): 11:38am On Jul 09, 2006
Here is mine, Hey you are doing a good though I never did like Java, I just had to do something to cheer you up.
Hey take a good look at the code. I used JBuilder. Sun's download server seems to be down.
//at least the last time I checked. JBuilder has an IDE but I used the command line with jdk1.4.
Dont give up now. Besides, JBuilder can be found at www.borland.com



import java.lang.Object;
import java.io.*;
public class Temperature extends Object{
// Temperature Class coded by h4rdc0d3d

private static double celsiusTemp;
private static double fahrenheitTemp;
public Temperature(double temp, char f)
{
switch (f)
{
case 'f':
fahrenheitTemp = temp;
break;
case 'c':
celsiusTemp = temp;
break;
default:
System.out.println("Houston, We have a problem !"wink;
}
}
public static double getTempFahrenheit()
{
return fahrenheitTemp;
}
public static double getTempCelsius()
{
return celsiusTemp;
}
public static double convertF2C(double fah)

{
double cel;
cel = (fah-32)* 5/9; // Formula to convert fahrenheit to Celsius
return cel;
}
public static double convertC2F( double cel)
{
double fah;
fah = (cel*(9/5)+32); // formula to do vice versa
return fah;
}
public void setcel(double cel)
{
celsiusTemp = cel;
}
public void setfah(double fah)
{
fahrenheitTemp = fah;




}
public static void main(String[] args)
{
Temperature Temp;
Temperature TempFaulty;
Temp = new Temperature(0, 'c'); // try switching between 'c' and 'f'
System.out.println("The temperature of Temp in celsius is " +Temp.getTempCelsius());
System.out.println("The temperature of Temp in fahrenheit is "

+Temp.convertC2F(Temp.getTempCelsius()));
Temp.setcel(37.7);
System.out.println("The temperature of a normal human in celsius is

"+Temp.getTempCelsius());
System.out.println("The temperature of a normal human in fahrenheit is

"+convertC2F(Temp.getTempCelsius()));
Temp.setfah(212);
System.out.println("The temperature of boiling water in fahrenheit is

"+Temp.getTempFahrenheit());
System.out.println("The temperature of boiling water in celsius is

"+convertF2C(Temp.getTempFahrenheit()));
TempFaulty = new Temperature(4,'n');

}
}
Re: Java Programming For Dummies by sbucareer(f): 12:01pm On Jul 09, 2006

h4rdc0d3d, with your algorithm I can tell you are fairly good Java programmer thanks for the contribution. You know the law of supply and demand. It would be waste of resource if supply is greater to demand.

Besides, since people here are generally web application developers, I'd say to digress to web application development. It will still be Java thread but focusing mainly on web application using Jakarta tomcat as our web container.

Then we will start learning JSP, Servlet, JSF, Javabean, CSS, HTML and JDBC. I have realize that people, particularly in Nairaland do not like desktop application development.

I used Swing as my early tutorial to acquaint newbie to Java programming. Now I want to try web app.

Re: Java Programming For Dummies by sbucareer(f): 12:57pm On Jul 09, 2006

Let start by defining what is web application?
Web application is a mixture of several technologies. In java web application includes but not limited to

1. HTML
2. CSS
3. Javascript
4. Script Language (In this particular instance Java)
5. Database (We will be using MySQL)
6. Graphics
7. Movies (Flash/Fireworks/Photoshop)

Web applications are accessed by users through various means, but the primary method is the web browser. Many web applications can be accessed through mobile phones, and users with impaired vision can use screen-readers which interpret text as sounds.

Like many programs you need a compiler to compile the source code and run the bytecode. In web application there are two ways this is done.

1. If the page has a dynamic content, i.e. some programming language in the page, it is compiled at the server side, that is why we need a web container. Java converts the Java code into HTML and send it across the network to the user browser. The browser on the second hand compiles the HTML to what we see as visual presentation of website pages.

Web application is the same as desktop application in terms of what they offer. But there are some glittering differences. Both solves problems for end users. You can use web application to solve lots of business solutions, ranging from simple tax return calculation to complex Enterprise Resource Planning. Either one you will need to understand business roles and complex data structure of a programming language.

Java offers this rare unique opportunity by providing well known standardized API and simple Classes to aid with development of Java related application.
Re: Java Programming For Dummies by Bossman(m): 4:34pm On Jul 10, 2006
Very nice notes sbucareer. Keep up the good work.

I noticed that below you mentioned compile, but I believe it was a typo and you actually meant translates or converts.

"The browser on the second hand compiles the HTML to what we see as visual presentation of website pages"
Re: Java Programming For Dummies by sbucareer(f): 1:27am On Jul 11, 2006

Thanks Bossman. Now let start by explaining the requirements for this tutorial. Like I said you need to download Jakarta Tomcat and install it and make sure you specify port 80 as your HTTP default port.

There are many interesting directory in tomcat. Assuming you installed a window binary, you would have your tomcat on this absolute path C:\Program Files\Apache Group\Tomcat 4.1

Under this directory, you should have the following subdirectories:

1. bin
2. common
3. conf
4. jtc-src
5. logs
6. server
7. shared
8. src
9. temp
10. webapps
11. work

The folder you should be particularly interested are the conf and webapps. In the conf directory the files you should learn to configure them are server.xml and web.xml More about this later

The webapps directory is where you create a subdirectory of your project. When you install tomcat and access it from the web browser, the default index.jsp page is under this webapps/ROOT directory. You can replace the default web page with your custom web page.

Re: Java Programming For Dummies by sbucareer(f): 1:43am On Jul 11, 2006

Now let start by creating a project under the webapps directory. Our project is going to be called temperature. Under webapps create a folder called temperature. Inside temperature create this folders

WEB-INF/classes
WEB-INF/lib
WEB-INF/web.xml
jsp

Now outside the temperature folder create a file called temperature.xml The content of this temperature.xml should be exactly like this.


<!--

    Context configuration file for the Tomcat Temperature Web App

-->


<Context path="/temperature" docBase="webapps/temperature"
        debug="0" privileged="true">

</Context>

Your webapps subdirectory should look something like this

Re: Java Programming For Dummies by sbucareer(f): 1:54am On Jul 11, 2006

Another interesting file is the web.xml under our temperature/WEB-INF/web.xml It should look like this

<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE web-app
    PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
    "http://java.sun.com/dtd/web-app_2_3.dtd">

<web-app>
  <display-name>Welcome to Tomcat</display-name>
  <description>
     Welcome to Tomcat
  </description>
</web-app>


This is just minimal web.xml. We use web.xml to configure our application. From now on, any project should be refered to as application. To configure our temperature application we employ the use of temperature web.xml, more on this later.


When you have done all this, I want you to go to your web browser and type http://locahost/temperature or http://127.0.0.1/temperature. You will see a directory listing. This is because we do not have any html, htm and jsp file(s) under the temperature application directory. Remember, our container can now process .jsp extensions

Re: Java Programming For Dummies by sbucareer(f): 2:08am On Jul 11, 2006

If you are following my tutorial, use my private website http://www.digitemsystems.com. This is where I will show you how my temperature will look like. Note I will expect you to show me yours. You do not need a domain name or dns server to resolve your IP to domain name. All I need is the IP of your machine you are working on and I can access your work.

If you use dynamic IP, put it into jpeg file and upload it no cheating. Like we did earlier using swing to develop temperature application. We are going to use HTML to design and develop a temperature application.

For the temperature to work, we are going to write a javabean class that performs the temperature convertion. We will use jsp tags and manipulate this bean in our HTML front-end.

Re: Java Programming For Dummies by gbengaijot(m): 12:44pm On Jul 18, 2006
@SBU career, sorry i didnt reply to this thread for a long time. I am glad you moved a bit to web applications. I am learning javascript for now as its part of my first year course and its the first programming language i am meant to learn. Any help u can offer?
Re: Java Programming For Dummies by Bossman(m): 4:54pm On Jul 18, 2006
Good job gbengaijot. I just want to clarify that JavaScript is not a programming language but a scripting language. You cannot use it to build standalone applications. But, it use is mainly to enhance the functionality web pages.


gbengaijot:

I am learning javascript for now as its part of my first year course and its the first programming language i am meant to learn. Any help u can offer?
Re: Java Programming For Dummies by gbengaijot(m): 9:55am On Jul 19, 2006
@bossman, yeah you are right oooo. sorry i should have said scriptiing language.
THanks man
Re: Java Programming For Dummies by sbucareer(f): 3:44pm On Jul 19, 2006

Yes Gbenga, I am still compiling the course structure and exercises for the web application development and I want people to accept the change from standalone to Java web apps.

JavaScript is not anywhere related to Java and do not have the same syntax. But they share the same Object oriented paradigm. Like in Java, what you need to know is the Object tree of JavaScript i.e.

You need to understand the methods and function and public attributes of JavaScript:

1. Window
2. Frame
3. Location
4. History
5. Document
6. etc

Learn all their methods and Events Handler, with a little knowledge of programming language you should be fine.
When writing Javascript for a web application, make it modular by writing your Javascript code in a separate file and import it into your web application. Don't write your Javascript directly into your web apps, it makes it unprofessional.

For example have a file called example.js



function a_message()
{
alert('I came from an external script! Ha, Ha, Ha!!!!');
}



Save this file as example.js In your html, jsp, php, have it imported as <script type="text/javascript" src="example.js"></script>

<HTML>
<HEAD><TITLE>Tutorial</TITLE>
<script type="text/javascript" src="example.js"></script>
</HEAD>
<BODY>

<A HREF="javascript:a_message()">Click for a message, </A>
</BODY>
</HTMl>


This will have exactly the same effect as writing the code into a web app, but is much better because now:

1. It's easier to update our code. If we want to change what the helloWorld() function does, we only have to change it in one place, and those changes will be reflected in all pages that include the hello.js file.

2. It's easier to manage our code. If you come back to a web site project, it's much easier to find out what's doing what if your styles (CSS) and functions (JavaScript) are kept separate from your content (HTML). These benefits increase as sites get more complex.

3. The browser should only have to download your JavaScript code once, no matter how how many pages use it, because it can cache (i.e. remember) the external file.

Re: Java Programming For Dummies by Seun(m): 10:26pm On Jul 19, 2006
Well done!
Re: Java Programming For Dummies by gbengaijot(m): 12:11pm On Jul 20, 2006
@sbucareer, i understand oooo. sort off. u mean like a javascript library.
Re: Java Programming For Dummies by sbucareer(f): 4:30pm On Jul 20, 2006

Thank your Seun.
Re: Java Programming For Dummies by goodguy(m): 7:54pm On Jul 23, 2006
I know I'm very late in this and I'm sorry for drawing you guys back.

I am also interested in the Java programming stuff and I've been following this thread since yesterday. (I actually don't know jack about programming or java or anything related to them).

I have downloaded textpad (I got the licensed version wink) but anytime I try compiling, it says, "The system cannot find the file specified". When I try running C:\> javac helloworld.java on Command prompt, it says "'javac' is not recognized as an internal or external command, operable program or batch file error". The thing is, javac.exe is no where to be found on my system so what should I do?

Note: I already did all the necessary configuration in the Environment variables.

P.S. I just found out that I have JRE 1.5.0_07. What should I do?
Re: Java Programming For Dummies by Bossman(m): 9:46pm On Jul 23, 2006
You need to download the JDK first. You can get it from sun's site. You have the Java Runtime Environment (JRE). That's just allows you to execute java progarams, for example an applet.


After installing the JDK, then reinstall textpad, it will find the JDK and do any necessary setup that will allow you to compile/execute from textpad's menu.
Re: Java Programming For Dummies by sbucareer(f): 9:24pm On Jul 28, 2006

Addition to the tutorial, I would like to introduce a framework for building a front-end web application. In Java web application development, there are many frameworks for building web application. The choice of technology makes it even more complex to developing java application.

The series of these frameworks has contributed immensely to the complexity associated with Java technology. But once you learn the idea and probably one framework, the rest will be much easier to adapt. Let look at these technologies.

1. Hibernate
2. Strut
3. JSTL
4. JSF
5. Spring

Hibernate, a relational persistence for Java and .NET, it is a powerful, high performance object/relational persistence and query service. Hibernate lets you develop persistent classes following object-oriented idiom - including association, inheritance, polymorphism, composition, and collections. Hibernate allows you to express queries in its own portable SQL extension (HQL), as well as in native SQL, or with an object-oriented Criteria and Example API.

You can conduct your internet research on the other following frameworks. But we are going to use JSF (Java Server Faces) JavaServer Faces (JSF) is a Java-based Web application framework that simplifies the development of user interfaces for Java EE applications. We will not worry so much about object relational mapping, rather we will concentrate on UI (user interface), hence we will be using JSF.

Re: Java Programming For Dummies by sbucareer(f): 9:44pm On Jul 28, 2006

I know this might be too heavy on you now, but java has got lots of technologies and lots of configuration files particularly .xml. I would want you to acquaint yourselves with this tutorial on JSF

I know by now you must have acquainted yourselves with tomcat directory structure and have setup a web server on your laptops or PC. If you have not already done so, you have started falling behind in the class.

You know where your directories are and where all the .xml files are and that you have also created a temperature directory and subdirectories and have created temperature.xml

To work with JSF we need three files from apache website site

1. tomcat/server/lib/commons-digester.jar
2. tomcat/server/lib/commons-beanutils.jar
3. tomcat/webapps/temperature/WEB-INF/lib/jstl.jar
4. tomcat/webapps/temperature/WEB-INF/lib/standard.jar


Learn these tutorial and download these jar files and put the once that need to be in your application WEB-INF directory

Re: Java Programming For Dummies by sbucareer(f): 10:09pm On Jul 28, 2006
[font=bradley hand itc][size=12pt]
To find out if your JSP is working, copy or type this code into a text editor or IDE and save it as index.jsp and put it in your temperature root directory.

[B]
<html>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>

<f:view>
<head>
<title>A Simple JavaServer Faces Application</title>
</head>
<body>
<h:form>
<h3>
Welcome to JavaServer Faces,
<h:outputText value="#{user.name}"/>!
</h3>
</h:form>
</body>
</f:view>
</html>
[/B]

Create a configuration file and put it in the WEB-INF directory called faces-config.xml i.e. temperature/WEB-INF/faces-config.xml. Here is how the file will look like

<?xml version="1.0"?>

<!DOCTYPE faces-config PUBLIC
"-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.0//EN"
"http://java.sun.com/dtd/web-facesconfig_1_0.dtd">

<faces-config>
<navigation-rule>
<from-view-id>/index.jsp</from-view-id>
<navigation-case>
<from-outcome>login</from-outcome>
<to-view-id>/welcome.jsp</to-view-id>
</navigation-case>
</navigation-rule>

<managed-bean>
<managed-bean-name>user</managed-bean-name>
<managed-bean-class>UserBean</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
</faces-config>

Finally, create create a bean called UserBean and put it in your application directory i.e. temperature/WEB-INF/classes/UserBean the class should look like this

public class UserBean {
  String name;
  String password;

  public String getName() {
      return name;

}

public void setName(String newValue) {
    name = newValue;
}

  public String getPassword() {
          return password;
  }

  public void setPassword(String newValue) {
        password = newValue;
  }

}


Also make sure you configure your application web.xml by doing this i.e. temperature/WEB-INF/web.xml

<?xml version="1.0"?>

<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">

<web-app>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.faces</url-pattern>
</servlet-mapping>

<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>

Don't be intimidated, once you have got the hang of it, it is dead easy. Try this and master it before we start the web application development. Your success of this lesson would be your mastering this concept.

I will explain what does what when we start but it will be a good idea if you do some homework to find out what does what before we start.
[/FONT][/SIZE]
Re: Java Programming For Dummies by sbucareer(f): 10:23pm On Jul 28, 2006

I forgot, the JSP must always have a success file to go to when all is well. If it fails, it must also have a failed page to show. The concept is called navigational structure. We do this in the faces-config.xml

The tag, outcome depict the file the login show go to if you have provided the right credentials i.e. username and password. We are going to have a welcome.jsp file. put this in the root directory of temperature web application.

<html>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>

<f:view>
<head>
<title>A Simple JavaServer Faces Application</title>
</head>
<body>
<h:form>
<h3>
Welcome to JavaServer Faces,
<h:outputText value="#{user.name}"/>!
</h3>
</h:form>
</body>
</f:view>
</html>

Re: Java Programming For Dummies by goodguy(m): 4:36pm On Jul 30, 2006
@Bossman, thanks. Everything is all set now.
Re: Java Programming For Dummies by clocky(m): 10:53pm On Jul 30, 2006
@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 dont gel together easily at all.
Re: Java Programming For Dummies by D3n3n(m): 12:40pm On Sep 13, 2006
Sorry to bring this back up but why did this thread go flat, some of us ( me in particular) are interrested in java and would like to know more about it. cool cool

(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. 80
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.