navigate site menu

Become a member and get unlimited access to every course in the library. Try it free for 7 days

Up and Running with Java Applications

Up and Running with Java Applications

with Todd Perkins

 


This course is an introduction to developing Java applications for various runtime environments. Author Todd Perkins explains how to configure the development environment, connect a web application to a MySQL database, and build a user interface with the Swing framework. The course also covers publishing applets in a web browser, working with XML data, and creating apps for Android devices.
Topics include:
  • Working with Eclipse
  • Using MySQL database drivers
  • Displaying data from a database as XML
  • Loading XML data from the web
  • Displaying data based on user input
  • Publishing a desktop application
  • Understanding applets
  • Building the layout
  • Viewing the app on an Android device

show more

author
Todd Perkins
subject
Developer, Web, Programming Languages, Web Development
software
Android , Java , Tomcat
level
Beginner
duration
1h 42m
released
Feb 24, 2012

Share this course

Ready to join? subscribe


Keep up with news, tips, and latest courses.

submit Course details submit clicked more info

Please wait...

Search the closed captioning text for this course by entering the keyword you’d like to search, or browse the closed captioning text by selecting the chapter name below and choosing the video title you’d like to review.



Introduction
Welcome
00:04Hi! I am Todd Perkins.
00:06Welcome to Up and Running with Java Applications.
00:09If you're just beginning to learn Java and you feel comfortable with the
00:12language but don't know how to build an app or what you can do with Java, this
00:17is the course for you.
00:18Throughout this course, you'll see how you can use Java to develop backend web
00:22applications, front-end web applications, desktop apps, and even an Android app.
00:27So we'll tour the most common uses of Java today, and you'll see how to build and
00:33publish these applications on your own.
00:36And now we'll move forward with Up and Running with Java Applications.
Collapse this transcript
What you should know before watching this course
00:00Before you go through this course, it's important to have a basic understanding
00:04of the Java language.
00:06There are many different places to learn Java, but the place I recommend is the
00:10Java Essential Training course in the Online Training Library.
00:14Java Essential Training will show you all that you need to know to get up to
00:18speed to start building Java applications like you learn how do in this course.
00:22So once you feel comfortable with Java then you can go ahead through this course
00:26and learn how to build Java applications on your own.
Collapse this transcript
Using the exercise files
00:00If you are a Premium subscriber to lynda.com then you have access to the
00:04exercise files for this course.
00:06Exercise files are organized by chapter. Each chapter folder contains the files
00:11used in the corresponding movies.
00:14For Chapter 1 here, you'll see that there are no files because there are no
00:17exercise files used in that chapter.
00:19For chapters that do have exercise files, you'll see the names of the folders,
00:24and they'll appear on your screen according to which movie you're watching so
00:27that you can follow along and use the appropriate files for each movie.
00:32Each folder has its final version and a starting version, so just in case you
00:36get lost, you can see the final code and compare your code against that code.
00:42I'll close that window.
00:43If you don't have access to the exercise files, don't worry.
00:46You could still follow along.
00:48Throughout the entire course I'm going to go through my projects line by line
00:52and explain what you can do to set up your files and folders in the same way so
00:58that you can follow along as well.
00:59So now that you've taken a look at how the exercise files are organized, you're
01:03ready to begin building apps using Java.
Collapse this transcript
Importing exercise files into Eclipse
00:00If you're working along with the exercise files for this course, you're going to
00:04need to do a lot of importing existing files.
00:08To do that, you can simply create the default Java project, so you can go to
00:14File > New > Java Project.
00:17Now of course if we're working with a different type of project for that chapter
00:21then you create the appropriate project for that chapter.
00:24For example, if I'm working in an Android project, you'd create an
00:29Android project, and so on.
00:31So I'll create a new Java project.
00:33I'm just going to use the default location in the workspace.
00:37I'll name this project "example." Then I'll hit Finish.
00:42And now I'm going to expand the example project.
00:45You'll notice there is a folder called src that holds the class files that we
00:49will be working with. And now I'll tab over to Finder.
00:54The exercise files contain start and final versions.
00:58If you just see a folder called com, that folder belongs in the source area of your project.
01:04So you can simply click and drag that com folder right onto src, choose Link to
01:11files and folders, and click OK. And now I can expand src and I can see my
01:17appropriate class path.
01:19For other chapters you won't just see a com folder.
01:22I'll go back to Finder.
01:24For example, in Chapter 5, you'll see a whole batch of files.
01:32In the event you see a lot of files, including the src folder, you can simply
01:37select all of those files--
01:39I'm doing that now by Shift+Clicking the bottom one and then the top one--and just
01:44drag all of the files right onto the main source folder for the project. And
01:50that's not the src folder, but the main project folder.
01:54That's because we want to make sure that we overwrite all of the files inside of our project.
02:01In the event that you get a conflict when you're trying to create a project, you
02:05might have to go into your workspace and manually delete the files.
02:10You can see at the top of my screen that Eclipse is telling me that my workspace
02:15is in the Documents folder, in a folder called workspace.
02:19I'll go back to Finder, into the workspace folder.
02:23In here you can delete any folders as needed.
02:27So if you need to create a second project called android_gb, for example, you
02:32can just delete that folder, and then you can create that same project with the
02:37same name without any problems.
Collapse this transcript
Getting the most out of this course
00:00The structure of this course is somewhat different than most of the courses in
00:04the Online Training Library.
00:06While this course doesn't follow the creation of one project from start
00:10to finish, it looks at one project from many different perspectives and applications.
00:17For that reason, I highly recommend watching all of the videos in the course in order.
00:23Now the reason for that is because we basically create one app toward the
00:28beginning of the course and then we look at porting the app to the web, to the
00:34desktop, and to Android throughout the rest of the course.
00:38Since we're porting the same application, I don't cover the intricacies of the
00:43app itself in detail, but rather, I mostly cover the nuances of the different
00:50publishing platforms.
00:52So again, I highly recommend watching all of the movies in this course in order,
00:57rather than jumping around randomly.
01:00That said, in the event that there are some more so that you want to get for a
01:04particular platform,
01:06you can feel free to jump ahead, but just know that you won't have all the
01:10context necessary to understand everything in the app.
01:14So now that you've seen how this course is structured, you're better prepared to
01:19know which movies to watch for your individual needs.
Collapse this transcript
1. Exploring Development Environments
Choosing a development environment
00:00There are many different choices of integrated development environments, or IDEs,
00:05for developing in Java.
00:07Let's look at some popular ones here, and you can explore on your own and choose
00:11which one best suits your needs.
00:13Eclipse is probably the most popular IDE for developing Java apps.
00:18Part of that is because it's so customizable.
00:21Not only you can use it to develop Java apps, but you can use it to develop many
00:26different types of apps.
00:27If you scroll down, at eclipse.org/ downloads, you'll see that you can also use C
00:33or C++, JavaScript, and other languages as well.
00:38And if you're using Eclipse, chances are, if you're missing a feature or a
00:42language, there's a plug-in out there somewhere that will add that feature to Eclipse.
00:48Another one is NetBeans.
00:50You can find NetBeans at netbeans.org.
00:53I've used both Eclipse and NetBeans, and one thing that I like about NetBeans is
00:59that you can easily create a user interface for your apps.
01:03Basically you could just drag and drop components onto the screen, and you can
01:07organize them in a visual way, and I really like that.
01:12And finally there is an app called IntelliJ that a lot of people like because it
01:17looks nice and it works really well.
01:21Also know that all of these IDEs are cross-platform and free.
01:26If you want to get in the realm of paid applications, there are plenty out there
01:30that can help you to develop with Java.
01:32So you can pick one from this list or choose an app on your own that best suits
01:37your needs for developing Java applications.
Collapse this transcript
Setting up the development environment
00:00The IDE I've chosen for this course is the Eclipse IDE for Java Developers, which
00:05you can find at eclipse.org/downloads.
00:09So once you've downloaded that file, you can install Eclipse.
00:13I've already installed it to my computer, and I'll launch it from the Dock.
00:18Here I'm going to choose the default workspace and click to use this as the
00:22default and do not ask again. I'll click OK.
00:28Now that we're in Eclipse, let's create a new project.
00:31So I go to File > New > Project.
00:34Under Java, I'll choose Java Project. Click Next.
00:38I'll call this TestProjct, I'll use the default location, and then I'll just click Finish.
00:46I'm going to choose to open the Java Perspective, and I'm going to expand the
00:51TestProject in the Navigator.
00:53I'll right-click the src folder and then choose New > Class.
00:59We'll just use the default package, and for the name we'll call this Test.
01:05I'll choose public static void main for method stubs to create. I'll click Finish.
01:12Here I see the class opened in my view.
01:15Now one thing that's important to note is that my font is probably a larger size than yours.
01:21You can adjust your font size by going to Eclipse > Preferences. In the General
01:25section expand the Appearance section, the Colors and Fonts, under the Basic
01:32option, scroll down to Text Font, and you can bump up your font size here.
01:37I've also edit Text Editor Block Selection Font, close the window, click
01:43Apply, then click OK.
01:46And the last thing I want to do is just make sure that Java is running,
01:49so inside of my main method I'm going to type System.out.println, short
01:56for print line, and in the parentheses I'm going to pass in the string "Hello World!"
02:03We'll save and test this, and in the console at the bottom of the screen we
02:09should see Hello World!
02:10and I see it there.
02:11So we've successfully installed Eclipse, adjusted font settings, and tested
02:16an app in the console.
Collapse this transcript
2. Building Dynamic Web Applications
Preparing Eclipse to build dynamic web pages
00:00One of the uses for Java is that you can communicate with a database to create
00:05dynamic web pages much like you would with PHP or ASP.
00:10To do that, you're going to need a testing server and some plug-ins in Eclipse.
00:15The most common testing server for Java Server Pages, or JSP, is called Tomcat.
00:22You can download Tomcat at tomcat.apache.org.
00:24I'm going to click to download Tomcat 7.0, the zip version.
00:32Once you have that folder, you can drag it to somewhere on your hard drive.
00:36I've chosen my Applications folder on my computer.
00:39Now let's go over to Eclipse.
00:41Once you've downloaded the zip file, make sure that it's unzipped, and you can
00:46drag that folder into your Applications folder or into your Program Files folder
00:51or anywhere else on your computer for that matter.
00:54Now we're going to install the plug-ins by going to Help > Install New Software.
00:59In the Work with box, start to type Indigo and click on it once you see it
01:04appear in the menu.
01:05It may take a few seconds for all the plug-ins to load, so you might have to
01:10wait while you see the word Pending, but eventually if you have an Internet
01:15connection, the plug-in should load in there. And you can scroll down and select
01:19any plug-ins that you'd like to install.
01:22So I'll scroll down, check the box that says Web, XML, Java EE, and OSGI
01:29Enterprise Development.
01:32Here I click Next, and you might see some information that your request has been
01:38modified because you already have some of the plug-ins installed.
01:41I'll just click Next, and then here you can look at the user license agreement.
01:46I'm going to click that I accept these terms and click Finish,
01:50and now the software will install, and afterwards you will be asked to restart Eclipse.
02:02So once the progress bar finishes, you'll see an option to restart Eclipse.
02:07So let's restart Eclipse, and then I'll just close the Welcome screen, and in
02:12here I'm going to create a new project.
02:15So File > New, and this is going to be under Other.
02:20In the type of project, scroll down to the Web section and choose Dynamic Web Project.
02:26I'll click Next. We'll call this TestJSP.
02:32Now I'll click the Next button, Next button again, and then I'll click Finish.
02:39Now we need to associate our project with Tomcat, so we need to associate it with a server.
02:45If you click that Servers tab at the bottom of the screen, you will see
02:49Tomcat server version 7.0.
02:52If you don't see that, you can Ctrl+Click or right-click and choose New > Server,
02:59and under Apache you'll see Tomcat version 7.0.
03:02You go through the process, and then we're going to move TestJSP over to
03:10Configured by clicking it and selecting Add. Then I'll click Finish, and then
03:17I'll click a server and then the Start Server button.
03:21All right, so I have the server running, and then I'm going to expand TestJSP,
03:32expand the WebContent folder, and then I'm going to right-click WebContent and
03:37then choose New > JSP File.
03:39I'll change the name of the file to Test.jsp, click Next. From the Templates
03:49I'll choose New JSP File (html), and then I'll click Finish.
03:54So this creates a JSP file that's based on a template.
03:57So you'll notice html code in here, in the bottom, and then you'll notice
04:01this tag that has a bracket and then a percent sign and the closing tag has percent bracket.
04:08Those are areas where we can put Java.
04:11So in the body I am going to click and type less than and a percent sign, and
04:16inside of that tag I'm going to type out.print. In parentheses I'm going to type
04:25"Hello World!" Make sure to add a semicolon after the closed parenthesis. And
04:32if this runs correctly, the Java should be processed and it should spit out
04:38"Hello World!" in the body tag, so we should see that in the published page.
04:43So I'll go to File > Save, and then I'll click the Run button.
04:48I will choose the server that's currently running, then click Finish, and
04:55we're testing this in a simulated web browser inside of Eclipse, and there we have Hello World!
05:01So we have JSP file successfully running in Eclipse.
05:06So just remember, if you want to execute Java inside of a web page, you'll
05:11need to set up the plug-ins in Eclipse and a testing server, which is normally
05:16going to be Tomcat.
Collapse this transcript
Installing MySQL on the Mac
00:00Our next step in getting our dynamic web page to work with the database is to
00:05install a testing database on our computer.
00:08On the Mac you can find a testing database server at mamp.info.
00:15MAMP is a Mac Apache MySQL, and PHP testing server.
00:21The free version is sufficient for what we're going to do in this course, so you
00:25can click to download the one on the left.
00:28Once you've downloaded and installed MAMP, you can launch it.
00:33You may be asked for a password, which is the default setting, and once you
00:37started it, you should see two green lights on the left.
00:41We're really mostly concerned with the MySQL server.
00:44Go to Preferences. Under Ports,
00:49you can click to set to default Apache and MySQL ports. Then click OK, and
00:56you should still have green lights. I'm going to have to enter my password to
01:01confirm that change.
01:02I should see two green lights. Everything looks good.
01:08And once you have MAMP set up, you see that your MySQL server is running.
01:13We are ready to start working with the database.
Collapse this transcript
Installing MySQL on Windows
00:00In order to use Java to build a dynamic web page, you'll need a testing server.
00:05For Windows, the easiest way to set that up is WampServer, which you can find at wampserver.com.
00:12I'm now in the Downloads section, and I'm going to click to download the 64-bit version.
00:17When the window opens up, I can skip filling out all my contact information and
00:20just click "download it directly."
00:23I'm taken to another link and WampServer is then being downloaded.
00:27I'm going to choose to run the file when it's downloading.
00:33Once it's done downloading, I'm going to click Run, because I do trust this application.
00:38I'm going to click Yes to make sure the application runs, and then the WampServer
00:45setup wizard starts.
00:47I am going to click Next to start the wizard.
00:49I'm going to accept the license agreement, and of course make sure you
00:52read through it before you click Yes. I'm going to install the default location
00:58at to c:\wamp. We're going to create a desktop icon. I'll click Next and
01:06then I'll click Install.
01:12Now it's asking for my default web browser.
01:14It's already on Internet Explorer, so I'm just going to click Open. It asks
01:17to install the new WampServer2 homepage.
01:21I'll just click Yes. And for PHP, we actually don't need any of this, so
01:25I'm not going to change it.
01:26I'll just click Next and then click Finish,
01:29and I'll launch WampServer now.
01:30Again, I'm going to click Yes to confirm that I still want to run WampServer.
01:35I'm going to minimize Internet Explorer for the moment and at the bottom right
01:40of my of my screen you can see the little green icon that indicates that
01:43WampServer is running.
01:45It says it is offline currently,
01:48so I'm going to click Put Online, after I click on the WampServer icon. I'll
01:56click the button again, and then I can launch phpMyAdmin from there.
02:01When this launches, you have actually confirmed that you're testing server
02:06is running properly.
02:07Now if you'd like to set a password, you can click on Privileges--that's at the
02:13top--and where that says root localhost, click Edit Privileges, and here I'm
02:22actually going to scroll down and change the password.
02:25Now in the Password field you'll notice that it's blank, so it's blank as the
02:30default, but I recommend typing in a password here.
02:33I'm going to type in a simple four- character password, but if you'd like to be
02:37more secure, you can click the Generate button to generate a better password.
02:43Remember that when you create the password you should write it down or have it
02:47somewhere so you can access it again if you ever need it.
02:50Now of course you will need it when we'll log in to the MySQL database later on.
02:55Now throughout this course we're going to use a server port for MySQL and
03:02Apache, so you might have to know that. For phpMyAdmin
03:06you can just note the URL right now, so mine is just localhost/phpmyadmin.
03:12If you need to change the port or you're having a problem, if you click on Wamp
03:16icon, go to the Apache folder to open up httpd.conf, you can actually use the Find
03:25command, So Ctrl+F, and then we'll find 80, which is the default port for
03:32Apache, and you want to find after it says localhost and a colon.
03:37So if you change that number from 80 to something else then you can change the
03:41default port number for Apache.
03:44So again, it's very unlikely that you'll have to change this, but this is just
03:48so you know, if you have to.
03:50Finally, we'll look at the port number for MySQL.
03:53If I click on that WampServer icon again, I go to MySQL.
03:58I can open up my.ini, and then right in here it says port equals 3306.
04:05Now of course that's the default port and you shouldn't need to change it, but
04:09in the event that you do, here is where you can change that value. Just make
04:13sure you change it in a plain text editor and then save the file.
04:17So once you have your WampServer up and running, you're ready to start building
04:21dynamic applications using Java.
Collapse this transcript
Importing data into a MySQL database
00:00With your MySQL server running, browse to the address on your screen.
00:05If you happen to browse to localhost/phpmyadmin and don't see what I have all
00:11on my screen, after localhost and before the forward slash, type a colon
00:16and then type the number of the port that you entered in your settings.
00:20You may also be asked for login information before you go to phpMyAdmin. The
00:25default login info is "root" for the user and for the password.
00:32You can of course change that later and I recommend doing that,
00:36but for now, root and root is sufficient.
00:39So the first thing we will do is create a new database and in the Create new
00:43database field type tours, t-o-u-r-s, all lowercase, and then click Create.
00:50Make sure you have the tours database selected. On the left side of the screen
00:56you could see that. And then click Import.
01:00For those of you who don't have access to the exercise files, we are going to
01:03provide this exercise file for free because it will save a lot of time in
01:09just downloading it.
01:10So you should have an SQL version of that file.
01:14So once you unzip it, it will be an SQL file, which is a plain-text export of
01:19the database we're using.
01:20So click Choose File, and you can browse in the chapter 02 folder, if you have the
01:26exercise files, in the importing data folder. You will see tours.sql there. Click
01:32Choose, choose SQL for the Format of the Imported file, and then click Go.
01:38At the top of the screen you should see a green check box and "Import has been
01:43successfully finished."
01:46If you click on tours on the left side of the screen, you will see there is one
01:49table in the database called tour.
01:51If I click on tour on the left, you will see all the different fields, and you
01:57can click Browse to see the actual data in the database.
02:01If creating databases is new to you and you'd like to learn more information,
02:05you can find that in the Online Training Library.
Collapse this transcript
Using MySQL database drivers
00:00The last step before we connect our code in our JSP file to our MySQL database
00:06is to download and install the database driver.
00:10You can find it at mysql.com/downloads/connector/j/
00:18Here I will click to download the zip file.
00:21I can click No thanks to take me to the download and then choose a mirror.
00:26I have already downloaded the files, so I am going to tab over to Eclipse, and
00:33in Eclipse I'm going to create a new project.
00:36Now you need do this whether or not you have access to the exercise files, so
00:40create a new dynamic web project.
00:42I will call this using_ drivers, and click Finish.
00:52Now if you already have access to the exercise files, then what you can do is
00:59just grab the folders and drag them into Eclipse, and so I'm going to grab
01:05WebContent, the source folder, and the build folder.
01:11Click and drag those three folders right on top of using_drivers, and you
01:16will be asked if you want to link the files. I'm going to choose Link and then click OK.
01:23And then I am asked if I want to overwrite the files, so I click Yes to All.
01:27So that's how you're going to be importing the existing projects if you're
01:31working with the existing exercise files.
01:34For those of you who don't have access to the exercise files, just expand the
01:38WebContent folder and right-click it, create a new jsp file called data.jsp, and
01:44just empty out all the code in it.
01:46So I just have a blank file here.
01:49And now what I'm going to do is in my project is expand the WEB-INF folder, and
01:57for the lib folder, you are going to go over to Finder,
02:01I'm going to go in my Downloads folder and find that mysql download that I have.
02:06In there, there is .jar file.
02:09And this is the file that contains all of the classes that we need to work with.
02:12So I'm going to click and drag that file right onto my lib folder and then make
02:18sure to copy the file into my project and click OK.
02:21Once you have done this, then you have the database drivers installed and you're
02:26ready to start writing code in your JSP file to connect to a database.
Collapse this transcript
Connecting to a database
00:00Now we'll write the code to connect to our database,
00:04so make sure first that your database server is running and that Tomcat is
00:08running inside of Eclipse and that you have installed the appropriate MySQL driver.
00:14So I'm in data.jsp. I am going to double-click the tab so that I can get a full
00:19view of just my code.
00:21You can always double-click it again to go back to the standard view.
00:25The first thing we are going to do is write some import statements.
00:27So open bracket, a percent sign and that symbol, we will close that out with a
00:35percent sign and a greater than sign.
00:39And inside of this tag I'm going to type page, space, import, an equal, and in
00:46quotes I am going to type in the classes that I want to import,
00:49so java.sql.*. And then I'm going to copy and paste this code right after itself
01:00to eliminate whitespace.
01:02So I'll paste that using the keyboard shortcut Command+C or Ctrl+C to copy and
01:08Command+V or Ctrl+V to paste.
01:11And I'm going to change the import code from java.sql.* to java.io.*.
01:18And I will repeat the process and paste the code again and change the import to
01:26com.mysql.* and then finally after that, still on the same line, I am going to
01:35write a declaration that this is an XML document.
01:37So open bracket, question mark, xml, space, version= and in quotes, the version
01:48is going to be 1.0, and then we will close it out with question mark and a greater than sign.
01:54So what we have done so far is just declare the classes that we want to import
01:59and use in Java and then outside of our Java code we have declared that this is an XML file.
02:04So let's go to the next line, and we are going to create the tours tag.
02:10So <tours>, and on the next line we will close that out with /tours tag.
02:19So we have an opening closing tag called to tours.
02:24And on the next line, inside of our tours tag, I'm going to write some Java code.
02:28So I will need to type a less than sign and a percent sign and Eclipse will
02:33autocreate the closing tag for me.
02:38And in here I'm going to initialize some variables that we will be using.
02:41So connection is the data type, and we will call this connection lowercase.
02:46We will just initialize it to null.
02:49We will do the same thing for a Statement. Statement is the class, statement
02:56lowercase is the name of the variable, set it equal to null, and the same thing
03:02for ResultSet. Capital R and capital S for the class name.
03:06And then result for the name, and again, we will initialize to null here.
03:11Now let's go down a few lines, and we need to connect to the database in a try catch block.
03:18So try and then some brackets and below the brackets, catch.
03:25The error is going to be of type SQLException.
03:32We will name it e. I will put the brackets there, and we will just type
03:36out .println and in the parentheses, pass in the string, "error
03:44connecting to database."
03:48No return to the try block. In there, we are going to create a new instance of
03:52the driver class by typing Class, capital C, .forName, and the name will pass in
04:00as a string so quotes and then pass in com.mysql.jdbc.Driver, with a capital D.
04:12And then after the close parenthesis type a dot and then newInstance.
04:19On the next line we will set the value of our connection.
04:22So connection all lowercase. We will set that equal to DriverManager, capital D,
04:31capital M, .getConnection, and then we pass in three parameters that are all strings.
04:40First the database url, then the username for the database and the password for the database.
04:48So in quotes url is going to be jdbc:mysql://localhost:3306. Remember that's the
05:02port for your MySQL server.
05:05And if you change it to something else in your settings, make sure you put that number here.
05:09And then /tours. That's the name of our database.
05:14After that string, type a comma. The next string is the username of our database.
05:19I kept mine at the default, which is root.
05:22And finally, the third parameter is also a string that's the password for the
05:25database, and I kept mine at the default as well, which is root.
05:30Make sure to add a semicolon after the end of the statement.
05:34And then here I am just going to type out.println, and in parentheses I will pass
05:39in the string "connected to database."
05:44So this is going to happen if there's no problem.
05:48So when we test this we should see either "connected to database" or "error
05:52connecting to database."
05:53So let's save the file and then test this using Tomcat. I am going to click OK
06:01to restart the server.
06:05And then in Eclipse's built-in browser I should see a message that says
06:11"connected to database."
06:13So that successfully connected to the database.
06:16If you have any problems with this, make sure that you're running both your
06:19MySQL server and Tomcat, and then check to see that the jar file is in the
06:25correct location so that you can load in the drivers.
06:30Finally, of course, make sure to check all of your code against mine, including
06:38the port number for your MySQL server.
Collapse this transcript
Displaying data from a database as XML
00:00Now that we have established our database connection, let's look at printing out
00:05the database data as XML.
00:07That way we can use this data in a later application to simulate exporting
00:13data from a real web server's database and bring it in from the web into a desktop app.
00:22So for now I'm going to delete the out.println line of code in the try block,
00:27and here I'm going to create a statement.
00:29So set the value of statement to connection.createStatement.
00:36Make sure to add the parentheses and a semicolon.
00:39Now on the next line we will create a string called s, short for statement,
00:44that will be the string version of our query.
00:47So in quotes, we will set it equal to Select with a capital S, space, asterisk, from, space, tour.
00:57Remember, tour is the name of the table in our database.
01:05So then we will loop through the records.
01:07The first thing to do is execute the query.
01:09So to do that, set the result equal to statement.executeQuery, passing in the
01:17string called s. Then we will loop through the results in a while statement.
01:23So while and in parentheses, result.next--so this will run as long as there
01:31is another result--and some brackets, and we are going to create the tour XML element.
01:40So here I'm going to close out the Java code by closing out that tag with a
01:45percent and a greater than sign.
01:46I will go down a few lines and I'll open it back up again, and then within that,
01:54I'm going to create the tour element.
01:56So tour first opening tag and then another line down, the closing tag.
02:02So for every record in the database, we are going to create this tour element,
02:08and inside of that element we are going to create subelements, one for each row in the table.
02:14So go between the opening and closing tag of tour, and tab in, and we will
02:19create an element called tourId, capital I. So I will create it.
02:25I will close it out right here.
02:29In here we are going to use Java and MySQL to grab the tourId from the database.
02:36So create a opening and closing Java block, so less than sign and percent and
02:44then percent greater than sign, and in here we are going to use out.print and in
02:50the parentheses, add the parentheses and a semicolon, and inside the
02:55parentheses, type result.getString, and we simply name the column label, which
03:04is going to match the name of the XML element, which in this case is tourID.
03:09This one has both a capital I and a capital D.
03:14So this tourIDs are integers, and if we save and test this in a browser, we
03:19should see some integers printed out to the screen.
03:21So File > Save, and then I'll test this app.
03:25I am restarting the server here, and in the web browser I should see all the
03:40different IDs for the different tours.
03:43So that's telling me that we are successfully grabbing data from the database.
03:46So that's wonderful.
03:47I will close that and return to data.jsp.
03:52And now what I am going to do is simply copy this line of code for all the other
03:56elements that we want to put in our XML.
03:59So select that line and then paste it, 1, 2, 3, 4, 5, 6, 7, 8, 9 times.
04:12Now what we are going to do is just change each of the XML elements and have
04:16them match the value that we have in result.getString.
04:20So right below tourID, the first one, I'm going to go to the second element
04:25and call this tourTitle, and I'm just going to paste that in the string and in
04:33the closing element.
04:34So tourTitle and then the next one is packageId. And once you have written them,
04:43you will see that we have tourId, tourTitle, packageId, packageTitle,
04:47description, price, difficulty, length, image, and link.
04:51This is all pulling the data directly from the database.
04:55So now let's save and test the file again.
04:57So now we see all of this data spewed out in one big page.
05:06If you want to see what it looks like as actual XML data, you can actually copy
05:10and paste this into a web browser and then click to view the source.
05:17So View > View Source and then here is all the XML data.
05:22So now this data is usable in another application.
05:26So in this chapter we have successfully established a connection between a
05:30dynamic web page and a MySQL server, and we've printed out data from the
05:35database as XML that we can use in another application.
Collapse this transcript
3. Creating a Desktop App
Loading XML data from the web
00:00In this chapter we're going to look at how to use XML data from a URL to run a
00:06desktop application.
00:08The XML data we're going to use is the same data that we created in the previous chapter,
00:13so for this you're going to need two projects in your Projects Explorer.
00:17First, the final version of the app created in the last chapter and here
00:23you'll see data.jsp.
00:26Note that the project name is jsp_final.
00:29And if you test this with the built-in Eclipse web browser, you'll see a URL in
00:34the Web Browser area.
00:36You can copy that URL now because we're going to use it in just a second.
00:39So I'm going to close those two files. And the main files we're going to be
00:43working with for this are in the loading _xml project, and I put them inside the
00:48com.toddperkins.uar package.
00:52So I'm going to double-click the tab for AppMain.java to expand the area.
00:57AppMain is the main class.
00:59Here I create a new instance of the View class and run some methods.
01:03Explain the DefaultCloseOperation, which is a method of JFrame.
01:08We'll look at that in just a minute.
01:09Set the size of the window and set it to be visible.
01:13So the View is the main visible class for our project.
01:17Let's go over to View.java.
01:19So here I've declared that's part of the com.toddperkins.uar package, and then I
01:25have a list of import statements.
01:27The class extends JFrame, which is part of the Swing framework, and it
01:33implements ActionListener.
01:35Keep in mind that we'll be talking more about the Swing framework later on in this chapter.
01:40Here I have some initialized properties, ArrayList to hold values from the XML,
01:46and some various Swing-framework objects that I'm mostly creating here.
01:51And later on we'll look at how to actually use them in an app.
01:56In the constructor, I call super and pass in Backpack CA, which sets the title
02:02area for the window that we're looking at.
02:05And I call setLayout to a new FlowLayout.
02:09What that does is it sets the class to present added visual elements vertically.
02:15Then I run the custom method loadData, passing in the URL copied from the
02:20Eclipse web browser when I looked at that XML data.
02:25Then I have public void actionPerformed.
02:27This is so that we can fulfill the requirements of ActionListener.
02:32And I have loadData, and I have a utility method called getTagValue that returns
02:39the value inside an XML tag.
02:42Let's return to loadData.
02:44I actually have this code already written, because if you watched the Java
02:49Essential Training, then you've already experienced loading data from a URL.
02:53So here we're just going to review.
02:55Note that we're loading a document in a try catch block.
02:59So we create a new DocumentBuilderFactory, then a new DocumentBuilder.
03:04Then we have the DocumentBuilder parse the URL and save it in that document object.
03:10Then we normalize it to condense the XML data.
03:13Then I have a NodeList called nodes, and that grabs all the elements by tag
03:18name, which is tour.
03:19And then I could simply loop through all the tags using the iterator called i.
03:25So I have a node that we set as nodes.item index i, and we check to see if the
03:33NodeType is an ELEMENT_NODE.
03:35And if so, I grab the element as an element, so I'm typecasting it here, and
03:41then I put these elements inside of the ArrayList.
03:46So titles.add, descriptions.add, et cetera, we pass in getTagValue.
03:51That's our custom method that returns the value of a tag, so we pass in a
03:55string which is the name of the tag and then the element.
04:00In the case of the link, I made sure to remove any extra whitespace, because
04:05links won't work if there's extra whitespace.
04:07So I'm using a regular expression here to grab all the space characters and
04:13replace all of them with nothing.
04:15And that's only for links.
04:17Now if you want to log this to the console, just to make sure that we're able to
04:22read the XML data okay, you can type System.out--don't forget to capitalize the
04:28S--.println and in the parentheses we'll pass in getTagValue.
04:38And in the parentheses for getTagValue, we'll pass in first the string
04:41tourTitle, capital T for Title, and then a comma, and then e for the element.
04:48So let's save and test this, and we should see all the tour titles in the console.
04:54So test the app, and we now have a blank view for the app.
04:59There's the window with Backpack CA at the top.
05:02I'll close that and if I look in the console, I can see all of the names
05:07on different lines.
05:08So I've successfully extracted the XML data. We're using it as XML, and the data
05:14is coming from a URL.
05:16And the last thing I'm going to do is just delete that line of code at the
05:20bottom, the System.out.println.
05:23We've seen that we can actually read XML data from a URL, and we'll look at,
05:30throughout this chapter, how to use that data in a desktop application.
Collapse this transcript
Creating a UI with the Swing framework
00:00Using the Swing framework, you can create a visual interface for your applications.
00:06In the Swing framework, elements start with a capital J. So we have JComboBbox,
00:11JTextArea, JLabel, JScrollPane.
00:15So the first thing we are going to do is create something called a JPanel.
00:19So the data type is going to be JPanel-- this is at the bottom of the constructor,
00:24right below load data--and we will call this panel.
00:27And a panel is basically a grouped visual area.
00:31We will set that equal to new JPanel. Then we'll set the layout of the panel, so
00:38panel.setLayout, and the layout is going to be a newBoxLayout.
00:47Now a box layout enables you to align things horizontally or vertically.
00:53So we can do that within each unique panel.
00:56So in the parentheses after new BoxLayout, you need to pass in two parameters.
01:02The first one is the element that the box layout is being applied to, so panel
01:08and then a comma, and then we pass in the alignment, which is going to be
01:12BoxLayout, capital B, capital L, .PAGE_AXIS, all caps.
01:18So that's going to be vertical.
01:21There is also line axis, which goes along with the flow of a line on a page,
01:26which is a horizontal layout.
01:27Go down to the next line. And then what we want to do is we want to display the panel,
01:33so we actually need to use the Add method to add it to the screen.
01:37So type add, and that's a method of JFrame, which this class is extending,
01:43as you could see here.
01:44So we are putting the panel on the screen.
01:46We just is pass in panel into the parentheses.
01:49The next line we will create a panel for the labels.
01:53And the way it's going to work is it will have the combo box and then the text
01:56area going vertically, and then below that is going to be a horizontally
02:02aligned set of labels.
02:04So let's create a panel for the labels so that we can align them horizontally.
02:09So JPanel and we will call this labelPanel and set it equal to new JPanel.
02:17Now I'll need to set the layout, so labelPanel.setLayout. It's going to be a new
02:25BoxLayout as well. And in the constructor for BoxLayout we will pass in
02:31labelPanel and then BoxLayout.LINE_AXIS.
02:37So remember, that's going to be horizontal.
02:39Then we are going to add the price label and the length label to the label panel,
02:44so labelPanel.add. And we will first pass in the priceLabel and then on the next
02:51line, instead of directly adding in the lengthLabel, we are going to put in some space.
02:57So labelPanel.add and then in the parenthesis we are going to create space by
03:06creating something called a dimension.
03:08To do that, type in Box with a capital B .createRigidArea, and then we pass in a dimension.
03:16So create a new dimension, and this is going to be a horizontal and
03:21vertical dimension.
03:22So we are specifying the size of space in between the object.
03:25So the Dimension constructor is going to take two parameters: first the width
03:31and then the height. So we will pass in 15 and then 0.
03:35So you have 15 pixels in between the labels. And then we'll add in the length label.
03:41So labelPanel.add and then in the parentheses we will pass in lengthLabel.
03:46Then we are going to add one more set of space, and this is going to be to
03:54separate the length label from the button.
03:59And so we will copy and paste the code to create some space between the length
04:03label and the button that we are going to add in just a second.
04:06We will set a default text for the price label, so priceLabel.setText, and pass
04:14in the string Price: $ and then 0.
04:20Now in the next line we will set default text for the length label, so
04:23lengthLabel.setText, and then pass in the string Length: and then 5 miles.
04:31On the next line we are going to set the value of our combo box, and we will
04:36automatically populate it with the data from our XML. And we look at how to do that right now.
04:41So combo equals new JComboBox and in the parentheses we are going to pass in
04:47an array of items. And to get the array, we will type titles, which is an
04:52array list, .toArray.
04:55That will automatically populate the combo box with all of the elements from our XML data.
05:01And then panel.add(combo), on the next line panel.add, and here we are going to
05:10create some vertical space, so Box.createRigidArea, pass in a new Dimension. And
05:19the dimension is going to be 0 for the width and 15 for the height.
05:23Remember that the panel is aligning items vertically along the page access, not
05:29to be confused with the label panel, which is using the line or horizontal axis.
05:35Onto the next line. textScroller equals new JScrollPane, so the scrollable area
05:44and in the parentheses of the constructor we will pass in textArea and then a
05:49comma, ScrollPane, capital S, capital P, Constants.VERTICAL_SCROLLBAR_AS_NEEDED,
05:58all caps, separated by underscores, and then a comma. We will pass in a value
06:04for the horizontal scrollbars, so,
06:06ScrollPaneConstants.HORIZONTAL_ SCROLLBAR_NEVER and to the next line,
06:13textArea.setLineWrap passing true. Next line, textArea.setRows.
06:24That's going to be an integer, and the number of rows we want to display is 10.
06:30This essentially controls the vertical size of the textArea.
06:33textArea.setWrapStyleWord and pass is true, so this does word wrap instead of a
06:43letter wrap, and we will add the text scroll to the panel, so panel.add, and in
06:48the parentheses pass in textScroller.
06:53Onto the next line. panel.add, and we will put in some more space, and so we will
07:00type box.createRigidArea. We will pass in a new Dimension, and that will be 0 for
07:08the width and another 15 for the height.
07:10Make sure to add a semicolon to close out that statement.
07:13And then we are going to add the label panel to the main panel, so
07:17panel.add, pass in labelPanel.
07:20Then finally, we will create the button and put it inside of the label panel.
07:27So JButton, capital B, will be the data type, call this btn, set it equal to a new
07:33JButton, and in the constructor we will pass in the string "Book Now." This is
07:39the string that's going to be on the button. And on the next line,
07:44labelPanel.add, and then will pass in the button. And finally for the last line
07:51we will set an initial item selected in the combo box.
07:54So combo.setSelectedIndex, pass in 0, semicolon to add that statement. And after
08:04we have typed this massive block of code, let's save and test and we should see
08:09the visual elements in the window.
08:11Going to test this as a Java Application, click OK, and there is my window.
08:17It's the appropriate size.
08:19I have the combo box with all of the data populated from the XML, some space,
08:25and then I have a text area that's 10 lines high, and then I have the default
08:30text labels that are organized with the button horizontally, and there's space
08:35between them and the text area.
08:37So I will close out that.
08:38So we have successfully used the Swing framework to create a layout for our app.
08:44Remember that when you're using the Swing framework use the add method to place
08:48an object on the screen and use an array to populate a ComboBox.
Collapse this transcript
Displaying data based on user input
00:00With our XML loaded and our user interface set up, we will connect our combo box
00:06to our text field so that when you change a value in the combo box the text
00:10filed will update with the appropriate description.
00:13Scroll down in your code, right below where we create the new combo box.
00:17So combo equals new JComboBox.
00:20On the next line we are going to add something called an ActionListener.
00:24This listens for an action, which is, for example, when a user changes a combo box.
00:30So type combo.addActionListener, and then the value that you pass in needs to
00:35be an ActionListener.
00:37Remember that this class implements ActionListener so I can actually pass in this.
00:43So make sure to add a semicolon to close out the statement, and just scroll
00:47down and find the actionPerformed method.
00:51So when the combo box has changed, this method receives an ActionEvent, which is
00:56held in the parameter e, which we can use to access information about the event.
01:01Keep in mind that this same handler can be used for all different types of events,
01:07so it's kind of a generic event handler.
01:10So inside of this method, the first thing we are going to do is capture the
01:14selected index of the combo box.
01:17So create an int called i, and we will set it equal to combo.getSelectedIndex and
01:25that will return the selected index, which is zero based.
01:29So go down a few lines and all we are going to do is just set the value of the
01:35text fields. So the first one is text area, which is the main big text area, so
01:39type textArea, capital A, .setText.
01:43Here we just need to pass in a string of the text, and we can get that string
01:48from our descriptions ArrayList.
01:51So if your Array List is declared as having only a certain datatype, for
01:55example, string here, we don't have to typecast it to a string.
02:00So in setText, we'll type descriptions.get and we pass in i. So we get item i
02:09from descriptions array list and that's it.
02:12Let's just save and test at this point to make sure that that's working, and
02:16then we will move forward and update the length and price labels.
02:21And so now we will save the file and actually before I can test it, I am going to
02:24need to open the main class file, so I am going to double-click the View tab and
02:30open up AppMain and then with AppMain selected, I will click to run the app.
02:34Again make sure that your servers are running. And so now I see the combo box
02:39and the appropriate text in the text field.
02:42And every time I change the value in the combo box, I should see the text update.
02:45You will notice one thing, that the scrollbar doesn't scroll back up to the top,
02:49so we will look at how to fix that in just a second.
02:50But everything else seems to be working just fine.
02:53So we just need to update the price and length labels and fix that scrollbar issue.
02:58So I will quit the app and return to view.java.
03:01What I'm going to do is just copy this line twice, so the text area lines, copy,
03:07Command+C or Ctrl+C and then go to the next line and paste with Command+C or Ctrl+V.
03:11And then I will change text area in the first paste code to priceLabel, capital L,
03:17and then the text area in the second block of code to lengthLabel.
03:22And then for the price label we will change descriptions to prices, and then
03:28before that we are going to put a string and then concatenate with the plus sign.
03:34So inside of that string, type Price, colon and then a space and a dollar sign,
03:39I will do the same thing for length.
03:42So change descriptions to lengths and then the string before that,
03:48make sure to add the plus sign to concatenate, and then in the string Length,
03:53colon, space, and then I'm going to add miles after we grab the value from the XML.
03:59So concatenate another string on the end of that, so plus and then some quotes,
04:04and inside of the quotes, miles.
04:06So you should be able to save and test this again if you'd like and just see the
04:10price and the length label update.
04:12Before I test it, I am just going to fix that issue with the scrollbar where it
04:16doesn't move all the way to the top every time.
04:18Now you can actually just set the scrollbar's position with one line of code;
04:23however, it won't work because you need to execute the code after the Swing
04:28framework has handled the user interface updating thread.
04:32So to do that, we are going to type javax.swing.
04:38capital S for SwingUtilities.invokeLater. And in the parentheses we are going to
04:46create a new object here, so new, space, Runnable and then after that last close
04:53parentheses I am going to add a semicolon and before the last close parenthesis
04:57I'm going to down a few lines.
04:59We are actually going to define the Run method inside of this method call for invokeLater.
05:05So I am defining this class right here.
05:10The open bracket right after the parentheses for new Runnable and the close
05:15bracket right before the close parenthesis of invokeLater.
05:21Inside here I need to define the run method, so public void run, and parentheses
05:27and some brackets and inside the run method, I can then update the scrollbar.
05:33So textScroller.getVerticalScrollBar. setValue, then pass in 0. Make sure to close
05:43out the statement with a semicolon.
05:45And what we are doing here is we are setting the position of the scrollbar to 0,
05:48which makes it go all the way to the top.
05:50We're doing it this way because we have to run it after the thread is completed
05:56that updates user interface, or else the update will not show.
06:00So save and then go to at AppMain.java and test this, and you should see
06:06that everything works.
06:07So I see the price and the length are updated.
06:10I can change that, and every time I change the combo box everything is updated.
06:18I could scroll down and scroll up and look at the text in the combo box. And the
06:22only thing that we could improve upon here is put a space between the number of
06:27the length and the word miles.
06:29So let's just quit our app, return to our code, and put a space right before
06:34miles in that string, save, and then we will test again, and we should see
06:39now, there is a space between miles, the combo box updates the text field, the
06:44price and length labels.
06:46You could update by changing the combo box and you will see that the scrollbar
06:50is moved all the way back to the top.
06:52So remember, you can handle events using the add ActionListener method so we
06:57apply that to the combo box.
06:59You handle it in a class that implements ActionListener in a method
07:03called actionPerformed.
07:06In the actionPerformed method, you could handle the event and get specific data
07:10about the event through the ActionEvent object.
07:13If you want to update a scrollbar in a Swing element's text field, then you need
07:18to make sure that you use invoke later so there won't be any conflicts when you
07:22update the scrollbar.
Collapse this transcript
Opening a URL when a button is clicked
00:00Let's complete the app by adding the button functionality so that when you
00:04click the "Book Now!" button a URL opens in the user's default browser.
00:10In your constructor find the line of code where you create the button.
00:13On the next line, type button.addActionListener and pass in this.
00:21We're using the same handler to handle the combo box event and the button event,
00:26so what we're going to need to do is create some way to differentiate between the two.
00:30To do that, go to the next line and type btn.setActionCommand, and then we can
00:36pass in a string that identifies the name of action for this particular object.
00:42So I'm going to type "click," all lowercase.
00:45So now when the ActionCommand is click in the actionPerformed method, I know
00:49that the button was clicked and it wasn't that the combo box was moved.
00:53Keep in mind, if you're going to have many events that you're handling, it's
00:56better to create constants than using direct strings like I'm using here, but
01:01for what we're doing in this tutorial, a standard string will suffice.
01:06So in actionPerformed scroll down and under int i, create a few extra new lines
01:12and create an if statement in there.
01:14In the if statement we're going to see if the action that was performed was
01:17indeed the click action.
01:19So type e.getActionCommand. After the parentheses type .equals, and the
01:27parentheses for equals, we're just passing the string, click, all lowercase,
01:30make sure it matches the value that you passed in btn.setActionCommand
01:33above, which it does, and inside of the if statement we're going to create try catch block.
01:40So just create that real quick, and the exception that we're going to catch is
01:45just a standard exception.
01:48We'll call this ex, and inside of the catch block all we'll do is just print that
01:53there was an error, so System.out. println, and in the parenthesis we will println
01:59just pass in the string "error loading url."
02:04In the try block, we'll load the URL, so when the button was clicked, we're
02:09going to launch that URL. And to open up the user's default browser, type
02:14java.awt.Desktop, capital D, .getDesktop, capital D again, .browse, and you can see
02:23in the code here that this launches the default browser to display a URI.
02:28So in there we need to create a new URI.
02:31So new space URI and in the parentheses for new URI, type links.get, and then
02:40pass in i. So we'll correspond to the current value that's selected in the
02:45combo box, and that's it.
02:48So save the file and go over to AppMain.java and test this and you should see
02:53the app launch, and click Book Now! And you'll see that your browser opens and
02:59if you look at the URL, you're getting the correct URL that was from the XML, so
03:04you can go through the different ones and test it if you'd like.
03:07And the main thing you're looking for at the top of the screen is that the URL
03:10matches the URL from XML.
03:13So once you get that working, you can see that you can add support in your apps
03:17to open up links from XML data that comes from a database.
03:22We'll tab that to Eclipse.
03:25So remember, you can add a button listener by using the simple addActionListener
03:30Command, and if you have different events that you're listening for in the same
03:34handler, use the setActionCommand and pass in a unique string for each
03:39particular event. That way inside of action performed, you can check to see
03:44which command happened and handle the event accordingly.
Collapse this transcript
Publishing a desktop app
00:00Now that our code is complete, we'll look at how to publish the application as a desktop app.
00:06Before you do anything else, make sure that all of your servers are running and
00:10that your data file is working.
00:12So again, that's your MySQL server, your Tomcat server, and you can make sure
00:16that you have the JSP project inside of your Project Explorer. So you can test
00:21it in Eclipse in the built-in web browser if you want; just make sure that URL works.
00:26So the first step is to select our project.
00:29I'm going to select publishing. I have AppMain selected.
00:32I'll go to Run, and then Run Configurations. And in Run Configurations, I'm
00:38going to select Java Application, and then I'm going to click the button to
00:42create a new configuration.
00:43I'm going to call this Backpack CA, and for the Main Class I'm going to select Search,
00:51I'll choose the AppMain class and click OK, and you can click through these
00:55different tabs and add any settings that you'd like.
00:58I'm going to leave them at the default and click Apply, and on the left side I should
01:03see Backpack CA run configuration. So I'll click Close.
01:08And then what I'm going to do is with publishing still selected, I'm going to
01:12go to File and then Export, and in the Other category I'm going to choose Mac
01:18OS X application bundle.
01:20Of course, if you're not running a Mac you're going to see a different icon there
01:24that's the appropriate application bundle for your operating system.
01:26So select that and click Next, and then when it says use this launch
01:32configuration, make sure to choose Backpack CA, make sure the main class is
01:36correct, application name should be written there as a default.
01:40For folder, we're going to choose the export location, and I'm going to
01:43choose the Desktop, and for the icon, I have an icon in the assets folder called icon.icns.
01:51There is also an icon.ico for Windows apps that you can use.
01:55If you don't have an icon file, you can create a 512x512 pixel image, and go to
02:03one of the free web sites that converts the icons for you, like for example
02:07iconverticons.com. That's where I created my icon.
02:12So you simply upload the image, click Convert, and you get icons for
02:16various operating systems.
02:19So I have that set up, and I'm just going to click Finish and then Eclipse will
02:23actually publish the app for me, so on my desktop, I should see the Backpack
02:28California app. And if I look there, I can see that the icon is displaying, and it
02:34looks just like any other Mac app.
02:37If I double-click the icon, the app opens, and it works just like the app did in
02:43Eclipse, except for this is actually desktop app. And if you look at the doc,
02:47you'll see there is the icon in there, so this actually runs just like any other
02:52native app on my computer.
02:54So again, you could see I can click to switch through and browse all of the data.
02:59I can click Book Now! and the URL opens.
03:03And the functionality is exactly the same as the app that we built in Eclipse,
03:07except for this is the desktop- published version of the app.
03:10So remember that if you want to publish a desktop app, you'll have to create
03:15your own run configuration and then you export the app as an application bundle
03:20in the Other category, and when you follow those steps and create your icon
03:24file, you'll have a native desktop app that you created using Java.
Collapse this transcript
4. Making Applets
Understanding applets
00:00Let's say you wanted to take the Java desktop application you created and
00:04publish it for the web using a browser plug-in.
00:07It's actually a fairly straightforward process and a version of the app
00:11is called an applet.
00:13Before we get started, I want to show you that I have this file called data.xml.
00:19I'm going to double-click that file and look at the source code.
00:23And you'll notice here the source is just exactly the same source that we've
00:27been kicking out from our database.
00:29I just copied and pasted the source code so you can view that in a web browser
00:33and then go to view source, copy and paste that into a plain text file, and
00:38change the extension to XML, and you'll have this file here.
00:42So what I've done is I've taken that data.xml file and I put that inside of a
00:48folder called resource.
00:50So that's in my resource folder, and then I have the com folder, and I just took
00:54those two folders and dragged them into the src folder for my project.
01:00So make sure you close out that data.xml file, and let's take a look at AppMain.Java.
01:06In here I've just condensed all of our code into one class.
01:10An applet basically works just like a regular Java app, except for your main
01:15class needs to extend JApplet, and JApplet is a visual class similar to JFrame.
01:21So this class is essentially the view class.
01:24And really the only change that I've made is I've called loadData instead of
01:28passing in a URL and passing the path to the resource.
01:31So that first forward slash gets us to the root of our project, and then inside
01:36of that, there's the resource folder, and in that folder you'll see data.xml.
01:41So if we scroll down to the loadData method, you could actually see how resource
01:46is loaded rather than data from URL.
01:49It's actually not that different at all. On the document builder.parse line of code
01:54all I changed was the value passed into the parentheses, and I typed
01:58this.getClass so that grabs a class, which has a method called
02:04getResourceAsStream.
02:05This is just built-in, and I didn't have to define that myself.
02:09So I pass in the string, a path to the file, and boom, it loads in just like the
02:16other content loaded in.
02:17And so I could test that right now inside of Eclipse
02:21if I click the Run button. And here you'll notice that the size isn't right, and
02:27that's because we're not setting the size inside of the Java code;
02:30we're actually going to set the size in an HTML element that will load to
02:35applet, so don't worry about that.
02:36So you see it works just like the desktop version did and so I'll close it out, and that's it.
02:43So if you want to create a Java app that runs in the web browser as a plug-in
02:49just extend the JApplet class, and if you want to load a resource, create a
02:54folder called resource inside of your source folder and put your files inside
02:59of there.
Collapse this transcript
Publishing and viewing an applet
00:00Now let's publish our applet and test it in a web browser.
00:04So I have my app opened here and I'm just going to go to File > Export and then
00:10choose under Java, JAR file.
00:14I'll click Next, and here I'm choosing the resources to export.
00:18I'm just going to have applet selected.
00:20I'm choosing Export generated class files and resources and Export Java source
00:25files and resources.
00:27And here I have the location of my JAR file, and you can set it here by clicking
00:34Browse. Then I have Compress the contents of the JAR file and Overwrite existing
00:40files without warning checked.
00:42And then since I've already exported this, I'm just going to click Cancel, and
00:46then I'm going to jump over to Finder.
00:49And inside of the assets folder I have the JAR file and the HTML file. And so if
00:56I open the HTML file then you can see that it'll run.
01:01So I double-click that and you should see the JAR file running inside of my web browser.
01:06So there it is, running inside of the Java plug-in, and you can note that it works
01:12just like it did in the Desktop.
01:15I can click the Book Now button to browse to the web page and everything
01:20is virtually the same.
01:22So let's take a look at the source code, especially for those of you who don't
01:25have the exercise files.
01:26I'll go to View and then View Source, and I'm pressing Command+Plus to bump up
01:31the file size so it's easier to see.
01:33In here we have the source code, so it's just a basic HTML file.
01:38I put the title in there.
01:39And in the body all I did is I put the applet tag, and then you set code=, and
01:46then in there you put the location of your class, and you use the .class instead of .java.
01:53So I have the full name for the class, including the package.
01:58And then I have the value for the width and the height.
02:03And then the archive file, which is the JAR file, I just have the name. It's in the
02:06same directory as the HTML file to keep things simple.
02:10And then if the browser doesn't have support for the applet tag then you'll see this message.
02:15So we successfully exported our application that was on the Desktop to being a
02:20web app that runs in the browser.
Collapse this transcript
5. Writing Android Applications
Installing the Android SDK
00:00Now we are going to port our application to Android.
00:03Go to developer.android.com/sdk/installing.html.
00:09Now step one here is to install Eclipse, and you have already done that.
00:13So go to step two, and you can click the link to go to the SDK download page.
00:17I go into Command+Click or Ctrl+Click it so that that I open it in a new tab.
00:22Here I'm going to click to download the version of the SDK that's appropriate
00:27for my operating system.
00:29And then I will go back to the steps to installing the Android plug-in.
00:34In Step 3 there is a link that says, Installing the ADT Plugin.
00:37I'm going to click that link and scroll down to Downloading the ADT Plugin,
00:42to where I see a URL.
00:44This I'm going to need to type into Eclipse.
00:47I'm going to select it and copy it and then before I go to Eclipse, I'm going to go to Finder.
00:54And now I'm going to take that folder that was just downloaded--
00:56you may have to unzip it of course--and just drag it into your Documents folder.
01:03And then I'm going to go to Eclipse.
01:05Go to Help > Install New Software and in the Work with field, paste, using
01:13Command+V or Ctrl+V the URL, that you just copied.
01:17Check the box to install the Developer tools and then click Next.
01:22And you will see the Install Details.
01:24I'm going to click Next and then choose to accept the terms of the license
01:28agreement. Of course you want to read over that first and then if you agree to
01:33the terms, you can choose that option and click Finish.
01:36Then the new software will be downloaded and installed.
01:39You may see a security warning that says you're installing content that is unsigned.
01:44Now I actually downloaded this directly from Google, so I trust it.
01:48So I'm going to click OK, and we'll wait for the software to be installed.
01:54Once you install the plug-in, Eclipse will need to restart,
01:57so I'm going to click to restart now.
01:59Once Eclipse is restarted, you may see that the SDK Platform Tools component is missing,
02:05so we'll look at managing the SDK Manager to install it.
02:09You also may see another pop-up window about the location of your Developer tools.
02:16If you see that window, you can tell the input box that you already
02:21have downloaded it.
02:22You can point your computer to the appropriate location of the folder.
02:27And don't worry, because you can always fix that later as well.
02:30And let's take a look at what I am talking about.
02:32If I go to Preferences, which is under Eclipse on the Mac and Window on the PC,
02:37then you will that in the Android tab
02:40I have my SDK Location here.
02:42If you don't have anything, just click Browse, and then you can browse to that
02:46folder on your computer.
02:48Once you're inside the Android SDK folder, you can click Open, then click
02:52Apply, and then click OK.
02:54Now let's look at managing the Android Development Tools plug-in.
02:59Go to Window > Android SDK Manager.
03:03Now this might be married with the AVD Manager if you're on Windows.
03:09So I'll launch that, and here what I want to do is just install the Android 2.3.3 API,
03:18so I'm going to check that box.
03:22And you may be wondering why we are not downloading the latest version of Android.
03:26That's just because for this project we are not using any features specific to
03:30later versions of Android.
03:32So this will be sufficient for our project, and I will just click Install 5
03:36packages, accept the defaults, and then click Install.
03:43Now it may take a minute for these to install.
03:47You will see the progress bar going.
03:54And once that's complete, you can close the Windows. And then we are going to go
03:59to Window > AVD Manager.
04:03AVD stands for Android Virtual Device.
04:08Now the previous installation of the SDK actually created a device
04:12already, so I'm going to delete that, and then I'm going to click New. And
04:18before we go through this, I want to explain that this is actually a simulator
04:23for running an Android app.
04:24So we are creating this virtual device.
04:28So the name is going to be Gingerbread, after the name of the operating system.
04:33And I'll choose the Target to Android 2.3.3. For the SD card I am just going to
04:40enter 100 in the Size field. Snapshot, I am going to click Enabled so that this
04:45will run faster in the simulator.
04:47I recommend doing that as well, and then I'm going to leave the Built-in Skin at
04:52WVGA800, and then I'm going to click Create AVD.
04:59Now I will close the Android Virtual Device Manager, and then it's time to
05:03create a new Android project.
05:05So go to File > New. I'm going to go to Other.
05:11I'm going to expand the Android folder and then choose Android Project. I will click Next.
05:19I will just call this android_test1 and I will click Next. And I'm choosing an
05:31SDK to target. We only have one, so I'll click Next again.
05:35And now I have to specify a package name so it's going to be com.toddperkins.uar,
05:42and I will click Finish.
05:44And then I'm going to expand the folder so I can see the project, and in the
05:49source folder, I can expand that and I can see Android_test1Activity.java.
05:57I'll open that file and when it opens in the Code view, I can see the default
06:01code that's written.
06:02This creates a hello-world app, and let's see what this looks like in the Android Simulator.
06:10So then I will click Run. Then you may see a window that asks you to choose
06:14which type of application you want to run. Make sure to choose Android
06:17application. Then the Simulator should launch, and it might take a minute for
06:22you to see your app in the Simulator.
06:25And so, once you've waited for the Simulator to start up all the way--and again
06:30it may take several minutes for this to happen--
06:33you should see the name of your app, which here I have Android_test1
06:38as the name of the main class that I'm running, and then it says Hello
06:42World, Android_test1Activity!
06:45So I have the initial hello-world app for Android running in the Simulator.
06:50So now you can see we've successfully installed the Android SDK into Eclipse,
06:56and we can now build Android apps.
Collapse this transcript
Building the app's layout
00:00We will start an Android app first with the layout.
00:04So if you have access to the exercise files, create a project called
00:07building_layout and then drag the appropriate exercise files right on to that
00:11project in Eclipse, making sure to link and overwrite all the files.
00:17If you don't have access to the exercise files, then in the Source folder you
00:21can create the Java classes AppMain and Detailview.
00:25We will go over them soon.
00:28And in the assets folder you go are going to need data.xml, which is just that
00:32same data file that we have been using, the static data file that we have been
00:36using in other chapters in this course.
00:37So you can just copy that into the assets folder, and in the resources folder, in
00:43layout, I have not only main.xml, which is the default file we get in Android
00:48project, but I also have detail.xml.
00:51So you can create that by clicking that icon on the screen that looks like a file
00:56with a plus on the top right.
00:58So let's start by opening up main.xml.
01:02Now if you don't see the same view that I do, which is the Android XML layout,
01:07you can right-click main.xml and choose Open With > Android Layout Editor.
01:13So here we have the default view for our main file.
01:16What I am going to do is select that text that says Hello World and I'm going to delete it.
01:21And then I'm going to go into Composite and then grab a ListView to drag
01:28into that window.
01:29And the last thing we need to do is give this ListView a special ID.
01:36So click to go to the code view in main.xml, and then we are going to change the
01:41id value, so inside of the quotes we are going to type @android:id/list.
01:54And now we can go back to the graphical layout.
01:57And what that does is it sets it as the main list view for our app,
02:05and that's all we need to do for now,
02:07so I will make sure to save this file, and then I will open that detail.xml.
02:13So in here I'm going to go to the graphical layout, and then I'm going to grab,
02:17in the Form Widgets section, Large Text, drop it in, and then I will go to Small
02:23Text and then two Medium Texts.
02:27Large, Small, Medium, Medium and finally I'm going to grab a button.
02:34So put that at the bottom.
02:36And now what I want to do is expand all of these to the whole height of the
02:40screen, so I will just click on Large Text, choose Distribute Weights Evenly, and
02:48now you can see that I have all even space between each of the elements.
02:54And now for my button, I actually want to have the text book now.
02:58So we'll look at changing that in just a minute.
03:01What I'm going to do first is assign the IDs to all my text fields.
03:06If you look on the right side in your Outline View, you can see all of the ID
03:11names for your Text Fields, so we have textView 1, 2, 3, 4 and then button1.
03:15So this isn't very descriptive of what these objects are.
03:18So I am going to right-click Large Text at the top, choose Edit ID, and we will
03:23call this tTitle, capital T for title.
03:29And then for the Small Text, I'm going to right-click it, choose Edit ID, and
03:33choose tDescription.
03:37For Medium Text, at the top, I am going to right-click it, edit the ID, and we
03:42will call that tLength, capital L, edit the ID for the last text field, and we
03:50will call this tPrice, capital P. And then for the button I'm going to
03:57right-click, Edit ID and I am just going to call this button, so we will click
04:02OK, and now we will look at how to change the text on the button.
04:07If I go into my code, after I save the file and I look at detail.xml in the
04:14code view, we can scroll down and find the button, and there's a text area that
04:19says text, but if I change that to say Book Now with an exclamation point,
04:25later on when I test my app, I will get a warning saying that this should be in
04:29the strings.xml file.
04:32So just in case you want to do that, just open up strings.xml from the values
04:36folder, which is in the resources folder.
04:37So open that and I am looking at this in the standard XML view, so what I want to
04:45do is open that in the string view, so Open With > Android Resource Editor.
04:54So I'll close the other instance of strings.xml, and in here you can see that I have
04:58already created the sBookNow (String).
05:00So if you don't have the exercise files, just click the Add button, and then
05:04you will choose string and then click OK. And with your new string selected,
05:08give it name, sBookNow with a capital B, capital N, and for the value put Book,
05:14space, Now with an exclamation point, and then save the file and go back to
05:19detail.xml. And you can use a string from your strings file by typing
05:25@string/sBook, with a capital B, and then now, so that's the ID value of our string.
05:34So you can save that, go over to Graphical Layout, and then you'll see Book Now
05:39in that button field.
05:40So now we have successfully set up our layout files, we are ready to move on
05:47in creating our app.
Collapse this transcript
Displaying loaded XML in a list
00:00Here is our main app file, which is the class AppMain.
00:05If you don't have exercise files, the best place to start is by using one of the
00:11files from one of the other apps that we made.
00:13So take the Main class file from another app that we made and then modify it
00:18to match this. That way you'll have the least amount of work, rather than
00:22starting from scratch.
00:23So we have these classes that are imported.
00:27Notice that the class extends ListActivity. The default Android class to extend
00:34is just activity, so make sure that you extend ListActivity.
00:38Now we have a list of properties, just the same as before, and then I have static
00:43properties for each of the XML fields. So if you don't have those, I recommend
00:49creating them now, because we're going to be using them in multiple places.
00:52The onCreate method is pretty much the default at this point. And then
01:01onListItemClick, I have most of it commented out, and this is going to be the
01:06handler for when a list item is clicked.
01:08We're going to look at how to handle that in another movie.
01:13And I have a loadData method to load the file data.xml, and I'm loading it by
01:20calling the DocumentBuilder parse method and passing in getAssets.open and then
01:26passing in the name of the file so we can parse that file.
01:29And I have all the XML elements added here, just as before, and then getTagValue,
01:36which you've also seen before.
01:39So let's go at the bottom of onCreate. What we're going to do is take the titles
01:43array and then put that in that list, so that we have a List view with all the
01:48titles from our XML.
01:51So the thing that we need to do first is to get a string array, and then
01:55we'll put in there. So type String, capital S, and then some brackets, and we'll call this titles_str.
02:05I will set it equal to titles.toArray, capital A, and in the parentheses after
02:14toArray, I'm going to get the length of our titles array list by typing new, space,
02:19String, and then brackets, so new string array. And the length is going to be
02:24titles.toArray, after the parentheses .length.
02:29So we create the array and it's the length of the titles array list, and then
02:36we go to the next list. We'll use that. Type this.setListAdapter and then here
02:44we pass a new, space, ArrayAdopter, capital A, capital A, and then less than and
02:53then a greater than in there.
02:56We'll define it as a string, and then in the parentheses after that pass in
03:01(this,android.R.layout.simple_list_item_1), separated by underscores, and a
03:19comma, and then titles_str.
03:22I'll just end that statement with a semicolon and go to the next line. So
03:28what we're doing here is we're just taking that title string and then putting
03:33it inside of our list.
03:38So here, this android.R.layout.simple_ list_item_1 just refers to the layout for
03:44the list items in the list.
03:46And now we'll save and test the app. And here's the Simulator, and you should see
03:54the app launching in the simulator, and here I have all of my XML data, so it's
04:00appearing in that list view.
04:02So now that we've taken that XML data that we created and we successfully used
04:06it to populate a list.
Collapse this transcript
Sending data to a new intent
00:00Now we're going to look at clicking an item in the ListView and having a
00:03new intent open up.
00:06Think of an intent as a separate view for your app, so that will show the DetailView.
00:11Before you can do that, open up AndroidManifest.xml and go to the Source Code
00:17view. Right below the closing tag for activity we need to declare the
00:22DetailView activity.
00:24So I create a new element called activity and inside of the opening tag set the
00:30attribute android:name=2 and in quotes, .Detail, capital D, View with a capital
00:41V. So we'll save the file, and we can close it. Then we'll go to AppMain.java.
00:50Scroll down into the OnListItemClick event handler.
00:55So here we receive the data, which is the ListView, the main View, integer for
01:04the position of the item that was clicked, and an ID.
01:07So first thing I do is I call super.onListItemClick.
01:14So right below that comment that says Get the item that was clicked,
01:18let's handle this event.
01:19So the first thing we'll do is create the new intent.
01:23So datatype Intent, capital I. We'll call this intent with a lowercase i, and
01:31we'll set it equal to a new intent. And in the parentheses for the constructor
01:38we'll pass in V, which is the view, .getContext. Make sure we include the
01:45parentheses. And the second parameter is going to be DetailView.class, so
01:50DetailView with a capital D, capital V, .class, so that we'll create a new
01:56instance, and then we're going to put an extra inside of that.
02:02What we use the extra for is to pass data from one intent to the new intent
02:08that's going to appear.
02:10So below that, type intent.putExtra, and then we pass in the name and the value.
02:17The name is going to be TITLE in all caps and then for the value we'll pass in
02:24titles.get, so we're grabbing an item inside of the titles array list.
02:31And the Item number that we want to get is the position that's passed into the
02:34onItemClick, so just passed in position, and then a semicolon to end the statement.
02:40Just make sure that you spelled it correctly, so position, and that's it. And what
02:45I'm going to do here is just highlight these lines of code that are commented
02:50out and I'm going to press Command+7 or Ctrl+7 on my keyboard to uncomment them.
02:56So I did the same thing for putExtra with description, price, and length, and the link.
03:02Then I run the method startActivity, passing in the intent.
03:06So let's save that file and before we test it, let's go over to DetailView.java.
03:11In DetailView we're importing several classes of a property called URL that's a string.
03:20It extends the activity class. onCreate is pretty much the default, and all that
03:27runs is this code in here, which are commented out.
03:29So right below set ContentView, which, by the way, calls that detail XML file
03:36through the value R.layout, so that's what associates the XML layout file with this class.
03:43I'll set the value of URL, so url = getIntent, capital I, and then parentheses,
03:55.getStringExtra. And then we pass in AppMainm so the class of name .LINK, all caps.
04:05So we'll close that line out, and then what we're going to do is make sure
04:08there's no white space in the URL. And I've already looked to doing this before.
04:12I'm just doing this after we've already parsed the XML.
04:16So url = url.replaceAll, and then we pass in the regularExpression, which in
04:24quotes is to \\s+. That's any space, and the replacement is going to
04:32be nothing, so just two quotes right there.
04:34So it removes all the white space, and then we'll look at one more example of
04:39grabbing the title, so create a string called title, and I'll set it equal to
04:44getIntent, same as before, after the parentheses .getStringExtra, and then in the
04:53parentheses for getStringExtra it's going to be AppMain.title.
04:58Now I'll go to the next line, and what we're going to do now is put the title
05:04inside of the Title field in the DetailView.
05:07We'll create a value of type TextView, we'll call this titleView, capital V, and
05:16we'll set it equal to in parentheses TextView, so we're telling it to treat
05:22whatever we put after the parentheses as a TextView.
05:27And then findViewById, after the parentheses, and then in the parentheses after
05:34findViewById, type capital R.id.tTitle. Now we'll set the text for the titleView.
05:44Go to the next line and type titleView.setText, and then we'll just pass in title.
05:52Make sure to add a semicolon to close out that statement, and then we'll just
05:57uncomment the rest of the code.
06:03So I'll select it here, Command+7 or Ctrl+7 to uncomment. And I didn't write this
06:08code by hand just now, just because we're repeating the same process of
06:12setting the text fields,
06:13so you can just look at the code and see how I did it there and just notice that
06:16it's exactly the same as what we've already done. So we'll save now.
06:20I'm going to return to AppMain.java and then run the app in the Simulator.
06:25Note that you might have to click on your project and then choose to run as
06:29an Android application, or you might have to go to the Run menu and run it.
06:34So you can see my app is loaded into the Simulator, and I can simply click on one
06:40of the list items. Then the new intent shows with the appropriate title,
06:44description, length, price, and a Book Now button.
06:48So we successfully created our app, and we can now see all that data from the
06:53XML directly in our application.
06:56So remember, you can transfer to a new intent by creating the intent, adding
07:04extra data with the putExtra method, and then running startActivity and
07:08passing in the intent.
07:10You can get the extraData by calling getIntent and then .getExtra.
07:19If it's the string, then it is getStringExtra;
07:22if it's intent then it is getIntentExtra; and so on.
Collapse this transcript
Opening a browser when a button is clicked
00:00Now we'll finish our Android application by adding the functionality so that
00:04when you click on the Book Now!
00:06button, the device's browser will open up.
00:09Below all the rest of your code, in DetailView.java, inside of the onCreate method,
00:17type the following code.
00:18The first step is to declare a button object, so data-type it to a button, and
00:25then we'll call this button, and we'll set it equal to, and we'll use the
00:30parentheses, and type Button in the parentheses, and after the parentheses
00:33findViewByID, just like we done before. And in the parenthesis for findViewByID, type R.id.button.
00:44We go to the next line, and we'll type button.setOnClickListener.
00:54Now, in the parentheses we pass in a method to handle what happens when
00:58the button is clicked.
00:59So in here we'll type new, space, View, capital V, .OnClickListenter. The beginning of
01:09each word will be capitalized. And if I follow the code hinting by pressing
01:14Enter or Return then Eclipse actually writes out that whole method for me.
01:19Now I'm getting this red x right here because I don't have a semicolon, so I'll
01:23put that at the end of after the close parenthesis. And in here in OnClick, we can
01:28handle the click event, so we want to open up that URL. And we already have that
01:34saved in our URL property,
01:36so what we do is we just create a new intent and that intent is going to be a
01:40new browser window, and then we just run start activity, passing that intent in,
01:44and the browser window should open up just fine.
01:46So Intent with a capital I, and we'll call this browserIntent, capital I. And we'll
01:55set it equal to a new intent, and in the parentheses we're going to pass in
02:01Intent with a capital I, .Action_View, and the next parameter is going to be Uri,
02:11with a capital U, .parse. And then it asked for uriString, which is going to be
02:17that URL that we created in this class. So we just passed that in, and then all
02:22we have to do is run startActivity, passing in browserIntent, capital I, and that's it.
02:32So when you click the button, it'll open up the appropriate URL in the device's
02:36default browser. So let's just save this and then we'll click Run.
02:41Now we'll just wait for a minute for the application to star tup.
02:44Now since we used a snapshot for the emulator, you might see a previous version
02:51of app before the current version loads in.
02:53So you might have to wait an extra second or two. And then here I'll just click
02:56one of the elements in the list and then I can see all of the description data.
03:02I can click the Book Now!
03:03button, and I should see the device's browser open up with the appropriate URL.
03:08So here I have this blank window.
03:10You can see that a URL is opening, and it does start with Explore California, and there we go.
03:16And if you want to go back, of course you can click the Back button, and we go
03:21back to the previous activity. And we can go back again to the main list view.
03:25So our application is now finished, and we've successfully created an Android
03:31port of our application.
03:33So with that, we've created an application for the web, for the Desktop, and for Android.
03:41Remember that when you need to handle a button click, on Android you need to
03:45call the button.setOnClickListener method, and then you create a new
03:49OnClickListener, and you can just write the code to handle the event inline.
Collapse this transcript
Viewing the app on a device
00:00Here is our app running on an actual Android device.
00:03So you can see all of the data pulled from XML in a list element, and then I
00:08could tap any one of them and see the details.
00:12I can press the Back button on my device to return back to the main screen. And
00:16if I select another object, you'll see information about the title, the
00:20description, the length, and the price, and if I hit the Book Now!
00:24button, then the URL opens in my device's default browser.
00:28So you can see we've successfully ported our Desktop app both to the web and now
00:34to Android.
Collapse this transcript
Conclusion
Next steps
00:00This concludes Up and Running with Java Applications.
00:04Throughout this course you saw how you can use Java to create server-side apps,
00:08desktop apps, web apps, and even Android applications.
00:13This was meant to be just a demo to show you what is possible using Java and the
00:18many ways you can use it to develop front-end and backend applications.
00:22If you're curious about learning more details about working with Java, I
00:26recommend going back to Java Essential Training.
00:29You can find this in the Online Training Library.
00:31For a more thorough explanation of how to work with Android using Java, see
00:36Android App Development with Java Essential Training. And as we've seen in this
00:40course, there is so much that you can accomplish with Java,
00:43so I encourage you to keep learning, exploring, and becoming better at
00:48developing Java apps, and if you make anything you'd like to show me, you can
00:52contact me on Twitter at asktodd. I'll see you next time!
Collapse this transcript


