Archive for the ‘Java’ Category
Leonardo Fibonacci was a talented Italian mathematician. He is best known for a number sequence named after him known as the Fibonacci Numbers.
These numbers take the following pattern:
0, 1, 1, 2, 3, 5, 8, 13, 21 …
The series is formed by adding two numbers in the series to generate the third.
The Rabbit Puzzle that Fibonacci investigated in the year 1202 is a great example to introduce you to the significance of the Fibonacci number series. Read the rest of this entry »
First Fit algorithm is used to allocate jobs in the memory in arbitrary order. I will only explain it briefly assuming you wouldn’t be interested in the code unless you know what this algorithm is all about. It works by placing each job in the first memory block that can accommodate it (memory block is equal to or larger than job size).
Read the rest of this entry »
Few days ago I published (here) an applet to encrypt/decrypt Caesar’s cipher. An issue I faced was that an applet must be signed to access windows clipboard. However, a page with a singed applet welcomes you with a security warning! which I so want to avoid on my site. I think that visitors to my blog should not be asked to deal with security messages from their system. The problem now is that users can not copy/paste text from and to the applet unless they run it on their local machines. As such, I thought the applet is functional and can be tested online and if any user require to copy/paste text (s)he may download the applet’s jar file and execute it locally whenever they want. Running the applet on your local machine does not include security restrictions on the code.
To create an executable a jar file there should be a main class (a class with a main method) inside the jar to run the software. An applet has no main method since it is usually designed to work inside a web browser. To make the jar file executable I had to do two things:
- One
I created a new class inside the jar file as a main class which I called StartClass. The job of this class is to call and host the applet; hence if the jar file is executed, the applet method is invoked. Check out the following code that I used supported by few comments to explain what it does.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | package CaesarCodePackage; public class StartClass { public static void main(String [] args) { // create an object of type CaesarCode which is the main applet class CaesarCode theApplet = new CaesarCode(); theApplet.init(); // invoke the applet's init() method theApplet.start(); // starts the applet // Create a window (JFrame) and make applet the content pane. javax.swing.JFrame window = new javax.swing.JFrame("Caesar's Cipher"); window.setContentPane(theApplet); window.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE); window.pack(); // Arrange the components. window.setVisible(true); // Make the window visible. } } |
- Two
I had to edit the MANIFEST.MF file and add the following line to define my main class correctly
Read the rest of this entry »
In cryptography, Caesar cipher is one of the simplest encryption techniques. It is a substitution cipher in which each letter in the plaintext is replaced by a letter after a fixed number of positions down the alphabet. However, this applet shifts each character (letter, number of symbol) after a number of positions down the ASCII table. Caesar’s cipher is categorised as a symmetric encryption and the secret key in this case is the number of shifts!
- To encrypt, select the encode mode, number of shifts and click Run.
- You may encode a message multiple times.
- To Decrypt, select the Read the rest of this entry »

