RSS

Monthly Archives: February 2012

Parallel Processing – المعالجة المتوازية

Parallel Processing – المعالجة المتوازية

طبقاً لقانون مور فإن كثافة الترانزيستورز تزداد كل 18~24 شهر. زيادة كثافة الترانزستورز فى شريحة المعالج تتصاحب ب زيادة فى سرعة ساعة البروسيسور والذي فى النهايه يقود الى اداء افضل من ذي قبل.
ولكن منذ التسعينيات اتجهت الشركات المصنعة للمعالجات إلى تصميم معالجات تستطيع أن تعمل فى توازي، وانقسم المعالج الرئيسي الى معالجات اقل حجما (شرائح) وأطلق عليها اسم الكور. وتم اختيار اتجاه المعالجات ذات الشرائح المتعدده من قبل الشركات المصنعه لان اي زيادة كانت فى كثافة الترانزستورز تقود إلى حرارة عالية من الصعب الخفض منها بالطرق العادية.
وتم تقديم العديد من المعالجات ذات الشرائح المتعددة مثل Intel dual-core, Intel quad-core, Intel oct-core..الخ
لذا فقد انتقل قانون مور من الترانزستور إلى الشرائح، فتضاعف عدد الشرائح فى المعالج الواحد كل 18~24 شهر.

فكرة المعالجة المتوازية هى تقسيم العملية الجاري معالجتها على اكثر من معالج بناء على قواعد معينه أساسها تصميم المعالج وتتبع سياسة  .divide and conquer

تصنيف فلْين

  صنف فلين أنواع المعالجة المتوازية على أساس التحكم كما يلي :-

1- Single Instruction Single Data.
ذلك النوع يعني أن هناك وحده معالجة واحده تستطيع معالجة عملية واحده و الولوج إلى وحده تخزين(ذاكرة) واحده وذلك النوع يعني المعالجات  العادية المتتابعة.
.فى كل خطوه يتم تنفيذ امر واحد والنتيجة يتم تخزينها فى وحدة الذاكرة *

2- Multiple instruction Single data
ذلك النوع يعني ان هناك اكثر من وحده معالجة لكل منها الذاكرة الخاصه ويمكنها ايضا الولوج الى ذاكرة مشتركة بين المعالجات، فى  كل خطوة يتم تحميل نفس البيانات من الذاكرة ويتم تحميل اوامر تستعمل تلك البيانات ويتم تنفيذ تلك الاوامر فى توازى. ومن الجدير بالذكر انه لم يتم تصنيع اي جهاز حاسب يتبني تلك التصميم من قبل الشركات التجارية المصنعه للمعالجات.

3- Single Instruction Multiple data
يمثل ذلك النوع التصميم ذو المعالجات المتعددة  وكل المعالجات تشترك فى وحدة ذاكرة واحده وهناك برنامج واحد يتم تنفيذه، فى كل خطوة يتم تحميل نفس الامر من الذاكرة ويتم تنفيذه على عدد من البيانات، كل وحدة بيانات يتم تحميلها ومعالجتها على اساس الامر الذي تم تحميلة من قبل معالج واحد.
ويعتبر ذلك التصميم جيد جدا مع معالجة الغرافيك او الاتصالات وذلك لتكرار نفس اوامر المعالجة على بيانات متعددة. ومن الشركات التى تتبني ذلك النوع من المعالجات انتل.

4- Multiple Instruction, Multiple data
هناك عدد من المعالجات لكل منها الولوج الخاص بها لذاكرة مشتركة ، ويتم فيها تحميل أمر وبيانات منفصله ومختلفه عن باقي المعالجات الأخرى، وتعتبر الأنظمة العنقودية (الكلستر) مثال لذلك النوع وكذلك المعالجات متعددة الشرائح.

 
Leave a comment

Posted by on February 29, 2012 in Featured, Software

 

Python is …… typed language !

Python is …… typed language !

The answer is : Python is “Dynamically typed” and “Strongly typed” language
but why ?! , and what’s the meaning of : Dynamically typed “and” Strongly typed ?!!!
First the opposite of Dynamically typed is : “Statically typed” , and Strongly typed is :”Weakly typed” .
Let’s know what’s the meaning of these types 🙂

 

1- Statically typed Language :

  • * The language that check the type during the compile time .
  • * it can catch many type errors early “types are fixed at compile time “
  • * Most statically typed languages enforce you to declare all variables with their data-types before using them.
  • * Ex : Java and C.

Code : In Java

here we declared the variable x as integer before assign it to 3

2- Dynamically typed Language :

  • * The language that check the type during the run time .
  • * Types are discovered at run-time .
  • * You don’t have to declare variables with their data-types before using them.
  • * Ex : Python and PHP

Code : In Python

here we assigned variable x to 3 without declaring it’s type

