Techhgeekz ™

Monday 30 September 2013

Calling a constructor from another constructor in same class using "this" keyword:-

class Flower

{

int num = 0;

 String s = new String("null");

 Flower() //Default Constructor

 { 

 this(1000,"Hello");     // calling constructor with 2 parameters

 System.out.println("Danger ! Inside the default constructor");
   }
  Flower(int x, String y)

 {

//constructor call must be the first statement in a constructor !!

 this(500);          //call to integer parametered constructor

  //! this(s);        // Can’t call two constructors within a unit!
 
  this.num = x ;      //simple num = x; is also right

    s = y;

   System.out.println("Danger ! Inside the double barelled constructor");

   System.out.println("values >>  [ "+num+" | "+s+" ]");
    }
   Flower(int x) {
   this("Buhaha");     //call the constructor with string parameter
   this.num = x ;      //simple num = x; is also right 
   System.out.println("Danger ! Inside integer constructor");
   System.out.println("values >>  [ "+num+" ]");
    }
   
    Flower(String y) {
    this.s = y ;    
    System.out.println("Danger ! Inside String constructor");
    System.out.println("values >>  [ "+s+" ]");
    }
}
public class ConstrInThis {
    public static void main(String[] args) {
        Flower rose = new Flower();
    }
}
 

Rules to be followed while using "this" keyword for calling another constructor in same class:-

You can call one constructor from another in the same class, or call the super class, with the following restrictions:

  1. It has to be the first line of code in the calling constructor.
  2. It cannot have any explicit or implicit reference to this. So you cannot pass an inner class (even an anonymous one if it references any instance methods), or the result of a non-static method call, as a parameter.
 

Friday 27 September 2013

Program to count word from user entered text:-

#include <stdio.h>
void main()
 {
  char a[100],b[10],t[20];
  int i=0,n=0,w=1;
  printf("\n Enter The String : ");
  scanf("%s",a);
  printf("\n Enter The Word Which Count : ");
  scanf("%s",b);
  while(a[i]!='\0')
  {
  t[n]=a[i];
   if(a[i]==' ')
  {
   t[n]='\0';
 
 //printf("\n %s",t);
   n=-1;
   if(strcmp(t,b)==0)
   w++;
    }
    i++;
    n++;
    }
    printf("\n %s comes %d times ",b,w-1);

   
}


Sunday 22 September 2013

                                                      Is Learning code a New Mantra ?!

learn to code

Is it really important to learn to code, even though you don't intend to pursuit a career in computer programming?

Some people agree, while others think that it's just a hype. I somewhat tend to agree with the former group. Even though learning to code might not help you directly in your career, it will improve how you think about problems and make you a better computer user, if nothing else.

Whether you agree or not, it's true that some of the most influential (and rich) people in the recent history had something to do with software development. Below is a video prepared by code.org which features Bill Gates, Mark Zuckerberg and several others. The theme is "Every student in every school should have the opportunity to learn to code."



Let's See what the Experts say ab it!:



With the advent of Web 2.0, interactive e-learning has become fun and immersive. The best part is being able to learn programming right from within your web browsers! Below is a quick round-up of extra ordinary resources for learning and polishing your programming skills.

The criteria used here is that only sites with free courses, which are either interactive or provide an instructor lead sessions are included.


Introduction to Programming:-


Code Academy
: This is perhaps the most famous of "learn to code" web sites. The main page of this web site starts interactively, and before you know it, you start programming! This is a good resources for coding in general but more importantly, there are several "track" courses such as those for learning JQuery, JavaScript, PHP, Python and Ruby. The non-track courses cover a diverse set of topics such as CSS Selectors and Evernote API.

Code Academy is a nice resource if you already know programming and would like to teach others!



Code School: Code School is really meant for people who already know the basics of programming and want to take the next step by building expertise in web technologies. There are courses available on Git, Backbone.js, SASS, Rails, JQuery and several others.




Learn Street: Like Code School, Learn Street also focuses on JavaScript, Python and Ruby.



Improving your programming skills


Code Learn: If you have done web development in the past, you would know that Ruby on Rails is getting popularity day by day. The aim of Code Learn is to teach you Ruby on Rails.

AppShed: With smart phones, "mobile application development" has made a number of people rich. The aim of AppShed is to teach you mobile application development.

