Full Transcript

**Basics of Programming ** **Programming Basics (DG Junior, 2023) ** A **computer program** is a sequential set of instructions, known as **codes**, written or "*programmed*" in a  computer language to let the computer perform a specific computation task. Examples include system  software, web bro...

**Basics of Programming ** **Programming Basics (DG Junior, 2023) ** A **computer program** is a sequential set of instructions, known as **codes**, written or "*programmed*" in a  computer language to let the computer perform a specific computation task. Examples include system  software, web browsers, utility software, multimedia software, and spreadsheet software.  It is important to note that the set of instructions in a computer program must be performed sequentially  unless directed otherwise. The instructions in the set will express a unit of work that a computer language  can support. A **computer language** is a set of grammatical rules that commands a computer or a device to  behave in a specific way. It also refers to **programming language**.  **Programming ** It is the art and science of instructing computers to perform tasks using a specific programming language. It  creates codes that tell a computer how to solve problems and accomplish various operations. By writing  code in programming languages, **programmers** can develop computer programs or software applications,  design websites, analyze data, and automate processes, among other operations**. ** As programming becomes a sought-after skill in various industries, proficiency in programming opens up  myriad career opportunities, from software development and web development to data science and artificial  intelligence. Programming also enhances critical thinking, logical reasoning, and problem-solving abilities that help programmers break down complex tasks into manageable steps and develop efficient algorithms.  **Evolution and History of Programming ** Programming involved writing machine code initially. This consisted of binary instructions (0 and 1) directly  communicating with the computer's hardware. As technology progressed, high-level programming  languages developed to simplify the coding process. These languages allowed programmers to write code  using more human-readable syntax.  Currently, a wide ecosystem of programming languages and tools caters to different programming  paradigms and application domains.  **Programming Paradigms ** The term "*paradigm*" is synonymous with "*pattern*." These refer to the different approaches to structuring  and organizing code. These provide a conceptual framework for solving problems and designing software.  Here are some commonly used programming paradigms:  **Procedural Programming** -- or **imperative programming**, focuses on organizing code into reusable  procedures or functions, emphasizing the sequence of steps to execute a program. Examples include  BASIC, C and C++, Pascal, and Java.  **Object-oriented programming (OOP)** -- revolves around the concepts of objects that encapsulate  data and behavior that promotes modularity, code reusability, and scalability. Examples include  Python, VB.NET, and C\#.  **Functional Programming -** treats computation as evaluating mathematical functions, emphasizing  consistency, and avoiding side effects.  The nature of the project, requirements, and the desired programming style are some of the basis for  choosing the appropriate programming paradigm. **01 Handout 1 *\*Property of STI*** 🖂 *[student.feedback\@sti.edu]* **Page 1 of 5 ** **IT2402 ** **Programming Languages ** Numerous programming languages are available, each with its unique syntax, features, areas of  specialization, and community support, making it suitable for specific projects. This can be classified into two (2) Low-level and high-level languages.   **Low-level Language** -- a programming language closer to machine code and hardware in terms of  syntax. It provides direct control over the computer's hardware and resources, allowing programmers to write code at a more detailed level. It is commonly used for tasks requiring  precise control and efficient execution. Examples of this language include the following:  o **Assembly Language** -- uses specific instructions to control a computer's hardware. o **Machine Language** -- all instructions are written as binary numbers (1 and 0).  **High-level Language** -- a programming language designed to be easy for humans to read, write,  and understand, allowing programmers to write computer programs and interact with a  computer system without needing specific knowledge of the processor or hardware that the  program will run on. Examples include C++, Pascal, PHP, Python, and Java.  Choosing a programming language depends on different factors such as project requirements, performance  needs, community support, and available libraries or frameworks.  **Other Programming Terminologies ** Here are some terminologies that can be useful to understand programming further.  **Syntax ** It is a set of rules defining the various combinations and arrangements of symbols or characters to create a  valid statement in a language.  **Command ** It is the unique instruction given to a computer application to perform a task of a function such as "*print*" to  display text on the screen.  **Integrated Development Environment (IDE) ** It is a software application for formatting the code, checking the syntax, and running and testing the code.  IDEs can work with multiple programming languages, while some are specific to only one language.   **Library ** It is a collection of useful resources, such as objects and functions, that can be used individually and must be  configured to work together. It is pre-built or installed in an IDE or Integrated Development Environment.  **Interpreter ** It is a program that directly executes instructions in a high-level language without converting them into a  machine language.  **Assembler ** It is a program that converts instructions written in low-level assembly code into relocatable machine  language.  **Compiler ** It is a program that converts high-level languages into machine-readable code that a computer can execute.  **Introduction to Java ** **The Java Environment (AWS, n.d.a.) ** **Java** is a free-to-use and highly dynamic high-level programming language for coding programs such as web  applications, mobile applications, enterprise software, big data applications, and server-side technologies. It  was created by Sun Microsystems in 1995 as a multi-platform, object-oriented, and network-centric language  that can be used as a platform in itself.   The common uses of Java include game development, cloud computing, big data, artificial intelligence (AI),  and Internet of Things.  **Java Runtime Environment (JRE) ** It is the software that Java programs require to run correctly. It provides the *class libraries* and other resources  that any Java program needs.  The advantages of using Java include the following:  o **Active Community Support**: Given its popularity and longevity, Java has many active users and a  community that can support developers.   o **High-Quality Learning Resources**: Learning resources such as detailed documentation,  comprehensive books, and courses are available to new programmers for additional support. o **Inbuilt Functions and Libraries**: Developers do not need to write every new function from scratch, as  Java provides a rich ecosystem of built-in functions and libraries to develop various applications. o **Security**: The Java security levels and restrictions are highly configurable. An untrusted Java code can  be downloaded and run in a secure environment in which it cannot do any damage. The untrusted  code also cannot damage the host system with a virus, nor can it read or write files from the hard  drive.   o **Platform Independent:** Java code can be written once and run on any underlying platform like  Windows, iOS, Android, and Linux without rewriting. This feature is called the **"Write Once, Run  Anywhere" (WORA) Philosophy** which became a highly sought feature by developers.  To use Java, a developer must understand two (2) things: Java Virtual Machine and Java Language and APIs. **Java Virtual Machine (JVM) ** It is a virtual machine that runs Java applications as a run-time engine. Natural programming languages fall into two (2) broad categories: compilers and interpreters.  **Compilers**: The program is written in natural English-like syntax with compilers, and the language then  translates the entire code into machine language. It converts the source code into a binary program  of bytecode.  **Interpreters**: This checks the bytecode and communicates with the operating system, executing the  bytecode instructions line by line.  Java was the first programming language to combine both using a **Java Virtual Machine (JVM**). A JVM is an  environment that translates Java bytecode, an intermediate-level language, into machine language and  executes it.   The **programming statements** or **source code** are stored on a disk with a *.java* file extension. The **Java compiler** converts the source code into a binary program of bytecode. The **Java interpreter** will then check the bytecode  and communicate with the operating system, executing the bytecode instructions line by line within the Java  **02 Handout 1 *\*Property of STI*** 🖂 *[student.feedback\@sti.edu]* **Page 1 of 4 ** ![](media/image1.png)**IT2402 ** Virtual Machine, named *java.exe*.  **Java APIs ** APIs (Application Programming Interface) are important software components bundled with the Java  Platform. **Java APIs** are pre-written Java programs that plug and play existing functionality into a code, such  as getting the time and date, performing mathematical operations, or manipulating text. The Java language  has only about 50 keywords, but the Java API has several thousand classes, with thousands of methods that  can be used in any program.  **Java Skeleton (Soma, T. & Streib, J., 2023) ** The best way to understand a programming language is by dissecting and examining its sample program.  Here is a simple example of a Java program that prints or displays "First Java Application":  +-----------------------------------+-----------------------------------+ | 1  | class Skeleton {  | | | | | 2  | public static void main | | | (String\[\] args){  | | 3  | | | | System.out.println(\"First Java | | 4  | Application\"); //for display  | | | | | 5 | }  | | | | | | } | +-----------------------------------+-----------------------------------+ Line 1 begins with the *reserved word* or *keyword* class. A **class** is the basic unit of a Java program. It also defines a group of *objects* that includes *data members,* which are places to store data, and *methods* which are  places to put the program logic. Think of a class as a blueprint for a house and the house itself as the object.  On the same line, the word Skeleton is the class name provided by the programmer.   A class name is a type of an identifier. An **identifier** is the name given to a program component, such as a class,  object, or variable. These are the requirements for naming an identifier:  It must begin with a letter of the English alphabet, an underscore (\_), or a dollar sign (\$), but **not** with  a digit.  It can have any combination of letters, digits, underscores, or dollar signs, but **not** with white spaces. It is case-sensitive such as the identifier NUMBER is not the same as the identifier number or Number. It cannot be one of the following values: true, false, or null. These are not keywords; they are  primitive values but reserved and cannot be used.  It cannot be a reserved word.  **Reserved Words  ** Reserved words or **keywords** are special words significant to the Java compiler. Aside from class names, these  cannot be used as *variables*, a name used to refer to data stored in the memory. Here is a list of Java keywords: abstract  continue  for  new  switch ----------- ----------- ------------- ------------ -------------- assert  default  goto  package  synchronized boolean  do  if  private  this break  double  implements  protected  throw byte  else  import  public  throws case  enum  instanceof  return  transient catch  extends  int  short  try char  final  interface  static  void class  finally  long  strictfp  volatile const  float  native  super  while