Posts

Showing posts with the label java

Prime Numbers Generator

Image
did u know that 34136029 is a prime number?!! well.. that's what i recently realized :) I thought of writing a piece of code for that purpose.. wondering how far i can get. The idea of the code is simple We know that 2 and 3 are prime numbers the code checks every following odd numbers to be prime or not. To verify a prime number, the number divisibility by the prime numbers generated so far is checked. (29 is a prime number.. because it id not divisible by 2, 3, 5, 7, 11, 13, 17, 19 nor 23) We only need to verify divisibility against the numbers smaller than or equal to the root of the number in hand. (We needn't check the divisibility of 33 with 11, as we already must have found out it is divisible by 3).. I did not want to go with the mathematical root evaluation as i am not sure about its load. I used bits handling instead. the root of a number uses at most half of the number of bits that the original number uses. i only made a naive java implementation so far. downloa...

Using maven with eclipse

As i first started using maven for my projects, I used to add the maven plugin to eclipse. The plugin makes you able to mark a project as "maven enabled". This adds the library maven dependencies to the classpath of the project so the dependency libraries can be visible to your classes. As i moved further, I found a better way dealing with maven projects using eclipse; maven eclipse:clean and eclipse:eclipse goals. the goals enables you to make all the configuration and settings through command line which is more powerful and stable. Actually i now never created a new project inside eclipse. It is better to created it outside using maven. Then through eclipse:eclipse u create eclipse project settings files that is ready to be imported to any running eclipse instance. M2_REPO variable that points to the local maven repository. The pretty thing is that you can add that variable to an eclipse workspace through mvn -Declipse.workspace={workspace-path} eclipse:add-maven-re...

One template file for all pages using Servlets and JSP

Image
One of my recent tasks was making a new skin for one of our websites. the site had a common header, left side area and right side area that are to be shared among all pages. we used to include file for "header", "left side", "right side" in each of the pages.. it wasn't that pretty i know. I wanted to think of something better where i can define the template in exactly one file and i do not have to include that file on every new page i add. something pretty much close the RubyOnRails " ' directive to import the page content inside the template. i finally managed to do it. I'll use two simple pages to illustrate the concept: mahmoud.jsp and index.jsp what we want is to have each of the two pages displayed in a layout where is one header, banners and so. which will look like the following. I was able to do this using a servlet that intercepts the request. and loads the template jsp file and pass the desired page to as a parameter to be inclu...

Effective Java Programming

Effective Java Programming, by Addison Wesley, is one of nice books i have read in software development material. and i recommend it to any developer developing in Java, starter or senior. programming by nature is very flexible. you have many choices. it is like creating a statue using clay. You choose at every point; Class names, methods and variable names. public methods, internal implementation algorithms, structure of the package classes,.. all of those and others are left for the programmer to choose. Effective Java programming comes to introduce a lot of the best practices for Java programmers; to enhance the stability, readability, clarity, reusability and maintainability of their code. it also has guides to the proper use of a lot of the java standard classes. A note inside the book really draw my attention; in item 8, chapter 3, Wesley was talking about overriding the hashCode method, he stated an example of a phone number class and an implementation of a suggested hashCode, ...