Java for Android - 001

by 06:56 0 comments
I'm going to produce a serious of articles to give a clear and good introduction to java and android.
This is the first one of the Java for Android serious where we are going to know what is java and explore the tools we will need to learn it.

What is Java?

Cup of Java

The word java is a noun, In dictionary can be defined as Coffee, for example, "I'm dying for a cup of java".
But when we say JAVA we mean a general-purpose computer programming language designed to produce programs that will run on any computer system.

The JAVA Language

Like any programming language, the Java language has its own structure, syntax rules, and programming paradigm. The Java language's programming paradigm is based on the concept of OOP, which the language's features support.
The Java language is a C-language derivative, so its syntax rules look much like C's. For example, code blocks are modularized into methods and delimited by braces ({ and }), and variables are declared before they are used.
Structurally, the Java language starts with packages. A package is the Java language's namespace mechanism. Within packages are classes, and within classes are methods, variables, constants, and more.
You don't understand what that means? It's okay only C/C++ programmers can, That won't affect your understanding through the tutorials here or any other place.

The Java Compiler

When you program for the Java platform, you write source code in .java files and then compile them. The compiler checks your code against the language's syntax rules, then writes out bytecode in .class files. Bytecode is a set of instructions targeted to run on a Java virtual machine (JVM). In adding this level of abstraction, the Java compiler differs from other language compilers, which write out instructions suitable for the CPU chipset the program will run on.

The JVM

At runtime, the JVM reads and interprets .class files and executes the program's instructions on the native hardware platform for which the JVM was written. The JVM interprets the bytecode just as a CPU would interpret assembly-language instructions. The difference is that the JVM is a piece of software written specifically for a particular platform. The JVM is the heart of the Java language's "write once, run anywhere" principle. Your code can run on any chipset for which a suitable JVM implementation is available. JVMs are available for major platforms like Linux and Windows, and subsets of the Java language have been implemented in JVMs for mobile phones and hobbyist chips.

The JAVA Development Kit (JDK)

When you download a Java Development Kit (JDK), you get — in addition to the compiler and other tools — a complete class library of prebuilt utilities that help you accomplish most common application development tasks.


Enough Talking, We need Just to run it.
Okay Sorry, We are about to start now, Ready? I know you are excited.

Install JDK

We will show you how to install it for Windows, If you are using different Operating System things are different.
  1. Browse to Java SE Downloads and click the Java Platform (JDK) box to display the download page for the latest version of the JDK.
  2. Agree to the license terms.
  3. Choose Your OS (Windows in our case), Download and Install.
You can just follow this video


Install Eclipse

We have the tools java need it to run on our device, but we don't have the IDE (Integrated Development Environment) we need to write the code and use for debugging and optimising our programs.
Throw this tutorial we are going to use Eclipse but, You are free to use any other IDE if you want.
  1. Browse to the Eclipse IDE downloads page.
  2. Click Eclipse IDE for Java Developers.
  3. Under Download Links on the right side, choose your platform (the site might already have sniffed out your OS type).
  4. Click the mirror you want to download from; then, save the file to your hard drive.
  5. Extract the contents of the .zip file to a location on your hard drive that you'll be able to remember easily 
This video shows you how I did it



Setup Eclipse

The Eclipse IDE sits atop the JDK as a useful abstraction, but it still needs to access the JDK and its various tools. Before you can use Eclipse to write Java code, you must tell it where the JDK is located.
To set up your Eclipse development environment:

  1. Launch Eclipse by double-clicking eclipse.exe
  2. The Workspace Launcher opens, allowing you to choose a root folder for your Eclipse projects. Use a folder you can easily remember, such as C:\home\workspace.
  3. Close the Welcome to Eclipse window.
  4. Click Window > Preferences > Java > Installed JREs.
  5. Eclipse points to an installed JRE. You must use the JRE that you downloaded with the JDK. If Eclipse does not automatically detect the JDK you installed, click Add..., and in the next dialogue box, clickStandard VM and then click Next.
  6. Specify the JDK's home directory (such as C:\home\jdk1.8.0_60 on Windows), and then click Finish.
  7. Confirm that the JDK that you want to use is selected and click OK.

You also can see this small video

Okay now everything is ready, you need to explore the IDE? go and play with it a little.
Are you afraid you make something wrong? Don't be for two reasons:


  • You don't have to be very careful when you explore something, We learn from problems so go and make some problems and I'm sure you can solve them.
  • You can easily restore the view of the IDE by clicking Window > Perspective > Reset Perspective.
Next, we will make our first java project - get it here[link].

Ammar Atef

Blog Creator

Always work and you will be happy, Writing code, designing system and learning some thing new, I call that real life, No matter what is the problem, humanity can solve it any way, Creative one who believes he is creative, Who really watch, think, try and success, World is watching us because we are engineers.

0 comments:

Post a Comment