Showing posts with label Technical. Show all posts
Showing posts with label Technical. Show all posts

Monday, March 03, 2008

لغة ج للبرمجة باللغة العربية

عنوان قد يكون مضحك لكم يا رفاق العمل .... أليس كذلك ؟

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

ولكنها فكرة جيدة بلا شك من وجهة نظرى محاولة تعريب لغة البرمجة

قرأت عن لغة ج منذ فترة ليست بالقصيرة لكنى فشلت فى استخدامها ثلاث مرات على ما أذكر بسبب مشاكل فى اللغة فى ويندوز إكس بى

واليوم هى أول مرة أنفذ على جهازى المتواضع برنامج مكتوب بلغة برمجة عربية !!!! ولم أتصور أنى سأفعل يوما ما

دعنا نرى الأمر من زاوية اخرى غير الضحك والتهكم

دعنا ننظر إليها كمحاولة مبدأية قد يكتب لها النجاح أو الفشل وقد تحتاج إلى سنوات وسنوات من العمل والتعديل والابتكار والإبداع و.... إلخ

ولكن من طلب منا أن نفنى أعمارنا فيها .... دعنا نلقى عليها نظرة ... ومن يكمنه المشاركة فليشارك ... ومن يقتنع بالفكرة فليمض

من قال أن العالم أعجمى أبد الدهر .... ربما يجتاج بناء نظم حاسب مماثلة أو قريبة من تلك فى العالم المتقدم إلى 1000 أو 2000 سنة

فإذا بدأنا الآن وكل وضع القليل سنصل بعد 2000 سنة وإذا لم نيدأ لن نصل أبداً

على أى الاحوال أنا غير مسموح لى التحدث فى شئ ليس له علاقة بالحاسب ومجالاته المختلفة هنا لأنى أنوى نشره على مدونة القسم إن شاء الله

وأرجوا المعذرة فى أخطأ اللغة العربية فأنا للأسف لست من الأقوياء فيها

دى روابط اللغة
الصفحة الرئيسية
http://www.jeemlang.com/index.php
كتاب التعريف
http://www.jeemlang.com/documentation/webframe.html

ده البرنامج اللى أنا شغلته النهاردة

! برنامج لحساب مضروب عدد صحيح

المتحول ن : صحيح

المتحول ص ، ع : صحيح

أجعل ع = 1

أكتب "أدخل عدداً صحيحاً لتعرف قيمة مضروبه :" ، سطر

أقرأ ن

أجعل ص = ن

أكرر طالما ص > 1

{

أجعل ع = ع × ص

أجعل ص = ص - 1

}

أكتب ن ، "! =" ، ع

Saturday, February 16, 2008

Signed Java Applets

Hey, welcome back with a new blog !! today I am talking about both Java and web, more clearly Java Applets

Let us see the problem. Days ago, I was developing a Java Applet that capture a snapshot for Desktop and send it to Flash movie embedded in the same HTML page to provide Desktop Sharing (viewing share not remote access) facility for our web application. I finished developing the applet on Eclipse IDE and it was running well. When embedding it in HTML page, it gave java.security.AccessControlException: access denied (java.awt.AWTPermission createRobot)
(as I used AWT package to capture the screen). So, what is the problem ?!!

I surfed the net for such problem and it was the first time to deal with Java security policy. This policy resides in java.policy file located at $JAVA_HOME\jre\lib\security. Problem is that Applets, unlike Applications, are not trusted by default by Java security policy. It is restricted for some operations like accessing the local file system, asking for socket connection,... etc. The solution is what called Signed Java Applet.

Before completing with Java Signed Applet, let us see why the applet run on Eclipse IDE the first time. When running the applet in Applet Viewer through Eclipse, Eclipse generates a policy file in the folder contains this applet called java.policy.applet and associate it with the applet. The content of the file (for my applet) was as following:

/* AUTOMATICALLY GENERATED ON Tue Apr 16 17:20:59 EDT 2002*/
/* DO NOT EDIT */

grant {
permission java.security.AllPermission;
};

It is clear that it allows the developer applet to do everything assuming that developers (which use Eclipse IDE) are mature enough to take care about disasters may harm their local computers. So everything is running on Applet Viewer.

