CMPE 012 - Computer Programming
CMPE 012 - Computer Programming
OF THE PHILLIPINES
Computer & Electronics Department
Institute of Technology
PUP Sta. Mesa
CMPE 012
Computer Programming
Website: [Link]
Email: inquire@[Link]
2|Page
The VMPGO
VISION
PUP: The National Polytechnic University
MISSION
Ensuring inclusive and equitable quality education and promoting lifelong
learning opportunities through a re-engineered polytechnic university by committing to:
• provide democratized access to educational opportunities for the holistic
development of individuals with global perspective.
• offer industry-oriented curricula that produce highly skilled professionals with
managerial and technical capabilities and a strong sense of public service for
nation-building.
• embed a culture of research and innovation.
• continuously develop faculty and employees with the highest level of
professionalism.
• engage public and private institutions and other stakeholders for the attainment
of social development goal.
• establish a strong presence and impact in the international academic
community.
PHILOSOPHY
As a state university, the Polytechnic University of the Philippines believes that:
• Education is an instrument for the development of the citizenry and for the
enhancement of nation-building; and,
• That meaningful growth and transformation of the country are best achieved in
an atmosphere of brotherhood, peace, freedom, justice and nationalist-
oriented education imbued with the spirit of humanist internationalism.
SHARED VALUES AND PRINCIPLES
1. Integrity and Accountability
2. Nationalism
3. Sense of Service
4. Passion for Learning and Innovation
5. Inclusivity
6. Respect for Human Rights and the Environment
7. Excellence
8. Democracy
3|Page
GOALS OF THE COLLEGE/CAMPUS
Provide quality education through instruction, advance research, and extension
services.
Produce technology graduates for industry leaders and job providers.
Develop practical-based learning facilities aligned with the emerging technology
needs.
Obtain National Certificate (NC) in their chosen field for further studies and other
professional certifications.
PROGRAM DESCRIPTION
The Diploma in Computer Engineering Technology (DCpET) program is a confluence
of theoretical and application - oriented courses delivered in traditional and digital
modalities. The program aims to develop proficient, creative, technologically adaptive,
service-oriented, resilient, ethical, national and globally competitive Computer
Engineering Technologists and Technicians with effective communication and
organizational skills through a strong understanding of the fundamental theories and
principles of mathematics, physical sciences, and computer engineering and
technology courses.
The program intends to meet the rising demand for competent and highly skilled
individuals and professionals with technical and managerial capabilities that will serve
as prime movers in the globalized construction industry and who will continuously
provide major contributions, studies, and developments in the field of computer
engineering technology.
COURSE DESCRIPTION
The students will be guided by general principles underlying the practice of object-
oriented programming. They will explore the steps and critical attributes involved in the
paradigm, examine the benefits of using it to develop applications, and compare it to
approaches used in previous programming courses. This course also introduces the
student to the use of JAVA programming in building application align on the design, code
and test pattern in building software application using Object Oriented Programming
approach.
4|Page
INSTITUTIONAL LEARNING OUTCOMES (ILOS)
1. Creative and Critical Thinking. Graduates use their imaginative as well as a rational
thinking ability to life situations in order push boundaries, realize possibilities, and deepen
their interdisciplinary and general understanding of the world.
2. Effective Communication. Graduates are proficient in the four macro skills in
communication (reading, writing, listening, and speaking) and are able to use these
skills in solving problems. Making decisions, and articulating thoughts when engaging
with people in various circumstances.
3. Strong Service Orientation. Graduates exemplify the potentialities of an efficient,
well-rounded and responsible professional deeply committed to service excellence.
4. Community Engagement. Graduates take an active role in the promotion and
fulfillment of various advocacies (educational, social and environmental) for the
advancement of community welfare.
5. Adeptness in the Responsible Use of Technology. Graduates demonstrate
optimized use of digital learning abilities, including technical and numerical skills.
6. Passion to Lifelong Learning. Graduates are enabled to perform and function in the
society by taking responsibility in their quest to know more about the world through
lifelong learning.
7. High Level of Leadership and Organizational Skills. Graduates are developed to
become the best professionals in their respective disciplines by manifesting the
appropriate skills and leaderships qualities.
8. Sense of Personal and Professional Ethics. Graduates show desirable attitudes and
behavior either in their personal and professional circumstances.
9. Sense of National and Global Responsiveness. Graduates’ deep sense of national
compliments the need to live in a global village where one’s culture and other people
culture are respected.
Preliminaries 1
The VMPGO 1
MISSION 2
PHILOSOPY 2
SHARED VALUES AND PRINCIPLES 3
GOAL OF THE COLLEGES / CAMPUS 3
PROGRAM DESCRIPTION 4
COURSE DESCRIPTION 4
INSTITUTIONAL LEARNING OUTCOME (ILO’s) 5
PROGRAM LEARNING OUTCOME (PLO’s) 5
COURSE LEARNING OUTCOME (CLO’s) 7
Chapter 1
Learning Outcomes:
✓ Understand the basic term in programming and programming languages and each type
of programming used.
✓ Understand the concept of computer algorithm and some logic formulation
✓ Explain the use and term of programming in design using flowchart
✓ Develop a system flowchart in different scenarios
Course Materials:
What is compiler?
A compiler is a program that converts a high-level language (such as C, C++, or Java) to a low-
level language (object program or machine program).The compiler also detects numerous
problems that occur during the compilation of a program. Various phases are used by the compiler
to transform high-level language to low-level language. A character stream entered by the
customer is compiled through several stages before providing the destination language.
The compiler's job is to translate a program written in one language into another without altering
its meaning. A program written in the HLL programming language is divided into two sections
when it is implemented. The source code is compiled and converted into object code in the first
component (low-level language).The second component uses the assembler to translate the
object program into the target code.
Algorithms are like menus or instruction materials because they provide a structured set
of steps to achieve a specific goal.
• Just as a menu outlines the available dishes and their ingredients, an algorithm
outlines the specific steps required to solve a problem or achieve a desired
outcome. Both menus and algorithms offer a clear and organized approach to
guiding individuals towards their objectives.
• Similarly, instruction materials, such as manuals or tutorials, provide step-by-step
instructions to accomplish a task. Algorithms serve a similar purpose in the realm
of computer science, providing detailed instructions for computers to follow.
Example:
Create an algorithm the user requires to input Two numbers, num1 and num2. And display
the results using sum. Output: The sum of num1 and num2.
Steps:
1. Initialize a variable sum to 0. This variable will store the final result.
2. Add num1 to sum. This updates the sum variable to include the value of num1.
3. Add num2 to sum. This further updates the sum variable to include the value of
num2.
4. Return sum. The final value of sum represents the sum of num1 and num2.
Example:
If num1 is 5 and num2 is 3:
1. sum is initialized to 0.
2. sum becomes 5 (0 + 5).
3. sum becomes 8 (5 + 3).
4. The function returns 8 as the sum of 5 and 3.
What is flowchart?
Flowcharts are written with program flow from top to bottom of a page. Each command is placed
in an appropriate-shaped box, and arrows are utilized to control program progress. Flowcharts
frequently employ the following shapes:
Display Results of
Sum = n1 + n2 ;
Sum
Chapter 2
INTRODUCTION TO JAVA
STOP
Learning Outcomes:
After successful completion of this lesson, you should be able to:
● Learn what is Java programming languages
● Discover the features of Java
● Identify how to install java
● Modify the use of JDK, JRE and JVM
● Code the first java program
Course Materials:
What is JAVA?
Java is a programming language and a platform. Java is a high level, robust, object-
oriented and secure programming language.
Java is a general-purpose, class-based, object-oriented programming language designed
for having lesser implementation dependencies. It is a computing platform for application
development. Java is fast, secure and reliable therefore it is widely used for developing Java
applications in laptops, data centers, game consoles, scientific supercomputers, cell phones, etc.
Earlier Java was only used to design and program small computing devices, but it was
later adopted as one of the platform-independent programming languages, and now according to
Sun, 3 billion devices run Java.
Java is one of the most important programming languages in today's IT industries.
Features of JAVA
● Object-Oriented - Java supports the features of object-oriented programming. Its object
model is simple and easy to expand.
● Platform independent - C and C++ are platform dependency languages hence the
application programs written in one Operating system cannot run in any other Operating
system, but in platform independence language like Java application programs written
in one Operating system can able to run on any Operating system.
● Simple - Java has included many features of C / C ++, which makes it easy to
understand.
● Secure - Java provides a wide range of protection from viruses and malicious
programs. It ensures that there will be no damage and no security will be broken.
● Portable - Java provides us with the concept of portability. Running the same program
with Java on different platforms is possible.
● Robust - During the development of the program, it helps us to find possible mistakes
as soon as possible.
● Multi-threaded - The multithreading programming feature in Java allows you to write a
program that performs several different tasks simultaneously.
● Distributed - Java is designed for distributed Internet environments as it manages
the TCP/IP protocol
Java Virtual Machine (JVM) is a engine that provides runtime environment to drive the
Java Code or applications. It converts Java bytecode into machines language. JVM is a part of
Java Run Environment (JRE). In other programming languages, the compiler produces machine
code for a particular system. However, Java compiler produces code for a Virtual Machine known
as Java Virtual Machine.
Here is how JVM works
First, Java code is compiled into bytecode. This bytecode gets interpreted on different
machines
Between host system and Java source, Bytecode is an intermediary language.
JVM in Java is responsible for allocating memory space.
JVM Architecture
1) ClassLoader
The class loader is a subsystem used for loading class files. It performs three major
functions viz. Loading, Linking, and Initialization.
2) Method Area
JVM Method Area stores class structures like metadata, the constant runtime pool, and
the code for methods.
3) Heap
In order to write and execute a software program, you need the following
1) Editor – To type your program into, a notepad could be used for this
2) Compiler – To convert your high language program into native machine code
3) Linker – To combine different program files reference in your main program together.
4) Loader – To load the files from your secondary storage device like Hard Disk, Flash
Drive, CD into RAM for execution. The loading is automatically done when you execute your code.
5) Execution – Actual execution of the code which is handled by your OS & processor.
JDK is an acronym for Java Development Kit. 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
The JDK contains a private Java Virtual Machine (JVM) and a few other resources such as an
interpreter/loader (java), a compiler (javac), an archiver (jar), a documentation generator (Javadoc), etc. to
complete the development of a Java Application.
Step 2 :
Step 4) Select the PATH for Java installation and click next.
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\jdk-13.0.1\bin\javac [Link] instead of simple javac [Link]
The CLASSPATH variable gives location of the Library Files.
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 4) Click
on new Button
of User
Step 7) Paste Path of bin folder in Variable value and click on OK Button.
Assessment 1
True or false
______ 1. JRE is an acronym for Java Runtime Environment
______ 2. The PATH variable gives the location of executables like javac
ENUMERATION. :
A : JVM ARCHITECTURE
Unit II.
Overview:
Variables are the nouns of a programming language: they are the entities (values,
data) that act or are acted upon. A variable declaration always contains two components:
the type of the variable and its name. Also, the location of the variable declaration, that
is, where the declaration appears in relation to other code elements, determines the
scope of the variable. All variables in the Java language must have a data type. A
variable's data type determines the values that the variable can have and the operations
that can be performed on it.
Learning Outcomes:
Course Materials:
Variable in Java is a data container that stores the data values during Java program
execution. Every variable is assigned data type which designates the type and quantity of value
it can hold. Variable is a memory location name of the data. The Java variables have mainly three
types : Local, Instance and Static.
In order to use a variable in a program you to need to perform 2 steps
1. Variable Declaration
2. Variable Initialization
Examples of other Valid Declarations are
int a,b,c;
float pi;
double d;
char a;
pi =3.14f;
do =20.22d;
a=’v’;
int a=2,b=4,c=6;
float pi=3.14f;
double do=20.22d;
char a=’v’;
Types of variables
In Java, there are three types of variables:
▪ Local Variables - local Variables are a variable that are declared inside the body of a
method.
▪ Instance Variables - Instance variables are defined without the STATIC keyword .They
are defined Outside a method declaration. They are Object specific and are known as
instance variables.
▪ Static Variables - Static variables are initialized only once, at the start of the program
execution. These variables should be initialized first, before the initialization of any
instance variables.
▪ Every variable in Java has a data type which tells the compiler what type of
variable it as and what type of data it is going to store.
▪ Data type specifies the size and type of values.
▪ Information is stored in computer memory with different data types.
▪ Whenever a variable is declared, it becomes necessary to define a data type that
what will be the type of data that variable can hold.
Example :
Program Output :
In this lesson, we will learn how to write the simple program of java. We can write a simple hello
java program easily after installing the JDK.
To create a simple java program, you need to create a class that contains the main
method. Let's understand the requirement first.
Type the following java code in your text editor ( notepad , sublime, notepad ++ )
Assessment 2
PART 1 : Multiple Choice – Select the best answer from list of choices
[Link] type should you use to represent the average grade for a course?
A. int
B. double
C. boolean
D. String
[Link] type should you use to represent the number of people in a household?
A. int
B. double
C. boolean
D. String
[Link] type should you use to hold the first name of a person?
A. int
B. double
C. boolean
D. String
[Link] type should you use to record if it is raining or not?
A. int
B. double
C. boolean
D. String
[Link] type should you use to represent the amount of money you have?
A. int
B. double
C. boolean
D. String
Unit III.
JAVA Operators
Overview:
Java operators are symbols that are used to perform mathematical or logical
manipulations. Java is rich with built-in operators. On this module we will elaborate each
types and transfer in to series of java code to let you understand each use.
Learning Outcomes:
Course Materials:
Arithmetic Operator
Example of Arithmetic operations in java. Type this code in your text editor then save as
[Link] then compile and run.
//Addition Operation
int sum = number1 + number2;
[Link]("Sum is: " + sum);
//Subtraction Operation
int dif = number1 - number2;
[Link]("Difference is : " + dif);
//Multiplication Operation
int mul = number1 * number2;
[Link]("Multiplied value is : " + mul);
//Division Operation
int div = number1 / number2;
[Link]("Quotient is : " + div);
//Modulus Operation
int rem = number1 % number2;
}
}
Program output :
Sum is: 16
Difference is : 8
Multiplied value is : 48
Quotient is : 3
Remainder is : 0
UNARY OPERATOR
In Java, unary arithmetic operators are used to increasing or decreasing the value of an
operand. Increment operator adds 1 to the value of a variable, whereas the decrement operator
decreases a value.
Syntax. :
val++;
val--;
Example of UNARY operations in java. Type this code in your text editor then save as
[Link] then compile and run.
int x = 6;
int y = 6;
[Link]("y=: " + ++y);
int p = 6;
[Link]("p=: " + --p);
}
}
Program output
r=: 6
r=: 7
x=: 6
x=: 5
y=: 7
p=: 5
RELATIONAL OPERATORS
The Java Relational operators compare between operands and determine the relationship
between them.
There are six types of relational operators in Java, these are:
Example of Relational operations in java. Type this code in your text editor then save as
[Link] then compile and run.
//is equal to
[Link]("num1 == num2 = " + (num1 == num2) );
//Greater than
[Link]("num1 > num2 = " + (num1 > num2) );
//Less than
[Link]("num1 < num2 = " + (num1 < num2) );
}
}
LOGICAL OPERATORS
The Java Logical Operators work on the Boolean operand. It's also called Boolean logical
operators. It operates on two Boolean values, which return Boolean values as a result.
Example of logical operations in java. Type this code in your text editor then save as
[Link] then compile and run.
//Logical AND
[Link]("bool1 && bool2 = " + (bool1 && bool2));
//Logical Not
[Link]("!(bool1 && bool2) = " + !(bool1 && bool2));
}
}
Program Output
//Bitwise AND
[Link]("num1 & num2 = " + (num1 & num2));
//Bitwise OR
[Link]("num1 | num2 = " + (num1 | num2) );
//Bitwise XOR
[Link]("num1 ^ num2 = " + (num1 ^ num2) );
}
}
Program Output
In a Java assignment statement, any expression can be on the right side and the left side
must be a variable name. For example, this does not mean that "a" is equal to "b", instead, it
means assigning the value of 'b' to 'a'. It is as follows:
syntax :
variable = expression;
EXAPLES :
int a = 6;
float b = 6.8F;
CONDITIONAL OPERATOR
The Java Conditional Operator selects one of two expressions for evaluation, which is
based on the value of the first operands. It is also called ternary operator because it
takes three arguments.
The above syntax means that if the value given in Expression1 is true, then Expression2
will be evaluated; otherwise, expression3 will be evaluated.
Example :
In the above example, the condition given in expression1 is false because the value of a
is not equal to the value of b.
Multiple choice
2. What are the values of x,y, and z, after the following code execute ?
int x = 0;
int y = 1;
int z = 2;
x = y;
y = y * 2;
z = 3;
A. x = 0, y = 1, z = 2
B. x = 1, y = 2, z = 3
Unit IV.
Java decision-making statements allow you to make a decision, based upon the result of
a condition.
All the programs in Java have set of statements, which are executed sequentially in the
order in which they appear. It happens when jumping of statements or repetition of certain
calculations is not necessary. However, there may arise some situations where programmers
have to change the order of execution of statements based on certain conditions which involve
kind of decision-making statements.
On this chapter, we will create a source code with java decision process from sort of if
statement to switch statement .
Learning Outcomes:
After successful completion of this lesson, you should be able to:
● produce informative layouts using text with an appropriate color for a theme
● construct and design graphics with styles
● create a suitable font for a specific event
Course Materials:
Decision Making
▪ if-else
▪ nested-if
▪ if-else-if
▪ switch-case
The if statement
if statement is the most simple decision making statement. It is used to decide whether a
certain statement or block of statements will be executed or not i.e if a certain condition is true
then a block of statement is executed otherwise not.
Syntax:
if(condition)
{
// Statements to execute if
// condition is true
}
Examples
if (i > 15)
Syntax:
if (condition)
{
// Executes this block if
// condition is true
}
else
{
// Executes this block if
// condition is false
}
Examples
class IfElseDemo
{
public static void main(String args[])
{
int i = 10;
if (i < 15)
[Link]("i is smaller than 15");
else
[Link]("i is greater than 15");
}
}
This example the user will input age and test the condition if eligible to vote…
import [Link].*;
public class Vote {
/** Enter the age of the person
* .it will show if the person is eligible to vote
If else if..else statement here, a user can decide among multiple [Link] if statements are
executed from the top down. As soon as one of the conditions controlling the if is true, the
statement associated with that if is executed, and the rest of the ladder is bypassed. If none of
the conditions is true, then the final else statement will be executed.
Syntax:
if (condition)
statement;
else if (condition)
statement;
.
else
statement;
Example :
public class oopifelseifDemo
{
public static void main(String args[])
{
int i = 20;
if (i == 10)
[Link]("i is 10");
else if (i == 15)
[Link]("i is 15");
else if (i == 20)
[Link]("i is 20");
else
[Link]("i is not present");
}
}
Example 2 :
import [Link];
public class AverageGrade {
/** Enter the marks of 3 subjects and find the average and the grade .
if (i == 10)
{
// First if statement
// Nested - if statement
// Will only be executed if statement above
// it is true
if (i < 12)
[Link]("i is smaller than 12 too");
else
[Link]("i is greater than 15");
}
}
}
Example 2 :
import [Link];
public class ScienceEligible {
Syntax:
switch (expression)
{
case value1:
statement1;
break;
case value2:
statement2;
break;
.
.
case valueN:
statementN;
break;
default:
statementDefault;
}
Example :
class SwitchCaseDemo
{
public static void main(String args[])
{
int i = 9;
switch (i)
{
case 0:
[Link]("i is zero.");
break;
case 1:
[Link]("i is one.");
break;
case 2:
[Link]("i is two.");
break;
default:
Example 2 :
import [Link];
public class MonthsName {
public static void main(String[] args) {
int month;
[Link]("Enter month number from 1 to 12 : ");
Scanner sc = new Scanner([Link]);
month = [Link]();
switch(month) {
case 1:
[Link]("January\n");
break;
case 2:
[Link]( "February\n");
break;
case 3:
[Link]("March\n");
break;
case 4:
[Link]("April\n");
break;
case 5:
[Link]("May\n");
break;
case 6:
[Link]("June\n");
break;
case 7:
[Link]("July\n");
break;
case 8:
[Link]("August\n");
break;
case 9:
[Link]("September\n");
break;
case 11:
[Link]("November\n");
break;
case 12:
[Link]("December\n");
break;
default:
[Link]("You have entered an invalid month number\n");
break;
}
}
}
Assessment 4
JAVA CODING : Open you java, answer the following problem and write your answer once
java code are already completed.
Problem No 1: create a java code name as [Link]. This program will ask the user to
enter Student ID and Student Name, after that program will ask to enter Midterm and Final
grade. Let’s use simple formula midterm + final / 2 and display result as final_grade. And check
if PASSED or FAILED. Use appropriate conditional if statement.
Problem No.2 : create a java code name as [Link]. This will program wil choose
from list of menus [ A - cake, B - fruits , C - drink , D- pasta ]. The user will enter choice from
Unit V.
Control Structure: LOOPING
Overview:
Learning Outcomes:
After successful completion of this lesson, you should be able to:
● learn how to code a java loop and ow its works
● provide a java solution using java looping
● design, code and test java loop
Course Materials:
import [Link];
public class MultiplicationTable {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
int number, term, i;
[Link]("Enter a number to print multiplication table");
number= [Link]();
[Link]("Enter number of terms in table");
term = [Link]();
// Prints multiplication table
[Link]("Multiplication table-------------------\n");
for (i = 1; i <= term; ++i) {
[Link](number + " X " + i + " = " + number*i);
}
}
}
Example 2:
public class WhileExample2 {
public static void main(String[] args) {
while(true){
[Link]("infinitive while loop");
}
}
}
Example 1 :
Example 2:
import [Link];
int sum = 0;
int number = 0;
Assessment 5
JAVA CODING
Unit VI.
Overview:
Learning Outcomes:
After successful completion of this lesson, you should be able to:
1. Enabled the importance of Object Oriented Programming in modern application and
used.
2. Develop a working with class and objects in Java platform
3. Modify each function of Object Oriented Programming features in java platform and
technologies
4. Create executable Java Applications that created using OOP principles and source code
arrangements
Course Materials:
Object-oriented programming
System(OOPs) is a programming paradigm
based on the concept of “objects” that contain
data and methods. The primary purpose of
object-oriented programming is to increase the
flexibility and maintainability of programs.
Object oriented programming brings
together data and its behavior(methods) in a
single location(object) makes it easier to
understand how a program works
The OOP concept was basically
designed to overcome the drawback of the
above programming methodologies, which
were not so close to real-world applications.
The demand was increased, but still,
conventional methods were used. This new
approach brought a revolution in the
programming methodology field.
Advantages of OOPs –
● It models the real world very well.
● With OOP, programs are easy to understand and maintain.
● OOP offers code reusability. Already created classes can be reused without having to write
them again.
● OOP facilitates the quick development of programs where parallel development of classes
is possible.
● With OOP, programs are easier to test, manage and debug.
Disadvantages of OOP –
● With OOP, classes sometimes tend be over-generalized.
● The relations among classes become superficial at times.
● The OOP design is tricky and requires appropriate knowledge. Also, one needs to do proper
planning and design for OOP programming.
● To program with OOP, the programmer needs proper skills such as that of
design, programming and thinking in terms of objects and classes etc.
Class
Polymorphism
If one task is performed in different ways, it is known
as polymorphism. For example: to convince the customer
differently, to draw something, for example, shape, triangle,
rectangle, etc.
In Java, we use method overloading and method
overriding to achieve polymorphism.
Another example can be to speak something; for
example, a cat speaks meow, dog barks woof, etc.
Encapsulation
Binding (or
wrapping)
code and data together into a single unit are known as
encapsulation. For example, a capsule, it is wrapped with
different medicines.
A java class is the example of encapsulation. Java bean
is the fully encapsulated class because all the data
members are private here
Assessment 6
3. The process by which one object can acquire the properties of another object:
A. Encapsulation
Unit VII.
Learning Outcomes:
Course Materials:
Classes and Objects in Java are two such concepts which go hand in hand. You can’t
learn one without having the knowledge of the other. Together they form the building blocks of
Java
.
1. Built-in Classes
Built-in classes in Java are the classes which come bundled within predefined packages in
Java. Predefined packages are the packages which are developed by Sun MicroSystems and are
provided as a part of JDK (Java Development Kit) to help out a java programmer. A few of the
majorly used built-in classes are:
i. [Link]
ii. [Link]
iii. [Link]
iv. [Link]
v. [Link]
vi. [Link]
vii. [Link]
viii. [Link]
ix. [Link]
x. [Link]
A class is a user defined blueprint or prototype from which objects are created. It represents the
set of properties or methods that are common to all objects of one type. In general, class
declarations can include these components, in order:
1. Modifiers: A class can be public or has default access
2. Class name: The name should begin with a initial letter (capitalized by convention).
3. Superclass (if any): The name of the class’s parent (superclass), if any, preceded by
the keyword extends. A class can only extend (subclass) one parent.
4. Interfaces (if any): A comma-separated list of interfaces implemented by the class, if
any, preceded by the keyword implements. A class can implement more than one
interface.
5. Body: The class body surrounded by braces, { }.
In order to create a full-fledged custom class, you need to know what are the various
elements a class is made up of. A Java class generally consists of the following:
1. Fields
Fields of a class are used to define the properties or state attributes of the class objects.
Thus they are declared within the body of the class. The general syntax to declare a class field is
given below:
1. A Java class must have the class keyword followed by the class name, and class must be
followed by a legal identifier.
2. The class name must start with a capital letter and if you are using more than one word to
define a class name, every first letter of the latter words should be made capital.
3. There should not be any spaces or special characters used in a class name except the
dollar symbol($) and underscore(_).
4. A Java class can only have public or default access specifier.
5. It must have the class keyword, and class must be followed by a legal identifier.
6. It can extend only one parent class. By default, all the classes extend [Link]
directly or indirectly.
7. A class may optionally implement any number of interfaces separated by commas.
8. The class’s members must be always declared within a set of curly braces {}.
9. Each .java source file can contain any number of default classes but can only have one
public class.
1. Concrete Class
A normal class is technically a concrete class containing methods, class variables,
constructors, blocks and everything. Below is a basic example of a concrete class in Java:
class oopDemo{
//class body
}
2. Abstract Class
An abstract class is a class which is defined with the keyword abstract will have at
least one abstract method (i.e a method without body) within. Abstract classes without any
abstract method in it cannot be instantiated but can only be inherited.
abstract class oopDemo{
//abstract method
abstract void show();
}
3. Interfaces
Interfaces are similar to classes except a Java Interface can only contain method
signatures and fields. In order to use an interface, it must be implemented by a class.
Suppose we have an object called Mobile. It will have some identity like its model,
attributes such as color, RAM, price, and behavior such as text, on, off, etc. All the instances of
the class Mobile share the same set of attributes and the behavior. Here one thing you must
remember is that attribute values of each object will be unique. Moreover, a single Java class can
have any number of instances.
There are three simple steps to create a Java object which are listed below:
● Declaration − This is the very first step of object creation. In this step, you need to declare
a variable with the class name as the data type.
● Instantiation − Next step is the instantiation where you need to use the ‘new’ keyword to
create the object.
● Initialization − Finally in the third step, you need to initialize the object by calling the class
constructor.
Overview:
In Java, a constructor is a block of codes similar to the method. It is called when an
instance of the class is created. At the time of calling constructor, memory for the object is
allocated in the memory.
It is a special type of method which is used to initialize the object.
Every time an object is created using the new() keyword, at least one constructor is called.
Learning Outcomes:
After successful completion of this lesson, you should be able to:
1. Enabled the importance of JAVA Constructor in particular java CLASS
2. Describe the elements and types of Java Constructor in coding arrangement
3. Develop a Java Constructor that connected in java class from design and execution
Course Materials:
Constructors are used to initialize the object’s state. Like methods, a constructor also
contains collection of statements(i.e. instructions) that are executed at time of Object creation.
A constructor is a special method that has the same method name as the class name.
A Java constructor is special method that is called when an object is instantiated. In other
words, when you use the new keyword. The purpose of a Java constructor is to initializes the
newly created object before it is used.
Here is a simple example that creates an object, which results in the class constructor being
called: MyClass obj = new MyClass()
The new keyword here creates the object of class MyClass and
invokes the constructor to initialize this newly created object.
class NoArgCon
{ this would be invoked while an
object of that class is created.
int num;
String name;
NoArgCon()
{
[Link]("Constructor called");
}
}
public class SampleNoArgCon this would invoke default
{ constructor.
public static void main (String[] args)
{ Default constructor provides the
NoArgCon output = new NoArgCon(); default values to the object like 0, null
[Link]([Link]);
[Link]([Link]);
}}
No argument Constructors
As the name specifies the no argument constructors of Java does not accept
any parameters instead, using these constructors the instance variables of a method
will be initialized with fixed values for all objects.
100 100
import [Link].*;
class ConsPar
{
constructor would initialize data
// data members of the class. members
String name; with the values of passed arguments
int id; while object of that class created.
Constructor is a block of code that allows you to create an object of class and has same name as
class with no explicit return type.
Whenever a class (child class) extends another class (parent class), the sub class inherits state
and behavior in the form of variables and methods from its super class but it does not inherit
constructor of super class because of following reasons:
● Constructors are special and have same name as class name. So if constructors were
inherited in child class then child class would contain a parent class constructor which is
against the constraint that constructor should have same name as class name.
If we define Parent class constructor inside Child class it will give compile time error for
return type and consider it a method. But for print method it does not give any compile
time error and consider it a overriding method.
● Now suppose if constructors can be inherited then it will be impossible to achieving
encapsulation. Because by using a super class’s constructor we can access/initialize private
members of a class.
● A constructor cannot be called as a method. It is called when object of the class is
created so it does not make sense of creating child class object using parent class
constructor notation. i.e. Child c = new Parent();
● A parent class constructor is not inherited in child class and this is why super() is
added automatically in child class constructor if there is no explicit call to super or this.
Source : [Link]
No argument Constructors
As the name specifies the no argument constructors of Java does not accept any parameters
instead, using these constructors the instance variables of a method will be initialized with fixed
values for all objects.
Example
Public class MyClass {
Int num;
MyClass() {
num = 100;
}
}
You would call constructor to initialize objects as follows
Parameterized Constructors
A constructor which has a specific number of parameters is called a parameterized
constructor.. Parameters are added to a constructor in the same way that they are added
to a method, just declare them inside the parentheses after the constructor's name.
Example
Here is a simple example that uses a constructor −
// A simple constructor.
class MyClass {
int x;
10 20
int a;
boolean b;
a=0
b = false
Which among the following is correct for the class defined below?
class student
{
int marks; Answer: c
public: student(){} Why ? : It is a special case of constructor with only 1
student(int x) argument. While calling a constructor with one
{
marks=x; argument, you are actually implicitly creating a
} conversion from the argument type to the type of
}; class. Hence you can directly specify the value of
main() that one argument with assignment operator.
{
student s1(100);
student s2();
student s3=100;
return 0;
}
a) Object s3, syntax error
b) Only object s1 and s2 will be created
c) Program runs and all objects are created
d) Program will give compile time error
class Subject {
String CourseName;
// public constructor
public Subject(){
CourseName = "CMPE 30023 – OOP ";
}
}
1. Which among the following is called first, automatically, whenever an object is created?
a) Class
b) Constructor
c) New
d) Trigger
3. In which access should a constructor be defined, so that object of the class can be
created in any function?
a) Public
b) Protected
c) Private
d) Any access specifier will work
6. How many types of constructors are available for use in general (with respect to
parameters)?
a) 2
b) 3
c) 4
d) 5
Overview:
Learning Outcomes:
After successful completion of this lesson, you should be able to:
1. Demonstrate use of Methods in java programming
2. Demonstrate syntax arrangement of methods types in different settings
3. Modify the syntax and process of methods to constructors
4. Create executable Java Applications in using java methods in different java application
procedures
Course Materials:
A method is a collection of statements that perform some specific task and return the result
to the caller. A method can perform some specific task without returning anything. Methods allow
us to reuse the code without retyping the code. Methods are time savers and help us to reuse the
code without retyping the code.
⮚ Modifier-: Defines access type of the method i.e. from where it can be accessed in your
application. In Java, there 4 type of the access specifiers.
● public: accessible in all class in your application.
● protected: accessible within the class in which it is defined and in its
subclass(es)
● private: accessible only within the class in which it is defined.
● default (declared/defined without using any modifier) : accessible within
same class and package within which its class is defined.
⮚ The return type : The data type of the value returned by the method or void if does not
return a value.
⮚ Method Name : the rules for field names apply to method names as well, but the
convention is a little different.
⮚ Parameter list : Comma separated list of the input parameters are defined, preceded with
their data type, within the enclosed parenthesis. If there are no parameters, you must use
empty parentheses ().
⮚ Exception list : The exceptions you expect by the method can throw, you can specify
these exception(s).
⮚ Method body : it is enclosed between braces. The code you need to be executed to
perform your intended operations.
Calling a method
The method needs to be called for using its functionality. There can be three situations
when a method is called:
A method returns to the code that invoked it when:
// method call
myMethod();
As discussed earlier, a Java method can have zero or more parameters. And, it may also
return some value.
Method parameters
Parameters are specified after the method name in a class, inside parentheses. You can
add as many parameters as you want but just separate them with a comma. Data can be passed
to functions as a parameter. Actually, parameters act as variables inside the method.
Hands-on Activity
Laboratory Exercises: 1 In this Program students is required to create a source code with return
value of parameters. On the main method, the program will ask the user to enter 2 whole numbers:
Enter Num1 and Enter Num 2 , after that the program will generate results by calling the formula
stored in a methods, name as addTwoInt() method, with parameter list of ( in a, int b) and formula
of sum = a + b and return the value of sum. And finally will display the results on the main
method. Student can use Scanner or JOptionPane. Or both libraries.
Answer :
import [Link].*;
import [Link].*;
class SampleMethodReturn {
int sum = 0;
sum = a + b;
return sum;
}
import [Link];
class SampleMethodReturnTwo {
float prod = 0;
float p = [Link](num1,num2);
[Link](null,"Product of two Floating values :" + p);
Assessment 9
Overview:
Inheritance in Java is a mechanism in which one object acquires all the properties and
behaviors of a parent object. It is an important part of OOPs (Object Oriented programming
system).
The idea behind inheritance in Java is that you can create new classes that are built upon
existing classes. When you inherit from an existing class, you can reuse methods and fields of
the parent class.
Learning Outcomes:
Course Materials:
JAVA INHERITANCE
In OOP, computer programs are designed in such a way where everything is an object that
interacts with one another. Inheritance is an integral part of Java OOPs which lets the properties of
one class to be inherited by the other. It basically, helps in reusing the code and establish a
relationship between different classes.
As we know, a child inherits the properties from his parents. A similar concept is followed in
Java, where we have two classes:
REMINDER: A class which inherits the
properties is known as Child Class whereas a
1. Parent class (Super or Base class) class whose properties are inherited is known as
the class being inherited from Parent class.
2. Child class (Subclass or Derived class) To inherit from a class, use
the class that inherits from another class the extends keyword.
Example NOTES :
class Animal In Java, we use the extends keyword to inherit from
{ a class. Here, we have inherited the Dog class from the
// eat() method Animal class.
// sleep() method The Animal is the superclass (parent class or base
} class), and the Dog is a subclass (child class or derived
class Dog extends Animal class). The subclass inherits the fields and methods of the
{ superclass.
// bark() method
}
Sample Inheritance
class Animal {
public void eat() {
[Link]("I can eat");
}
public void sleep() { Here, we have inherited a subclass Dog
[Link]("I can sleep"); from superclass Animal. The Dog class
} inherits the methods eat() and sleep() from
} the Animal class.
class Dog extends Animal { Hence, objects of the Dog class can access
public void bark() { the members of both the Dog class and the
[Link]("I can bark"); Animal class.
}
}
public class SampleInheritance {
public static void main(String[] args) {
[Link]();
[Link]();
[Link]();
}
}
NOTES : Remind the students that When a subclass extends a superclass in Java, all protected
and public fields and methods of the superclass are inherited by the subclass. By inherited is meant
that these fields and methods are part of of the subclass, as if the subclass had declared them itself.
protected and public fields can be called and referenced just like the methods declared directly in the
subclass
You can also assign methods and fields protected. Protected members are accessible
● from within the class
● within its subclasses
● within the same package
Example of Protected Key word
class Animal {
protected String type;
private String color;
[Link] = "mammal";
[Link]("black");
[Link]([Link]());
}}
Single Inheritance
In single inheritance, one class inherits the properties of another. It enables a derived
class to inherit the properties and behavior from a single parent class. This will, in turn, enable
code reusability as well as add new features to the existing code.
CLASS A
CLASS B
class Animal{
void eat(){
[Link](“eating”);}
}
class Dog extends Animal{
void bark(){
[Link](“barking”);}
}
class TestInheritance{
public static void main(String args[]){
Dog d=new Dog();
[Link]();
[Link]();
}
}
CLASS A
CLASS B
CLASS
class C
B inherits the properties and
behavior of class A and class C
inherits the properties of class B.
Here Class A is the parent class for B
and class B is the parent class for C.
So in this case class C implicitly inherits
the properties and methods of class A
along with Class B. That’s what is
multilevel inheritance.
class Animal{
voideat(){
[Link](“eating…”);}
}
class Dog extends Animal{
void bark(){
[Link](“barking…”);}
}
class Puppy extends Dog{
void weep(){
[Link](“weeping…”);}
}
class TestInheritance2{
public static void main(String args[]){
Puppy d=new
Puppy();
[Link]();
[Link]();
[Link]();
}
}
When a class has more than one child classes (subclasses) or in other words, more than
one child classes have the same parent class, then such kind of inheritance is known as
hierarchical.
CLASS A
class Animal{
void eat(){
[Link](“eating…”);}
}
class Dog extends Animal{
void bark(){
[Link](“barking…”);}
}
class Cat extends Animal{
void meow(){
[Link](“meowing…”);}
}
class TestInheritance3{
public static void main(String args[]){
Cat c=new Cat();
[Link]();
[Link]();
}
}
Default superclass: Except Object class, which has no superclass, every class has one
and only one direct superclass (single inheritance). In the absence of any other explicit
superclass, every class is implicitly a subclass of Object class.
Superclass can only be one: A superclass can have any number of subclasses. But a
subclass can have only one superclass. This is because Java does not support multiple
inheritance with classes. Although with interfaces, multiple inheritance is supported by java.
Inheriting Constructors: A subclass inherits all the members (fields, methods, and
nested classes) from its superclass. Constructors are not members, so they are not inherited by
subclasses, but the constructor of the superclass can be invoked from the subclass.
Private member inheritance: A subclass does not inherit the private members of its
parent class. However, if the superclass has public or protected methods(like getters and setters)
for accessing its private fields, these can also be used by the subclass.
In sub-classes we can inherit members as is, replace them, hide them, or supplement them with
new members:
✔ The inherite fields can be used directly, just like any other fields.
✔ We can declare new fields in the subclass that are not in the superclass.
✔ The inherited methods can be used directly as they are.
✔ We can write a new instance method in the subclass that has the same signature
as the one in the superclass, thus overriding it (as in example above, toString()
method is overridden).
✔ We can write a new static method in the subclass that has the same signature as
the one in the superclass, thus hiding it.
✔ We can declare new methods in the subclass that are not in the superclass.
✔ We can write a subclass constructor that invokes the constructor of the superclass,
either implicitly or by using the keyword super.
Important terminology:
● Super Class: The class whose features are inherited is known as super class(or a
base class or a parent class).
● Sub Class: The class that inherits the other class is known as sub class(or a
derived class, extended class, or child class). The subclass can add its own fields
and methods in addition to the superclass fields and methods.
Types of Inheritance in Java
✔ Single Inheritance: In single inheritance, subclasses inherit the features of one
superclass.
✔ Multilevel Inheritance: In Multilevel Inheritance, a derived class will be
inheriting a base class and as well as the derived class also act as the base class
to other class.
Hand-On Exercises
Create a source code with base class Teacher and subclass ProgrammingTeacher. Since
class ProgrammingTeacher extends the properties from the base class, we need not declare
these properties and method in the subclass.
For base class Teacher, declare a String with variable teachers, designation and
collegeName. With method void() name as “does” with printed of “Class Adviser”;
On your main method, create an object name as “obj” that use to call all derived properties.
Answer:
class Teacher{
String teachers = "Juan A. Dela Cruz";
String designation = "Professor";
String collegeName = "School of Education";
void does(){
[Link]("Class Adviser");
}
}
public class ProgrammingTeacher extends Teacher{
String mainSubject = "ICT 002 Culminating Activity in ICT";
Example 2 :
Student to expect type the given source code and test then provide personal analysis for
what type of inheritance. after that student required to add 2 solutions on given code for
subtraction and divisions
import [Link];
class Calculation {
int z;
Example 3 :
import [Link];
class ArithmeticOperation {
int z;
}
public void Division(int x, int y) {
z = x - y;
[Link]("The Qoutient between the given numbers:"+z);
}
}
[Link]("Results :");
[Link](a,b);
[Link](a, b);
[Link](a,b);
[Link](a,b);
}
}
Assessment 10 :
Multiple Choice: Encircle the correct answer in given set of question and situations. Avoid
any form of erasures and duplicate answer per number. Read carefully before you answer.
9. Which access type data gets derived as private member in derived class?
a) Private
b) Public
c) Protected
d) Protected and Private
10. If a base class is inherited in protected access mode then which among the following is
true?
a) Public and Protected members of base class becomes protected members of derived
class
b) Only protected members become protected members of derived class
c) Private, Protected and Public all members of base, become private of derived class
d) Only private members of base, become private of derived class
11. Members which are not intended to be inherited are declared as ________________
a) Public members
b) Protected members
c) Private members
Learning Outcomes:
After successful completion of this lesson, you should be able to:
Course Materials:
Static Polymorphism
class Calculator A polymorphism that is resolved
{ during compile time is known as static
int add(int x, int y) polymorphism. Method overloading is an
{ example of compile time polymorphism.
return x+y;
} Example
int add(int x, int y, int z) Method Overloading is a feature
{ that allows a class to have two or more
return x+y+z; methods to have the same name, but
} with different parameter lists. In the
} below example, you have two definitions
public class TestOverload of the same method add(). So, which
{ add() method would be called is
public static void main(String args[]) determined by the parameter list at the
{ compile time. That is the reason this is
Calculator obj = new Calculator(); also known as compile time
[Link]([Link](100, 200)); polymorphism.
[Link]([Link](100, 200, 300));
}
}
Example 2 : Override
class MacBookOverride{
public void myMethod(){
[Link]("Example of Overridden Method");
}
}
Dynamic Polymorphism
Dynamic polymorphism is a process in which a call to an overridden method is resolved
at runtime, that’s why it is called runtime polymorphism. Method Overriding is one of the ways to
achieve Dynamic Polymorphism. In any object-oriented programming language, Overriding is a
feature that allows a subclass or child class to provide a specific implementation of a method that
is already provided by one of its super-classes or parent classes.
Overloading is about same function have different signatures. Overriding is about same function,
same signature but different classes connected through inheritance.
Overloading is an example of compiler time polymorphism and overriding is an example of run
time polymorphism.
Example 3 :
create a source code with base class Doctor and subclass Surgeon. The
property based on images at the right corner of the activity sheet.
class Doctor{
public void treatPatient(){
}
}
class Surgeon extends Doctor{
public void treatPatient(){
[Link]("treatPatient method in class Surgeon will be executed");
}
}
class runOverriding{
public static void main (String args[]){
Doctor doctorObj = new Doctor();
[Link]();
[Link]("treatPatient method in class Doctor will be executed");
class Test
{
public void prints()
{
[Link]("ICT 002");
}
}
public class Derived extends Test
{
Ans. (a)Explanation: A child class
public void prints()
reference variable cannot be used to {
store an instance of parent class. [Link]("Culiminating");
}
public static void main(String[] args)
{
Derived obj = new Test();
[Link]();
}
}
a) Compilation error
class Test
{
void myMethod()
{
[Link]("Culminating Activity");
}
}
public class Derived extends Test
Explanation: A child class cannot be used as a {
reference to an object of super class. void myMethod()
{
[Link]("ICT 002 ");
}
Create a source code that use the principles of Polymorphism. Create a base class Forest that
extend to leon and eagle. For each method create printed of their animal sound (leon and eagle).
Then on your main class create each object and call their object properties.
class Forest {
public void forestSound() {
[Link]("The animal makes a sound");
}
}
class MainClassPolymorphism {
public static void main(String[] args) {
Forest mySound = new Forest(); // Create aal object
Forest myleon = new leon(); // Create a Pig object
Forest myeagle = new eagle(); // Create a Dog object
[Link]();
[Link]();
[Link]();
}
}
Assessment 11:
Multiple Choice: Encircle the correct answer in given set of question and
situations. Avoid any form of erasures and duplicate answer per number. Read
carefully before you answer.
7. If 2 classes derive one base class and redefine a function of base class, also overload
some operators inside class body. Among these two things of function and operator
overloading, where is polymorphism used?
a) Function overloading only
b) Operator overloading only
c) Both of these are using polymorphism
d) Either function overloading or operator overloading because polymorphism can be
applied only once in a program
Unit XII.
Overview:
On this chapter we will differentiate the use of java abstraction and encapsulation
Abstraction is the process or method of gaining the information. While encapsulation is the
process or method to contain the information. Abstraction is the method of hiding the unwanted
information. Whereas encapsulation is a method to hide the data in a single entity or unit along
with a method to protect information from outside.
Course Materials:
Encapsulation is an OOP technique of wrapping the data and code. In this OOPS
concept, the variables of a class are always hidden from other classes. It can only be
accessed using the methods of their current class. For example - in school, a student
cannot exist without a class.
class Student {
private String name;
public String getName() { Note : As you can see in the sample code, we
return name; have created a class Student which has
} a private variable name. Next, we have created a
public void setName(String name) { getter(get) and setter (set) to get and set the name of
[Link] = name; a student. With the help of these methods, any class
} which wishes to access the name variable has to do
} it using these getter and setter methods.
class TestEncap{
public static void main(String[] args) {
Student s=new Student();
class Person {
protected String profession;
Why Encapsulation?
✔ In Java, encapsulation helps us to keep related fields and methods together, which
makes our code cleaner and easy to read.
✔ It helps to control the modification of our data fields.
Illustration
Since we have
fetched/removed/selected the customer
information from a larger pool, the process
is referred as Abstraction.
However, the same information
once extracted can be used for a wide
range of applications. For instance, you
can use the same data for hospital
application, job portal application, a
Government database, etc. with little or no
modification. Hence, it becomes your
Master Data. This is an advantage of
Abstraction.
Source : [Link]
2 Ways of Abstraction
Abstract Class
Abstract class contains the ‘abstract’ keyword. But what exactly it means? If you make the
class abstract, it cannot be instantiated, i.e you cannot create an object of an abstract class. Also,
an abstract class can contain abstract as well as concrete methods.
Interface
Advantages of Abstraction
✔ The main benefit of using an abstract class is that it allows you to group several related
classes as siblings.
✔ Abstraction helps to reduce the complexity of the design and implementation process of
software.
Example of Abstraction
Create source file name [Link] with the following content. After you create compile then
run.
public interface Shape{
public void draw();
public double getArea();
}
Create another source file name as [Link] After you create compile then run.
class Circle implements Shape{
private double radius;
class AbsInterfaceTest{
public static void main (String args[]){
Result :
Drawing Circle
Area=201.06192982974676
class Student { }
private String name; class Dog extends Animal {
public String getName() { public void makeSound() {
return name; [Link]("Bark bark.");
} }
public void setName(String name) { }
[Link] = name; class Cat extends Animal {
} public void makeSound() {
} [Link]("Meows ");
class TestEncap{ }
public static void main(String[] args) { }
Student s=new Student(); class Main {
[Link]("Harry Potter"); public static void main(String[] args) {
[Link]([Link]()); Dog d1 = new Dog();
} [Link]();
}
Cat c1 = new Cat();
[Link]();
}}
class MainEncap {
public static void main(String[] args) {
person p1 = new Person[];
[Link](24);
[Link]("My age is " + [Link]());
}
}
Question : Student to expect type the given source code and test its functions.
The following source must be save in personal google drive with folder name
of Activity_Abstraction with 3 files [Link], [Link] and
[Link] and shared to your teacher
****** file name = [Link]
Assessment 12
Multiple Choice: Encircle the correct answer in given set of question and situations.
Avoid any form of erasures and duplicate answer per number. Read carefully before
you answer.
1. Which among the following best a) Create public member functions
describes encapsulation? to access those data members
a) It is a way of combining various b) Create private member functions
data members into a single unit to access those data members
b) It is a way of combining various c) Create protected member
member functions into a single unit functions to access those data
c) It is a way of combining various members
data members and member d) Private data members can never
functions into a single unit which can be accessed from outside the class
operate on any data 3. While using encapsulation, which
d) It is a way of combining various among the following is possible?
data members and member a) Code modification can be
functions that operate on those data additional overhead
members into a single unit b) Data member’s data type can be
2. If data members are private, what changed without changing any other
can we do to access them from the code
class object? c) Data member’s type can’t be
NAME : ________________________________
Part 1: underline the wrong code in the given java program. ( Correct Answer )
imports [Link];
public class Input_Quiz
{
public statics void main(Strings args[])
{
int a:
float b;
String s;
[Link]("Enter an integer");
a = [Link]();
[Link]("You entered integer " + a);
[Link]("Enter a float");
bs = [Link]();
[Link]("You entered float " + ba);
[Link]("Enter a string");
s - [Link]();
[Link]("You entered string " + as);
NAME : ________________________________
Multiple Choice
1. ____________ are containers for storing data values.
a. Syntax b. data type c. variable
2. ____________ - includes byte, short, int, long, float, double, boolean and char
a. Numbers b. Primitive data types c. Strings
3. ____________ are used to determine the logic between variables or values
a. Assignment operator b. Arithmetic Operator c. Logical
Operator
4. ____________ are used to perform common mathematical operations.
a. Assignment operator b. Arithmetic Operator c. Logical
Operator
5. ____________ - such as String, Arrays and Classes
a. Numbers b. Primitive data types c. Non-primitive data type
6. ____________ - stores text, such as "Hello". String values are surrounded by
double quotes
a. Char b. String c. Integer
7. ____________ - stores integers (whole numbers), without decimals, such as 123 or
-123
a. integer b. float c. double
NAME : ________________________________
Grading Criteria:
Assigning Variable / data type - 15 point
Proper Code Arrangement - 35 point
Program Execution - 35 point
Attitude / Knowledge - 15 point
-------------------------
100 points
Machine Problem (Laboratory)
Create a java program using do/while loop, that the user required to
input username and password, the program will ask the user to continue
[Y/N] if the user select N, the program process will terminate and display
message “System Close”
Multiple Choice :
Thank you
1st Grading
Class Standing
● Assessment……………..40
● Quiz………………………60
100 x 70% ……….. 70%
Midterm Exam
● Drawing/Sketch…………………………….…..30%
Midterm Grade…………………………………………………..100%
2nd Grading
Class Standing
● Assessment……………..40
● Quiz………………………60
100 x 70% ……….. 70%
Final Exam
● Script……………………………..………….…..30%
Finals Grade……………………………………………………..100%
References
Books :
Java for Absolute Beginners: Learn to Program the Fundamentals the Java 9+ Way
Iuliana Cosmina Edinburgh, UK
ISBN-13 (pbk): 978-1-4842-3777-9
Installer :
[Link]
[Link]
[Link]
[Link]
[Link]
[Link]
:[Link]
[Link]