Discover millions of ebooks, audiobooks, and so much more with a free trial

Only $11.99/month after trial. Cancel anytime.

My First In Java
My First In Java
My First In Java
Ebook326 pages1 hour

My First In Java

Rating: 0 out of 5 stars

()

Read preview

About this ebook

An introduction to programming book using java. Best book for students who have no idea yet in programming. Less discussion of theories and more on applications are used with sample problems. Simulation exercises are discussed to help students learn the algorithm through step-by-step.

Concepts are discussed chapter by chapter in progressive order. It is suggested that student answers chapter exercises to gauge the understanding of the topics discussed.

Students may download all sample programs with the provided link.

YouTube video links were also provided if one opts to learn the topics through video presentations.

Object-oriented programming(OOP) is not yet discussed on this book. Though java is an OOP language, the author believes OOP concepts are too broad or too early to discuss for students who are just starting to learn programming.
LanguageEnglish
PublisherLulu.com
Release dateApr 21, 2014
ISBN9781312122246
My First In Java

Related to My First In Java

Related ebooks

Computers For You

View More

Related articles

Reviews for My First In Java

Rating: 0 out of 5 stars
0 ratings

0 ratings0 reviews

What did you think?

Tap to rate

Review must be at least 10 words

    Book preview

    My First In Java - Jeremias Esperanza

    potential.

    Chapter 1

    An Introduction to Java

    At the end of this chapter, you will be able to:

    Know history that drove development of java;

    Specify the developement stages of a java program;

    Realize the importance of an IDE;

    Install java compiler;

    Install Eclipse IDE.

    Java is a high-level programming language. High-level language means a program can be written in a human language that the computer machine can later on decipher and understand.

    James Gosling and associates at Sun Microsystems, during the 1990s, started developing a programming language (PL) that will suit automation of household appliances (TV, VCRs, Refs, etc..). Oak was the original name they could think of for the PL only to realize there was already an existing name for that PL. The name Java was later on derived from a flavor of a coffee when they were sipping it from a coffee shop during those times.

    The popularity of Java grew tremendously during the mid-1990s. It was also on those times internet is paving its way to mainstream computing. The timing of Java was perfect because applications can be developed using the PL without concerns on which platforms it will run. Soon the defacto language of choice of most software development companies is Java up to the present time. It is estimated that Java runs on 5.5 billion devices worldwide today.

    Phases of a Java program

    Java boasts its strengths in terms of portability. Once you write and compile, it will run on any platform a computer has. Platform means is the operating system used by a machine. Example of this is Windows, Linux, MacOS, Android, and many others.

    How do we develop program in Java? The following are stages:

    1. Write. A java program can be written in any text editor softwares such as MS Word (without the format codes), Notepad, Crimson Editor, Sidekick, etc. What you need is to supply a file extension name .java once you save the file. The file you have just saved will be the source code of a java program.

    2. Compile. You can easily download for free from the internet the latest java development kit (JDK) that you may use in developing java programs. Together with the JDK is a program called javac.exe. This is the compiler of java.

    What does a compiler do? Compiler checks the syntax or formats of the codes you have written on a java program. It will ensure that all the words you have written comply with the java statement commands. If errors are detected from your program, it will specify the line number on where the mistake/s took place. You need to correct those errors, and re-compile. You will only proceed on the next stage of the development if your program is error-free.

    C1.Stages

    Figure C1.1 Phases of Java program

    An error-free program compiled by the javac.exe produces a byte code file. Byte code is a machine-language codes that will be interpreted by a Java Virtual Machine (JVM). The codes are no longer expressed in a human language but with the codes the machine understands. Byte code file has an extension filename of .class. An example on how to compile a program in a command line is as follows (Hello is the name of the program):

    javac Hello.java

    3. Run. Along with the downloads of JDK is an interpreter called java.exe. An interpreter is used to serve as an interface so the processor of the machine can understand what your program wants to achieve once you run it. Please note that the byte code file (filename with the .class extension) is the one interpreted and not the original file you have written (filename with the .java extension). Below is an example on how to run a java byte code program on a command line:

    java Hello

    Role of IDE

    Integrated Development Environment (IDE) is a software tool that will increase the development of a java program. You do not need to have an IDE to develop a java program. You need a text editor program, compiler, and interpreter to develop program.

    Detection of errors are made earlier even the program is not yet compiled when you use an IDE. The IDE notifies a syntax error occurs in the command/statement or no declaration yet has made on a variable as the programmer types the program. It even suggests solutions on how to quick fix an error in the program. It also gives a hint on what available methods and parameters you could use for a particular command/statement.

    The interface with the java compiler and interpreter is already done by an IDE. Running your program can easily be done with a push of a command button. It also includes a debugger on where you could trace the values of the variables. An IDE is a java solution tool rolled into one.

    There are many popular IDEs available on where you could download for free. Examples of IDEs are Eclipse, Net Beans, among others.

    Before we could write our first java programs, we need to install our java compiler that will convert our source program into an bytecode file that a machine can understand.

    An Integrated Development Environment (IDE) is a software tool used by developers in writing, compiling, debugging, and running their programs. This is where Eclipse IDE is known for.

    The following installation will guide us on how to download and install java compiler and Eclipse IDE on our computer.

    Installing Java Compiler for Windows

    Go to your browser.

    Visit http://google.com

    Type in the google search box: java jdk.

    Click Java SE Downloads

    C1.1

    Figure C1.2 Java sites to download compiler

    5. Click the latest release. On this case it is the Java Platform (JDK) 7u6. (see Figure C1.3).

    C1.2

    Figure C1.3 Java Development Kit to download

    6. Click the Accept License Agreement.

    C1.3

    Figure C1.4 Accept License Agreement

    7. Underneath select the appropriate java compiler suited for your OS. On this case, we choose Windows X86 for the 16-bit Windows 7 OS.

    C1.4

    Figure C1.5 Version to download

    8. Wait for the download to complete. Double click the downloaded file (see Figure C1.6).

    C1.5

    Figure C1.6 Version downloaded

    9. On Windows 7 you will be prompted if the installer is allowed to make changes. Just click yes.

    10. You will be prompted on the installation procedure. Accept the default settings. Just click Next.

    C1.6

    Figure C1.7 Opening window prior to installation

    C1.7

    Figure C1.8 Folder location on where to install

    11. This is the last window when the installation is completed. Click Finish.

    C1.8

    Figure C1.9 Final window after installation

    Video presentation: Install compiler

    Installing Eclipse IDE

    1. Visit http://www.eclipse.org/downloads/

    C1.9

    Figure C1.10 Choices of eclipse version

    2. Depending on your computer OS, click the corresponding link (normally, XP is Windows 32 bit, Windows 7 is 32 or 64 bit). On my case, I’m using Windows 7, I will click Eclipse Classic 3.7.2 Windows 32 bit. Skip 3 if you are running under Windows OS.

    3. If you are running a different OS (Linux or Mac OS), you may select it on the dropdown box. Just the same, click the bit version your OS supports.

    C1.10

    Figure C1.11 Choose appropriate OS

    4. You will be prompted to select the mirror location where downloads will come from. Click the suggested default site (green down arrow). Depending on the speed of your modem, this may take a while. Wait for the download to complete.

    C1.11

    Figure C1.12 Mirror site of download

    5. Double click the zip file to begin extraction of eclipse.

    C1.12

    Figure C1.13 Eclipse downloaded installer

    6. Click the Extract To commence.

    C1.13

    Figure C1.14 WinRAR extraction of eclipse

    7. Select (C:) Local Disk as the destination of our extraction. Click OK.

    C1.14

    Figure C1.15 Folder location on where to install eclipse

    8. After completing the extraction of the file, close the Winzip program.

    9. Click. Start | My Computer

    10. Double click (C:) Local Disk.

    11. Double Click the Eclipse folder.

    12. Right-click the Eclipse icon and Send To | Desktop to create a shortcut.

    C1.15

    Figure C1.16 Shortcut icon for eclipse

    Video presentation: Install Eclipse IDE

    Chapter 2

    Java First Programs

    At the end of this chapter, you will be able to:

    Write your first sets of java programs;

    Familiarize with the terminator symbol semicolon;

    Use comments, new line and tab characters;

    Hello, world!

    Enjoying the preview?
    Page 1 of 1