RANGER GAMEZ

CompTIA Tech+ (FC0-U71) · chapter 12 of 18

How the web store is written

Objective 4.1

Language families

Compiled or interpreted?

A CPU only runs machine code, its own 1s and 0s. People write code in languages they can read, so something has to translate. A compiled language, like C or C++, is translated into machine code ahead of time by a program called a compiler. You get a file that runs fast on its own. An interpreted language is read and run line by line by another program, the interpreter, every time it runs. There's no separate build step: change a line, run it again.

Two ways code gets to the CPU. Compiled: the source code goes through a compiler once, ahead of time, which makes a machine code file; that file then runs fast on its own. Interpreted: the source code is read by an interpreter, which translates and runs it line by line every time the program runs; there is no separate build step, so a changed line can run right away.
Compiled: translate once, then run fast. Interpreted: translate as you go, quick to change.

Exam tip Compiled: translate once, then run fast. Interpreted: translate as you go, quick to change.

Scripting languages

Scripting languages are interpreted languages used to automate tasks and add behavior. Python, JavaScript, PowerShell and Bash are common ones. Sam's nightly file that copies scanner logs to a server is a script. So is the JavaScript that makes the web store's Add to cart button work. A script needs its interpreter installed on the computer that runs it.

Sam: My log script ran fine on my PC and failed on a store PC. No Python installed there.

Theo: Classic. Compiled programs carry their machine code with them. Scripts need their interpreter.

Markup languages

A markup language labels the parts of a document so another program knows how to show them. HTML marks up web pages: headings, paragraphs, images and links. The browser reads it each time the page loads. XML marks up data. Markup describes structure only. It doesn't make decisions or do math, so the cart's logic lives in a script.

<h1>Salmon Crunch</h1>
<p>12 lb bag</p>
<a href="/cart">Add to cart</a>

Query and assembly languages

A query language asks a database to find, add or change data. SQL is the classic one. Assembly language sits at the other extreme: each line is one tiny instruction for one specific type of CPU, written as a short code like MOV or ADD. It's precise and fast, but slow to write and tied to that CPU, so few apps are written in it today.

SELECT name, price
FROM products
WHERE price < 20;

Exam tip SQL asks a database. Assembly talks almost directly to the CPU.

Check yourself 1Sam writes a small text file of commands that copies the day's scanner logs to the server each night. He runs it straight from the file with no build step. What has he written?

  1. A compiled program
  2. A markup document
  3. A script
  4. An assembly program
Show the answer

Answer: C. A script

A short file of commands run by an interpreter with no build step is a script, written in a scripting language like PowerShell or Python.

Objective 4.2

Data types

Every value has a type