3- Strongly typed Language :

  • * The language which its types are always enforced .
  • * If you declared a variable as integer , you can’t do operations on it as a string ” without explicitly converting it ” .
  • * Ex : Java and Python .

Code : In Python

yes “Type error”  , because you can’t add string to int

but if you wanted to add 3 to 30 , you should convert y from string to integer

it’s 33 🙂

4- weekly typed Language :

  • * The language which its types may be ignored .
  • * if you declared a variable as string and another as integer  , you can concatenate the string ‘1’ and the integer 1 to get the string ’11’  .. “without explicitly converting it ” .
  • * Ex : Java script

Code : In Java script

yes it’s “33” as string
here : it converts integer x 3 to string x “3” ,then concatenate them (“30″+”3”) and the result is “33”

So Python is “Dynamically typed” and “Strongly typed” language 🙂 .

 
Leave a comment

Posted by on February 28, 2012 in BeBsata, Featured, Programming, Software

 

Tags:

Django: Part(2)

Django: Part(2)

فى هذا الجزء سوف نتناول مزيد من التفصيل كيفية عمل (web app) فى الجانجو اولا  بداخل الفولدر الذى قمنا بانشائه اخر مرة والذى كان يحتوى على :

:  (__init__.py) -1

 لكى يقوم البايثون بالتعامل مع المشروع كوحدة (package)  وعادة ما يكون ملف فارغ .

:  (manage.py) -2

 

تمكنك من التعامل مع المشروع ولمعرفة ماذا يمكن فعله قم بكتابة هذا الامر في التيرمينال (python manage.py help)

 (settings.py) -3

 

يحتوى على اعدادات المشروع بصفة عامة مثل :  ( INSTALLED_APPS,TIME_ZONE , LANGUAGE_CODE,….)

: (urls.py) -4

وهو اشبه مايكون بالجدول الذى يحتوى على اسم التطبيق والدالة التى تقوم بتنفيذه ، وبعد استعراض هذه الملفات  سوف نقوم بعمل ملف جديد وليكن اسمه(views.py)  بداخل هذا الملف نقوم بكتابة الكود الاتى :

اذا اتجهنا الى الملف (urls.py) فانه يحتوى على كود يشبه التالى :

 

كل ماعليك فعله هو اضافة اسم للتطبيق الذى قمت بعمله للتو وعمل استدعاء للدالة التى تقوم بتنفيذ هذا التطبيق وبتجاهل الكومنت يصبح الشكل اقرب للتالى :

ال ^ , $ هى regular expression characters وسوف نتحدث عنها فيما بعد ، ولكن فائدة  ^  هى التاكد من ان المعطى في url يماثل البداية بمعنى انه بدونه يصبح

وفائدة $ التاكد من انه يماثل النهاية بمعنى انه بدونه يصبح

والان دعونا نتناول باختصار ماذا يحدث عند طلب Request فى هذا المثال :

1-      عند طلب Request يقوم الجانجو بالذهاب الى ROOT_URLCONF الموجود بملف settings.py ، وتكون قيمته مثلا ROOT_URLCONF = ‘mysite.urls’

2-      يقوم الجانجو بالذهاب الى ملف urls  ومنه الى urlpatternsويقوم بعمل مقارنة بين الاسم الذى تم اعطائه فى ال (127.0.0.1:8000/hello)  والاسماء الموجودة بداخل  patterns

3-      عند وجود تطابق يقوم بعمل الدالة بتنفيذ الدالة المجاورة والموجودة  فى ملف views

4-      تقوم الدالة بارجاع HttpResponse ويقوم الجانجو بتحويله الى صفحة ويب لكى  تظهر لك على ال browser

 
Leave a comment

Posted by on February 27, 2012 in Featured, Software, Web

 

Hibernate & JDBC

Hibernate & JDBC

Hibernate & JDBC

  •  JDBC “Java Database Connectivity” : It’s the tool by which developers can connect, query and update database using the SQL, developer has to write code to map an object model’s data representation to a relational data model and its database schema, JDBC is Java version of ODBC.
  •  Hibernate : It’s a Flexible ORM soultion for JAVA “Object-Relational Mapping” to map Java classes to database tables, that allows java developers to develop persistent classes by object-oriented using association, inheritance and polymorphism mechanisms, developer does not need to write code explicitly to map database tables tuples to application objects during interaction with RDBMS.


* Note that :
JDBC simples the interaction with RDBMS “Relational database management systems” ,

So that if you want to access database using JAVA application you have to :-

 —  Load the JDBC driver because this driver actually communicates with the database, Then Open connection to database.

Create JDBC Statement object, This object contains SQL query Then execute statement which returns resultset.

 ResultSet : contains the tuples of database table as a result of SQL query.
Then send SQL queries to database using JDBC drivers and work on the returning results from database.

Close the Database connection.

JDBC uses two techniques to communicate with database:

