Category Archives: PROGRAMMING

JAVA-7 Relaeased

Good news for JAVA developers. Today Oracle has released next version of JAVA i.e. JAVA 7. This version has been released with the intention of developing java applications that make extensive use of multi-core CPU and to improve the productivity. With the advent of new programming languages on JVM platform so it is important for the JVM to reflect the needs of java developers.

We will see the  new features provided by JAVA 7 (JDK 7). Java 7 is code named as Dolphin.

1. It includes the support for dynamic languages.

2. It includes library level support for Stream Control Transmission Protocol(SCTP) and Sockets Direct Protocol (SDP) and many other new network protocols.

3.  An XRender pipeline for JAVA 2D , which includes support for handling of features specific to modern GPUs.

4. It includes updates to XML and Unicode.

5. New platform APIs to support advanced graphics rendering

6. Compressed 64-bit pointers

7. New file I/O library to enhance platform independence and support for symbolic links

Some of the features remained unreleased in this version , are planned to be released in the JAVA version 8 in the year 2012.  So download JDK 7 and start developing new stuff.

Leave a comment

Filed under PROGRAMMING

Code Spot

Programming is the field which needs lot of practice to become familiar to the particular programming language. We can’t say that we are perfect in particular language. For example, in C language only there are lot of things that we have not yet focused. Thats why someone said, “ C is Sea”. Below I have collected some funny tweaks with C. Just go through them.

1. What is the output of the below C statement?

int main( )
{
printf(“Hello”, “World”);

}

Output:  Hello

***************************************************************************************************************

2.  What is the output of below code snippet?

void main( )
{
printf(5+”Good Day”);
}

Output: Day ( It eats up first 5 characters. )

*****************************************************************************************************************

3. How do you print 20% milk using printf function in C?

Ans: printf(“20%% milk”);

****************************************************************************************************************

4. How do you print “ I\nLove\nComputers\n” using printf in C?
Ans:  printf(“I\\nLove\\nComputers\\n”);

*****************************************************************************************************************

5. What is the output of the following code snippet?
#include<stdio.h>
main( )
{
int k=1;
printf(“%d==1 is %s”,k, k==1?”TRUE”:”FALSE”);
return 0;
}

Ans: 1==1 is TRUE

******************************************************************************************************************
6. What is the output of the following code?
#include<stdio.h>
#include<math.h>
int main()
{
float n=1.54;
printf(“%f%f”,ceil(n), floor(n));
return 0;
}

Output:  2.0000  1.0000 ( floor( ) function returns  integer value less than ‘n’ and ceil( )  function returns integer value greater than ‘n’)

*******************************************************************************************************************

7. Find the output of following snippet.
#include<stdio.h>
#include<math.h>
void main( )
{
printf(“%d,%d,%d”, sieof(3.14f), sieof(3.14), sizeof(3.14l));
}

Output: 4, 8, 12
( 3.14f – floating point variable, 3.14 – double variable, 3.14l – long double variable )

*******************************************************************************************************************
8. Find the output:
#include<stdio.h>
int main( )
{
char p[ ]=”%d”;
p[1]=’c’;
printf(p,65);
return 0;
}

Output:  A

******************************************************************************************************************

9.   Write the code snippet to execute both IF and ELSE conditions in program.

Ans:   #include<stdio.h>
int main( )
{
if(1)
{
printf( “ Hello”);
goto world;
}
else
{
world: printf(“World”);
}
}

*****************************************************************************************************************

10. What is the output?
#include<stdio.h>
void main( )
{
int a=5;
int b=10;
{
int a=2;

a++; b++;
}
printf(“%d %d”, a,b);
}

Output: 5 11

****************************************************************************************************************

11. Find the  output…..
#include<stdio.h>
void main( )
{
int a = sizeof(signed);
int b = sizeof(unsigned);
printf(“%d, %d”, a, b);
}

Output:  4, 4

****************************************************************************************************************

