Monday, November 16, 2015

Tomecat v7.0 Server, Eclipse, and Ubuntu. Server Name is blank when defining a new server

Problem: 
Tomecat v7.0 Server, Eclipse, and Ubuntu. When you Define a new Server and choose tomcat v7.9, the Server host name is populated however the server name is blank. It is expected to be something like "Tomecat v7.0 Server at localhost"

Solution:
  1. Close Eclipse
  2. In {workspace-directory}/.metadata/.plugins/org.eclipse.core.runtime/.settings. delete the following:
    • org.eclipse.wst.server.core.prefs
    • org.eclipse.jst.server.tomcat.core.prefs
  3. Restart Eclipse
Source (thanks whoever wrote the solution):
http://crunchify.com/eclipse-how-to-fix-installing-apache-tomcat-server-issue-blank-server-name-field/

Sunday, November 8, 2015

Very simple Java String methods: "Split String" and "Capitalize the First Letter "

// Some common simple Java String methods: "Split String" and "Capitalize the First Letter " 

// Split Strings, just like the String split method, but it removes all white spaces.
// I expect a million other implementation of this, but this does the job as well.
public static String[] splitString(String text, String splitChar){
String [] list = text.split(splitChar);

for (int i=0; i<list.length; i++){
list[i] = list[i].trim();
}
return list;
}

// Capitalize the First Letter of the passed in String s
public static String capitalizeFirstLetter(String s){
String result = null;

if (s != null){
if (s.length() >1)
result = s.substring(0, 1).toUpperCase() + s.substring(1, s.length());
else
result = s.toUpperCase();
}
return result;
}

Sunday, October 25, 2015

Simple Java Serialization

// this is a very simple example of java serialization example
//Serializations: Assume this is my class to be serialized
import java.util.ArrayList;

public class Dish {
private String dishName;
private ArrayList<String> ingredient;

public String getDishName(){
return this.className;
}
public ArrayList<String> getIngredient(){
return this.variableNames;
}
public void setDishName(String dishName){
this.dishName = dishName;
}
public void setIngredient(ArrayList<String> ingredient){
this.ingredient = ingredient;
}
}

// This class will read and write. I reused the one found here which is awesome.
// Thanks Awesome person who did this
import java.beans.XMLDecoder;
import java.beans.XMLEncoder;
public class Builder {
    public static void writeXML(Schema f, String filename) throws Exception{
        XMLEncoder encoder =
           new XMLEncoder(
              new BufferedOutputStream(
                new FileOutputStream(filename)));
        encoder.writeObject(f);
        encoder.close();
    }

    public static Schema readXML(String filename) throws Exception {
        XMLDecoder decoder =
            new XMLDecoder(new BufferedInputStream(
                new FileInputStream(filename)));
        Schema o = (Schema)decoder.readObject();
        decoder.close();
        return o;
    }
}

// This is a class using both
public class Food {
    public static void main(String[] args) {
        String filename = "/home/...../Dishes.xml";
        String name = "Pizza";
        ArrayList<String>  ingredients= new ArrayList<String>();
        vars.add("dough");
        vars.add("cheese");
        vars.add("sauce");

        Schema s = new Schema();
        s.setDishName(name);
        s.setIngredient(ingredients);

         try { Builder.writeXML(s, filename);  }
            catch (Exception ex){ System.out.println(ex); }
         try {
         Schema s2 = Builder.readXML(filename);
         System.out.println(s2.getDishName());
         System.out.println(s2.getIngredient().toString());
         } catch (Exception ex){ System.out.println(ex); }
    }

}//Food


// Java read from a file and return the string
public static String readFile(String fileName){

try (BufferedReader reader = new BufferedReader(new FileReader(fileName))) {

String content = "";

String line = null;
   while ((line = reader.readLine()) != null) {
       content = content + line;
   }
   reader.close();
 
   return content;
 
} catch (IOException x) {
   System.err.format("IOException: %s%n", x);
   return null;
}

}

Tuesday, June 19, 2012

Google Master Search terms

-- Search on specific site
site: websiteNameHere yourTextHere
-- Related word; Synonyms
~yourTextHere
-- Exact words
"yourWordHere"
-- Exclude term
-yourWordHere
-- Between two dates
2008..2010 yourTextHere
-- File type search
filetype:PDF yourTextHere
-- Show results with the word in title
intitle:yourTextHere
-- * Will be replaced with other words common with the searched term
*yourTextHere
yourTextHere*PartTextHere*OtherPartTextHere
-- Search for papers with specific author
author:AutherNameHere
-- Definition
define: yourWordHere
-- Calculator
2*2
(3/2)*100
-- Unit converter
10 KM in Miles
-- research, use: http://www.jstor.org/

Tuesday, June 5, 2012

Floating-point errors. They cannot precisely represent all real numbers. Here is an example.


"Floating-point numbers cannot precisely represent all real numbers, and that floating-point operations cannot precisely represent true arithmetic operations, leads to many surprising situations. This is related to the finite precision with which computers generally represent numbers." (From Wiki)

Read more about my example here.
http://majedline.blogspot.ca/2012/06/floating-point-errors-they-cannot.html