First technique :-

  1.   The JDBC driver connects to database.
  2.   Executes SQL statements.
  3.   Results are sent back from driver to driver manager and finally to the application.
     

Second technique :-

  1.   The JDBC driver communicates with ODBC driver.
  2.   Then ODBC driver executes SQL query
  3.   Then results are sent back to JDBCdriver to driver manager and then to application.ODBC “Data Source” >> JDBC Servlet >> Browser.

Mapping of Java objects with database tables and vice versa conversion is done by the developer “manually” with lines of code.

JDBC supports “only” native Structured Query Language (SQL), Developer has to find out the efficient way to access database, to select query from a number of queries to perform same task.


With JDBC ..
Mapping between Java objects and database tables is done manually.
It is developer’s responsibility to handle JDBC result set and convert it to Java objects through code to use this persistent data in application, So if table changed or database changed then It is developer’s responsibility to change object structure and to change code written to map table-to-object & object-to-table.

Spring’s JDBC framework makes code easy to read and manages connections.

* Note that :

Hibernate is more flexible, powerful and high
performance object relational persistence and query service ,

So that if you want to access Database using Hibernate technique, you will find that :

1. Load the Hibernate configuration file and create configuration object. It will automatically load all mapping files.

Hibernate opens connection to database by itself.

2. Create HQL query “Hibernate Query Language”, Hibernate converts HQL “Hibernate Query Language” statements to database    data   and receives result set – (independent from type of database) that is expressed in SQL like syntax and includes full support for polymorphic queries.

** Hibernate also supports native SQL statements.

Hibernate also selects an effective way to perform a database manipulation task for an application,
Then execute query to get list containing Java objects.

3. Hibernate maps of these database data to Java objects which are directly used by Java application “Automatic Mapping”.


With Hibernate ..
Hibernate provides this mapping “itself“, Actual mapping between tables and application objects is done in XML files, So if there is change in Database or in any table then the need will be to change XML file properties.

  •   Hibernate uses JDBC to connect to the database and execute the dynamic SQL that it generates.
  •   Hibernate is nothing more than a SQL generation engine – it uses bjects and mappings to generate SQL, instead of making writing it by hand.

Now we have these question .. Why Hibernate .. So why not !?

  Why Hibernate :

  1.   Open-Source, Zero-Cost Product License.
  2.   Less code in Hibernate than JDBC.
  3.   Hibernate is standard ORM “Object-Relational Mapping” solution.
  4.   Database Independent.
  5.   Hibernate is layers architecture, So you only use whatyour appllication need.
  6.   Support for Query Language,While JDBC supports only native Structured Query Language “SQL“, Hibernate provides a powerful query language Hibernate Query Language (independent from type of database) and supports native SQL statements.
  7.   Updates and Maintenance, Hibernate reduces lines of code by update object table mapping itself and returns result to the application in Java objects, While is developer’s responsibility to handle JDBC result set and convert it to Java objects and mapping between Java objects and database tables is done manually.

 

  Why not Hibernate :

  1. Debugging and Performance are difficult.
  2. Hibernate is slower than JDBC as it executes lots of SQL statements in runtime.
  3. Internet Support for Hibernate is not powerful.
  4. Hibernate is an overhead for the applications which are simple and use one database that will never change or there are no objects will map between two different tables.
  5. Need to know Hibernate to update application using Hibernat.
 
Leave a comment

Posted by on February 26, 2012 in Database, Featured, Software

 

Tags: , ,

Playing with the User Interface in Android -Part2!

Playing with the User Interface in Android -Part2!

Hi there , The last time we have created the user Interface Of our Android Application . We created many screens and Views , today we will learn how to connect between them!..

First , we have to create two more Activities : SignUpForm Activity class and LogInForm Activity Class . We will set signup.xml as the layout of SignUpForm Activity and set the login.xml as the layout of LogInForm Activity ..

 

The Code of SignUpForm.java :

The Code of LogInForm,java :

We will notice from the previous codes that setContentView(R.layout.login); or setContentView(R.layout.signup); >> setContentView is used to set the layout and the view of the screen using (R.layout.layoutName)..

The Code of CATaZineActivity.java :

//The previous class set : main.xml using ( R.layout.main )as the layout of the this Activity ..

Then, create two buttons signUpButton ,logInButton that we will use to go to the signUp Form and LogInForm . Create two OnClick Methods , both of them use the intent to transfer from view to another. one method for SignUp Button and one for LogIn Button , so you can go to any view just by Clicking on a Button!..

The last thing you have to do is to define the activities in AndroidManiFest.xml by adding the Following xml code Lines to your it :


The full code of AndroidManiFest.xml File :

Now , try to press signUp Button >> you will go to SignUp Form and press LogIn Button you will go to LogIn Form ..

That’s all , Thanks! ..

 
Leave a comment

Posted by on February 25, 2012 in Android, Featured, SmartPhones Development