One of the more fundamental concepts to uderstand in programming is in finding the maximum or minumum in an array. Suppose you want to find the largest number in an array. Keep a candidate for the maximum. If you find an element with a larger value, then replace the candidate with that value. When you have reached the end of the array list, you have found the maximum. There is just one problem. When you visit the beginning of the array, you don’t yet have a candidate for the maximum. One way to overcome that is to set the candidate to the starting element of the array and start the comparison with the next element.
1 2 3 4 5 6 7 8 9 10 11 | //creating an array with 5 numbers int[] numbers = {1, 3, 5, 7, 9}; //creating a variable and setting it to array position 0 int largestYet = numbers[0] //looping through the rest of the array to find maximum num for(int i = 0; i < numbers.lenght; i++) { int a = numbers[i]; if(a > largestYet) largestYet = a; } |
Inheritance: is a mechanism for enhancing existing classes. If you need to implement a new class and a class representing a more general concept is already available, then the new class can inherit from the existing class. For example , suppose you need to define a class SavingsAccount to model an account that pays a fixed interest rate on deposit. You already have a class BankAccount, and a savings account is a special case of a bank account. In this case, it makes sense to use the language construct of inheritance. Here’s the syntax for the class definition. Read the rest of this entry »
Since this days I’m spending lots of time doing programming in Java, I decided to make this page as a central repository of the more basic concepts in Java programming language that I will be updating over time.
Q: What is an object?
A: Objects are entities in your program that you manipulate by calling methods.
Q: What is a class?
A: A class defines the methods that you can apply to an object.
Q:What is a method?
A: A Java method is a set of Java statements which can be included inside a Java class.
Q: What is a constructor?
A: The process of creating a new object is called a construction. Read the rest of this entry »
Here’s a little Java program that calculates the Acceptable Dating Age Range, based on this comics http://www.xkcd.com/314/ which basically says that as you get olderĀ the dateable age range gets wider based on this formula DateableRange = ( Age/2 ) + 7
Java Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | package testproject; /** * * @author jorge */ import java.util.*; public class DatingRange { public static void main(String[] args) { // TODO code application logic here Scanner Age = new Scanner (System.in); //asking the user for age System.out.println("How old are you?"); int UserAge = Age.nextInt(); //calculating acceptable range int AcceptableRange = (UserAge/2)+ 7; //calculating Difference int Diff = UserAge - AcceptableRange; //calculating the oldest you can date int oldest = UserAge + Diff; //output information to user System.out.println("You are "+UserAge+" years old!"); System.out.println("The youngest you can date is "+AcceptableRange+" years old!"); System.out.println("The oldest you can date is "+oldest+" years old!"); } } |
In the process of making the “pwn3d zite” I wanted to add a search capability to the site, so that led me to create this very simple tutorial that covers how to make a PHP search engine for your site. Search engines can range from very simple (the one we’re about to do) or something a bit more complex like [Google]. This tutorial assumes that all the data you want to search resides in a MYSQL database. I should say that there are tons of way on how you could build a search engine, but like the title implies this is the basics on how you could do it, and something you could build on…so lets get started Read the rest of this entry »
I recently posted a hacker challenge that consisted in a vulnerable login form, and specifically the vulnerabilities was found in the way the cookie was set, well for this tutorial I’ve decided to do a basic introduction to the mechanics of login forms and cookies in php using mysql as the database backend. On the application side, you can use cookies in you PHP scripts to control access to certain areas of your web site. A cookie is a small amount of data stored by the user’s browser in compliance with a request from a server or script. A host can request that up to 20 cookies be stored by a user’s browser. Read the rest of this entry »