Suggested courses to watch next:

Java Essential Training (7h 17m)
David Gassner


Are you sure you want to delete this bookmark?

cancel

Bookmark this Tutorial

Name

Description

{0} characters left

Tags

Separate tags with a space. Use quotes around multi-word tags. Suggested Tags:
loading
cancel

bookmark this course

{0} characters left Separate tags with a space. Use quotes around multi-word tags. Suggested Tags:
loading

Error:

go to playlists »

Create new playlist

name:
description:
save cancel

You must be a lynda.com member to watch this video.

Every course in the lynda.com library contains free videos that let you assess the quality of our tutorials before you subscribe—just click on the blue links to watch them. Become a member to access all 100,984 instructional videos.

start free trial learn more

If you are already an active lynda.com member, please log in to access the lynda.com library.

Get access to all lynda.com videos

You are currently signed into your admin account, which doesn't let you view lynda.com videos. For full access to the lynda.com library, log in through iplogin.lynda.com, or sign in through your organization's portal. You may also request a user account by calling 1 1 (888) 335-9632 or emailing us at cs@lynda.com.

Get access to all lynda.com videos

You are currently signed into your admin account, which doesn't let you view lynda.com videos. For full access to the lynda.com library, log in through iplogin.lynda.com, or sign in through your organization's portal. You may also request a user account by calling 1 1 (888) 335-9632 or emailing us at cs@lynda.com.