Java Signed Applet is an applet associated with a digital certificate. Digital certificates are authored by trustworthy authorities. Signing an Applet needs to get a certificate from one of these authorities, which is most of time costs money for sure, so users can trust your applet and give it permission to do its operation. Digital certificate contains the holder party(which is you in this case) besides the certificate authority (e.g. Sun MicroSystems). No specific authorities monopoly giving certificates, but companies have good reputation or something like that can give this certificate. You can create your own certificate for developing and testing issues.

After singing the applet, browser will pop up a dialog to users when the applet is loading displaying the digital certificate associated with the applet and let the user permit the applet to be authorized on his computer or reject the certificate which let the applet behave like unsigned one.

We may talk about digital certificates in details later; but at a glance, it depends on public key encryption algorithms (e.g. RSA algorithm, click here to read more about RSA) that generates a pair of public and private keys and use this to verify the validity of the certificate within its expiration period.

Now, let us see how to sign our applets with our own digital certificate for development purposes:

1. Create your code for the applet as usual.
It is not necessary to set any permissions or use security managers in
the code.

2. Install JDK 1.5
Path for use of the following commands: $JAVA_HOME\bin
(commands are keytool, jarsigner)
Password for the keystore is any password.

3. Generate key:
keytool -genkey -keyalg rsa -alias tstkey
Enter keystore password: ******* (any password)
What is your first and last name?
[Unknown]: Your Name
What is the name of your organizational unit?
[Unknown]: YourUnit
What is the name of your organization?
[Unknown]: YourOrg
What is the name of your City or Locality?
[Unknown]: YourCity
What is the name of your State or Province?
[Unknown]: YS
What is the two-letter country code for this unit?
[Unknown]: US
Is CN=Your Name, OU=YourUnit, O=YourOrg, L=YourCity, ST=YS, C=US
correct?
[no]: yes

(wait...)

Enter key password for tstkey
(RETURN if same as keystore password):

(press [enter])

4. Export key: keytool -export -alias tstkey -file tstcert.crt

Enter keystore password: *******
Certificate stored in file tstcert.crt

5. Encapsulate your applet in a JAR file (click here to read how to create JAR files).

6. Sign JAR:
jarsigner signedApplet.jar tstkey
Enter Passphrase for keystore: *******

8. Verifiy Signing: jarsigner -verify -verbose -certs signedApplet.jar

130 Thu Feb 12 13:04:12 GMT+02:00 2008 META-INF/MANIFEST.MF
183 Thu Feb 12 13:04:12 GMT+02:00 2008 META-INF/TSTKEY.SF
920 Thu Feb 12 13:04:12 GMT+02:00 2008 META-INF/TSTKEY.RSA
Thu Feb 12 12:58:28 GMT+02:00 2008 META-INF/
smk 849 Thu Feb 12 12:49:04 GMT+02:00 2008 SignedApplet.class

X.509, CN=Your Name, OU=YourUnit, O=YourOrg, L=YourCity, ST=YS, C=US
(tstkey)

s = signature was verified
m = entry is listed in manifest
k = at least one certificate was found in keystore
i = at least one certificate was found in identity scope

jar verified.

9. Create HTML file for use of the Applet using tag

<"applet" code="SignedApplet.class" width=100 height=140 archive="signedApplet.jar">"</"applet">

where signedApplet.jar reside next to HTML file and SignedApplet.class encapsulated in it.


10. Run HTML page and test your applet.

I tested it on my PC using JDK 1.5 Update 8 to sign the applet and take the applet on my laptop and run well.

I hope this helps.

Sunday, January 27, 2008

Actionscript 3: Strict-Mode Versus Standard-Mode Compilation

ActionScript offers two different modes for compiling a program: strict mode and standard mode. In strict mode, the compiler reports more errors than in standard mode. The extra strict-mode errors are intended to help programmers locate potential sources of problems in a program before the program actually runs. Strict mode is, therefore, enabled by default in all of Adobe's compilers. Programmers who wish to use ActionScript's dynamic features, or who simply prefer to solve problems (i.e., debug) at runtime rather than at compile time can choose to compile using standard mode.

