TvQuran
Showing posts with label J2SE. Show all posts
Showing posts with label J2SE. Show all posts

Monday, December 14, 2009

Unknown Java Traps that most of us fall in, Video Inside

I watched yesterday awesome tutorial that you deserve to see.
It's about Traps, Pitfalls, and Corner Cases in our lovely language, Java, It deals with 8 issues that most of us fall in it, Not to talk too long, I'll show you the first easy example and let you discover the rest and the reasons at this awesome video introduced by Google.

Problem One:
Here is a Java code and the question is to find the output and the reason of your selection, there are 4 multiple choices to select one from it, let's dance :)

public static void main(String args[]) {
            Set set = new HashSet();
            for (short i = 0; i < 99; i++) {
                set.add(i);
                set.remove(i - 1);
            }
            System.out.println(set.size());
        }

The Options is :
  • 1.
  • 99.
  • Through an Exception.
  • None of the above.
You will find the detailed solution with reasons at the first 5 minutes of the video.
Now, I'll let you with the awesome video by Josh Bloch and Bill Pugh.




for any questions, I'll be here and hope to enjoy the tricks.
read more...

Saturday, December 12, 2009

Java Editing in NetBeans IDE 6.8, Video Tutorial

One of the most powerful feature in NetBeans IDE is it's Editor. The language-aware NetBeans editor detects errors while you type and assists you with documentation pop-ups and smart code completion-all with the speed and simplicity of your favorite text editor.








read more...

Thursday, December 10, 2009

How to Make Awesome Program Interface in less than 10 Minutes by Integrating SwingX in NetBeans IDE

Did you dreamed about making free highly designed desktop programs in Java ?!
Do you see that the MS Product have a point for it's IDE and it's ease of use to build GUI in short time ?!
Do you want to make awesome program GUI in less than 10 Minutes ?!!

Yeah, you can do more than that.We will know how to Integrate SwingX(Coolest UI API, I used) in NetBeans IDE(The only IDE you need), So let's dance.

