الأربعاء، ١٧ أغسطس ٢٠١١

Java Native Access


Java Native Access

Java Native Access provides Java programs easy access to native shared libraries without using the Java Native Interface. JNA's design aims to provide native access in a natural way with a minimum of effort


JNA Development First Steps

Here are a few things you have to take care of when starting a JNA project

Download jna.jar from the JNA project site (http://java.net/projects/jna/downloads) and add it to your project's build path. This file is the only JNA resource you need.    Remember that jna.jar must also be included in the run-time classpath

    Find the names of the DLLs that your Java code will access. The DLL names are required to initialize JNA's linkage mechanisms    

 Create Java interfaces to represent the DLLs your application will access 

 Test linkage of your Java code to the native functions. The first example below, "Linkage: What's in a Name?", describes the exceptions to expect when JNA can't find a DLL or a function in a DLL


Figure 1. Creation of a Java proxy object for a DLL


From last figure we noticed that JNA work with Proxy pattern, it’s like RMI proxy
 
Now from this small introduction, lets start JNA test  GOoO

First, let's write the Native (CPP) library using MS Visual Studio 2008 see this figure


 Now we have the file " JNA_TEST.dll" >> copy this file to System32 under windows directory = till now every thing is good
                    
     Let's write the Java program that will call this native function, I will use netbeanse IDE 7.0
   First I will write JNA interface then Main class see this figure








References:
http://en.wikipedia.org/wiki/Java_Native_Access

الجمعة، ٢٢ يوليو ٢٠١١

Building Your custom JSP Tag

In this tutorial we will learn what are custom JSP tags and how to build your first JSP tag
This tutorial assumes prior knowledge about JSP tags.
.

الأربعاء، ١٨ مايو ٢٠١١

الدرس الثاني (عمل Netbeans plugin)

السلام عليكم ورحمه الله وبركاته

  انتهينا الدرس السابق اننا عملنا ايكون وظهرت في النت بينز

Resized to 91% (was 1003 x 603) - Click image to enlargeارفق صورة : monthly_03_2011/post-237048-065242900 1299419870.jpg


يمكن لل module اللي عملناه ان يكون له احد التبعيات التي يجب توافرها عن التثبيت وان لم تكن موجود عند التثبيت يسالك النت بينز عنها كيفما يحدث في الباكدج بتاعه اللينوكس

هنعمل الكلام ده حاليا في ال module بتاعنا

كليك يمين عالمشروع بتاعنا وبعدين نختار properties

ارفق صورة : monthly_03_2011/post-237048-059487600 1299420625.jpg

الوضع الافتراضي ستلاحظ وجود UI Utilities API و Utilities API

الان سنقوم باضافه تبعيه لل Dialog API .. سنقوم بالضغط علي زر Add

قم بكتابه Dialog في filter ومن ثم انتظر حتي يجدها وقمت باضافتها كما بالصوره

ارفق صورة : monthly_03_2011/post-237048-004885500 1299420999.jpg


حاليا نقوم بفتح الملف HelloWorld.java الذي قمنا بعمله في الدرس السابق ونقوم بكتابه actionPerformed method

ارفق صورة : monthly_03_2011/post-237048-069650400 1299421387.jpg

نقوم الان بعمل اكشن عند الضغط علي الزر يقوم بعمل Dialog

نقوم باضافه هذا الكود كا action في actionPerformed method
String msg = "Hello Netbeans World!";
        int msgType = NotifyDescriptor.INFORMATION_MESSAGE;
        NotifyDescriptor d = new NotifyDescriptor.Message(msg, msgType);
        DialogDisplayer.getDefault().notify(d);


ونقوم بعمل import اللازم
import org.openide.DialogDisplayer;
import org.openide.NotifyDescriptor;


نقوم بعمل run الان وتجربه
Resized to 79% (was 1153 x 681) - Click image to enlargeارفق صورة : monthly_03_2011/post-237048-061194200 1299421779.jpg


حاليا هنعمل مثال اخر باستخدام NotifyDescriptor.InputLine

نقوم باضافه هذا الكود كا action
NotifyDescriptor.InputLine question;
    question = new NotifyDescriptor.InputLine("Name:",
        "What's your name?",
        NotifyDescriptor.OK_CANCEL_OPTION,
        NotifyDescriptor.QUESTION_MESSAGE);
 
    if (DialogDisplayer.getDefault().notify(question) == NotifyDescriptor.OK_OPTION) {
         String msg = "Hello "+question.getInputText()+"!";
         int msgType = NotifyDescriptor.INFORMATION_MESSAGE;
         NotifyDescriptor d = new NotifyDescriptor.Message(msg, msgType);
         DialogDisplayer.getDefault().notify(d);
     }


نقوم بعمل run ونلاحظ النتيجه

Resized to 79% (was 1147 x 683) - Click image to enlargeارفق صورة : monthly_03_2011/post-237048-031051900 1299422220.jpg


Resized to 79% (was 1153 x 683) - Click image to enlargeارفق صورة : monthly_03_2011/post-237048-050801900 1299422257.jpg


بكده يكون الدرس انتهي .. وان شاء الله الدرس القادم نعمل تطبيق صغير

يا رب يكون الدرس افاد الجميع ...

الأحد، ١٥ مايو ٢٠١١

خطواتك الاولي نحو RMI

الدرس الاول (عمل Netbeans plugin)

السلام عليكم ورحمه الله وبركاته

هنتكلم النهارده ان شاء الله عن كيفيه اضافه plugin لل netbeanse وهكيون ان شاء الله شيئ سهل جدا

في البدايه نقوم بعمل مشروع جديد

ارفق صورة : monthly_03_2011/post-237048-058484800 1299058236.jpg


نختار netbeanse module >module

ارفق صورة : monthly_03_2011/post-237048-031106800 1299058363.jpg

نقوم بتسميه المشروع

ارفق صورة : monthly_03_2011/post-237048-088756800 1299058511.jpg

ارفق صورة : monthly_03_2011/post-237048-027426600 1299058816.jpg

حاليا اصبح لدينا module فارغ لابد من اضافه action له بالشكل الاتي

ارفق صورة : monthly_03_2011/post-237048-078144300 1299059107.jpg


وهنا هحدد شويه خصائص للاضافه بتاعتي مثلا انا حددت الخيارات ديه يمكن التحديد كيفما تشاء

ارفق صورة : monthly_03_2011/post-237048-025100500 1299059455.jpg

بعد كده هحدد اسم action class والايقون اللي هستخدمها عشان تظهر في النت بينز وتكون 16*16 انا استخدمت دي ارفق صورة : monthly_03_2011/post-237048-036283800 1299060656.gif

ارفق صورة : monthly_03_2011/post-237048-096589400 1299059756.jpg

كده المفروض كل حاجه جاهزه :D

اعمل build وبعدين run هلاقيه فتح instant جديد من netbeanse وفيه الايقون اللي عملتها واللي حددتله مكان الظهور وانا شغال فوق


Resized to 91% (was 1003 x 603) - Click image to enlargeارفق صورة : monthly_03_2011/post-237048-043785700 1299060107.jpg


اقدر كمان اضيفه في netbeanse اللي انا شغال عليه عن طريق كليك يمين عالمشروع ثم Install/Reload in Development IDE

لو الايقون ظهرت زي الصوره اللي فوق يبقي كده كل شيئ تمام لو مظهرتش بقا يبقي فيه حاجه غلط وراجع خطواتك تاني :041:

كده الدرس انتهي .. ان شاء الله الدرس القادم نعرف ازاي نتفاعل من البلاجن بتاعتنا و نظبط ال action

يا رب يكون الشرح افاد الجميع ونلقاكم في الدرس الثاني

:022:

الجمعة، ١ أبريل ٢٠١١

Project Lombok

كثير منا كمبرمجي جافا يكتبون في الغالب Getters, Setters, Constructors و اشياء اخري تكون نمطيه بشكل كبير في الكود .. ربما في الاصدارات القادمه من jdk نجد البديل.

اثناء تصفحي بعض المواقع وجدت هذا البديل وهو Project Lombok

فقط قم باضافه annotations اثناء كتابتك للكود الخاص بك ومن ثم يقوم lombok بعمل اضافه Getters, Setters, Constructors ..الخ طبقا لل annotations الذي قمت بوضعه

وهذا سوف يتضح مع الامثله

احدالعيوب التي اراها:
اعتماديتها علي JDK version
عند قراءه الكود سنجد صعوبه اذا لم نكن لدينا معرفه ب Lombok او annotations المستخدم ولكن يمكنك كتابه تلك المعلومات ب documentation فيسهل التعامل معاها

يمكنك تحميل Lombok.jar ثم اضافته و استخدام النت بينز او اكليبس


هذه تجارب سريعه وبسيطه

مثال:- استخدام @Getters and @Setters
--------------------------------------------------------

بالطريقه النطميه سنكتب الكلاس بتلك الطريقه

class Student{
    private int id;
    private String name;
    private int age;
    public Student(){
    }

    public int getId() {
        return id;
    }
    public void setId(int id) {
        this.id = id;
    }
    public String getName() {
        return name;
    }
  // وهكذا 
.
.
.
.
}


باستخدام Lombok سنكتبه بتلك الطريقه
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
@NoArgsConstructor class Student{
    @Getter @Setter private int id;
    @Getter @Setter private String name;
    @Getter @Setter private int age;
}



مثال اخر باستخدام Lombok

--------------------------------------

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@NoArgsConstructor
@AllArgsConstructor
@Data
class Student {
    private int id;
    private String name;
    private int age;
    public static void main(String[] args){
        Student s1 = new Student(1,"ahmed",21);
        Student s2 = new Student(2,"mouhamed",30);

        System.out.println(s1);
        System.out.println(s2);
    }
}


run:
Student(id=1, name=ahmed, age=21)
Student(id=2, name=mouhamed, age=30)
BUILD SUCCESSFUL (total time: 1 second)


لمعرفه باقي مميزات Lombokهنا

-- للعلم المكتبه مفتوحه المصدر :)

دورة قواعد البيانات oracle 10g

سيحتوى المقال التالى على كورس قواعد بيانات  أوراكل باللغة العربية بإذن الله, الكورس يتكون من فيديوهات او مقالات نصية يكتبها م.احمد غانم


اضافه المستخدم HR

 

الدرس الثالث