0% found this document useful (0 votes)
14 views9 pages

Chapter 1 Java

The document provides an introduction to Java, detailing its origins, features, and basic concepts. It explains the development of Java from the Green Project to its official announcement in 1995, highlighting its object-oriented nature and key features like portability and security. Additionally, it covers Java's environment setup, basic syntax, data types, and variable types.

Uploaded by

mansamusa1670
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)
14 views9 pages

Chapter 1 Java

The document provides an introduction to Java, detailing its origins, features, and basic concepts. It explains the development of Java from the Green Project to its official announcement in 1995, highlighting its object-oriented nature and key features like portability and security. Additionally, it covers Java's environment setup, basic syntax, data types, and variable types.

Uploaded by

mansamusa1670
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

1.

Introduction to JAVA

 In 1990, Sun Micro Systems Inc. (US) was conceived a project to develop software
for consumer electronic devices that could be controlled by a remote.
 This project was called Stealth Project but later its name was changed to Green Project.
 In January 1991, Project Manager James Gosling and his team members Patrick
Naughton, Mike Sheridan, Chris Wrath, and Ed Frank met to discuss about this project.
 Gosling thought C and C++ would be used to develop the project. But the
problem he faced with them is that they were system dependent languages.
 The trouble with C and C++ (and most other languages) is that they are designed
to be compiled for a specific target and could not be used on various processors, which
the electronic devices might use.
 James Gosling with his team started developing a new language, which was
completely system independent.
 This language was initially called OAK. Since this name was registered by some other
company, later it was changed to Java.
 James Gosling and his team members were consuming a lot of coffee while
developing this language. Good quality of coffee was supplied from a place
called “Java Island‟. Hence they fixed the name of the language as Java.
 The symbol for Java language is cup and saucer.
 Sun formally announced Java at Sun World conference in 1995.
 On January 23rd 1996, JDK1.0 version was released

1.2 Features of JAVA


 Simple: Learning and practicing java is easy because of resemblance with c and C++.
 Object Oriented Programming Language: Unlike C++, Java is purely OOP.
 Distributed: Java is designed for use on network; it has an extensive library
which works in agreement with TCP/IP.
 Secure: Java is designed for use on Internet. Java enables the construction of virus-free,
tamper free systems.

1
 Robust (Strong/ Powerful): Java programs will not crash because of its exception
handling and its memory management features.
 Interpreted: Java programs are compiled to generate the byte code. This byte code can
be downloaded and interpreted by the interpreter. “.class” file will have byte code
instructions and JVM which contains an interpreter will execute the byte code.
 Portable: Java does not have implementation dependent aspects and it yields or gives
same result on any machine.
 Architectural Neutral Language: Java byte code is not machine dependent, it can run
on any machine with any processor and with any OS.
 High Performance: Along with interpreter there will be JIT (Just In Time)
compiler which enhances the speed of execution.
 Multithreaded: Executing different parts of program simultaneously is called
Multithreading. This is an essential feature to design server side programs.
 Dynamic: We can develop programs in Java which dynamically change on
Internet (e.g.: Applets).

1.3 Basic concepts of JAVA

When we consider a Java program, it can be defined as a collection of objects that


communicate via invoking each other's methods. Let us now briefly look basic concepts of
java.
1. Object
An object is a real world entity which may represent place, person, and data item related to
program.
An object is a variable/instance of class.
An object is a run-time entity.
An object has state, behavior and identity.
E.g. A „Mouse‟ object has,
State: moving or working
Behavior: picking or pointing an object on the screen
Identity: color, company, Identification No. etc.

2
2. Class
It is the template or blueprint that defines the states and the behaviors common to all objects of a
certain kind. It is a collection of objects of similar type.
Classes are user-defined data types & behave like the built- in types of programming language.
3. Data Abstraction
Abstraction means representing essential features without including the background details or
explanations. A Class can use the concept of Abstraction and are defined as list of abstract data
and functions to operate on these data. Since the classes use the concept of Data Abstraction,
they are known as Abstract Data Type (ADT).
4. Data Encapsulation
The wrapping up of data and methods into a single unit (called class) is known as encapsulation.
This insulation of the data from direct access by the program is called data hiding.
5. Inheritance
It is the process by which objects of one class acquire the properties of objects of another class. It
provides the idea of reusability (reusing the code)
6. Polymorphism
In polymorphism, „Poly‟ means many and „morph‟ means forms, i.e. many forms.
Is the ability to take more than one form. It allows a function responding in different ways.
7. Dynamic Binding
Dynamic binding means that the code associated with a given procedure call is not known until
the time of the call at runtime. Memory is allocated at runtime not at compile time.
8. Message Passing
The process of invoking an operation of an object is called Massage Passing.
In response to the given massage, the respective method or operation is called also.
OOPs include objects which communicate by sending/ receiving information with each other.
Message Passing involves specifying the name of the object, the name of the function (message)
and the information to be sent.
Eg. [Link] (name);
A message for an object is a request for the execution of a procedure.

