0% found this document useful (0 votes)
57 views12 pages

Chapter One: Structure Programming

This document provides an introduction to object-oriented programming and Java. It discusses the history of OOP and Java, the features of Java including being object-oriented, simple, secure, platform independent, robust, architecture-neutral, high-performance, distributed, multi-threaded, dynamic. It also covers downloading and installing the JDK, understanding the differences between the JDK, JRE, and JVM, and setting environment variables for the Java path and classpath.

Uploaded by

Zen Ye
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
57 views12 pages

Chapter One: Structure Programming

This document provides an introduction to object-oriented programming and Java. It discusses the history of OOP and Java, the features of Java including being object-oriented, simple, secure, platform independent, robust, architecture-neutral, high-performance, distributed, multi-threaded, dynamic. It also covers downloading and installing the JDK, understanding the differences between the JDK, JRE, and JVM, and setting environment variables for the Java path and classpath.

Uploaded by

Zen Ye
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

True Hope Core Java (J2SE)

Chapter One
Introduction to OOP and Java

1. Introduction to Programming
2. History of OO methodology
3. Object-Oriented Programming
4. The History of Java
5. Features of Java?
6. Install JDK
7. Understand JDK, JVM and JRE
8. Primitive data type
9. Rules in Java used
10. Create Java Program

1. Introduction to programming
Program is logical sequence of instructions or series of commands for the computer to
perform a specific task. Now programmers are using high level programming languages. In old
days, programmers used low level or machine language.
Low level or machine language
 Machine language (The hardware can be controlled using machine language)
01001011001010010010010010101
 Assembly language
MOV AX, BX
ADD R3, #32, R9
High level programming languages are:
 Pascal
Structure Programming
 C
 COBOL
 Foxpro Database Programming
 C++
 Java OOP Programming
 C#.NET etc.,
To develop a program
Step One: Problem definition
Define the problem in terms of:
- Input data
- Calculate data
- Oupt data
Sept Two: Algorithm
Define the step by step solving of the problem. Algorithms are specified in
flowchart or pseudo.
Step Three: Coding
Writing program codes in text editor using selected programming language.
Step Four: Testing

Page 1
True Hope Core Java (J2SE)

2. History of OO methodology
Programming
 1967s Simula 67 developed by Ole-Johan Dahl and Kristen Nygaard, Norway.
 1970s Smalltalk developed by Alan Kay's group, inspired from Simula.
 1980s C++ by Bjarne Strustrup
Simula 67 introduced most of the key concepts of object-oriented programming: both classes and
subclasses (usually referred to as inheritance), objects.
3. Object-Oriented Programming
Object-oriented programming (OOP) is a programming paradigm based upon objects (having both
data and methods) that aims to incorporate the advantages of modularity and reusability. Objects,
which are usually instances of classes, are used to interact with one another to design applications
and computer programs.
Advantages of OOP
 Reusability
 Easy to maintain
 Reliability
4. The History of Java
1991, Sun was investigating consumer electronic products. James Gosling, the father of Java, was
intent on building a low-cost, hardware-independent software platform using C++. For a number of
technical reasons, C++ was dropped, and a new language, called Oak, was developed, based on
C++, but eliminating its shortcomings. This shortcoming includes problems associated with
multiple inheritances, automatic type conversion, the use of pointers, and memory
management.
Oak was used to develop a small electronics device called *7. This project resulted in the precursors
of many of the components of Java: the development environment, runtime system, and API.
By 1994 the Web emerged, Oak was renamed Java.In 1995, Java was ported to Windows 95 and
Linux.
On January 23, 1996, Java 1.0 was officially released and made available for download over the
Internet.
What is Java?
• Java was developed in early 1991 by Sun Microsystems
• Java is a high level language
• Java programs are portable across platflorm
• Object-oriented programming language
Java Programming Step

Page 2
True Hope Core Java (J2SE)

Host platform
The developer writes programs in the Java language. The developer compiles his or her programs
using the Java compiler. This results in what is known as complied bytecode. Bytecode is in a form
that can be executed on the Java virtual machine, the core of the Java runtime system.
5. Features of Java?
Object Oriented
Distributed Simple

Secured
Multithreaded

High Java Platform independent


Performance

Interpreted
Robust

Dynamic Architecture
neutral Portable
 Object-oriented
Object-oriented means we organize our software as a combination of different types of objects that
incorporates both data and behaviour.
Basic concepts of OOPs are:
1. Object
2. Class
3. Inheritance
4. Polymorphism

 Simple