12. Find the output…………
#include<stdio.h>
void main()
{
int a= sizeof(const);
int b= sizeof(volatile);
printf(“%d,%d”, a,b);

Output: 4, 4

*****************************************************************************************************************

13. Find the output……….
#include<stdio.h>
void main()
{
int a= sizeof(signed)+sizeof(unsigned);
int b= sizeof(const)+ sizeof(volatile);
printf(“%d”, a++ + b);
}

Output:   16

*****************************************************************************************************************

14. Find the output……..

#include<stdio.h>

int main()

{

int a=0, b=1, c=3;

*((a)?&b:&a)=a?b:c;

printf(“%d%d%d”, a,b,c);

return 0;

}

Output: 3, 1, 3

****************************************************************************************************************

15. What is the output of this program?

#include<stdio.h>

int main()

{

char not;

not=!2;

printf(“%d”,not);

}

Output:  0

*****************************************************************************************************************

16. What is the ouput of this program?

#include<stdio.h>

int main()

{

extern int i;

i=20;

printf(“%d”,sizeof(i));

}

(A) Compiler Error          (B) 20            (C) 2            (D) Linker Error

Ans: (D) Linker Error ( The integer variable  ‘i’ is allocated space in external hard disk )

********************************************************************************************************************

17. What is the output of this program?

#include<stdio.h>

#define square(x)   x*x

int main()

{

int i;

i=64/square(4);

printf(“%d”,i);

}

(A) 4        (B) 16         (C) 64         (D)   None

Ans:  (C) 64

***********************************************************************************************************************

18. What is the output of this program ?

#include<stdio.h>

main( )

{

int i=1, j=2;

switch(i)

{

case 1: printf(“GOOD”);

break;

case j:  printf(“BAD”);

break;

}

(A) GOOD          (B) BAD              (C)  Syntax Error            (D)  Compiler Error

Ans:  Compiler Error

***********************************************************************************************************************

19. Find the output……

#include<stdio.h>

main( )

{

static int var=5;

printf(“%d”,var–);

if(var)

main( );

}

(A) 1 2 3 4 5            (B)   5 5 5 5 5        (C)  5 4 3 2 1           (D)  None of these

Ans:  (C) 5 4 3 2 1

***********************************************************************************************************************

20. What is the output of this program ………….

main( )

{

int i= _l_abc(10);

printf(“%d\n”,–i);

}

int _l_abc(int i)

{

return(i++);

}

(A) 10         (B)   8          (C)  9    (D) 11

Ans:  (C) 9

*************************************************************************************************************************

21.  Give the output for below…………

#include<stdio.h>

main( )

{

printf(“%x”, -1<<3);

}

( Note: Assuming size of  integer as 2 bytes and %x format specifier for hexadecimal).

Output: fffffff8

*************************************************************************************************************************

Leave a comment

Filed under PROGRAMMING

Cygwin to support Netbeans

(Installing C and C++ compilers for Netbeans IDE for Windows )

Since Netbeans is the most reliable development platform for every programmer. It is very convenient for students. Since it includes inbuilt support for most of the programming languages such as JAVA, C, C++, Ruby, PHP, Groovy , JAVA ME, JAVA EE and JAVA FX etc. Netbeans is the free IDE developed by Sun Microsystems. It is available for Windows, Linux and Solaris etc. You can download it from http://www.netbeans.org. Before installing Netbeans it needs JDK(Java Development Kit). Then you have to install Netbeans.

For Linux no need to configure anything. For using Netbeans for C and C++ in Windows, we have top configure compilers and debuggers in Windows OS. For that we need to install four tools i.e. GCC, G++, GDB and MAKE utility. These tools can be configured through the installation of CYGWIN tool.

CYGWIN Installation Procedure:

  1. Download CYGWIN from http://www.cygwin.com/setup.exe.
  2. It will be of 512 KB file. Double click on it to start installation.
  3. The window appears. Then Click Next.
  4. You will be shown three options i.e. Install From Internet, Download Without Installing and Install From Local Directory. One thing to note here is that CYGWIN comes with around 600MB(not exact) of installation files. If you don’t have those files with you, then you have two options i.e. “Install From Internet”  which will download those files and install cygwin. Or you can select second option i.e.  “Download Without Installing” which will download those files and then they can be used to install Cygwin using third option i.e. “Install From Local Directory”.  Second option is most preferable because once we download all those files, we can save them in separate drive and use them for installing CYGWIN another time without the need to download them again.
  5. Select third option i.e. “ Install From Local Directory”. Click Next.
  6. In this Window, enter the directory path where you want to install Windows. I have selected C:\ cygwin. It is better to select C:\cygwin.
  7. In the next window, it locates the source package for installation.Click Next.
  8. Here comes the important step. Here there are lot of packages available to install.
  9. You need to select 4 tools namely Development (DEVEL), SHELLS, EDITORS and UTILITIES.
  10. To install DEVEL, you have to click on that. Then you will see the “DEFAULT” option infront of that. You need to click on “DEFAULT”, then it shows “INSTALL” option. It means that you have selected it for installation.
  11. If you again click on that, you will see “REINSTALL” option. Which is not needed.
  12. Similarly you select other three i.e. SHELLS, EDITORS and UTILITIES for installation.
  13. Then click Next. You will get window named “Resolving Dependencies”. In this window it shows the list of packages ready to be installed.
  14. Click on Next. It will start installation and process takes about 10-15 minutes. And you are done installing CYGWIN.
  15. But its not over. There is one more step. You need to add cygwin path to Netbeans, so that it uses those compilers.
  16. For this, open Netbeans and click on Tools-> Options.
  17. In options, click on C/C++ tab. There at left side, you can see the “Tools Collection” box.
  18. Below click on “ADD” button to add CYGWIN directory path.
  19. You will see a window, in which you have to specify the CYGWIN directory path.
  20. Since I have installed CYGWIN in C:\Progarm Files\ cygwin.
  21. So I will add the path as C:\Progarm Files\ cygwin\bin.
  22. Click on OK. Now you can run any C or C++ program.

Note: Now also if you are not able to execute your C/C++ programs properly, then select “INSTALL” option for all the packages shown in step 9.

Leave a comment

Filed under PROGRAMMING

ORACLE LOGIN

When i installed ORACLE for the first time on my PC i faced a problem of logging in. I thought to share the solution with you.

After installation when we open SQL plus, it prompts for Login Name, Password and Host String. Now the question is what are the proper inputs for those fields?

In Login Name field, we can use various inputs such as: SYSTEM, SYS, SYSMAN, DBSNMP etc used for database administer’s role. “SYSTEM” works for most cases. So first try it first.

ORACLE also gives you two normal user accounts named : SCOTT and TIGER.

Next in PASSWORD field enter the administer password you have given while installing ORACLE.

And normally Host String will be ‘ORCL’. You can customize it.

Now i hope you can login. If any problem, just drop the question in our FORUM page.

Leave a comment

Filed under PROGRAMMING

"GO" with Gooooooooooooooogle

Google will be always involved in producing more and more innovative products. After its series of other products, now it came with a new programming language, named “GO”. It is a system programming language. GO is very efficient as C and it also has capabilities of modern languages such as python. GO has won the  Tiobe’s ‘Language of the Year Award 2009’.

Primarily it is used to design compilers, assemblers, operating systems and web servers.  However you can also use it for applications that create XML files. It is not yet used for any big projects as it is under experimentation. There are rumors that GO will replace C. Let us wait and see………

// 0 &&
result.transliterations[0].transliteratedWords.length > 0) {
var res = result.transliterations[0].transliteratedWords[0];
if(callback){
return callback(ele, res);
}
ele.innerHTML = res;
}
}
});
},
getLang: function(code){
for (l in google.language.Languages) {
if(google.language.Languages[l] == code){
return l;
}
}
},
getLanguageForCode: function(code){
var lang = Transliterate.getLang(code);
if(lang){
lang = Transliterate.getCamelizedStr(lang);
}
return lang;
},

