blog RSS

The Programmer Blog is here to help you, the programmer. We do our best to provide useful resources that offer explanations to popular programming problems, across a variety of programming languages. If you would like to suggest a blog topic or have a question, please leave us a message.


PHP, PHP Redirect, Redirect

PHP - How to Redirect

Creating a PHP redirect allows you to redirect a user to a different page on your site. PHP redirection typically is used when you are attempting to permanently redirect the page, therefore it should return a 301 Moved Permanently response. If you are only temporarily redirecting you should use a 302 Found response. Check below for a examples of each implementation. ...

Read more

Java, random

Java - Generating random integers

While generating random int values in a specific range is fairly simple, it still requires that you understand the syntax and how to use the Java Random class. Let's take a quick look at some examples below which go over some options when generating a random number in Java depending on your Java version. Java 1.6 and older In older version of java it...

Read more

CLASSPATH, Java

Java - "Could not find or load main class" Error

One of the most frequently encountered errors when learning Java programming is the "Could not find or load main class" error. Before we dive into understanding the cause of the error, it's first important to understand how to launch a program using the java command. The "Could not find or load main class" error can be caused by many things, let's start with the basics...

Read more

python

Python - Reading a file line-by-line into a list

A common question asked when programming with Python is How do I read every line of a file in Python and store each line as an element in a list? Below we will go over an example to show you how to read the file and append each line to the end of a list. Reading a small file into a...

Read more

python, python external command, shell command, STDIN, STDOUT

Python - Call an External Command

Learning how to run an external command from inside python is fairly straightforward. Python supports several methods for calling an external command. Determining which method to use depends on the use case, view our examples below of calling an external command. Use subprocess.call() The recommended way to execute an external command in Python is by using the subprocess module. The example below uses the call() method to invoke...

Read more