How Do You Troubleshoot “/usr/bin/java no such file or directory”?

Problem scenario
You run java commands but you get the error “/usr/bin/java no such file or directory.” What should you do?

Possible Solution #1
Reinstall Java.

Possible Solution #2
You may have deleted a linked file. To find the destination file, run this:

sudo find / -name java -type f

Based on the results,

What is the Difference between a Bottom-Up Approach and a Top-Down Approach in Computer Programming?

Problem scenario
You have heard of bottom-up programming and top-down programming. How are the two types different?

Solution
A bottom-up programming approach involves composing small sub-solutions into a bigger whole solution. There is an integration of components to make a whole with bottom-up programming. This method can be difficult to create the final, coherent product.

A top-down programming approach involves decomposing a big problem into smaller fragments.

Do “if x in dic” Statements Look at Keys or Values in Python Dictionaries?

Problem scenario
In Python if you test if a value is in a dictionary, does it look at the keys, the values, or both?

For example, you have code like this:

good_kv = {}
good_kv[”a”] = 1
good_kv[”b”] = 2
good_kv[”c”] = 3

if “b” in good_kv:
print(“The value is in the dictionary!”)
else:
print(“The value is not in the dictionary!”)

print (“testing keys of dictionary above and values of dictionaries below”)

if 3 in good_kv:
print(“The value is in the dictionary!”)
else:
print(“The value is not in the dictionary!”)

Do dictionaries keys,

In Python when Source Code is Used to Create Byte Code, what is the Intermediate Content?

Problem scenario
Python can compile source code. There is a process that happens. What form does the code take in the interim (before byte code is created)?

Solution
Abstract Syntax Tree (according to page 175 of Expert Python Programming by Jaworski and Ziade). There is an ast module that allows you to interact with the Abstract Syntax Tree via its grammar.

Why Cannot You Browse to a URL Path with a File Name in a Web Browser when the index.html File is Available?

Problem scenario
You know foobar.html is in a directory on a web server that houses index.html. You cannot go to foobar.html in a web browser — but you can go to index.html. How do you fix this?

Possible solution #1
Are the permissions of foobar.html different from index.html? Is there a slight spelling error in the file name on the back-end?

Using Python How Do You Print Log Entries for a Given Time Range?

Problem scenario
Using Python, you want to parse a log file. You want to print out entries that have a datetime stamp that are within 24 hours of a given date.

The log file is in this format:

Sep 18 07:28:11 server1 sshd[29284]: Received disconnect from 115.52.17.109 port 46970:11: Bye Bye [preauth]
Sep 18 07:28:11 server1 sshd[29284]: Disconnected from 115.52.17.109 port 46970 [preauth]
Sep 18 07:28:11 server1 sshd[29282]: Failed password for root from 51.10.7.109 port 24844 ssh2
Sep 18 07:28:13 server1 sshd[29287]: pam_unix(sshd:auth): authentication failure; …

What Is The Space Complexity when There Are Two Variables in a Program?

Question
You have a program with two (or three) variables, but no other data structures. What is the space complexity?

Answer
O(1). An algorithm, as long as the number of variables is fixed, can have 1,000 variables and be said to have O(1) space complexity. The source is here:

https://stackoverflow.com/questions/43260889/what-is-o1-space-complexity …

How Do You Set a Date-Time Value with a Default Year in Python?

Problem scenario
You are printing out some dates with a Python program. You are using the datetime module and the strptime method. The year is always defaulting to 1900 because the log entries have no year designated in them. How do you seed the dates with a specific year of your choice?

Solution
Here is an example of how to seed the dates with the year 2021 (but it assumes you have a file name auth.log with dates without years in it):

import datetime
from datetime import datetime, …

How Do You Troubleshoot the Python Problem “ValueError: time data … does not match %m”?

Problem scenario
You are trying to parse a log file with Python. The date entries use abbreviated spellings of months — not integer month values. You get an error like this:

“ValueError: time data ‘Jul 15 06:10:32’ does not match format ‘%m %d %H:%M:%S'”

What should you do?

Solution
Replace the “%m” with “%b”.

import datetime
log_reader = open(‘auth.log’, …