Schedule A Java Program Windows 7 – Windows 7 Cron Job

Recently I wrote a Java program to clean up a directory on my Windows 7 machine. I wanted this java program to run each day at 5pm. Here is how I scheduled it to do so.

1 – Compiled my java program into a jar file named “FileArchiver.jar”

2 – Created a batch file with the command which runs my program. Creating a batch file is as simple as opening notepad and saving the file with a “.bat” extension. The contents of my batch file, which is named “archive.bat”, consisted entirely of the following line:

java -jar “C:\GlenIris\NetBeansProjects\FileArchiver\dist\FileArchiver.jar” C:\\GlenIris\\NetBeansProjects\\FileArchiver\\properties\\securecam.properties

I then tested that the batch file ran my program by double clicking on it. It did.

3 – Schedule the task to run every day at 5. I did this by opening Windows Task Scheduler like so:

Start>>All Programs>>Accessories>>System Tools>>Task Scheduler

On the right hand side, click ‘create task’.

Select ‘Start a program’ from the action dropdown. In the text field, type the path to the bat file. eg:

C:\GlenIris\archive.bat

Each option in each of the other tabs is now self explanatory.

A divil for scheduling tasks on Windows Machines was Stefan Schwarz

A divil for scheduling tasks on Windows Machines was Stefan Schwarz

 

Advertisements

Software Engineer Interview Guide

After almost 5 years as some class of Software Engineer (titles ranged from Associate Software Engineer to Software Engineer to Web Support Engineer to Senior Consultant and back to Software Engineer), having moved companies a number of times, I have realised that the job interview process for technical jobs is broadly the same.

For each interview I have done, both successfully and unsuccessfully, I had to put in a certain amount of preperation. I usually put together a dossier on each position I apply for based on the following information.

Do Your Homework on The Company

  • Why do you want to work for them?
  • Why are you leaving your current position?
  • Who are their competitors?
  • If you get a name for your interviewer, look them up on Linked In to see their area of interest. This may tip you off as to what they are likely to ask about.
  • Have 3 – 4 good questions ready for the interviewer. The goal here should be to genuinely learn something as opposed to just ticking the box of asking a question A bad example of this is –   “What is your favourite thing about working here at X”. A good example is “I noticed that you mentioned that you use Technology X to achieve goal A, I find this interesting as previously I had never heard of that, in my experience I would have used Technology Y to achieve goal A. Can you tell me why using technology X suits you better?” To reiterate, show that you are not afraid to chat about technical topics rather than just asking a question for the sake of it.

Understand Why You Want THIS Job

Look, ideally we would all play professionally for Arsenal and only use computers to place job adverts on line for pool cleaners / drivers. However, the squad is full so we need to get employed elsewhere.

If you are applying for the job as it is a job for which you are qualified fair enough, but you will stand a much better chance of being employed if you actually want the job.

What I mean is that the job is the best fit for you. ie, the job involves the technologies with which you are most interested and to a lesser extent, skilled in. The job will offer you the chance to work in an environment and culture which will allow you to meet your career goals – weather that is to stay at a junior level all your life or to progress to the highest levels of management before you are 30.

Have this clear in your own head before you are expected to make it clear in the interviewers head.

Common Interview Running Order

In my experience, it is common to be interviewed by the Human Resources department, the potential manager and a potential team member (skill level similar to you). They will all probably allow you to ask questions at the end f their individual sessions. If in session 1, all of your questions were genuinely answered, dont just say “no” when session two asks you if you have any questions. A better response is “well I did want to find out more about X but Jimmy Five Bellies answered that question for me in the last session”.

  • The HR interview tries to see how you are as a person. They will want to judge you on actual experiences of your career and life and how you reacted to them. They would rather specific examples of a time when you did X as opposed to what would you do if X happened? Past behaviour is the best predictor of future behaviour.
  • The manager interview likes to hear of your work experience. He / She may even get technical but if they do it will probaly be at a high level. For example, what web servers have you used as opposed to which Java Collection is best for storing an ordered list of objects.
  • The peer will ask technical questions and may even present you with a whiteboard and ask you to give an overview of a system which you have worked on in the past. This task has numerous purposes:
  1. Test your communication skills. Can you explain a technical problem. This is a common ask for a software engineer. How are you supposed to work through technical problems with team members if you cannot describe issues?
  2. Test your overall understanding of the system which you worked on. Did you know the architecture or were you just concerned with the little piece which you had responsibility for?
  3. Technical knowledge. This diagram will offer the interviewer the chance to ask specific questions on single parts of your system. They will probably focus on their area of expertise. For example, if your diagram includes a database and the interviewer is a database administrator, they may ask you about normalisation, choice of database (MySQL, Oracle, SQL), database performance etc.