According to Sun, Java language is simple because:
syntax is based on C++ (so easier for programmers to learn it after C++).
removed many confusing and/or rarely-used features e.g., explicit pointers, operator overloading etc.
No need to remove unreferenced objects because there is Automatic Garbage Collection in java.

 Secured
Java is secured because:
Java compiler generates the bytecode from .java file.The bytecode is not the machine code. And it is
this bytecode which travel form one computer to another computer not the machine code. JVM, java
virtual machine creates the machine code from this bytecode .So the machine code of java program
never save on any operating system, program carry the bytecode.
Java is secure because of this bytecode.

Page 3
True Hope Core Java (J2SE)

 Platform Independent

A platform is the hardware or software environment in which a program runs.


There are two types of platforms software-based and hardware-based. Java provides software-based
platform.

 Robust
Java is robust as it is capable of handling run-time errors, supports automatic garbage collection and
exception handling, and avoids explicit pointer concept. Java has a strong memory management
system. It helps in eliminating errors as it checks the code during both compile and runtime.
Java is garbage-collected language – JVM automatically deallocates the memory blocks and
programmers do not have to worry about deleting the memory manually as in case of C/C++.

 Architecture-neutral
It means that the program written on one platform or OS is independent of other platforms or
environments and can run on any other Operating System without recompiling them.
In other words, it is based on the ‘Write-once-run-anywhere’ (WORA) or ‘Write-once-run-
everywhere’ (WORE) approach.

 High-performance
Java is faster than traditional interpretation since byte code is "close" to native code still somewhat
slower than a compiled language (e.g., C++)

 Distributed
A distributed application is software that is executed or run on multiple computers within a
network. We can create distributed applications in java. RMI( Remote Method Invocation)

Page 4
True Hope Core Java (J2SE)

and EJB are used for creating distributed applications. We may access files by calling the methods
from any machine on the internet.
 Multi-threaded
A thread is an independent path of execution within a program, executing concurrently.
Multithreaded means handling multiple tasks simultaneously or executing multiple portions
(functions) of the same program in parallel. It shares a common memory area. Threads are important
for multi-media, Web applications etc.

 Dynamic
Java is dynamic and extensible means with the help of OOPs, we can add classes and add new
methods to classes, creating new classes through subclasses. This makes it easier for us
to expand our own classes and even modify them.

6. Download and Install JDK (Java Installation)


Step 1) Click on Download JDK. For java latest version.

Step 2) Next,
 Accept License Agreement
 Download latest Java JDK for your version (32 or 64 bit) of java for Windows.
Step 3) Once the download is complete, run the exe for install JDK. Click Next

Step 4) Once installation is complete click Close

How to set Environment Variables in Java: Path and Classpath


The PATH variable gives the location of executables like javac, java etc. It is possible to run a
program without specifying the PATH but you will need to give full path of executable
like C:\Program Files\Java\jdk1.8.0_131\bin\javac .
The CLASSPATH variable gives location of the Library Files.

Page 5
True Hope Core Java (J2SE)

Let's look into the steps to set the PATH and CLASSPATH
Step 1) Right Click on the My Computer and Select the properties
Step 2) Click on advanced system settings
Step 3) Click on Environment Variables
Step 4) Click on Edit Button of User variables
Step 5) Click New Button
Step 7) Paste Path of bin folder in Variable value and click on OK Button.
Step 8) click on OK Button.

7. Understanding JDK, JRE, and JVM


We must understand the differences between JDK, JRE, and JVM before learning to Java.
 JVM
JVM (Java Virtual Machine) is an abstract machine. It is called a virtual machine because it doesn't
physically exist. It is a specification that provides a runtime environment in which Java bytecode
can be executed.
JVMs are available for many hardware and software platforms. JVM, JRE, and JDK are platform
dependent because the configuration of each OS is different from each other. However, Java is
platform independent.
 JRE
JRE is an acronym for Java Runtime Environment. The Java Runtime Environment is a set of
software tools which are used for developing Java applications. It physically exists. It contains a set
of libraries + other files that JVM uses at runtime.

 JDK
The Java Development Kit (JDK) is a software development environment which is used to develop
Java applications and applets. It physically exists. It contains JRE + development tools.
JDK is an implementation of any one of the below given Java Platforms released by Oracle
Corporation:
o Standard Edition Java Platform
o Enterprise Edition Java Platform
o Micro Edition Java Platform

Page 6
True Hope Core Java (J2SE)

8. Primitive Data type

Data Type Width Minimum Value Maximum Value