Contents :
  1. What is SwingX?
  2. Downloading SwingX Library.
  3. Adding SwingX Library to NetBeans IDE.
  4. Adding SwingX Library to your Project.
  5. Integrating SwingX with NetBeans IDE (To use drag and drop).
    SwingX ?!

    Contains extensions to the Swing GUI toolkit, including new and enhanced components that provide functionality commonly required by rich client applications. Highlights include:
    • Sorting, filtering, highlighting for tables, trees, and lists
    • Find/search
    • Auto-completion
    • Login/authentication framework
    • TreeTable component
    • Collapsible panel component
    • Date picker component
    • Tip-of-the-Day component
    Many of these features will eventually be incorporated into the Swing toolkit, although API compatibility will not be guaranteed. The SwingX project focuses exclusively on the raw components themselves.



    Demos:

    • JXTaskPane
    • JXTipOfTheDay
    • JXBusyLabel



    Downloading SwingX Lib:

    You can download it from SwingLabs Downloads Page.















    Adding SwingX Library to NetBeans IDE:

    From Tools > Libraries, Choose New Library.

















    Write the Lib Name and press OK.











    Click Add Jar/Folder.















    Go To the Downloading Dir and After extracting the Lib and choose the SwingX Jar and SwingX-BeanInfo Jar and press Add JAR/Folder.
















    If you want you may add the Source Code and the Java Doc.
    I will add the JavaDoc to benefit from the Awesome Code Completion NetBeans IDE Feature, So if you will, add the JavaDoc press JavaDoc tab and click Add ZIP/Folder.














    Choose the doc dir and press Add ZIP/Folder.
















    Click Ok to Finish Creating the SwingX Library.





























    Adding SwingX Library to your Project :

    Now we will add the SwingX Library to our project and you must make this step every time you create a project that will uses SwingX.

    Right Click on Libraries and choose Add Liberary.










    Select SwingX from Add Library window and click Add Library.























    Congrats you added the lib and now can use it's components.


    Integrating SwingX with NetBeans IDE (To use drag and drop)

    From Tools > Palette > Swing/AWT Components, press on New Category.

















    Write the Category Name and press OK.









    Select the category we created and then click Add from Library.

















    Choose SwingX lib and click Next.



























    Select All by pressing “Ctrl + A” and Press Next (You may choose some beans only, It' s up to you).



























    Choose SwingX Category and press Finish.



























    Congratulations, We made it. Thanks everybody for your time and hope that was useful, If you have any question please contact us or hit the comment button and we all here for you. 
    read more...

    Wednesday, December 9, 2009

    How to use Hibernate and MySQL Server in NetBeans IDE,The easy way.

    Want to Create a Hibernate Application using NetBeans IDE and MySQL in just 7 minutes ?!
    Well, We will learn how to add MySQL library and Hibernate library to NetBeans IDE, and how to make small application to connect Hibernate to MySQL, So stay with us.








    Contents:

    1.  Add MySQL library to NetBeans IDE.
    2.  Add Hibernate library to NetBeans IDE.
    3.  Use MySQL Server to make small table.
    4.  Make the first Hibernate application and connect it to MySQL Server.
    5.  Download Source Code.


    1- Add MySQL library to NetBeans IDE.
    • Right-click on project name choose properties
    • Click on library




    • Add library





    • Choose MySQL
    • Add the library




    2- Add Hibernate library to NetBeans IDE.





    3- Use MySQL Server to make small table




    • Install these two file the very important step
    1- setting the password ( if you have loder version and removed it you will see current root password , if not you will not see it )(hint : we use password -- 12345)






    2- Ensure that mysql server installed correctly (otherwise you must reinstall mysql)




    4-
    Make the first Hibernate application and connect it to MySQL Server.


    1. Make java application
    2. Add mysql liberary and hibernate library
    3. Build our database

    Table name student (use default schema test)



    Name
    Age
    Ahmed
    21
    Islam
    21
    Ali
    20



    4- build hibernate configuration file ( this file define you database engine ,your password , and driver that’s essentially to connect to mysql or other database engines) . configuration file is an xml file .it is name ( hibernate.cfg.xml ) . place in default package .

    right-click on default -package choose other











    Then click finish


    • Now we will explain hibernate configuration file
    5 – build java bean class . this class have fields that we name it in our database
    Every table in our database have one bean implements database fields place it in default package .








    6- now build xml file have name like the java bean class name (in our project Main ) this file named with hibernate mapping file . we use this file to assign each attribute in our bean class to each field in our database.(hint :each table in our database has java bean class and mapping file to connect each).









    - Now to begin our first project we must do the main class we will name it (insert )




    When you run the project





    Download Source Code:
    Thanks for your time and consideration and hope you enjoyed this tutorial.

    read more...

    Saturday, December 5, 2009

    How to secure Java Applications by using VBScript to get a Unique Computer Serial Number

    Did you tried many times to get a unique computer ID to use it in securing your java application?!
    Do you want to know the easy way to get that ID in just 5 minutes?!!
    Yes you can, We will learn how to get basic hardware serial numbers at windows platform and you will find the complete code at the end of the tutorial.

    before we start any one may ask why I even want to get this number?
    Well, consider that scenario :
    you have developed some application and want to distribute it for some of money. We here have a point, how we will be sure that if I sold it for someone, he will not redistribute it, So we will use that Unique ID to give him a copy that will run only on his PC. 
    Make sense !, So lets dance.
    We will use the VBScript codes on the fly to get the system info like CPU information or Motherboard information Like this:






















    Here is the Java source code to get the Unique ID divided on to two parts.
    First Part of Java Code:
    • We here open temp File to put the script on it, We use temp folder on C:\ Drive to execute the script and then delete it.












    Second Part of Java Code:
    • We here execute the ".vbs" file after writing the script on it and then we retrieve the results and close the file.


















    Take on your mind that:
    • When you put your VBScript Code as String you must convert all special characters(e.g the " will be \" ). 
    For Example:
    If the VBScript is
    Set objReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")
    
    The String will be
    String vbs="Set objReg = GetObject(\"winmgmts:{impersonationLevel=impersonate}!\\\\\" & strComputer & \"\\root\\default:StdRegProv\")";
    
    Here is the full source code with sample VBScript:
    import java.io.File;
    import java.io.FileWriter;
    import java.io.BufferedReader;
    import java.io.InputStreamReader;
    
    public class VBSUtil {
    
        private VBSUtil() {
        }
        static String result = "";
    
        private static String getMotherboardSN() {
            try {
                File f = new File("C:\\");
                File file = File.createTempFile("realhowto", ".vbs", f);
                file.deleteOnExit();
                FileWriter fw = new java.io.FileWriter(file);
                String vbs = "On Error Resume Next\n" + "strComputer = \".\"\n" + "Set objWMIService = GetObject(\"winmgmts:\\\\\" & strComputer &  \"\\root\\cimv2\")\n" + "Set colItems = objWMIService.ExecQuery(\"Select * from  Win32_Processor\")\n" + "For Each objItem in colItems\n" + " Wscript.Echo \"Processor Id: \" & objItem.ProcessorId\n" + "Next\n" + "strComputer = \".\"\n" + "Set objWMIService = GetObject(\"winmgmts:\" _\n" + "  & \"{impersonationLevel=impersonate}!\\\\\" & strComputer &  \"\\root\\cimv2\")\n" + "Set colBIOS = objWMIService.ExecQuery _\n" + "(\"Select * from Win32_BIOS\")\n" + "For each objBIOS in colBIOS\n" + "  Wscript.Echo \"Release Date: \" & objBIOS.ReleaseDate\n" + "next";
                fw.write(vbs);
                fw.close();
                Process p = Runtime.getRuntime().exec("cscript //NoLogo " + file.getPath());
                BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
                String line;
                while ((line = input.readLine()) != null) {
                    result += line;
                }
                input.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
            return result.trim();
        }
    }
    
    
    
    Thanks for your time and hope this was helpful. For any questions, Please feel free to comment the post.
    read more...

    Why Java From Egypt in 2.5 minutes

    For most of us, the term tutorial is nothing but boring long files that contain lots of information, we often not need to meet our need,We just need a small hack of how it work. We thought to introduce the boring long tutorials in a simple form for most of us.

    Here, from Egypt where one of the oldest civilizations, We provide Mini-Tutorials in one of the newest technologies.

    We hope to enjoy your journey with our Mini-Tutorials. If you have an interesting tutorial want to share, please feel free to contact us at : javafromegyptblog[AT]gmail[DOT]com
    read more...