You are on page 1of 12

INTRODUCTION TO JAVA

FOR ANDROID DEVELOPMENT


Lesson 2.01 Project Structure

Creating Java Projects


Now that we have an Eclipse environment setup, its time to take a better look at the project creation
process, the files created, and what they mean. Well create a standard Java project, as well as an
Android based one, and review the differences, and the similarities.

Java Project
To create a new Java project, you can right-click over the working set in the Project Explorer, and
select "New", then "Java Project".

Java Project
Fill out the form to create a new project.
Project name This is the name you want to give to your project. It
should be unique (Eclipse wont let you create the same project
twice).
Use default location Checking this option will put your project into
the workspace as defined by Eclipse. Alternatively, uncheck the
option and select a folder where you want your project to reside.
JRE This section controls the version of the Java youre going to
be working with. Unless you have specific requirements to work
with an older version for some reason, go with the latest (already
pre-selected for you).
Project layout This section specifies the project structure you want
to use. Personally, I like having everything in sub-folders, which
makes it easier for you to find files, and support your application.
Use the "Create separate folders..." option for that, or "Use project
folder as root" to pile everything in one folder.
Working sets If working sets are enabled in the project explorer,
this option can let you create your new project in the specified set.

Java Project Structure


In this screenshot, "Intro to Java" is the name of the working set.

This working set can contain any number of open and closed
projects.
Below that, the blue, opened folder called "Hello_World" is the
root project folder for the "Hello_World" Java application.
src folder represents the folder where we keep our source code,
which typically consists of our class files (.java files).
It is a good idea to break down our source folder into packages.
Each package should contain a set of related classes. Since our
applications can have hundreds of class files, this helps keep
things neat, organized, and easy to find.
The "JRE System Library" folder contains all of the compiled Java
1.7 class files that we use while writing Java applications. We
dont have source code for these files, as they are part of Java.

Android Project
To create a new Android project, use the following methods:
Right-click over the working set you want to create the project in, then select "New", then "Project".
Youll be presented with the "New Project" dialog. Choose "Android Application Project" under the
"Android" folder.

Android Project

Creating Android projects requires going through a wizard,


with several screens and many options. On the first screen:
Application Name This is the name of your application.
Project Name This is the project name. As with the Java
project, it should be unique to your Eclipse installation.
Application name and project name can be the same.
Package Name This is a unique identifier for your Android
application. Typically this is a reversed URL, followed by the
project name. Example:
com.learnandroiddevelopment.hello_world_android.
Minimum Required SDK The lowest version of the SDK to
support.
Target SDK This will be the latest supported version for your
application.
Compile With The version of the SDK to compile your
project with.
Theme The default look and feel of your application.

Android Project
On the second screen of the wizard, you get to choose
whether or not a custom icon for your app is created.
You almost always want to create a starting activity using
the Create activity checkbox. This activity will be the default
screen that is displayed when your application is launched.
The exception being that you're working on a service or
library, which doesn't provide an initial interface, or if you're
planning on doing this work yourself.
Create Project in Workspace specifies the location for where
your project will be created.
Optionally, if you're using Working sets, you can specify
which working set to add your application to.

Android Project
If you selected the option to create a launcher icon on the
second screen, the third screen allows you to create and
customize this icon.
The screen allows you to specify an image, built-in clip art, or
text as the icon image, and specify the padding around your
graphic. You can then decide on the shape of your icon
(None, Square, or Circle), and its foreground and background
colors.

Android Project
On the Create Activity dialog, youre defining what your
default activity will look like.
There are several options here that can get you started quickly,
including a LoginActivity with a username / password prompt,
MasterDetailFlow for applications that display differently on
tablets versus smaller screen devices, FullScreenActivity for a
display that takes up the entire screen, and BlankActivity,
which is most likely the one you should start with. The
BlankActivity allows you to create your own interface for the
application.

Android Project

The Blank Activity screen lets you to define the details about
your new activity. An activity is a screen with a user interface,
so here, were defining the details of that screen and
associated class file.
Activity Name This is the name of your Java class file that
will handle the code for this screen. Typically Java classes
are named in "CamelCase", where the first letter in the class
is capitalized. Other capitals are used when starting new
words, and spaces are removed.
Layout Name This is the filename of the XML user interface
document that the wizard will create for you automatically.
Navigation Type This lets you define the type of navigation
to use for your project. Choices here include tabs, gestures,
and dropdown menus. For now, stick to "None", as some of
the other options may not be supported by the minimum
version of the SDK you chose on the first screen.

Android Project Structure


Android projects have a lot more files to them, but luckily, you dont
have to work with many of them.
src / Package The src folder contains one or more package folders,

each of which contains one or more java class files. This is the same
as with a standard Java application.
gen This folder contains a special class used throughout Android
development, which compiles pointers to resources used in your
application such as graphics, audio, video, fonts, etc.
res The res folder holds resources used by our project. This includes
images stored in the "drawable" folders, layout XML files stored in
"layout" folders, menu XML files stored in "menu" folders, and string and
style XML files stored in the "values" folders.
AndroidManifest.xml This is the main configuration file for our project.
This contains permissions our application requires, as well as a list of
special libraries (if any), version of our app, and a list of our activities
used in the application.
The rest of the folders contain compiled libraries and other resources
we need in order to run our application.

You might also like