Access to lynda.com videos

Your organization has a limited access membership to the lynda.com library that allows access to only a specific, limited selection of courses.

You don't have access to this video.

You're logged in as an account administrator, but your membership is not active.

Contact a Training Solutions Advisor at 1 (888) 335-9632.

How to access this video.

If this course is one of your five classes, then your class currently isn't in session.

If you want to watch this video and it is not part of your class, upgrade your membership for unlimited access to the full library of 1,945 courses anytime, anywhere.

learn more upgrade

You can always watch the free content included in every course.

Questions? Call Customer Service at 1 1 (888) 335-9632 or email cs@lynda.com.

You don't have access to this video.

You're logged in as an account administrator, but your membership is no longer active. You can still access reports and account information.

To reactivate your account, contact a Training Solutions Advisor at 1 1 (888) 335-9632.

Need help accessing this video?

You can't access this video from your master administrator account.

Call Customer Service at 1 1 (888) 335-9632 or email cs@lynda.com for help accessing this video.


site feedback

Thanks for signing up.

We’ll send you a confirmation email shortly.


By signing up, you’ll receive about four emails per month, including

We’ll only use your email address to send you these mailings.

Here’s our privacy policy with more details about how we handle your information.

Keep up with news, tips, and latest courses with emails from lynda.com.

By signing up, you’ll receive about four emails per month, including

We’ll only use your email address to send you these mailings.

Here’s our privacy policy with more details about how we handle your information.

   
submit Lightbox submit clicked