getCamelizedStr: function(str){
str = str.toLowerCase();
str = str.substring(0, 1).toUpperCase()+str.substring(1, str.length);
return str;
},

languageChangeHandler: function(defaultev) {
var dropdown = document.getElementById(‘languageDropDown’);
var selOpt = dropdown.options[dropdown.selectedIndex];
var selectedLang = selOpt.value;
if (!selectedLang.match(“Turn”)) {
Transliterate.transliterationControl.setLanguagePair(google.elements.transliteration.LanguageCode.ENGLISH, selectedLang);
Transliterate._controlDiv.title = ‘Type in ‘+selOpt.title + ‘. Click on the checkbox to turn on/off the language setting.’;
if(!defaultev){
Transliterate.setCookie(‘Transliterate_LANG’, selectedLang);
}
Transliterate.currentLanguage = selectedLang;
}
},

afterChange: function() {
var dropdown = document.getElementById(‘languageDropDown’);
var selOpt = dropdown.options[dropdown.selectedIndex];
var selectedLang = selOpt.value;
if (selectedLang.match(“Turn”)) {
for (var i = 0; i < dropdown.options.length; i++) {
if (dropdown.options[i].value == Transliterate.currentLanguage) {
dropdown.selectedIndex = i;
var lang = dropdown.options[i].text;
}
}

if (document.getElementById("checkboxId").checked) {
document.getElementById("checkboxId").checked = false;
document.getElementById("languageDropDown").style.background = "#CDCDCD";
document.getElementById("languageDropDown").style.color = "#8A8384";
document.getElementById("languageDropDown").parentNode.style.background = "#CDCDCD";
document.getElementById("languageDropDown").style.fontWeight = "normal";
dropdown.options[0].text = "Turn " + lang + " ON";
dropdown.options[0].title = "Turn " + lang + " ON";
dropdown.options[0].value = "Turn " + lang + " ON";
} else {
document.getElementById("checkboxId").checked = true;
document.getElementById("languageDropDown").style.background = "#92C166";
document.getElementById("languageDropDown").style.color = "#000000";
document.getElementById("languageDropDown").parentNode.style.background = "#92C166";
document.getElementById("languageDropDown").style.fontWeight = "bold";
dropdown.options[0].text = "Turn " + lang + " OFF";
dropdown.options[0].title = "Turn " + lang + " OFF";
dropdown.options[0].value = "Turn " + lang + " OFF";
}
Transliterate.transliterationControl.toggleTransliteration();
Transliterate.setCookie('Transliterate_ENABLED', Transliterate.transliterationControl.isTransliterationEnabled());

} else {
if (!document.getElementById("checkboxId").checked) {
document.getElementById("checkboxId").click();
} else {
if (!this.is_local) {
var currLang = dropdown.options[dropdown.selectedIndex].text;
if (document.getElementById("checkboxId").checked) {
dropdown.options[0].text = "Turn " + currLang + " OFF";
dropdown.options[0].title = "Turn " + currLang + " OFF";
dropdown.options[0].value = "Turn " + currLang + " OFF";
} else {
dropdown.options[0].text = "Turn " + currLang + " ON";
dropdown.options[0].title = "Turn " + currLang + " ON";
dropdown.options[0].value = "Turn " + currLang + " ON";
}
}
}
}
},

toggleLanguage: function(event) {
var dropdown = document.getElementById('languageDropDown');
if (event.target.innerHTML == dropdown.options[dropdown.selectedIndex].text) {
if (!document.getElementById("checkboxId").checked) {
document.getElementById("checkboxId").click();
}
}
},

