Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
172 views

2 Computer Programming Module 2

This document provides an introduction to the basic components of a Java program. It discusses classes, methods, variables, data types, packages, comments, and input/output. It also explains what a compiler is and provides examples like Eclipse and JCreator. The document contains a pre-test on true/false statements about Java programming concepts and instructs students to code a simple Hello World program in DCoder to check their understanding. It notes that post-tests and activities will be collected by the instructor.

Uploaded by

joel lacay
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
172 views

2 Computer Programming Module 2

This document provides an introduction to the basic components of a Java program. It discusses classes, methods, variables, data types, packages, comments, and input/output. It also explains what a compiler is and provides examples like Eclipse and JCreator. The document contains a pre-test on true/false statements about Java programming concepts and instructs students to code a simple Hello World program in DCoder to check their understanding. It notes that post-tests and activities will be collected by the instructor.

Uploaded by

joel lacay
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

MODULE 2 – BASIC PROGRAMMING LANGUAGE CODES

Pre-test: True or False – Write True if the said statement is true, and write False if the statement is false, on a
one-half cross-wised sheet of yellow pad paper.

1. A class is an object constructor, or a “blueprint” for creating objects. It can be private or public.
2. Data type is a block of code which runs when it is called. Methods are used to perform certain
actions, and they are also known as functions.
3. Variable is a piece of memory that can contain a data value. A variable thus has a data type.
Variables are typically used to store information which your java program needs to do its job.
4. A compiler is a program that converts instructions into a machine-code or lower-level form so that
they can be read and executed by a computer.
5. The Java API or built-in package is a library of prewritten classes that are free to use.
6. Data types specify the different sizes and values that can be stored in the variable.
7. The comments can be used to provide information or explanation about the variable, method, class
or any statement.
8. I/O is an essential concept while working on Java programming.
9. JCreator is an example of a compiler.
10. Java is a class-based, object-oriented programming language developed by James Gosling.
MODULE 2 – BASIC PROGRAMMING LANGUAGE CODES

Lesson 1 – What is inside a Java Program

Now, if you are curious what’s inside a Java program, let me introduce you this:

So what are these parts of the source code or program that I specified?

1. Import package (or package) – is used to group related classes.

Why use packages?


We use packages to avoid name conflicts, and to write a better maintainable code.

Packages are divided into two categories:

 Built-in Packages – the Java API is a library of prewritten classes that are free to use.

Example: import package.name.Class;

 User-defined packages – to create your own package, you need to understand that
Java uses a file system directory to store them.

Example: packagemypack;

Explanation: To better understood what is a package, let’s use the example of a Balikbayan
box, full of candies, chocolates, clothes, etc. A certain package should be sent to
the receiver in order for that receiver to use the contents of the box.

2. Class – a class is an object constructor, or a “blueprint” for creating objects. It can be private or
public.

Explanation: To better understood what is a class, let’s use the example of an anime drawing,
you cannot draw directly the character without using a blueprint or a guide. Same
goes to classes, you cannot proceed in what you want to code if there’s no class in
it.
MODULE 2 – BASIC PROGRAMMING LANGUAGE CODES

3. Method – is a block of code which runs when it is called. Methods are used to perform certain
actions, and they are also known as functions.

Why use methods?


Simple, to reuse code: define the code once, and use it many times.

Explanation: To better understood what is a class, let’s use the example of an anime drawing,
you cannot draw directly the character without using a blueprint or a guide. Same
goes to classes, you cannot proceed in what you want to code if there’s no class in
it.

4. Data types – data types specify the different sizes and values that can be stored in the variable.

There are two types of data types in Java:

 Primitive data types – this include boolean, char, byte, short, int, long, float and
double.
 Non-primitive data types – the non-primitive data types include classes, interfaces
and arrays.

5. Variable – is a piece of memory that can contain a data value. A variable thus has a data type.
Variables are typically used to store information which your java program needs to do its job.

Explanation: To better understood what are data types and variables, let’s use the example of a
glass container full of salt. The data type is the container, and the variable is the
salt inside the container.

6. Comments – are the statements that are not executed by the compiler and interpreter. The comments
can be used to provide information or explanation about the variable, method, class or any statement.

Why put comments?


To identify what is inside the source code.

Comments are usually starts with either “/”, “//” or “/* */”.

7. Input and output –is an essential concept while working on Java programming. It consists of
elements such as input, output and stream.

Teacher’s trivia!

Against all odds, DO NOT forget to end your code line with a semicolon (;), or you will face the
consequences.

1.1 – Compilers

In creating a source code, of course, we need to have a compiler to compile our source code created.

So, what is a compiler?

A compiler is a program that converts instructions into a machine-code or lower-level form so


that they can be read and executed by a computer.

Explanation: To understand further a compiler, let’s use the concept of folded clothes in your
cabinet. Notice that your cabinet has full of clothes, and were being placed in a
cabinet, segregated. So, a compiler is like a cabinet, and the source code is like
the folded clothes.
MODULE 2 – BASIC PROGRAMMING LANGUAGE CODES

Some examples of a compiler applications are the following:

1. Eclipse
2. JCreator
3. DCoder (for mobile coding)
4. Turbo C++
5. Microsoft Visual Studio

Before you proceed to this part, you must download DCoder first and then follow the instructions
below on how to open DCoder and start coding using Java programming language.

class HelloWorld{
public static void main (String [] args){
System.out.println(“Hello World”);
}
}

After you code this one, what have you noticed in the output part? Is the Hello world! output popped up?
If so, then you’re good to go for the next activity.

Evaluation: True or False – Write True if the said statement is true, and write False if the statement is false,
on a one-half cross-wised sheet of yellow pad paper.

1. A class is an object constructor, or a “blueprint” for creating objects. It can be private or public.
2. Data type is a block of code which runs when it is called. Methods are used to perform certain
actions, and they are also known as functions.
3. Variable is a piece of memory that can contain a data value. A variable thus has a data type.
Variables are typically used to store information which your java program needs to do its job.
4. A compiler is a program that converts instructions into a machine-code or lower-level form so that
they can be read and executed by a computer.
5. The Java API or built-in package is a library of prewritten classes that are free to use.
6. Data types specify the different sizes and values that can be stored in the variable.
7. The comments can be used to provide information or explanation about the variable, method, class
or any statement.
8. I/O is an essential concept while working on Java programming.
9. JCreator is an example of a compiler.
10. Java is a class-based, object-oriented programming language developed by James Gosling.

Essay: For ten points, write what have you learned about this weekly topic that we have on this interactive
module.

Some Notes:

1. Post-test will be recorded and the instructor will collect your answers.
2. Activities will also be recorded and the instructor will collect your exercises.

Bibliography/References:

Internet Connection, Wikipedia


https://www.geeksforgeeks.org/the-complete-history-of-java-programming-language
MODULE 2 – BASIC PROGRAMMING LANGUAGE CODES

https://www.onlinecollegeplan.com/computer-programming-languages

You might also like