Learning Java 4 – Swing, SQL, and Security API

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

0 comments

Post a comment

    Post a comment
    Embed Video
    Edit your comment Cancel

    Favorites, Groups & Events

    Learning Java 4 – Swing, SQL, and Security API - Presentation Transcript

    1. Learning Java 4: Swing, SQL, Security Christopher Swenson Center for Information Security University of Tulsa 600 S. College Ave Tulsa, OK 74104
    2. Overview
      • SQL
      • Security API
      • Swing
    3. SQL
      • Load a runtime driver for the database you want to connect to
        • Class.forName(“com.microsoft.jdbc.sqlserver.SQLServerDriver”)
        • Make sure that the class is in your ClassPath
      • java.sql.DriverManager.getConnection()
        • Pass it a URL, name and password to connect
      • Get a Statement object from the connection
        • Use this to execute queries and updates
      • Tons of Exception s: catch them all
    4. Code
      • Class.forName(“com.microsoft.jdbc.sqlserver.SQLServerDriver”)
      • Connection conn = java.sql.DriverManager.getConnection(“jdbc:microsoft:sqlserver://127.0.0.1:1433”, “sa”, “123”);
      • Statement stmt = conn.createStatement();
    5. Queries / Updates
      • Use the Connection methods execQuery(“…”) and execUpdate(“…”)
        • Return ResultSet object
      • Queries – SELECT
        • rs.next() – moves one row down to the next object and returns true, or returns false when you are out of rows
        • rs.getObject(int i) – gets the object in the specified column number
          • i starts at 1
          • Often, columns must be accessed IN ORDER (can’t go back)
      • Updates
        • INSERT, DELETE, UPDATE
        • Returns number of rows affected
    6. Code
      • ResultSet rs = stmt.executeQuery(“select name from person”);
      • while (rs.next())
      • {
      • System.out.println(rs.getObject(1));
      • }
    7. Security API
      • Cryptography architecture, provided by Cryptographic Services
      • Message digest, digital signatures, key generation and management, encryption, decryption
      • java.security, javax.crypto
      • http://java.sun.com/j2se/1.5.0/docs/guide/security/CryptoSpec.html
    8. Digest Example
      • MessageDigest sha = MessageDigest.getInstance("SHA-1");
      • sha.update(i1); sha.update(i2); sha.update(i3); byte[] hash = sha.digest();
    9. Digest Types
      • MD2
      • MD5
      • SHA-1
      • SHA-256
      • SHA-384
      • SHA-512
    10. Cipher Example
      • KeyGenerator keygen = KeyGenerator.getInstance("DES");
      • SecretKey desKey = keygen.generateKey();
      • Cipher desCipher = Cipher.getInstance("DES/ECB/PKCS5Padding");
      • desCipher.init(Cipher.ENCRYPT_MODE, desKey);
      • byte[] cleartext = "This is just an example".getBytes();
      • byte[] ciphertext = desCipher.doFinal(cleartext);
      • desCipher.init(Cipher.DECRYPT_MODE, desKey);
      • byte[] cleartext1 = desCipher.doFinal(ciphertext);
    11. Cipher Types
      • Algorithms
        • AES
        • RC2/RC4/RC5
        • RSA – actually, PKCS #1
        • DES
        • DESede
      • Modes
        • NONE
        • CBC
        • CFB
        • ECB
        • OFB
        • PCBC
      • Padding
        • NoPadding
        • PKCS5Padding
    12. RSA
      • Will need Bouncy Castle provider
      • KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA");
      • keyGen.initialize(1024);
      • KeyPair key = keyGen.generateKeyPair();
      • Cipher cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding");
      • cipher.init(Cipher.ENCRYPT_MODE, key.getPublic());
      • byte[] cipherText = cipher.doFinal(plainText);
      • cipher.init(Cipher.DECRYPT_MODE, key.getPrivate());
      • byte[] newPlainText = cipher.doFinal(cipherText);
    13. Swing
      • Swing is a platform-independent GUI-building kit
        • javax.swing
      • Very easy to use
        • Most constructs are simple
      • Clean for most uses
      • Event-driven
      • Based on the AWT, the original GUI package for Java
        • java.awt
    14. JFrame
      • JFrame is the basic class
        • Creates a window
        • Extend it, and override the constructor
        • Make a new JFrame, add stuff to it
        • Starts out invisible by default
      • JFrame f = new JFrame(“Title here”);
      • f.setVisible(true);
    15. Close Window
      • Closing the window should exit your program, right?
        • Use “actions” to do this
        • Also for keystrokes, mouse clicks
      • WindowAdapter is a skeleton class to capture Window actions (like, clicking the close button)
      • Catches ActionEvent s, and figures out what to do with them
      • Also InputEvent s
    16. Example
      • JFrame f = new JFrame(“Test”);
      • f.setVisible(true);
      • f.addWindowListener(new WindowAdapter()
      • {
      • public void windowClosing(WindowEvent we)
      • {
      • System.exit(0);
      • }
      • });
    17. Let’s add stuff
      • Some basic classes to mess with
        • Most everything subclasses JComponent
      • JLabel
        • Text (can use simple HTML, like <b>text</b>)
      • JTextField
        • An line of text input
      • JButton
        • A clickable button
        • Anything implementing AbstractButton is “clickable”
        • JRadioButton – set a group with ButtonGroup
      • JProgressBar
    18. Adding objects
      • Pre-Java 1.5
        • Container c = frame.getContentPane();
        • c.add(new JLabel(“Text”));
      • Now, just frame.add(…)
      • By default, uses an empty FlowLayout
        • Change the Layout via setLayout(…)
        • BorderLayout, BoxLayout, CardLayout, FlowLayout, GridBagLayout, GridLayout, SpringLayout
    19. Layouts
    20. Menus
      • JMenuBar is the bar at the top (setJMenuBar)
        • Add JMenus, which have JMenuItems
        • addMenuListener to catch stuff
          • menuCanceled
          • menuDeselected
          • menuSelected
    21. Panes
      • JPanel – create a new container to work with
        • A sub-frame
      • Allow you to do more complicated things
        • JTabbedPane – tabs
      • Most JComponent extended objects can have borders added
        • setBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED, Color.GRAY, Color.WHITE))
        • setBorder(BorderFactory.createTitledBorder(“Stuff&quot;));
    22. Extra tips for Swing
      • UIManager.setLookAndFeel(&quot;com.sun.java.swing.plaf.windows.WindowsLookAndFeel&quot;);
        • Makes things more native looking
      • GridBagLayout
        • Powerful, difficult to use layout

    + caswensoncaswenson, 6 months ago

    custom

    592 views, 0 favs, 0 embeds more stats

    Basic introduction to the Java Swing, SQL, and Secu more

    More info about this document

    © All Rights Reserved

    Go to text version

    • Total Views 592
      • 592 on SlideShare
      • 0 from embeds
    • Comments 0
    • Favorites 0
    • Downloads 34
    Most viewed embeds

    more

    All embeds

    less

    Flagged as inappropriate Flag as inappropriate
    Flag as inappropriate

    Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

    Cancel
    File a copyright complaint
    Having problems? Go to our helpdesk?

    Categories