Tags: java

Sort by: Date / Title /

  1. 6 months ago by jemini_fr
    1. ArrayList<Object> list = new ArrayList<Object>();
    2. ...
    3. //tri
    4. Collections.sort(list, new Comparator(){
    5.     public int compare(Object o1, Object o2) {
    6.        return o1.compareTo(o2);
    7.     }
    8. });
    9.  
    10. Ecrire la fonction compareTo() pour l'objet de la liste. Elle doit renvoyer 0 si les 2 objets sont égaux, <0 si o1 < o2 et >0 si o1>o2.
  2. 6 months ago by haduart
    With this function we can save a serialized class into a MySQL's table.
    1. /**
    2.           * Actualitza l'objecte serialitzat (scorm_structure) de
    3.           * l'usuari amb l'identificador indicat.
    4.           *
    5.           * Nota! Fa un update, per tant ha d'existir l'usuari!
    6.           *
    7.           * @param courseStudentName : El nom de la taula en que ho guardem.
    8.           * @param studentId : L'identificador de l'usuari.(int Type)
    9.           * @param object : Retornarà l'UserObjective, caldrà fer un cast.
    10.           * @return int Type: Retornarà l'identificador del resultset.
    11.           * @throws Exception : Llança una excepció si hi ha un error.
    12.           */
    13.         private int writeJavaObject(
    14.                         final String courseStudentName,
    15.                         final int studentId,
    16.                         final Object object)
    17.          throws Exception {          
    18.                 String sqlUpdateScormStructure =
    19.                         "UPDATE " + courseStudentName
    20.                         + " set scorm_structure = ? WHERE student_id = ?";
    21.                 /** We already have
    22.                   * private Connection conn = DriverManager.getConnection(url, userName, password);
    23.                   */
    24.                 PreparedStatement pstmt =
    25.                         conn.prepareStatement(sqlUpdateScormStructure);
    26.                
    27.                 ByteArrayOutputStream baos = new ByteArrayOutputStream();
    28.                 ObjectOutputStream oout = new ObjectOutputStream(baos);
    29.                 oout.writeObject(object); //serializing
    30.                     
    31.                 // set input parameters
    32.                 pstmt.setBytes(1, baos.toByteArray());        
    33.                 pstmt.setInt(2, studentId);
    34.                 pstmt.executeUpdate();
    35.  
    36.                 // get the generated key for the id
    37.                 ResultSet rs = pstmt.getGeneratedKeys();
    38.                 int id = -1;
    39.                 if (rs.next()) {
    40.                         id = rs.getInt(1);
    41.                 }
    42.                
    43.                 rs.close();
    44.                 pstmt.close();
    45.                 return id;
    46.         }
  3. 7 months ago by haduart
    I'm not loading a .jar library, I'm only loading a .class, which implements my library functions. To test this code you must have in the directory D:\LoadLibrary a TestHelloWorld.class and the interface TestString WITH THE SAME package that you have in the main code. It means that if your TestString in your main code is com.haduart.TestString you must put your TestString.class in the D:\LoadLibrary\com\haduart\TestString.class.
    1. /**
    2. * In the D:/LoadLibrary we must have .class and the same interface (TestString) with the same pacakge as the
    3. * main program.
    4. */
    5. URL urlToJar = new URL("file://D:/LoadLibrary/");
    6. URLClassLoader cl = new URLClassLoader(new URL[] { urlToJar });
    7.                
    8. System.out.println("loading...");
    9. Class c2 = cl.loadClass("TestHelloWorld");
    10. System.out.println("loaded!");
    11. Object nouObject = c2.newInstance();
    12.  
    13. TestString ts = (TestString) cons.newInstance(args);
    14. /**
    15. * Now we can use the "ts" object as a normal TestString interface. No matter which is the implementation that is begin it.
    16. */
    17. System.out.println("S1: " + ts.printS1());
    18. System.out.println("S2: " + ts.printS2());
  4. 8 months ago by bobuse
    1. echo "swing.defaultlaf=com.sun.java.swing.plaf.gtk.GTKLookAndFeel" | sudo tee /usr/lib/jvm/java-6-sun/lib/swing.properties
  5. 9 months ago by sebclick
    Vim peut indenter automatiquement du code source (c, java, ...)
    
    Sélectionner la partie du code source à traiter en mode visuel (v)
    Appuyer sur la touche =

First / Previous / Next / Last / Page 1 of 1 (5 posteets)