Wednesday, August 10, 2016

Update Ubuntu 14.04 to 16.04. Unity / OS menu is not loading.

If you are an Ubuntu fan and have recently updated from 14.04 to 16.04, you may run into a situation once you are done. "WHERE ARE MY MENUS?". If you don't see the menus of the OS (i.e. icons on left side aka unity), then don't panic! Do the following:

1- Right click
2- Open Terminal
3- Type the following:
dconf reset -f /org/compiz/
setsid unity


And you are done!! Life can go back to normal now...ish

Source (Thank you O master of askubuntu.com under the following link):
http://askubuntu.com/questions/761035/ubuntu-16-04-no-menu-bar-or-launcher-help

Monday, November 16, 2015

Deploy Servlets on Eclipse on Ubuntu - links to help.

How to deploy Servlets via Eclipse on Ubuntu -- start here
http://www.codejava.net/ides/eclipse/how-to-create-deploy-and-run-java-servlet-in-eclipse

If you run into problems then go here -- (I was using tomcat v7.0)
http://stackoverflow.com/questions/13423593/eclipse-4-2-juno-cannot-create-a-server-using-the-selected-type-in-tomcat-7

Last, if you have permissions preventing you to run the web application, close the eclipse and run it as admin. it will by-pass some of the restrictions with deployments. In the eclipse application directory, type:  sudo ./eclipse and it will run as admin.

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;
}

}