Std 12 computer chapter 6 object oriented concepts (part 1) by Nuzhat Memon
Introduction to class and object
Procedural (Structural) programming language
Object Oriented programming language
Two ways of programming language (POP and OOP)
four specific object properties
4 pillars of OOPs
Encapsulation in Java
Abstraction in Java
Messaging in Java
Polymorphism in Java
The course aims to provide you with an understanding of the fundamental concepts involved in object-oriented programming (object, class, protocol, hierarchy, inheritance, encapsulation, polymorphism and collaboration).
The programming language you will use is Java. However, the purpose of the course is not to teach you the minutiae of the Java language, but rather to teach you fundamental object-oriented programming concepts and skills that will be transferable to any object¬ oriented language
Std 12 computer chapter 6 object oriented concepts (part 1) by Nuzhat Memon
Introduction to class and object
Procedural (Structural) programming language
Object Oriented programming language
Two ways of programming language (POP and OOP)
four specific object properties
4 pillars of OOPs
Encapsulation in Java
Abstraction in Java
Messaging in Java
Polymorphism in Java
The course aims to provide you with an understanding of the fundamental concepts involved in object-oriented programming (object, class, protocol, hierarchy, inheritance, encapsulation, polymorphism and collaboration).
The programming language you will use is Java. However, the purpose of the course is not to teach you the minutiae of the Java language, but rather to teach you fundamental object-oriented programming concepts and skills that will be transferable to any object¬ oriented language
Brainsmartlabs is one of the excellent online tutorials for beginners which offers the best java and core java courses online. Enroll now to learn core java programming from scratch and become an expert.
An overview of object oriented programming including the differences between OOP and the traditional structural approach, definitions of class and objects, and an easy coding example in C++. This presentation includes visual aids to make the concepts easier to understand.
Object Oriented Programming in Java _lecture 1Mahmoud Alfarra
Introduction to OOP
Let’s start with the first set of concepts
What is Object-Oriented Programming ?
Procedural vs. Object-Oriented Programming
OO Programming Concepts
Brainsmartlabs is one of the excellent online tutorials for beginners which offers the best java and core java courses online. Enroll now to learn core java programming from scratch and become an expert.
An overview of object oriented programming including the differences between OOP and the traditional structural approach, definitions of class and objects, and an easy coding example in C++. This presentation includes visual aids to make the concepts easier to understand.
Object Oriented Programming in Java _lecture 1Mahmoud Alfarra
Introduction to OOP
Let’s start with the first set of concepts
What is Object-Oriented Programming ?
Procedural vs. Object-Oriented Programming
OO Programming Concepts
In this session you will learn:
1. Principles of Object-Oriented Programming
2. Writing your first Java Application
3. Elements of Java programming language
4. Built in Data Types
5. Conditional Statements
6. Loops
Object-Oriented Programming in Java
Java is a well-liked programming language that may be used to create a wide range of applications, from straightforward desktop programs to intricate web programs. It is an object-oriented programming language that enables programmers to create modular, reusable code, making it simple to maintain and update.
We shall look at the fundamentals of Java object-oriented programming in this tutorial. The fundamentals of object-oriented programming in Java, oops concepts such as classes and objects, inheritance, polymorphism, and encapsulation will all be covered. You will have a solid understanding of object-oriented programming in Java and how to use it to create robust and scalable programs at the end of this article.
Introduction to OOPs concept
Object-oriented programming in Java is a programming paradigm that revolves around objects. An object is a real-world entity that has a set of attributes and behaviors. In Java, even basic data types like integers and booleans are considered objects.
In OOPS, a program is designed by creating objects that interact with each other to perform tasks. Objects have attributes that define their properties and methods that define their behavior.
In Java, we create classes, which are templates that define the attributes and behaviors of objects. A class can be compared to an object creation blueprint. Once a class is defined, objects can be created based on that class.
Principles of Object-Oriented Programming
There are four main principles of object-oriented programming:
a. Abstraction
Abstraction is the process of hiding complex details and providing a simplified interface for the user. It helps developers to create simpler and more understandable models of a complex system, by just exposing only the required features and not the implementation part. In Java, abstraction can be achieved using interfaces and abstract classes.
b. Encapsulation
Encapsulation is the process of hiding the internal details of an object and providing a public interface for accessing and modifying the object. It helps in maintaining the integrity of the object and ensures that its internal state cannot be modified by external code. In Java, encapsulation can be achieved using access modifiers such as public, private, and protected.
Got confused between Abstraction and Encapsulation?
Abstraction is about simplifying the complexity of a system by focusing on its essential features, while encapsulation is about protecting the integrity of an object by hiding its internal details.
c. Inheritance
The process of creating a new class from an existing one is called Inheritance. The new class inherits the attributes and behaviors of the existing class and can add additional attributes and behaviors. This helps in reducing code duplication, promoting code reuse, and making the code more modular and maintainable. In Java, the extend keyword is useful for achieving inheritance.
d. Polymorphism
The ability of an
Hashing notes data structures (HASHING AND HASH FUNCTIONS)Kuntal Bhowmick
A Hash table is a data structure used for storing and retrieving data very quickly. Insertion of data in the hash table is based on the key value. Hence every entry in the hash table is associated with some key.
HASHING AND HASH FUNCTIONS, HASH TABLE REPRESENTATION, HASH FUNCTION, TYPES OF HASH FUNCTIONS, COLLISION, COLLISION RESOLUTION, CHAINING, OPEN ADDRESSING – LINEAR PROBING, QUADRATIC PROBING, DOUBLE HASHING
introduction to E-commerce, Electronic commerce, EDI, CS802E,
e-commerce ,edi ,electronic data interchange ,traditional commerce ,buyer and seller ,origin of e-commerce ,business process ,impact of e-commerce ,value chain analysis ,company value chain ,case studies on e-commerce ,advantages of e-commerce ,disadvantages of e-commerce
Vaccine management system project report documentation..pdfKamal Acharya
The Division of Vaccine and Immunization is facing increasing difficulty monitoring vaccines and other commodities distribution once they have been distributed from the national stores. With the introduction of new vaccines, more challenges have been anticipated with this additions posing serious threat to the already over strained vaccine supply chain system in Kenya.
About
Indigenized remote control interface card suitable for MAFI system CCR equipment. Compatible for IDM8000 CCR. Backplane mounted serial and TCP/Ethernet communication module for CCR remote access. IDM 8000 CCR remote control on serial and TCP protocol.
• Remote control: Parallel or serial interface.
• Compatible with MAFI CCR system.
• Compatible with IDM8000 CCR.
• Compatible with Backplane mount serial communication.
• Compatible with commercial and Defence aviation CCR system.
• Remote control system for accessing CCR and allied system over serial or TCP.
• Indigenized local Support/presence in India.
• Easy in configuration using DIP switches.
Technical Specifications
Indigenized remote control interface card suitable for MAFI system CCR equipment. Compatible for IDM8000 CCR. Backplane mounted serial and TCP/Ethernet communication module for CCR remote access. IDM 8000 CCR remote control on serial and TCP protocol.
Key Features
Indigenized remote control interface card suitable for MAFI system CCR equipment. Compatible for IDM8000 CCR. Backplane mounted serial and TCP/Ethernet communication module for CCR remote access. IDM 8000 CCR remote control on serial and TCP protocol.
• Remote control: Parallel or serial interface
• Compatible with MAFI CCR system
• Copatiable with IDM8000 CCR
• Compatible with Backplane mount serial communication.
• Compatible with commercial and Defence aviation CCR system.
• Remote control system for accessing CCR and allied system over serial or TCP.
• Indigenized local Support/presence in India.
Application
• Remote control: Parallel or serial interface.
• Compatible with MAFI CCR system.
• Compatible with IDM8000 CCR.
• Compatible with Backplane mount serial communication.
• Compatible with commercial and Defence aviation CCR system.
• Remote control system for accessing CCR and allied system over serial or TCP.
• Indigenized local Support/presence in India.
• Easy in configuration using DIP switches.
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...Dr.Costas Sachpazis
Terzaghi's soil bearing capacity theory, developed by Karl Terzaghi, is a fundamental principle in geotechnical engineering used to determine the bearing capacity of shallow foundations. This theory provides a method to calculate the ultimate bearing capacity of soil, which is the maximum load per unit area that the soil can support without undergoing shear failure. The Calculation HTML Code included.
Event Management System Vb Net Project Report.pdfKamal Acharya
In present era, the scopes of information technology growing with a very fast .We do not see any are untouched from this industry. The scope of information technology has become wider includes: Business and industry. Household Business, Communication, Education, Entertainment, Science, Medicine, Engineering, Distance Learning, Weather Forecasting. Carrier Searching and so on.
My project named “Event Management System” is software that store and maintained all events coordinated in college. It also helpful to print related reports. My project will help to record the events coordinated by faculties with their Name, Event subject, date & details in an efficient & effective ways.
In my system we have to make a system by which a user can record all events coordinated by a particular faculty. In our proposed system some more featured are added which differs it from the existing system such as security.
TECHNICAL TRAINING MANUAL GENERAL FAMILIARIZATION COURSEDuvanRamosGarzon1
AIRCRAFT GENERAL
The Single Aisle is the most advanced family aircraft in service today, with fly-by-wire flight controls.
The A318, A319, A320 and A321 are twin-engine subsonic medium range aircraft.
The family offers a choice of engines
Explore the innovative world of trenchless pipe repair with our comprehensive guide, "The Benefits and Techniques of Trenchless Pipe Repair." This document delves into the modern methods of repairing underground pipes without the need for extensive excavation, highlighting the numerous advantages and the latest techniques used in the industry.
Learn about the cost savings, reduced environmental impact, and minimal disruption associated with trenchless technology. Discover detailed explanations of popular techniques such as pipe bursting, cured-in-place pipe (CIPP) lining, and directional drilling. Understand how these methods can be applied to various types of infrastructure, from residential plumbing to large-scale municipal systems.
Ideal for homeowners, contractors, engineers, and anyone interested in modern plumbing solutions, this guide provides valuable insights into why trenchless pipe repair is becoming the preferred choice for pipe rehabilitation. Stay informed about the latest advancements and best practices in the field.
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdffxintegritypublishin
Advancements in technology unveil a myriad of electrical and electronic breakthroughs geared towards efficiently harnessing limited resources to meet human energy demands. The optimization of hybrid solar PV panels and pumped hydro energy supply systems plays a pivotal role in utilizing natural resources effectively. This initiative not only benefits humanity but also fosters environmental sustainability. The study investigated the design optimization of these hybrid systems, focusing on understanding solar radiation patterns, identifying geographical influences on solar radiation, formulating a mathematical model for system optimization, and determining the optimal configuration of PV panels and pumped hydro storage. Through a comparative analysis approach and eight weeks of data collection, the study addressed key research questions related to solar radiation patterns and optimal system design. The findings highlighted regions with heightened solar radiation levels, showcasing substantial potential for power generation and emphasizing the system's efficiency. Optimizing system design significantly boosted power generation, promoted renewable energy utilization, and enhanced energy storage capacity. The study underscored the benefits of optimizing hybrid solar PV panels and pumped hydro energy supply systems for sustainable energy usage. Optimizing the design of solar PV panels and pumped hydro energy supply systems as examined across diverse climatic conditions in a developing country, not only enhances power generation but also improves the integration of renewable energy sources and boosts energy storage capacities, particularly beneficial for less economically prosperous regions. Additionally, the study provides valuable insights for advancing energy research in economically viable areas. Recommendations included conducting site-specific assessments, utilizing advanced modeling tools, implementing regular maintenance protocols, and enhancing communication among system components.
Welcome to WIPAC Monthly the magazine brought to you by the LinkedIn Group Water Industry Process Automation & Control.
In this month's edition, along with this month's industry news to celebrate the 13 years since the group was created we have articles including
A case study of the used of Advanced Process Control at the Wastewater Treatment works at Lleida in Spain
A look back on an article on smart wastewater networks in order to see how the industry has measured up in the interim around the adoption of Digital Transformation in the Water Industry.
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Class notes(week 2) on basic concepts of oop-2
1. Page 1 of 11
Class Notes on Basic concepts of OOP (Part - 2)
Contents:-Class & Object Overview Basic concepts of Java programming-advantages of Java, byte-code & JVM,
data types, Basic idea of inheritance, encapsulation, polymorphism, How to compile and execute Java
Programs
Class
In object-oriented programming, a class is a construct that is used to create instances of itself – referred to as
class instances, class objects, instance objects or simply objects. A class defines constituent members which
enable its instances to have state and behavior. Data field members (member variables or instance variables)
enable a class instance to maintain state. Other kinds of members, especially methods, enable the behavior of
class instances. Classes define the type of their instances.
Objects
An object is a location in memory having a value and referenced by an identifier. An object can be a variable,
function, or data structure. With the introduction of object-oriented programming the same word, "object,"
refers to a particular instance of a class.
Basic concepts of Java Programming
Java platformoverview
Java technology is used to develop applications for a wide range of environments, from consumer devices to
heterogeneous enterprise systems.
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 object-oriented
programming (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.
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 bytecodes in .class files.
Bytecodes are standard 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.
2. Page 2 of 11
The JVM
At run time, 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 bytecodes 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 garbage collector
Rather than forcing you to keep up with memory allocation the Java platform provides memory management
out of the box. When your Java application creates an object instance at run time, the JVM automatically
allocates memory space for that object from the heap, which is a pool of memory set aside for your program
to use. The Java garbage collector runs in the background, keeping track of which objects the application no
longer needs and reclaiming memory from them. This approach to memory handling is called implicit memory
management because it doesn't require you to write any memory-handling code. Garbage collection is one of
the essential features of Java platform performance.
The Java Development Kit
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 just about any task common to application
development.
The Java Runtime Environment
The Java Runtime Environment (JRE; also known as the Java runtime) includes the JVM, code libraries, and
components that are necessary for running programs written in the Java language. It is available for multiple
platforms. You can freely redistribute the JRE with your applications, according to the terms of the JRE license,
to give the application's users a platform on which to run your software. The JRE is included in the JDK.
Object-oriented programming concepts
The Java language is object-oriented. If you haven't used an object-oriented language before, its concepts
might seem strange at first. This section is a short introduction to OOP language concepts, using structured
programming as a point of contrast.
What is an object?
Structured programming languages like C and COBOL follow a very different programming paradigm from
object-oriented ones. The structured-programming paradigm is highly data-oriented, which means that you
3. Page 3 of 11
have data structures on one hand, and then program instructions that act on that data. Object-oriented
languages like the Java language combine data and program instructions into objects.
An object is a self-contained entity that contains attributes and behavior, and nothing more. Rather than
having a data structure with fields (attributes) and passing that structure around to all of the program logic
that acts on it (behavior), in an object-oriented language, data and program logic are combined. This
combination can occur at vastly different levels of granularity, from fine-grained objects like a Number, to
coarse-grained objects such as a Funds Transfer service in a large banking application.
Parent and child objects
A parent object is one that serves as the structural basis for deriving more-complex child objects. A child object
looks like its parent but is more specialized. The object-oriented paradigm allows you to reuse the common
attributes and behavior of the parent object, adding to its child objects attributes and behavior that differ.
Object communicationand coordination
Objects talk to other objects by sending messages (method calls in the Java language). Furthermore, in an
object-oriented application, program code coordinates the activities among objects to perform tasks within
the context of the given application domain.
Object summary
A well-written object:
Has crisp boundaries
Does a finite set of activities
Knows only about its data and any other objects that it needs to accomplish its activities
In essence, an object is a discrete entity that has only the necessary dependencies on other objects to perform
its tasks. Now you'll see what an object looks like.
The Personobject
I'll start with an example that is based on a common application-development scenario: an individual being
represented by a Person object.
Going back to the definition of an object, you know that an object has two primary elements: attributes and
behavior. You'll see how these apply to the Person object.
Attributes
What attributes can a person have? Some common ones include:
Name
Age
Height
Weight
Eye color
Gender
4. Page 4 of 11
You can probably think of more (and you can always add more attributes later), but this list is a good start.
Behavior
An actual person can do all sorts of things, but object behaviors usually relate to some kind of application
context. In a business-application context, for instance, you might want to ask your Person object, "What is
your age?" In response, Person would tell you the value of its Age attribute.
More-complex logic could be hidden inside of the Person object, but for now suppose that Person has the
behavior of answering these questions:
What is your name?
What is your age?
What is your height?
What is your weight?
What is your eye color?
What is your gender?
State and string
State is an important concept in OOP. An object's state is represented at any moment in time by the value of
its attributes.
In the case of Person, its state is defined by attributes such as name, age, height, and weight. If you wanted to
present a list of several of those attributes, you might do sousing a String class, which I'll talk more about later
in the class.
Together, the concepts of state and string allow you to say to Person: tell me who you are by giving me a
listing (or String) of your attributes.
Principles ofOOP using JAVA
If you come from a structured-programming background, the OOP value proposition might not be clear yet.
After all, the attributes of a person and any logic to retrieve (and convert) their values could be written in C.
This section clarifies the benefits of the OOP paradigm by explaining its defining principles: encapsulation,
inheritance, and polymorphism.
Encapsulation
Recall that an object is above all discrete, or self-contained. This is the principle of encapsulation at work.
Hiding is another term that is sometimes used to express the self-contained, protected nature of objects.
Regardless of terminology, what's important is that the object maintains a boundary between its state and
behavior, and the outside world. Like objects in the real world, objects used in computer programming have
various types of relationships with different categories of objects in the applications that use them.
On the Java platform, you can use access specifiers (which I'll introduce later in the class) to vary the nature of
object relationships from public to private. Public access is wide open, whereas private access means the
object's attributes are accessible only within the object itself.
The public/private boundary enforces the object-oriented principle of encapsulation. On the Java platform,
you can vary the strength of that boundary on an object-by-object basis, depending on a system of trust.
Encapsulation is a powerful feature of the Java language.
Inheritance
5. Page 5 of 11
In structured programming, it is common to copy a structure, give it a new name, and add or modify the attributes
that make the new entity (such as an Account record) different from its original source. Over time, this approach
generates a great deal of duplicated code, which can create maintenance issues.
OOP introduces the concept of inheritance, whereby specialized objects — without additional code — can "copy"
the attributes and behavior of the source objects they specialize. If some of those attributes or behaviors need to
change, then you simply override them. You only change what you need to change in order to create specialized
objects. As you know from the Object-oriented programming concepts section, the source object is called the
parent, and the new specialization is called the child.
Inheritance at work
Suppose you are writing a human-resources application and want to use the Person object as the basis for a
new object called Employee. Being the child of Person, Employee would have all of the attributes of a Person
object, along with additional ones, such as:
Taxpayer identification number
Hire date
Salary
Inheritance makes it easy to create the new Employee class of the object without needing to copy all of the
Person code manually or maintain it.
You'll see plenty of examples of inheritance in Java programming later in the class and in my class notes.
Polymorphism
Polymorphism is a harder concept to grasp than encapsulation and inheritance. In essence, it means that
objects that belong to the same branch of a hierarchy, when sent the same message (that is, when told to do
the same thing), can manifest that behavior differently.
To understand how polymorphism applies to a business-application context, return to the Person example.
Remember telling Person to format its attributes into a String? Polymorphism makes it possible for Person to
represent its attributes in a variety of ways depending on the type of Person it is.
Polymorphism is one of the more complex concepts you'll encounter in OOP on the Java platform and not
within the scope of an introductory tutorial.
Advantages ofJAVA
JAVA offers a number of advantages to developers.
Java is simple: Java was designed to be easy to use and is therefore easy to write, compile, debug, and learn
than other programming languages. The reason that why Java is much simpler than C++ is because Java uses
automatic memory allocation and garbage collection where else C++ requires the programmer to allocate
memory and to collect garbage.
Java is object-oriented: Java is object-oriented because programming in Java is centered on creating objects,
manipulating objects, and making objects work together. This allows you to create modular programs and
reusable code.
6. Page 6 of 11
Java is platform-independent: One of the most significant advantages of Java is its ability to move easily from
one computer systemto another.
The ability to run the same program on many different systems is crucial to World Wide Web software, and
Java succeeds at this by being platform-independent at both the source and binary levels.
Java is distributed: Distributed computing involves several computers on a network working together. Java is
designed to make distributed computing easy with the networking capability that is inherently integrated into
it.
Writing network programs in Java is like sending and receiving data to and from a file. For example, the
diagram below shows three programs running on three different systems, communicating with each other to
perform a joint task.
Java is interpreted: An interpreter is needed in order to run Java programs. The programs are compiled into
Java Virtual Machine code called bytecode.
The bytecode is machine independent and is able to run on any machine that has a Java interpreter. With
Java, the program need only be compiled once, and the bytecode generated by the Java compiler can run on
any platform.
Java is secure: Java is one of the first programming languages to consider security as part of its design. The
Java language, compiler, interpreter, and runtime environment were each developed with security in mind.
Java is robust: Robust means reliable and no programming language can really assure reliability. Java puts a
lot of emphasis on early checking for possible errors, as Java compilers are able to detect many problems that
would first show up during execution time in other languages.
Java is multithreaded: Multithreaded is the capability for a program to perform several tasks simultaneously
within a program. In Java, multithreaded programming has been smoothly integrated into it, while in other
languages, operating system-specific procedures have to be called in order to enable multithreading.
Multithreading is a necessity in visual and network programming.
Disadvantages of JAVA
Performance: Java can be perceived as significantly slower and more memory-consuming than natively
compiled languages such as C or C++.
Look and feel: The default look and feel of GUI applications written in Java using the Swing toolk it is very
different from native applications. It is possible to specify a different look and feel through the pluggable look
and feel system of Swing.
Java bytecode
Java bytecode is the form of instructions that the Java virtual machine executes. Each bytecode opcode is one
byte in length, although some require parameters, resulting in some multi-byte instructions. A Java
programmer does not need to be aware of or understand Java bytecode at all.
7. Page 7 of 11
Java virtual machine
A Java virtual machine (JVM) is a virtual machine that can execute Java bytecode. It is the code execution
component of the Java platform. Sun Microsystems has stated that there are over 5.5 billion JVM-enabled
devices.
A Java virtual machine is a program which executes certain other programs, namely those containing Java
bytecode instructions. JVMs are most often implemented to run on an existing operating system, but can also
be implemented to run directly on hardware. A JVM provides a run-time environment in which Java bytecode
can be executed, enabling features such as automated exception handling, which provides root-cause
debugging information for every software error (exception). A JVM is distributed along with Java Class Library,
a set of standard class libraries (in Java bytecode) that implement the Java application programming interface
(API). These libraries, bundled together with the JVM, form the Java Runtime Environment (JRE).
JVMs are available for many hardware and software platforms. The use of the same bytecode for all JVMs on
all platforms allows Java to be described as a write once, run anywhere programming language, versus write
once, compile anywhere, which describes cross-platform compiled languages. Thus, the JVM is a crucial
component of the Java platform.
Java bytecode is an intermediate language which is typically compiled from Java, but it can also be compiled
from other programming languages. For example, Ada source code can be compiled to Java bytecode and
executed on a JVM.
Java Basic Data Types
Variables are nothing but reserved 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, 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
Reference/Object Data Types
Primitive Data Types
There are eight primitive data types supported by Java. Primitive data types are predefined by the language
and named by a key word. Let us now look into detail about the eight primitive data types.
byte:
Byte data type is a 8-bit signed two's complement integer.
Minimum value is -128 (-2^7)
Maximum value is 127 (inclusive)(2^7 -1)
Default value is 0
8. Page 8 of 11
Byte data type is used to save space in large arrays, mainly in place of integers, since a byte is four
times smaller than an int.
Example : byte a = 100 , byte b = -50
short:
Short data type is a 16-bit signed two's complement integer.
Minimum value is -32,768 (-2^15)
Maximum value is 32,767(inclusive) (2^15 -1)
Short data type can also be used to save memory as byte data type. A short is 2 times smaller than an
int
Default value is 0.
Example : short s= 10000 , short r = -20000
int:
Int data type is a 32-bit signed two's complement integer.
Minimum value is - 2,147,483,648.(-2^31)
Maximum value is 2,147,483,647(inclusive).(2^31 -1)
Int is generally used as the default data type for integral values unless there is a concern about
memory.
The default value is 0.
Example : int a = 100000, int b = -200000
long:
Long data type is a 64-bit signed two's complement integer.
Minimum value is -9,223,372,036,854,775,808.(-2^63)
Maximum value is 9,223,372,036,854,775,807 (inclusive). (2^63 -1)
This type is used when a wider range than int is needed.
Default value is 0L.
Example : int a = 100000L, int b = -200000L
float:
Float data type is a single-precision 32-bit IEEE 754 floating point.
Float is mainly used to save memory in large arrays of floating point numbers.
Default value is 0.0f.
Float data type is never used for precise values such as currency.
Example : float f1 = 234.5f
double:
double data type is a double-precision 64-bit IEEE 754 floating point.
This data type is generally used as the default data type for decimal values. generally the default
choice.
Double data type should never be used for precise values such as currency.
Default value is 0.0d.
9. Page 9 of 11
Example : double d1 = 123.4
boolean:
boolean data type represents one bit of information.
There are only two possible values : true and false.
This data type is used for simple flags that track true/false conditions.
Default value is false.
Example : boolean one = true
char:
char data type is a single 16-bit Unicode character.
Minimum value is 'u0000' (or 0).
Maximum value is 'uffff' (or 65,535 inclusive).
Char data type is used to store any character.
Example . char letterA ='A'
Reference Data Types:
Reference variables are created using defined constructors of the classes. They are used to access
objects. These variables are declared to be of a specific type that cannot be changed. For example,
Employee, Puppy etc.
Class objects, and various type of array variables come under reference data type.
Default value of any reference variable is null.
A reference variable can be used to refer to any object of the declared type or any compatible type.
Example : Animal animal = new Animal("giraffe");
Java Literals:
A literal is a source code representation of a fixed value. They are represented directly in the code without any
computation.
Literals can be assigned to any primitive type variable. For example:
byte a = 68;
char a = 'A'
byte, int, long, and short can be expressed in decimal(base 10),hexadecimal(base 16) or octal(base 8) number
systems as well.
Prefix 0 is used to indicates octal and prefix 0x indicates hexadecimal when using these number systems for
literals. For example:
int decimal = 100;
int octal = 0144;
int hexa = 0x64;
String literals in Java are specified like they are in most other languages by enclosing a sequence of characters
between a pair of double quotes. Examples of string literals are:
10. Page 10 of 11
"Hello World"
"twonlines"
""This is in quotes""
String and char types of literals can contain any Unicode characters. For example:
char a = 'u0001';
String a = "u0001";
Java language supports few special escape sequences for String and char literals as well. They are:
Notation Character represented
n Newline(0x0a)
r Carriage return(0x0d)
f Formfeed(0x0c)
b Backspace (0x08)
s Space (0x20)
t tab
" Double quote
' Single quote
backslash
ddd Octal character(ddd)
uxxxx Hexadecimal UNICODEcharacter(xxxx)
A Simple Java Program
Now that the basic object-oriented underpinning of Java has been discussed, let’s look at some actual Java
programs. Let’s start by compiling and running the short sample program shown here. As you will see, this
involves a little more work than you might imagine.
/*
This is a simple Java program.
Call this file "Example.java".
*/
class Example {
// Your program begins with a call to main().
public static void main(String args[]) {
System.out.println("This is a simple Java program.");
}
}
About the Program
For most computer languages, the name of the file that holds the source code to a program is arbitrary.
However, this is not the case with Java. The first thing that you must learn about Java is that the name you
give to a source file is very important. For this example, the name of the source file should be Example.java.
Let’s see why? In Java, a source file is officially called a compilation unit. It is a text file that contains one or
more class definitions. The Java compiler requires that a source file use the .java filename extension. Notice
that the file extension is four characters long. As you might guess, your operating system must be capable of
supporting long filenames. This means that DOS and Windows 3.1 are not capable of supporting Java.
However, Windows 95/98 and Windows NT/2000/XP work just fine. As you can see by looking at the program,
11. Page 11 of 11
the name of the class defined by the program is also Example. This is not a coincidence. In Java, all code must
reside inside a class. By convention, the name of that class should match the name of the file that holds the
program. You should also make sure that the capitalization of the filename matches the class name. The
reason for this is that Java is case-sensitive. At this point, the convention that filenames correspond to class
names may seem arbitrary. However, this convention makes it easier to maintain and organize your programs.
Compiling the Program
To compile the Example program, execute the compiler, javac, specifying the name of the source file on the
command line, as shown here:
C:>javac Example.java
The javac compiler creates a file called Example.class that contains the bytecode version of the program. As
discussed earlier, the Java bytecode is the intermediate representation of your program that contains
instructions the Java interpreter will execute. Thus, the output of javac is not code that can be directly
executed. To actually run the program, you must use the Java interpreter, called java. To do so, pass the class
name Example as a command-line argument, as shown here:
C:>java Example
When the program is run, the following output is displayed:
This is a simple Java program.
When Java source code is compiled, each individual class is put into its own output file named after the clas s
and using the .class extension. This is why it is a good idea to give your Java source files the same name as the
class they contain—the name of the source file will match the name of the .class file. When you execute the
Java interpreter as just shown, you are actually specifying the name of the class that you want the interpreter
to execute. It will automatically search for a file by that name that has the .class extension. If it finds the file, it
will execute the code contained in the specified class.