3
1.4 Java Environment Setup
Downloading JDK
We can download the JDK (Java Development Kit) including the compiler and runtime engine
from Sun at: [Link]
 Install JDK after downloading, by default JDK will be installed in
C:\Program Files (x86)\Java\jdk1.8.0 (Here jdk1.8.0 is JDK‟s version)
Setting up Java Environment:
After installing the JDK, we need to set at least one environment variable in order to able to
compile and run Java programs.
A PATH environment variable enables the operating system to find the JDK executable
when our working directory is not the JDK's binary directory.
Setting environment variables as system variables:
If we set the variables as system variables they will hold continuously.
1. Right-click on My Computer
2. Choose Properties
3. Select advances system setting
4. Select the Advanced tap
5. Click on Environment Variables button at the bottom
6. in system variables tab, click on new button
7. A window with variable name, write JAVA_HOME.
8. A window with variable value, add to that path at the end;
C:\Program Files (x86)\Java\jdk1.8.0 \bin;
9. Finally press OK button.

4
1.5 JAVA BASIC SYNTAX
I. First Java Program
// [Link] = comments about this class
public class myfirstprogram class header
{
// comments about the method
public static void main( String args[]) class body
{ Method header
Method body
[Link](“ Hello World! “);
}
Let us discuss the program line by line:
Class Declaration: the first line class myfirstprogram declares a class, which is an object
constructor. Class is keyword and declares a new class definition and myfirstprogram is a java
identifier that specifies the name of the class to be defined.

Braces : Every class definition in java begins with an opening brace “{“ and ends with a closing
brace “}”.

The main line: the third line public static void main(String args[]) defines a method named as
main, is the starting point for the interpreter to begin the execution of the program.

public: is an access specifier that declares the main method as “unprotected” and therefore
making it accessible to all other classes.

static: declares that this method as one that belongs to the entire class and not a part of any
objects of the class.

 Main must always be declared as static since the interpreter uses this method before any
objects are created.

void : states that the main method does not return any value (but prints some text to the screen.)

5
All parameters to a method are declared inside a pair of parenthesis. Here, String args[ ]
declares a parameter named args, which contains array of objects of the class type String.

The Output Line: The only executable statement in the program is [Link](“Hello
World!” );This is similar to cout<< constructor of C++.

The println method is a member of the out object, which is a static data member of System
class. It is like endln of C++.

II. Data types of Java


Variables are nothing but reserve memory locations to store values. This means
that when you create a variable you reserve some space in memory. Based
on the data type of a variable, because data types specify the size and type of
values that can be stored in the memory, the operating system allocates memory
and decides what can be stored in the reserved memory. Therefore, by
assigning different data types to variables, you can store integers, decimals, or
characters in these variables. There are two data types available in Java:
 Primitive Data Types (also called intrinsic or built-in data types)
 Non-Primitive data Types (also known as Derived or reference types)

6
There are eight built-in data types in Java:

 4 integer types (byte, short, int, long)


 2 floating point types (float, double)
 Boolean (boolean)
 Character (char)
 Integer Data Types: These data types store integer numbers

 Float Data Types: These data types handle floating point numbers

 Character Data Type: This data type represents a single character. char data type in java uses
two bytes of memory also called Unicode system. Unicode is a specification to include
alphabets of all international languages into the character set of java.

 Boolean Data Type: can handle truth values either true or false
e.g.:- boolean response = true;

7
III. Variable Types
A variable provides us with named storage that our programs can manipulate.
Each variable in Java has a specific type, which determines the size and layout
of the variable's memory; the range of values that can be stored within that
memory; and the set of operations that can be applied to the variable.
You must declare all variables before they can be used. The basic form of a
variable declaration is shown here:
data type variable [ = value][, variable [= value] ...] ;
Here data type is one of Java's data types and variable is the name of the
variable. To declare more than one variable of the specified type, you can use a
comma-separated list. Following are valid examples of variable declaration and
initialization in Java:
int a, b, c; // Declares three ints, a, b, and c.
int a = 10, b = 10; // Example of initialization
byte B = 22; // initializes a byte type variable B.
double pi = 3.14159; // declares and assigns a value of PI.
char a = 'a'; // the char variable a is initialized with value 'a'
There are three various kinds of variable types available in Java Language.
1. Instance Variables: are declared in a class, but outside a method, constructor
or any block.
 Are created when an object is created with the use of the key word 'new'
and destroyed when the object is destroyed.
 They take different values for each object

8
2. Class Variables: are also known as static variables, are declared with the static
keyword in a class, but outside a method, constructor or a block.
 Are global to a class and belong to the entire set of objects that class
creates.
 Only one memory location is created for each class variable.
3. Local Variables: are variables declared and used inside methods.
 Can also be declared inside program blocks that are define between
{ and }

You might also like