Learn X in Y minutes: This is a community driven site, which provides an extremely quick overview of different programming languages. This could be very useful to get a quick grasp of common construct in a new language.

Wednesday 18 September 2013

Project loon by Google :-

project loon by Google:-

Project Loon is a research and development project being developed by Google with the mission of providing Internet access to rural and remote areas. The project uses high-altitude balloons placed in the stratosphere at an altitude of about 20 km to create an aerial wireless network with up to 3G-like speeds. Because of the project's seemingly outlandish mission goals, Google dubbed it "Project Loon".

The balloons are maneuvered by adjusting their altitude to float to a wind layer after identifying the wind layer with the desired speed and direction using wind data from the National Oceanic and Atmospheric Administration (NOAA). Users of the service connect to the balloon network using a special Internet antenna attached to their building. The signal travels through the balloon network from balloon to balloon, then to a ground-based station connected to an Internet service provider (ISP), then onto the global Internet. 

The system aims to bring Internet access to remote and rural areas poorly served by existing provisions, and to improve communication during natural disasters to affected regions. Key people involved in the project include Rich DeVaul, chief technical architect, who is also an expert on wearable technology; Mike Cassidy, a project leader; and Cyrus Behroozi, a networking and telecommunication lead.
Project Loon



Friday 13 September 2013

Thursday 12 September 2013

substring in c

substring using pointers in C :-

#include <stdio.h>
#include <malloc.h>

char *substring(char*, int, int);

int main()
{
   char string[100]="c substring", *pointer;
   int position=3, length=5;

   printf("Enter a string\n%s",string);

   printf("Enter the position and length of substring\n");
   printf("%d\t%d",position,length);

   pointer = substring( string, position, length);

   printf("\nRequired substring is \"%s\"\n", pointer);

   free(pointer);

   return 0;
}

/*C substring function: It returns a pointer to the substring */

char *substring(char *string, int position, int length)
{
   char *pointer;
   int c;

  pointer = malloc(length);

   for (c = 0 ; c < position -1 ; c++)
      string++;

   for (c = 0 ; c < length ; c++)
   {
      pointer[c] = *string;      //      
*(pointer+c)=pointer[c] //both are same

      string++;  
   }

   *(pointer+c) = '\0';

   return pointer;
}

for compilation:-click here

Tuesday 10 September 2013

strchr and strrchr functions in c

C - strrchr function

#include <stdio.h> 

int main()

 { 

 char *s; 

 char buf [] = "This is a testing";

s = strrchr (buf, 't');

if (s != NULL)

printf ("found a 't' at %s\n", s); 

return 0;

}

It will produce following result:

found a 't' at ting

Explanation:-

The strrchr function searches string for the last occurrence of c. The null character terminating string is included in the search.

C - strchr function

#include <stdio.h>

int main() 

{

char *s;

char buf [] = "This is a testing";

s = strchr (buf, 't');

if (s != NULL)

printf ("found a 't' at %s\n", s);

return 0;

}

It will produce following result:

found a 't' at testing

Explanation:-

The strchr function searches string for the first occurrence of c. The null character terminating string is included in the search.

string manipulation functions in C

string manipulation functions in C :-


char *strcpy (char *dest, char *src) - Copy src string string into dest string.

char *strncpy(char *string1, char *string2, int n) - Copy first n characters of string2 to stringl .

int strcmp(char *string1, char *string2) - Compare string1 and string2 to determine alphabetic order.

int strncmp(char *string1, char *string2, int n) - Compare first n characters of two strings.

int strlen(char *string) - Determine the length of a string.

char *strcat(char *dest, const char *src); - Concatenate string src to the string dest.

char *strncat(char *dest, const char *src, int n); - Concatenate n chracters from string src to the string dest.

char *strchr(char *string, int c) - Find first occurrence of character c in string.

char *strrchr(char *string, int c) - Find last occurrence of character c in string.

char *strstr(char *string2, char string*1) - Find first occurrence of string string1 in string2.

char *strtok(char *s, const char *delim) - Parse the string s into tokens using delim as delimiter.

Tuesday 3 September 2013

finding the string position using strcspn

finding string position using "strcspn":-

#include <stdio.h>
#include <string.h>
int main ()
{
  char str[] = "fcba73";
  char keys[] = "f";
  int i;
  i = strcspn (str,keys);
  printf ("The first number in str is at position %d.\n",i+1);
  return 0;
}