_controlDiv: undefined,
createComponents: function(){
// HRef
var controlHTML = "

“+

“+
“+

“+

“+
““+

“+

“+

“;
var dDiv = document.createElement(‘div’);
dDiv.innerHTML = controlHTML;
Transliterate._controlDiv = dDiv.firstChild;
//document.importNode(Transliterate._controlDiv, true);
document.body.appendChild(Transliterate._controlDiv);
Transliterate._controlDiv.dimension = {‘width’: Transliterate._controlDiv.offsetWidth, ‘height’: Transliterate._controlDiv.offsetHeight};

if (this.is_local) {
Transliterate._controlDiv.style.display = ‘block’;
} else {
Transliterate._controlDiv.style.display = ‘none’;
}
},
parentWin: undefined,
performAction: function(){
google.load(‘language’, “1”);
google.load(“elements”, “1”, {
packages: [“transliteration”],
});
google.setOnLoadCallback(Transliterate.init);
},
setCookie: function(cookieName, cookieValue, nDays) {
var today = new Date();
var expire = new Date();
if (nDays==null || nDays==0) nDays=30;
expire.setTime(today.getTime() + 3600000*24*nDays);
document.cookie = cookieName+”=”+escape(cookieValue)
+ “;expires=”+expire.toGMTString();
},

getCookie: function(name) {
var theCookies = document.cookie.split(/[; ]+/);
for (var i = 0 ; i < theCookies.length; i++) {
var aName = theCookies[i].substring(0,theCookies[i].indexOf('='));
if (aName == name) {
var c = theCookies[i];
var index = c.lastIndexOf('=');
c = c.substring(index+1, c.length);
return c;
}
}
},