char 16 bit Unicode
byte 8 bit integer -128 127
short 16 bit integer -32768 32767
int 32 bit integer -2147483648 2147483647
long 64 bit integer -9223372036854775808 9223372036854775807
float 32 bit floating point -1.4E-45F 3.4E38F
double 64 bit floating point - 4.9 E-324 1.8E308

9. Rules in Java used


Identifiers
 Begin with a letter, an underscore, and a currency sign (cannot start with a
number)
 After first character, identifiers can also include any letter or digit.
 Identifiers can be of any length.
 cannot use Java keyword
 case sensitive
Source file Declaration
 A source code file can have only public class.
 A file can have only one package statement, but multiple imports.
 The package statement must be the first line in source code.
 The import statements must come after package and before the class declaration.

10. Create Java Program


(a)Using Notepad++ IDE
Select : Notepad++ IDE
Click : File menu, New

Write a Java program to print text of "Hello World".


//To print the Hello World
//Date : 1/8
import java.io.*;
public class HelloApp {
public static void main(String args[]) {
System.out.print("Hello world");
}
}

Page 7
True Hope Core Java (J2SE)

Meaning for each statement


// - Comment or Remark
import java.io.* - Used input and output definition in the program
class HelloApp - The name of the class. This name is used by the Java
compiler as the name of the executable output class.
static void main - The single method in the HelloApp class is called main. The
main method is where execution begins when the class is
executed in the Java interpreter.
String args[] - args is an array of String objects that represents command-
line arguments passed to the class upon execution.
System.out.println( ) - prints the message " Hello World" to the standard out stream.
{} - Block defined

Run Java Program in Console Window

Type : cmd in Search box


Press : Enter key

Change require folder


If Java file save in D:\
Type : D:\
Type : javac HelloApp.java
Type : java HelloApp

b) Using Eclipse IDE


Download and Install Eclipse IDE
a) Download :Open browser
Type : Eclipse IDE for Java EE Developer

Page 8
True Hope Core Java (J2SE)

Select : Elipse IDE for Java EE Developers | Eclipse Packages

Select : Window 32 bit or Window 64 bit

Steps to Install Eclipse

- After finished download you will see eclipse zip file in download folder

- To install on windows, you need a tool that can extract the contents of a zip file.

- Using any one of these tools, extract the contents of the eclipse zip file to any folder of your choice.

Page 9
True Hope Core Java (J2SE)

Launching Eclipse

On the windows platform, if you extracted the contents of the zip file to c:\

- You can start eclipse by clicking c:\eclipse\eclipse.exe

- Select a folder for your workspace (for Java files are stored locally)

Select : Eclipse IDE


Click : File menu, New,Project, Java Project
The New Java Project Wizard has two pages.
Type : Project Name in Project Name box
Select : The Java Runtime Environment (JRE) or leave it at the default
Select : Create separate folders for sources and class files
The Project Layout which determines whether there would be a separate folder for the sources code
and class files. The recommended option is to Create separate folders for sources and class files.

Page 10
True Hope Core Java (J2SE)

Click : Finish button

Viewing the newly created project


The package explorer shows the newly created Java project. The icon that represents a Project is
decorated with a "J" to show that it is a Java Project. The folder icon is decorated to show that it is a
java source folder.

To create a Java class


Right Click : src Folder
Select : New, Class
Type : Class name in Name box
Click : Finish button

Write a Java program to print text of "Hello World".


// To print the Hello World
import java.io.*;
public class HelloApp {
public static void main(String args[]) {
System.out.print("Hello world");
}
}

Page 11
True Hope Core Java (J2SE)

Run Program
Select : Run button in tools bar
You will see output in console window

Example 2: Write a Java program to assign values and print the variables.
// Assign the values to variables and to print the variables
import java.io.*;
public class VariablesApp {
public static void main(String args[]) {
boolean flag = true;
char ch = 'B';
int n = 20;
float x=3.14159f;
String str=null;
String country =” United States”;
System.out.println("flag = " + flag);
System.out.println("ch = " + ch);
System.out.println("n = " + n);
System.out.println("x = " + x);
System.out.println("str = " + str);
System.out.println("Country = " + country);
}

}
---------------------------------------------------------------------------------------------------------------------
Exercises for chapter one
1. Write a Java program to print the result of c.
float a = 1.5f;
int b = 20;
float c = a*b;
System.out.println(“C = " + c);
2. Write a Java program to print the following text on screen
Hello
My name is Java.
Easy to understand.
3. Define JRE i.e. Java Runtime Environment?
Java Runtime Environment is an implementation of the Java Virtual Machine which executes Java
programs. It provides the minimum requirements for executing a Java application;

Page 12

You might also like