A data type tells a program what kind of value it holds and what it can do with it: numbers can be added, text can be joined, and true/false can be tested. The basic types:

  • Char: one single character, like A or 7, in languages that have it (C, C#, Java)
  • String: text, a row of characters in quotes, like "Salmon Crunch" or "01844"
  • Integer: a whole number, positive, negative or zero, like 42 or -7
  • Float: a number with a decimal point, like 12.5
  • Boolean: only true or false

Numbers vs. strings

Digits inside quotes are a string, not a number. That's right for ZIP codes and phone numbers: nobody does math on them, and a string keeps a leading zero that a number drops. It's wrong for quantities: "12" + "3" joins the text into "123" instead of adding to 15. Here's Python showing both:

>>> 12 + 3
15
>>> "12" + "3"
'123'
>>> int("01844")
1844

Theo: There it is. The ZIP code became a number and the zero fell off.

Integers vs. floats

Use an integer for things you count in whole units: bags in stock, boxes on a pallet. Use a float for measurements that can have decimals: a 12.5-pound bag, a price. Turning a float into an integer drops the decimal part, so 12.5 becomes 12, and a label can end up wrong by half a pound.

>>> type(12)
<class 'int'>
>>> type(12.5)
<class 'float'>
>>> int(12.5)
12

Rosa: So a float is just a number that brought its decimal point to work.

Booleans and chars

A Boolean holds only true or false. It's perfect for yes/no fields like 'box damaged?' or 'in stock?', and a test like weight > 50 gives back a Boolean. A char holds exactly one character. A shelf code like B7 has two characters, so it needs a string. Python has no separate char type at all: one character is just a string of length 1.

>>> 62 > 50
True
>>> len("B7")
2

Check yourself 2Theo stores each product's weight, like 12.5 pounds. Which data type fits that field best?

  1. Integer
  2. Boolean
  3. Float
  4. Char
Show the answer

Answer: C. Float

A float holds numbers with a decimal point, so 12.5 is kept exactly. An integer would drop the .5.

Go deeper

More on the objectives in this chapter, in the same exam-ready detail.

Objective 4.1 · Interpreted; Compiled programming languages; Query languages; Assembly languages

Kinds of programming languages

Interpreted vs. compiled

Interpreted languages run straight from their text form, with no separate build step. Theo changes one line of JavaScript, reloads the page and sees the change at once. The catch: the computer needs the interpreter installed. A Python script fails on a PC without Python. Compiled languages are translated ahead of time by a compiler into machine code, often an .exe file on Windows. Compiled programs usually run faster and need no interpreter, but every change means building again.

Two ways code gets to the CPU. Compiled: the source code goes through a compiler once, ahead of time, which makes a machine code file; that file then runs fast on its own. Interpreted: the source code is read by an interpreter, which translates and runs it line by line every time the program runs; there is no separate build step, so a changed line can run right away.
Compiled: translate once, then run fast. Interpreted: translate as you go, quick to change.

Exam tip Fast edit-and-try = interpreted. Faster running, build step first = compiled. C and C++ are classic compiled languages.

Scripting and markup

Two kinds of interpreted language:

  • Scripting languages automate tasks and add behavior: Python, JavaScript, PowerShell (.ps1 files) and shell scripts. A nightly script that renames log files, or the code that makes a Print button do something, is scripting.
  • Markup languages label content but run no logic. HTML labels a page's headings, paragraphs, links and buttons. XML (Extensible Markup Language) labels data.

Exam tip A Friday-only banner: HTML holds the banner, and a script checks the day and shows it. Markup can't make decisions.

Query languages

A query language asks a database to find, add or change data. The best-known one is SQL (Structured Query Language). Its keywords read almost like English:

SELECT name, price
FROM products
WHERE weight_lb < 20;

Exam tip A script might send that line to a database, but the line itself is SQL, a query language.

Assembly language

Assembly is a low-level language. Each short code, called a mnemonic, stands for one instruction of a certain CPU family. It gives exact control of the hardware, but each line does only one tiny step, so big programs are slow to write and only run on that one kind of CPU. That's why apps like a web store are written in higher-level languages.

mov  eax, 5
add  eax, 3
cmp  eax, 8

Objective 4.2 · Char; Strings; Numbers; Boolean

Data types: what kind of value is it?

Char vs. string

A char (character) holds exactly one character: a letter, a digit, a symbol or a space, like 'A'. A string holds a sequence of characters, like the product name Salmon Crunch. A shelf code like B7 is two characters, so it needs a string. Anything in quotes is text, even digits: "42" is a string, not a number.

Numbers: integers and floats

Integers are whole numbers with no decimal part, positive or negative, like 42 or -7. Use them for counts: bags in stock, boxes on a pallet. Floats (floating-point numbers) can have a decimal part, like 12.5. Use them for measured values like weight. Converting 12.5 pounds to an integer drops the .5 and leaves 12, which is how a label can end up wrong.

Exam tip Counted = integer. Measured = float. In Python, 7 / 2 gives the float 3.5.

Boolean: true or false

A Boolean has only two values: true or false. It answers yes/no questions: is the order shipped, is the box damaged? A comparison like weight > 50 gives a Boolean result. A damaged-box field that accepts typed text ends up with Y, N, yes, no and y, and reports miss boxes. A Boolean field allows only the two valid values.

Tricky cases

Pick the type by what the value means, not just how it looks:

  • ZIP code 01844: a string. As an integer it loses the leading zero and becomes 1844. You never do math with it.
  • In JavaScript, "40" + 2 prints 402: the quotes make 40 a string, so + joins text.
  • A phone number: a string, for the same reasons as a ZIP code.
  • Is the box heavy? A Boolean, even though it compares numbers.

Practice questions

Answer in your head, then open the answer. Ranger’s First Byte has 455 questions like these for Tech+, with mock exams.

Question 1Theo builds the online kibble store's pages with HTML, which labels headings, paragraphs and links. Which language category is HTML?

  1. An assembly language
  2. A markup language
  3. A query language
  4. A compiled programming language
Show the answer

Answer: B. A markup language

HTML (HyperText Markup Language) is a markup language: its tags label what each part of the content is, like a heading or a link. A query language such as SQL asks a database for data instead.

Question 2Which category of language was designed for asking a database to find, add or change data?

  1. An assembly language
  2. A query language
  3. A markup language
  4. A scripting language
Show the answer

Answer: B. A query language

A query language, like SQL (Structured Query Language), was built to retrieve, add and update data in a database. A scripting language can automate many jobs, but it was not designed around database requests.

Question 3What does it mean when a programming language is compiled?

  1. Its code is translated into machine code before the program runs
  2. Its code is read and run line by line while the program runs
  3. Its code only labels and arranges content on a page
  4. Its code asks a database to return the records that match a search
Show the answer

Answer: A. Its code is translated into machine code before the program runs

A compiled language is translated ahead of time, by a compiler, into machine code the computer can run, often an .exe file on Windows. Reading and running code line by line as the program runs describes an interpreted language.

Question 4Which language category uses short codes called mnemonics, where each line stands for one instruction of a specific CPU?

  1. Query language
  2. Assembly language
  3. Scripting language
  4. Markup language
Show the answer

Answer: B. Assembly language

Assembly language is low level: each mnemonic, like mov or add, stands for one machine instruction of a certain CPU family. A scripting language is high level, so one line can do far more and is not tied to one CPU.

Question 5Sam wants a small file that renames the warehouse scanner logs every night on a Windows server. It should run as plain text commands, with no build step. Which kind of language fits this job best?

  1. A scripting language
  2. A query language
  3. An assembly language
  4. A markup language
Show the answer

Answer: A. A scripting language

Scripting languages automate everyday tasks like renaming files. A PowerShell script, for example, is a plain text .ps1 file of commands that runs without being compiled first. A query language works with database data, not files in a folder.

Practice it in Ranger’s First ByteThe same lessons as a story, with drills, hands-on labs and mock exams. Free, in your browser.
Play free

CompTIA, Tech+, A+, Network+, Security+ and Linux+ are trademarks of CompTIA, Inc. Ranger Gamez is not affiliated with or endorsed by CompTIA. The practice questions are written to the published exam objectives; they are not real exam questions.