The following questionable acts of programming will cause a compiler error in strict mode, but not in standard mode:

  • Supplying the wrong number or types of parameters to a function

  • Defining two variables or methods with the same name

  • Accessing methods and variables that are not defined at compile time (but might be defined at runtime using the dynamic features techniques)

  • Assigning a value to a nonexistent instance variable of an object whose class is not dynamic

  • Assigning a value to a constant variable anywhere other than the variable's initializer or, for instance variables, the constructor method of the class containing the variable's definition

  • Attempting to delete (via the delete operator) an instance method, instance variable, static method, or static variable

  • Comparing two incompatibly typed expressions

  • Assigning a value to a type-annotated variable where the value is not a member of the declared type (some exceptions to this rule exist, see the special cases of Strict Mode below)

  • Referring to nonexistent packages


Strict Mode's Three Special Cases

There are three situations in which the compiler ignores type mismatch errors in strict mode, deferring possible type errors until runtime:

  • When an untyped expression is assigned to a typed variable or parameter, or returned from a function with a declared return type

  • When any expression is assigned to a typed variable or parameter whose declared type is Boolean, or returned from a function whose declared return type is Boolean

  • When any numeric value is used where an instance of a different numeric type is expected

Saturday, January 26, 2008

JavaScript Function Closure

Coming from a C++/JAVA background, it was hard for me to assimilate the concept of Function Closure in JavaScript. Now that I understand it, I'd like to share it here with you. Seriously, it's best explained by example than description. Here's an example.


var thingsToDo = {};

function initializeThingsToDo() {
var food= {
name: "Ramen",
type: "Tokatsu"
};
thingsToDo.eat = function() {
alert("I'm going to eat: " + food.name);
}
}

//Execute
initializeThingsToDo();
thingsToDo.eat();


Okay, what did I do here? First, I created an empty (global) Object called "thingsToDo", then I added a global function called "initializeThingsToDo". Inside this function I defined food object. I referenced the global object "thingsToDo" and attached a dynamic function called "eat" in the object.

After the code definitions, I ran the global function initializeThingsToDo, and called the method thingsToDo.eat().

I know you would say that this is crazy because when I ran thingsToDo.eat(), the method uses the food object but it's already out of scope.


//Execute
initializeThingsToDo();
thingsToDo.eat(); // When this is executed,
// the food object is already out of scope!