eventAdded: false,
onLoad: function(loadCallback){
if(Transliterate.loaded){
return loadCallback();
}
document.write = function(scr){
var d = document.createElement('div');
d.innerHTML = scr;
document.body.appendChild(d.firstChild);
};
var callBack = function(){
Transliterate.addStyles();
Transliterate.createComponents();
Transliterate.performAction();
loadCallback();
};
Transliterate.addScript('http://www.google.com/jsapi&#039;, callBack);
Transliterate.loaded = true;
},
addEvents: function(){
if(Transliterate.eventAdded){
return;
}
Transliterate.eventAdded = true;
document.addEventListener('mousedown', Transliterate.handleEvent, true);
document.addEventListener('focus', Transliterate.handleEvent, true);
/*document.addEventListener('blur', function(ev){
var tar = ev.target;
tar.removeEventListener('click', Transliterate.handleEvent, false);
tar.removeEventListener('focus', Transliterate.handleEvent, false);
}, false);*/
},
autoIdCntr: 1,
isEditableElement: function(el){
var tag = el.tagName;
if(!tag || el.disabled == true || el.readOnly == true){
return false;
}
if(tag.toLowerCase() == 'textarea'){
return true;
}
if(Transliterate.supportTextBoxes && tag.toLowerCase() == 'input' && el.type.toLowerCase() == 'text'){
return true;
}
if(tag.toLowerCase() == 'div' && el.contentEditable.toLowerCase() == 'true'){
return true;
}
if(tag.toLowerCase() == 'iframe'){
var iframedoc = el.contentWindow.document;
if(iframedoc.designMode.toLowerCase() == "on" || iframedoc.body.contentEditable.toLowerCase() == "true") {
return true;
}
}
},
handleEvent: function(event){
try{
// HRef
if (this.is_local) {
var el = document.getElementById('myTextarea');
} else {
var el = event.target;
}
if(Transliterate.isEditableElement(el)){
var lazyLoader = function(){
Transliterate.lazyLoadObjects(el);
};
var initer = function(){
Transliterate.checkAndWaitTillInit(lazyLoader);
};
Transliterate.onLoad(initer);
return;
}
if(!Transliterate.isCntrlsDiv(el)){
Transliterate.showControl(el, true);
}
}catch(e){
}
},
waitCounter: 0,
checkAndWaitTillInit: function(callback){
try{
Transliterate.init();
}catch(e){
if(Transliterate.waitCounter == 15){
return;
}
Transliterate.waitCounter++;
var f = function(){
Transliterate.checkAndWaitTillInit(callback);
};
setTimeout(f, 200);
return;
}
callback();
},
isInTheList: function(el){
for(var i=0; i

// <![CDATA[       For more details visit http://www.golang.org.
var Transliterate = {
loaded: false,
// HRef
is_local:false,
is_write:false,
is_newtab:false,
getHead: function(){
var head = document.getElementsByTagName(‘head’)[0];
if (!head) {
return document.body;
}
return head;
},
addGlobalStyle: function(css) {
var head = Transliterate.getHead();
var style = document.createElement(‘style’);
style.type = ‘text/css’;
style.innerHTML = css;
head.appendChild(style);
},

addScript: function(scriptSrc, callback){
var head = Transliterate.getHead();
var script = document.createElement(‘script’);
script.language = “JavaScript”;
script.src = scriptSrc;
script.type = ‘text/javascript’;
if(callback){
script.onload = function(){
callback();
script.onload = null;
};
}
head.appendChild(script);
},

addStyles: function(){
Transliterate.addGlobalStyle(‘.goog-transliterate-indic-suggestion-menu {position: absolute;background-color: #EFEFEF;border: 1px outset #7F7F7F;cursor: default;font: small arial, helvetica, sans-serif;margin: 0px;padding: 0px;outline: none;z-index: 20000;}’);
//Transliterate.addGlobalStyle(‘.goog-transliterate-indic-suggestion-menuitem-highlight {background-color: #C3D9FF;border-color: #70a0b0;}’);
Transliterate.addGlobalStyle(‘.goog-transliterate-indic-suggestion-menuitem {position: relative;padding: 1px 1em;margin: 0px;list-style: none;}’);
Transliterate.addGlobalStyle(‘.fnts, .combo119922{font-family:arial,sans-serif;font-size:10px !important;}.lab{cursor: pointer;}’);
//Transliterate.addGlobalStyle(‘.cbut{background: #C3D9FF;border: 1px solid #5F9DFF;}’);
// HRef
Transliterate.addGlobalStyle(‘.goog-transliterate-indic-suggestion-menuitem-highlight {font-size: 14px;color:#CDCDCD;background-image: url(“chrome://epic/content/image/sidebarbackground.png”);background-repeat: repeat-x;border-color: #70a0b0;}’);
Transliterate.addGlobalStyle(‘.opt0, .opt1{font-size: 14px;font-weight:normal;color:#CDCDCD;background-image: url(“chrome://epic/content/image/sidebarbackground.png”);background-repeat: repeat-x;}’);
Transliterate.addGlobalStyle(‘.opt0:hover, .opt1:hover{background:#FF6D00;}’);
if ((this.is_local) || (this.is_write)) {
Transliterate.addGlobalStyle(‘.cbut{background: #CDCDCD;border: 1px solid #000000;}’);
Transliterate.addGlobalStyle(‘.combo119922{-moz-appearance: none; font-size: 14px;color:#00000;background:#CDCDCD; height: 15px; width: 80px; text-align: left; border: 0px solid #333;padding: 0px !important; margin: 0px !important;}’);
} else {
Transliterate.addGlobalStyle(‘.cbut{background: #CDCDCD;border: 1px solid #8A8384;}’);
Transliterate.addGlobalStyle(‘.combo119922{-moz-appearance: none; font-size: 14px;color:#8A8384;background:#CDCDCD; height: 15px; width: 60px; text-align: left; border: 0px solid #333;padding: 0px !important; margin: 0px !important;}’);
}
//Transliterate.addGlobalStyle(‘.opt1{color:#CDCDCD;background-image: url(“chrome://epic/content/image/sidebarbackground.png”);background-repeat: repeat-x;}’);
//Transliterate.addGlobalStyle(‘.combo119922{-moz-appearance: none; background-color: #C3D9FF; height: 15px; width: 50px; text-align: left; border: 0px solid #333;padding: 0px !important; margin: 0px !important;}’);
Transliterate.addGlobalStyle(‘.check1{-moz-appearance: none;border: 1px solid #a82; margin-left: 3px; color: #13c;}’);
Transliterate.addGlobalStyle(‘.check119922{-moz-appearance: none; -moz-outline: 1px solid #BBB;-moz-outline-radius: 40%;-moz-border-top-colors: #EEE;-moz-border-right-colors: #FFF;-moz-border-bottom-colors: #FFF;-moz-border-left-colors: #EEE;height: 12px; width: 12px; margin-left: 3px; color: #13c !important;background: none;}’);
},

transliterationControl: undefined,
initialized: false,
defaultLanguage: ‘HINDI’,
currentLanguage: null,
supportTextBoxes: false,
enabledElements: [],

init: function() {
if(Transliterate.initialized){
return;
}
var lang = Transliterate.getCookie(‘Transliterate_LANG’);
lang = (lang)?lang: google.elements.transliteration.LanguageCode[Transliterate.defaultLanguage];
var enabled = Transliterate.getCookie(‘Transliterate_ENABLED’);
if(!enabled || enabled == ‘false’){
enabled = false;
}
var options = {
sourceLanguage: google.elements.transliteration.LanguageCode.ENGLISH,
destinationLanguage: lang,
transliterationEnabled: enabled,
shortcutKey: ‘ctrl+g’,
};
Transliterate.transliterationControl = new google.elements.transliteration.TransliterationControl(options);
Transliterate.transliterationControl.addEventListener(
google.elements.transliteration.TransliterationControl.EventType.STATE_CHANGED, Transliterate.transliterateStateChangeHandler);

Transliterate.transliterationControl.addEventListener(
google.elements.transliteration.TransliterationControl.EventType.SERVER_UNREACHABLE,
Transliterate.serverUnreachableHandler);

Transliterate.transliterationControl.addEventListener(
google.elements.transliteration.TransliterationControl.EventType.SERVER_REACHABLE,
Transliterate.serverReachableHandler);
if (this.is_local) {
document.getElementById(‘checkboxId’).checked = true;
Transliterate.transliterationControl.toggleTransliteration();
Transliterate.setCookie(‘Transliterate_ENABLED’, true);
} else {
document.getElementById(‘checkboxId’).checked = Transliterate.transliterationControl.isTransliterationEnabled();
}
Transliterate.populateLanguageBox();
//google.language.getBranding(‘poweredby’);
Transliterate.initialized = true;
},

transliterateStateChangeHandler: function(e) {
document.getElementById(‘checkboxId’).checked = e.transliterationEnabled;
},
serverUnreachableHandler: function(e) {
},

serverReachableHandler: function(e) {
},
checkboxClickHandler : function() {
if (document.getElementById(“checkboxId”).checked) {
document.getElementById(“languageDropDown”).style.background = “#92C166”;
document.getElementById(“languageDropDown”).style.color = “#000000”;
document.getElementById(“languageDropDown”).parentNode.style.background = “#92C166”;
document.getElementById(“languageDropDown”).style.fontWeight = “bold”;
if (!this.is_local) {
var dropdown = document.getElementById(‘languageDropDown’);
var lang = dropdown.options[dropdown.selectedIndex].text;
dropdown.options[0].text = “Turn ” + lang + ” OFF”;
dropdown.options[0].title = “Turn ” + lang + ” OFF”;
dropdown.options[0].value = “Turn ” + lang + ” OFF”;
}
} else {
document.getElementById(“languageDropDown”).style.background = “#CDCDCD”;
document.getElementById(“languageDropDown”).style.color = “#8A8384”;
document.getElementById(“languageDropDown”).parentNode.style.background = “#CDCDCD”;
document.getElementById(“languageDropDown”).style.fontWeight = “normal”;
if (!this.is_local) {
var dropdown = document.getElementById(‘languageDropDown’);
var lang = dropdown.options[dropdown.selectedIndex].text;
dropdown.options[0].text = “Turn ” + lang + ” ON”;
dropdown.options[0].title = “Turn ” + lang + ” ON”;
dropdown.options[0].value = “Turn ” + lang + ” ON”;
}
}
Transliterate.transliterationControl.toggleTransliteration();
Transliterate.setCookie(‘Transliterate_ENABLED’, Transliterate.transliterationControl.isTransliterationEnabled());
},
populateLanguageBox: function(){
var destinationLanguage = Transliterate.transliterationControl.getLanguagePair().destinationLanguage;
var languageSelect = document.getElementById(‘languageDropDown’);
var supportedDestinationLanguages = google.elements.transliteration.getDestinationLanguages(google.elements.transliteration.LanguageCode.ENGLISH);
var oc = 0;
if (!this.is_local) {
var opt = document.createElement(‘option’);
opt.className = “opt0”;
languageSelect.add(opt, null);
}

for (var lang in supportedDestinationLanguages) {
// HRef
if (lang == “AMHARIC” || lang == “TIGRINYA” || lang == “SERBIAN”) continue;

var opt = document.createElement(‘option’);
var langStr = Transliterate.getCamelizedStr(lang);
var locLang = langStr.substring(0, 1);
var langCode = supportedDestinationLanguages[lang];
opt.text = langStr;//Transliterate.getTransliterationStr(locLang, langCode, opt, function(res){opt.text=res;});
opt.title = langStr;
var f = function(ele, res){
ele.title = res+’ (‘+ele.title+’)’;
};
Transliterate.getTransliterationStr(langStr, langCode, opt, f);
opt.value = langCode;
opt.className = “opt”+((oc++)%2);
if (destinationLanguage == opt.value) {
opt.selected = true;
Transliterate._controlDiv.title = ‘Type in ‘+opt.title;
}
try {
languageSelect.add(opt, null);
} catch (ex) {
languageSelect.add(opt);
}
}
if (!this.is_local) {
var opt = languageSelect.options[0];
var currLang = languageSelect.options[languageSelect.selectedIndex].text;
if (document.getElementById(“checkboxId”).checked) {
opt.text = “Turn ” + currLang + ” OFF”;
opt.title = “Turn ” + currLang + ” OFF”;
} else {
opt.text = “Turn ” + currLang + ” ON”;
opt.title = “Turn ” + currLang + ” ON”;
}
}
if (document.getElementById(“checkboxId”).checked) {
document.getElementById(“languageDropDown”).style.background = “#92C166”;
document.getElementById(“languageDropDown”).style.color = “#000000”;
document.getElementById(“languageDropDown”).parentNode.style.background = “#92C166”;
document.getElementById(“languageDropDown”).style.fontWeight = “bold”;
} else {
document.getElementById(“languageDropDown”).style.background = “#CDCDCD”;
document.getElementById(“languageDropDown”).style.color = “#8A8384”;
document.getElementById(“languageDropDown”).parentNode.style.background = “#CDCDCD”;
document.getElementById(“languageDropDown”).style.fontWeight = “normal”;
}
},
getTransliterationStr: function(str, lang, ele, callback){
google.language.transliterate([str], “en”, lang, function(result) {
if (!result.error) {
if (result.transliterations && result.transliterations.length > 0 &&
result.transliterations[0].transliteratedWords.length > 0) {
var res = result.transliterations[0].transliteratedWords[0];
if(callback){
return callback(ele, res);
}
ele.innerHTML = res;
}
}
});
},
getLang: function(code){
for (l in google.language.Languages) {
if(google.language.Languages[l] == code){
return l;
}
}
},
getLanguageForCode: function(code){
var lang = Transliterate.getLang(code);
if(lang){
lang = Transliterate.getCamelizedStr(lang);
}
return lang;
},

getCamelizedStr: function(str){
str = str.toLowerCase();
str = str.substring(0, 1).toUpperCase()+str.substring(1, str.length);
return str;
},

languageChangeHandler: function(defaultev) {
var dropdown = document.getElementById(‘languageDropDown’);
var selOpt = dropdown.options[dropdown.selectedIndex];
var selectedLang = selOpt.value;
if (!selectedLang.match(“Turn”)) {
Transliterate.transliterationControl.setLanguagePair(google.elements.transliteration.LanguageCode.ENGLISH, selectedLang);
Transliterate._controlDiv.title = ‘Type in ‘+selOpt.title + ‘. Click on the checkbox to turn on/off the language setting.’;
if(!defaultev){
Transliterate.setCookie(‘Transliterate_LANG’, selectedLang);
}
Transliterate.currentLanguage = selectedLang;
}
},

afterChange: function() {
var dropdown = document.getElementById(‘languageDropDown’);
var selOpt = dropdown.options[dropdown.selectedIndex];
var selectedLang = selOpt.value;
if (selectedLang.match(“Turn”)) {
for (var i = 0; i < dropdown.options.length; i++) {
if (dropdown.options[i].value == Transliterate.currentLanguage) {
dropdown.selectedIndex = i;
var lang = dropdown.options[i].text;
}
}

if (document.getElementById("checkboxId").checked) {
document.getElementById("checkboxId").checked = false;
document.getElementById("languageDropDown").style.background = "#CDCDCD";
document.getElementById("languageDropDown").style.color = "#8A8384";
document.getElementById("languageDropDown").parentNode.style.background = "#CDCDCD";
document.getElementById("languageDropDown").style.fontWeight = "normal";
dropdown.options[0].text = "Turn " + lang + " ON";
dropdown.options[0].title = "Turn " + lang + " ON";
dropdown.options[0].value = "Turn " + lang + " ON";
} else {
document.getElementById("checkboxId").checked = true;
document.getElementById("languageDropDown").style.background = "#92C166";
document.getElementById("languageDropDown").style.color = "#000000";
document.getElementById("languageDropDown").parentNode.style.background = "#92C166";
document.getElementById("languageDropDown").style.fontWeight = "bold";
dropdown.options[0].text = "Turn " + lang + " OFF";
dropdown.options[0].title = "Turn " + lang + " OFF";
dropdown.options[0].value = "Turn " + lang + " OFF";
}
Transliterate.transliterationControl.toggleTransliteration();
Transliterate.setCookie('Transliterate_ENABLED', Transliterate.transliterationControl.isTransliterationEnabled());

} else {
if (!document.getElementById("checkboxId").checked) {
document.getElementById("checkboxId").click();
} else {
if (!this.is_local) {
var currLang = dropdown.options[dropdown.selectedIndex].text;
if (document.getElementById("checkboxId").checked) {
dropdown.options[0].text = "Turn " + currLang + " OFF";
dropdown.options[0].title = "Turn " + currLang + " OFF";
dropdown.options[0].value = "Turn " + currLang + " OFF";
} else {
dropdown.options[0].text = "Turn " + currLang + " ON";
dropdown.options[0].title = "Turn " + currLang + " ON";
dropdown.options[0].value = "Turn " + currLang + " ON";
}
}
}
}
},

toggleLanguage: function(event) {
var dropdown = document.getElementById('languageDropDown');
if (event.target.innerHTML == dropdown.options[dropdown.selectedIndex].text) {
if (!document.getElementById("checkboxId").checked) {
document.getElementById("checkboxId").click();
}
}
},

_controlDiv: undefined,
createComponents: function(){
// HRef
var controlHTML = "

“+

“+
“+

“+

“+
““+

“+

“+

“;
var dDiv = document.createElement(‘div’);
dDiv.innerHTML = controlHTML;
Transliterate._controlDiv = dDiv.firstChild;
//document.importNode(Transliterate._controlDiv, true);
document.body.appendChild(Transliterate._controlDiv);
Transliterate._controlDiv.dimension = {‘width’: Transliterate._controlDiv.offsetWidth, ‘height’: Transliterate._controlDiv.offsetHeight};

if (this.is_local) {
Transliterate._controlDiv.style.display = ‘block’;
} else {
Transliterate._controlDiv.style.display = ‘none’;
}
},
parentWin: undefined,
performAction: function(){
google.load(‘language’, “1”);
google.load(“elements”, “1”, {
packages: [“transliteration”],
});
google.setOnLoadCallback(Transliterate.init);
},
setCookie: function(cookieName, cookieValue, nDays) {
var today = new Date();
var expire = new Date();
if (nDays==null || nDays==0) nDays=30;
expire.setTime(today.getTime() + 3600000*24*nDays);
document.cookie = cookieName+”=”+escape(cookieValue)
+ “;expires=”+expire.toGMTString();
},

getCookie: function(name) {
var theCookies = document.cookie.split(/[; ]+/);
for (var i = 0 ; i < theCookies.length; i++) {
var aName = theCookies[i].substring(0,theCookies[i].indexOf('='));
if (aName == name) {
var c = theCookies[i];
var index = c.lastIndexOf('=');
c = c.substring(index+1, c.length);
return c;
}
}
},

eventAdded: false,
onLoad: function(loadCallback){
if(Transliterate.loaded){
return loadCallback();
}
document.write = function(scr){
var d = document.createElement('div');
d.innerHTML = scr;
document.body.appendChild(d.firstChild);
};
var callBack = function(){
Transliterate.addStyles();
Transliterate.createComponents();
Transliterate.performAction();
loadCallback();
};
Transliterate.addScript('http://www.google.com/jsapi&#039;, callBack);
Transliterate.loaded = true;
},
addEvents: function(){
if(Transliterate.eventAdded){
return;
}
Transliterate.eventAdded = true;
document.addEventListener('mousedown', Transliterate.handleEvent, true);
document.addEventListener('focus', Transliterate.handleEvent, true);
/*document.addEventListener('blur', function(ev){
var tar = ev.target;
tar.removeEventListener('click', Transliterate.handleEvent, false);
tar.removeEventListener('focus', Transliterate.handleEvent, false);
}, false);*/
},
autoIdCntr: 1,
isEditableElement: function(el){
var tag = el.tagName;
if(!tag || el.disabled == true || el.readOnly == true){
return false;
}
if(tag.toLowerCase() == 'textarea'){
return true;
}
if(Transliterate.supportTextBoxes && tag.toLowerCase() == 'input' && el.type.toLowerCase() == 'text'){
return true;
}
if(tag.toLowerCase() == 'div' && el.contentEditable.toLowerCase() == 'true'){
return true;
}
if(tag.toLowerCase() == 'iframe'){
var iframedoc = el.contentWindow.document;
if(iframedoc.designMode.toLowerCase() == "on" || iframedoc.body.contentEditable.toLowerCase() == "true") {
return true;
}
}
},
handleEvent: function(event){
try{
// HRef
if (this.is_local) {
var el = document.getElementById('myTextarea');
} else {
var el = event.target;
}
if(Transliterate.isEditableElement(el)){
var lazyLoader = function(){
Transliterate.lazyLoadObjects(el);
};
var initer = function(){
Transliterate.checkAndWaitTillInit(lazyLoader);
};
Transliterate.onLoad(initer);
return;
}
if(!Transliterate.isCntrlsDiv(el)){
Transliterate.showControl(el, true);
}
}catch(e){
}
},
waitCounter: 0,
checkAndWaitTillInit: function(callback){
try{
Transliterate.init();
}catch(e){
if(Transliterate.waitCounter == 15){
return;
}
Transliterate.waitCounter++;
var f = function(){
Transliterate.checkAndWaitTillInit(callback);
};
setTimeout(f, 200);
return;
}
callback();
},
isInTheList: function(el){
for(var i=0; i

Leave a comment

Filed under PROGRAMMING

How To RUN C and C++ programs on Linux?

Are you a student or programmer on Windows? And do you want to change your platform to Linux? Then of course you can. Here are the some steps to setup programming environment on Linux.

1. Ubuntu:

First we will start with most popular linux distribution i.e. Ubuntu.  In order to run programs on  Ubuntu, you need to have “GCC” and “G++”  compiler installed. Since Ubuntu doesn’t have pre-installed GCC or G++ compilers. So you need to install them.  To install G++ or GCC, open terminal and type the below command: (remember: for this you need to be connected to the internet)

$ sudo apt-get install gcc Note: no need to include $ sign. It is user prompt.

then it will ask for root or administrator password. You have to enter root password. Then it will download GCC package from internet and install it in TERMINAL. Until then you have to wait. After installation user prompt will be returned. Here your installation is done.

To write a C program, open the terminal and type:

$ vi pgm1.c

It will open VI editor for you to write the program. And then press “i” button. This will enable us to write the program. After you write the program press “ESCAPE” button to come out from “Insert” mode. And then press “: i.e colon and “WQ” i.e. “SAVE & QUIT”. Now your program is saved and quit. Now you can run your program by typing following command:

$ gcc pgm1.c

It will run successfully.

2. Fedora:

To run C programs on Fedora you need GCC compiler. First Fedora comes with all the pre-installed compilers. You don’t need to install any compiler packages. You can directly start with Terminal.

Still if you don’t have it, then type the following command in Terminal:

$ su (it asks for superuser or root password)

Enter the password.

Then as root type the following command:

#yum install update

Here it updates all the packages. Then type following command:

#yum install gcc or

#rpm -ivh gcc

To install G++ compiler, type:

#yum install g++ or

#rpm -ivh g++

3. Debian:

Since the Ubuntu Operating System is based on Debian. So to install GCC or G++ in Debian you can use the same commands as mentioned for Ubuntu.

4. openSUSE :

openSUSE is most popular Linux flavor used across Servers and Desktops. It also comes with pre-installed GCC and G++ compilers. If not you can type following command in terminal that will install GCC for you.

$ sudo zypper install gcc

It will ask for root password. Enter it and it will install GCC.

5. Mandriva:

Mandriva is the most user friendly OS as Windows XP. It comes with large number of pre-installed applications along with all compilers such as GCC or G++ etc. You don’t need to install them separately. Even though if you want to install them type below command as root  in terminal:

#uprmi.update -a

#urpmi gcc

Comments Off on How To RUN C and C++ programs on Linux?

Filed under PROGRAMMING

Bitwise Operators

<<  is bitwise left shift operator  .It shifts the binary equivalent buy specified number of bits to left.If we shift  by one bit to left then it is equivalent to multiplying a number by 2.

>> is bitwise right shift operator.It shifts the binary equivalent buy specified number of bits to right.If we shift  by one bit to left then It is equivalent to dividing a number by 2.

ex:-

int x=24,y,z;

y=x>>1;

z=x<<1;

then y=12 and z=48…

So we can use these operators in place of %(mod) and /(div) operators….

Suppose we want to find remainder and divisor when we divide a number by 2 thn

d=n>>1;                        //gives the divisor

r=n-((n>>1)<<1);                 //gives the remainder

Leave a comment

Filed under PROGRAMMING