Common Interview Questions Which I have Encountered

  • Tell me about an improvement which you made to a system.
  • Have you ever been given a set of requirements which you didnt understand, if so, how did you go about completing the assignment.
  • Have you ever worked with somebody who held the team back, or with whom you had a personality clash, if so, what happened in this situation.
  • How do you manage tight deadlines.
  • Where do you see your career going?
  • Describe your ideal colleague.
  • How do you feel about mentoring?
  • What motivates you?
  • What does success mean to you?
  • Have you ever made a mistake that impacted a live system?
  • Describe how the software model which you used in your last job.
  • Describe the last project you worked on to a person with no technical experience beyond checking their email and surfing the net.
  • How would you improve the performance of a system which uses a database?
  • How would you get two machines to communicate with each other?

Dont try and fudge answers. If you dont know ,say “I am not sure but if I was to guess I would say…”.

Summary

  • Prepare and practice drawing block diargams of a system which you previously worked on.
  • Be clear why you want the job.
  • Be clear what the position is.
  • Be clear who the company are and what they do.
  • Know your resume and what it claims inside out, for example, if you only used Apache Ant once, dont list it as a skill on your resume.
  • Arsenal are more successful and have more class than Spurs.

More as I remember it.

Deploy the Spring application, reading from different properties files.

From the good person over at MyThinkPond, here is how I deployed the same WAR file, into the same webapps directory of Tomcat, but had it read from different properties files. The reason for my need to do this was that I wanted the application, depending on its URL (the war file name) to pick up its relevant properties file.

Therefore, I needed the app to be able to know its name.

Just like my buddy over at  MyThinkPond I created the following class with a static method to get my context:

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

public class ApplicationContextProvider implements ApplicationContextAware{
 private static ApplicationContext ctx = null;
 public static ApplicationContext getApplicationContext() {
return ctx;
 }
 public void setApplicationContext(ApplicationContext ctx) throws BeansException {
this.ctx = ctx;
 }
}

and in my spring bean configuration xml file I added the following:

 <bean id="applicationContextProvider" class="com.mydomain.myappname.ApplicationContextProvider"></bean>

and then in my classes, I was able to do the following:

ApplicationContext ctx = ApplicationContextProvider.getApplicationContext();

step-up-your-context-path

Igor Stepanovs was famous for changing his property files depending on his application name.

Running SQL file directly from command line

To run your SQL script directly from the command line:

 

1 – FTP your SQL file up to the server / machine / host

2 – cd to the SQL file location.

3 – to run the file type:

sql databaseName < yourscriptname.sql> yourScript.log

example:

sql my_database <load_table.sql> loading_log.log

Load SQL table from text file Linux command line

Recently I was required to read in a text file into an SQL database table. The pre-requisite was that the fields of the file were an even width, ie, each column was 50 characters wide even if the text filling it was less than 50 characters.

To run the below script, I ftp’d it to a directory on a linux machine. The sql database was on the same machine.

First I wrote the housekeeping function. This set up logs and took care of general good housekeeping practices.

Then I had a function create the table I required.

Then I had a function read from the text file (which just happened to be saved with a .OUT file extension.  Of course, the file which you want to read from should be in the directory as specified in the housekeeing function.

Below are the contents of the shell script. Of course, to run the script the command on linux command line was

./script_name.sh

 

 

 

housekeeping() {

work=/vectorwise/rawdata/dNiall log=$work/mydirectory/log data=$work/mydirectory/data tmp=$work/mydirectory/tmp my_database=xynt_db my_database_logfile=$log/mydirectory/my_database_sql.log FILE_DELIMITER=$

if [ ! -d $work ]; then      mkdir $work fi

if [ ! -d $log ]; then      mkdir $log fi

if [ ! -d $data ]; then      mkdir $data fi

if [ ! -d $tmp ]; then      mkdir $tmp fi

}

create_table() {

sql $my_database << !! > $my_database_logfile

drop table people \p\g

create table people (         type char(2),         name char(50),         addr1 char(50),         addr2 char(50),         addr3  char(50),         addr4 char(50) )

\p\g

CALL VECTORWISE( COMBINE ‘people-people’) \p\g !! } load_table_from_file() { sql $my_database << !! > $my_database_logfile copy people (         type = char(2),         name char(50),         addr1 char(50),         addr2 char(50),         addr3  char(50),         addr4 char(50)         nl ) from ‘$work/files/PEOPLE_FILE.OUT’ \p\g !! } #below calls the functions in order housekeeping create_table load_table_from_file

SQL select varchar substring from middle of varchar

I recently had to pull out a substring from a larger string in SQL.  The problem was that I required 7 digits from an 20 digit varchar value.

So, the id field contained:

1928P746781S3390W563

and I wanted the 7 digits from the middle of the varchar as highlighted in bold below:

1928P746781S3390W563.

 

The following SQL statement achieved this for me:

SELECT substring(id from 11 for 7) as new_id from persons.

This left me with a value of S3390W5.

SQL Update Table 1 from Table 2

In the following example, I wanted to update a persons id in table 1 to the value of the same persons id in table 2.

 

UPDATE table_1

SET id =

 ( SELECT table_2.id

FROM table_2

WHERE table_1.id = table_2.id)