Na ah?! Not in JavaScript. You see, when you run the code, JavaScript will create a closure to the food object. After that, it saves it in the memory. The interpreter knows that it will be used for later. (It doesn't deallocate the food object in the memory. )

The power of function closure is well executed when you use AJAX. When you define your AJAX callback function, it gets called asynchronously. It creates a closure and call the objects/functions when it's ready.

If you are not familiar with JavaScript Object and Functions, you can read these links:

Java vs. JavaScript object
JavaScript usign Prototype.js
JavaScript Function

Source:
http://liminescence.blogspot.com/2007/11/javascript-function-closure.html

Wednesday, January 23, 2008

W3C offers HTML 5 draft

Upgrade to Web spec boosts interoperability and adds 2D graphics and audio and video backing, but it will need strong support from browsers

The first major upgrade to the HTML specification since 1997, HTML 5, was published in an early draft form Tuesday by the World Wide Web Consortium, featuring APIs for drawing two-dimensional graphics and control of audio and video content. The final version of the specification is not expected until late-2010, and it will be up to browser vendors to support it, one analyst stressed.

HTML serves as the base markup language for building Web pages. HTML 5 is intended to boost interoperability and reduce software costs by providing rules on handling correct HTML documents and recovering from errors.

With version 5, W3C has two main intentions: Catching up to how HTML actually is practiced versus what the specifications say should be practiced and adding new features, said Dan Connolly, a co-chair of the W3C HTML Working Group. "We've been doing a lot of things [since the last upgrade], but basically, the scale of the Web went way up, and the scale of our efforts really didn’t match it until now," he said.

New features mostly pertain to Web applications and integrating video as a first-class medium on the Web, Connolly said. In proposing its new features, W3C studied what people do on the Web and what leading-edge Web sites do. "Now it's time to standardize them," so these capabilities can show up in authoring tools, said Connolly.

By standardizing these capabilities, they become easier to learn, and it is easier to hire someone who can tackle these tasks, according to Connolly.

Other new capabilities planned for HTML 5 include the ability for users to edit documents and parts of documents interactively. Also planned are features to make it easier to represent familiar page elements, including section tags, page footers, and navigation elements. Maintenance of persistent client-side storage is another highlight in version 5.

In developing a new standard, W3C was mindful of Web progressions, such as the emergence of media-rich Web sites over static page collections, and innovations like AJAX (Asynchronous JavaScript and XML). Recent innovations have boosted demand for a standard for building Web applications that interoperate across mobile and desktop platforms, W3C said.

W3C will need adoption of HTML 5 by companies supplying browsers, said Jeffrey Hammond, Forrester senior analyst. "I guess the big comment that I would have is [HTML 5 is] going to be important to the extent that browsers move forward and adopt it," he said. "Developers are interested in writing HTML that goes to as many browsers on as many devices as possible."
Mozilla already is supporting HTML 5 in its Firefox browser, the company said.

"Mozilla has been actively involved in the WHATWG (Web Hypertext Application Technology Working Group) applications spec, which is the basis for HTML 5," said, Vlad Vukicevic, infrastructuralist for Mozilla, in a statement released by the company. "Firefox 3 supports many parts of the proposed standard, including DOM (Document Object Model) Storage, offline apps, the HTML Canvas, and many smaller features. While we are supporting these parts, there are other parts of the full HTML 5 proposal that are still under discussion."

Other browser companies, including Microsoft, Apple and Opera, are active participants in the HTML Working Group, W3C said.

Capabilities offered in HTML 5 currently are being offered through plug-in technologies, such as Adobe Flash and Microsoft Silverlight, Hammond said.

"The most interesting thing will be what happens when those capabilities get into native HTML and what impact that has on the rich Internet development market," he said. Specific plug-in technologies are not supported on every platform, he said. "[Thusly], as a developer I might be more interested in writing HTML 5," Hammond said.

The finalization of the specification will take some time, though. The plan is to have it available in a preliminary candidate recommendation form in the middle of 2009 and as a formal, final recommendation by September 2010, Connolly said. The process is lengthy because it takes time to get the technology to the point where Web authors can rely on it, he said. "It's up to each Web author to decide when he wants to implement new features," he noted.

Also new to HTML 5 is it will be the first version implemented under the W3C Royalty-Free Patent Policy. This gives implementers greater assurance that standards can be implemented free of royalties, W3C said.

Source:
http://www.infoworld.com/article/08/01/22/W3C-offers-HTML-5-draft_1.html
23rd Jan, 2008

Monday, January 07, 2008

AppJet

AppJet is a website that allows users to create web based applications in their web browser. AppJet was founded by 3 MIT graduates, 2 of whom were engineers at Google prior to AppJet. They launched their initial public beta on December 12, 2007, allowing anyone to create a web app.

AppJet received funding from Y Combinator in the summer of 2007.

"AppJet" also refers to the open-source server-side javascript framework that powers AppJet applications. This is an example of a recent trend in web development to run JavaScript on both the client and the server, allowing developers to code entire web apps in a single language, instead of using a separate language for server-side scripting and client-side scripting.

The virtual machine that powers AppJet apps is currently closed-source, but is reportedly written using Scala (programming language).

Source:
http://en.wikipedia.org/wiki/AppJet

AppJet website:
http://appjet.com/

Sunday, December 24, 2006

JAR Files

JAR file (or Java ARchive) is a ZIP file used to distribute a set of Java classes. It is used to store compiled Java classes and associated metadata that can constitute a program.
__________________________________________________________
How to Create JAR file :

*Traditional method:

*Quick Method:

1- put all your .class files and packages next to a folder named "META-INF" containing a file named "MANIFEST.MF"
2- open "MANIFEST.MF" using any text editor
3- write in "MANIFEST.MF" file
Manifest-Version: 1.0
Main-Class: MainClass
where MainClass is your main class
4- add your .class files and this folder to a ZIP archive ( not .RAR ) using WinRAR or any other program
5-change the extension of resulting file to .jar

*Preferred Method for me:
Generate it using IDE you use
In Eclipse 3.2, follow
File -> Export -> Java -> Jar File
and continue with the wizard specifying your main class and exported classes
_________________________________________________________________________
How to run a jar file:

*In case you have JDK 1.5 Updat 8 or above:
double click on JAR file or use the fllowing method.

*In case of older versions of JDK :
1- create a batch file ( you can create a text file and change its extension to .bat)
2- wirte in batch file "java -jar file.jar" to execute file.jar archive
3- double click on batch file

For more about JAR files, check