Saturday, July 23, 2016

Node.js



Starting with Node.js


Node.js is a server side open source, crossplatform built for easily building fast and scalable realtime web applications. It uses event driven, non-blocking I/O model that makes it lightweight and efficient, perfect for data-intensive real-time applications that run across distributed devices.provides a rich library of various JavaScript modules which simplifies the development of web applications using Node.js to a great extent.
Node is not a webserver. If you want it to be a HTTP server you have to write an HTTP server (with the help of its built-in libraries). Node.js is just another way to execute code as it is just a JavaScript runtime platform with powerful set of libraries(modules) for doing real things.

Let's start with simple Node.js works,

Reading a file from node.js


Assume that you have a file named "myfile.txt" with some context written.

To read the file in the log,

// Load the fs (filesystem) module

var fs = require('fs');

// Read the contents of the file into memory.

fs.readFile('myfile.txt', function (err, logData) {
  
// If an error occurred, throwing it will

// display the exception and end our app.

  if (err) throw err;
  
// logData is a Buffer, convert to string.
var text = logData.toString(); //converts the byte array into string

console.log(text);
});

This is a simple work done without connecting to the server. Node.js makes files I/O really easy with the built in filesystem(fs) module which has a function named readFile that takes a file path and a call back.The file content is read in a form of Buffer as a  byte array. This can be converted to string using javascript to read in string form. 


Now let's write a server

Creating  HTTP Server

var http = require('http'); //requiring http server 

http.createServer(function (request, response) {
    
    response.writeHead(200);
    response.write("Hello world");//writing hello world in server
    response.end();//ending the response from server
    
}).listen(8080);//server created port number

console.log('Listening on port 8080...');


This will create a basic http server which will have your first "Hello world" written.
You can run this and view on your browser at http://localhost:8080 



Asynchronous Call backs

The typical pattern in Node.js is to use asynchronous callbacks. Basically you are
telling it to do something and when it is done it will call your function(call back).
This is because Node is single threaded. While you are waiting on the call back
to fire, Node can go off and do other things instead of blocking until the request 
is finished.
  • Example for Blocking Call :-

var fs = require('fs');

var contents = fs.readFileSync('myfile.txt');
console.log(contents);
console.log('Doing something else');

  • call back :-

var callback = function (ree, contents) {
    console.log(contents);
}
fs.readFile('second.js',callback);
  • A non blocking call with call back :-

fs.readFile('second.js',function (err,contents){
    console.log(contents);
});
console.log('Doing somethingelse');

Now you may have an understanding of asynchronous call backs done in 
Node.js. Also the inbulid function "readFile" under filestream(fs). As we 
have now read files in the log and written something in our server, we can 
read a file and write it in the server under asynchronous call backs in node.



Reading and writing a file in  HTTP server using callback 


Let's view our HTML file named "myhtmlfile" in  http://localhost:8080 with 
asynchronous call back

var fs = require('fs');
var http = require('http');

http.createServer(function (request, response) {
    
    response.writeHead(200,{'Content-Type':'text/html'}); //to write a html type file 

    fs.readFile('myhtmlfile.html',function (error,contents) {
        console.log(contents);//to view the buffer in byte code array 
        response.write(contents);
        response.end();
    });

    
}).listen(8080);

console.log('Listening on port 8080...');

You can view write different types of content by defining at the writeHead.

Hopefully now you would have understood the main concepts in node and
can start building your first widget with Node.js.



 
 



Sunday, June 7, 2015

Java Programming.

Object Oriented Programming.

Object Oriented Programming is an approach that provides a way of modulating programs by creating partitioned memory area for both data and functions that can be used as templates for creating copies of such modules on demand.
  

Basic Concepts of Object Oriented Programming.


  • Classes and Objects.
             


  • Data Abstraction and Encapsulation.
                             Data and Methods are wrapped up into a single unit called class.
                             Data Hiding - The insulation of data from direct access by the program.
                             Encapsulation makes it possible for objects to be treated like "Black boxes".


  • Inheritance.
                            The process which objects of one class acquire the properties of objects of another.
                            Gives the concept of   "is a"  relationship in a hierarchical classification.
                            Provides the idea of  "Re-usability".

                       
                        Parent / Super /Base class  -   The existing, inherited class.
                        Child / Sub / Derived class-   The new class which inherits the parent class.
                     

  • Polymorphism.
                      This gives the ability to take more than one form. i.e a general class of operations may be accessed in the                              same manner even though specific actions associated with each operation may differ.
                      Extensively used in implementing inheritance.
                   
                   

                       It is similar to a particular word having several different meanings depending on the content. 


  • Dynamic Binding.
                         Process of converting the labels into memory address. This is done at runtime.
                         i.e The linking of a procedure call to the code to be executed in response to the call.

  • Message Communication.
                         An object communicates with the other object by using method calls.
                         A message for an object is a request for execution of a procedure, and therefore will invoke a method                                      (procedure) in the receiving object that generates the desired results.



           
                            

Friday, December 26, 2014

Creating a simple web page using HTML.



    HTML 5



            HTML is a very simple markup Language which you can use to create your own webpage simply and quickly. It has tags, easily understandable & can manage with a simple knowledge of web developing. One thing you have to take concern on it is placing the opening tag & its closing tag appropriately in between the text you are going to display in your webpage.
           First, lets go through with the basic tags used for creating a simple webpage.



   Basic HTML Tags.
  •     <HTML>   </HTML>    :    Indicates the start & the end of the HTML Document.
  •     <TITLE>   </TITLE>    :    For giving the title of the webpage.
  •     <HEAD>   </HEAD>    :    Meta information of the document is given.
  •     <BODY>   </BODY>    :    Content to be displayed in the web page is given. 
  •  <P>            </P>             :    Indicates a paragraph.
  •  <BR/>                             :   For giving a single line break.
  • <H1>         </H1>          :   This defines the headers.  

  • <HR/>                          :   For giving a horizontal line. 

  • <PRE>                          :   This defines the preformatted text.
  • <B>          </B>            :    Defines bold text.
  • <I>           </I>              :    Defines Italic text.
  • <U>         </U>             :    Defines Underlined text.
  • <SUB>    </SUB>        :     Defines subscripted text.
  • <SUP>     </SUP>        :    Defines superscripted text.
  • <OL>      </OL>           :    Defines ordered list.
  • <UL>      </UL>           :    Defines unordered list.
  • <UL TYPE="SQUARE">    </UL>   :   To give a different bullet shape.
  • <LI>        </LI>                                  :    When giving the items in the list one by one.    
             Eg:    
                       <UL TYPE="square">    
                       <LI> One </LI>    
                       <LI> Two </LI>      
                                    <UL TYPE="circle">    
                                    <LI> Three </LI>     
                                    <LI> Four </LI>      
                                                 <UL TYPE="square"> 
                                                 <LI> Five </LI>          
                                                 <LI> Six </LI>        
                                                 </UL>      
                                   </UL>  
                     </UL>    
  •    Giving  hyper links :   
                            <a href="/name/">   Home  </a>
  •  Giving an image :      
               <img src="icon.png" width="42" height="42"> 
                          Make sure that the image is kept in the same folder where the document is saved.
                          If not the path to the image should be given instead of the image name.
  •  Adding a video :
                      <video width="480" height="360">
<source src="videoplayback (27).mp4"> </source>
                    </video>
                         
                          Make sure that your video is supported with your browser.
                          And it is kept in the same folder where the document is saved.
                          If not the path to the video should be given instead of the video name.
  •  Inserting a table :
                   <TABLE>
                            <TR>    </TR>       :   Creating a row.
                            <TD>   </TD>        :   Creating a column.
                   </TABLE>         
                         
                  
                           
                      Now you must have a basic idea on how to create a simple webpage. I give you a sample webpage and the tags used in it underneath it. Hope it would be understandable to try out your first webpage following it.           

                            


SAMPLE WEBPAGE.

                   
     Home Page About Us Our Articles Contact Us Sitemap

Categories

Fresh News

  • Augest 01, 2014


  • Mid Semester examintion will be commenced from 11th Augest 2014
  • July 12, 2014


  • A project will be assigned as a group work of maximum 6 members for a group
  • June 23, 2014


  • Lectures, tutorial & practical sessions will be starting from the first week itelf

Professional Online Education


Recent Article

         

  • About Site
    The site will be maintained to convey messages to students regarding Internet Technology & applictions(ITA)which is provided to 1st year 2ndsemester IT/IS/CSN students






  • Connecting People
    This is to connect students with each other as well as lecturers & students. This will allow students to actively communicate with themselves & share knowledge.







  • Student's Time
    Students will be given 2 hours of lectures, 2 hours of practical sessions & 1 hour of tutorial hours per week for the Internet Technology & applications(ITA) courses.

  

      Page source code in HTML :


 <html>
<head><title>Home Page</title></head>
<body>
<nav>
<a href="/Home Page/">Home Page</a>
<a href="/About Us/">About Us</a>
<a href="/Our Articles/">Our Articles</a>
<a href="/Contact us/">Contact Us</a>
<a href="/Siteap/">Sitemap</a>
</nav>


<br>
<B>Categories</B>
<ul >
<nav>
<li><a href="/Programs/">Programs</a></li>
<li><a href="/Student Info/">Student Info</a></li>
<li><a href="/Teachers/">Teachers</a></li>
<li><a href="/Descriptions/">Descriptions</a></li>
<li><a href="/Administrators/">Administrators</a></li>
<li><a href="/Basic Information/">Basic Information</a></li>
<li><a href="/Vacancies/">Vacancies</a></li>
<li><a href="/Calendar/">Calendar</a></li>
</nav>
</ul>
<br>



<h2><B>Fresh News</h2></B>

<ul><B><li>Augest 01, 2014</li></B><br>

<B><nav>
<a/ href="/Mid Semester Exam/">Mid Semester Exam</a>
</nav></B><br>
<p>Mid Semester examintion will be commenced from 11th Augest 2014</p>

<B><li>July 12, 2014</li></B><br>

<B><nav>
<a/ href="/ITA Course Assesments/">ITA Course Assesments</a>
</nav></B><br>
<p>A project will be assigned as a group work of maximum 6 members for a group</p>

<B><li>June 23, 2014</li></B><br>

<B><nav>
<a/ href="/Start of new Semester/">Start of new Semester</a>
</nav></B><br>
<p>Lectures, tutorial & practical sessions will be starting from the first week itelf</p>

</ul>


<B><h2>Professional Online Education</h2><br>
<h3> Recent Articles</h3></B>

<ul>
<li><img src="icon1.png"><width="62" height="62"></li>
<p><B>About Site</p></B>
<p>The site will be maintained to convey messages to students regarding Internet Technology & applictions(ITA)which is provided to 1<sup>st</sup> year 2<sup>nd</sup>semester IT/IS/CSN students</p><br>
<li><img src="icon2.png"><width"62" height="62"></li>
<p><B>Connecting People</B></p>
<p>This is to connect students with each other as well as lecturers & students. This will allow students to actively communicate with themselves & share knowledge.</p><br>
<li><img src="icon3.png"><width="62" height="62"></li>
<p><B>Student's Time</B></p>
<p>Students will be given 2 hours of lectures, 2 hours of practical sessions & 1 hour of tutorial hours per week for the Internet Technology & applications(ITA) courses.</p><br>

</ul>
</body>
</html>
       



         Hope It was useful to you.





Monday, December 8, 2014

Creating a simple network in Cisco Packet Tracer.

      Connecting two PCs through a Switch. 

      Steps.


1.   Drag and drop two PC s and a switch from the below bar. .

2.   Connect both PC s with the switch.
  •       Use Straight Through cable and select the Fast Ethernet port in both the PCs & the switch.


   



 3.  Give IPv4 addresses for both the PCs.

      Assigning  IPv4 addresses.     

      Make sure that both IPv4 addresses are in same subnet.

                            Eg:
                                      For  PC0 -     IPv4 address :           192.168.10.10
                                                            Subnet Mask:           255.255.255.0

                                      For  PC1-      IPv4 address:            192.168.10.11
                                                            Subnet Mask:           255.255.255.0





4.  Configure both PCs.

      Click on PC0  ->  Desktop -> IP Configuration -> select Static

      Give the IPv4 address & the Subnet mask.

 

           
   

5.   Configure PC1

      Click on PC1  ->  Desktop -> IP Configuration -> select Static

      Give the IPv4 address & the Subnet mask.


 
                           



6. Now ping both PCs.

          Pinging PC1 from PC0.
 
         Click on PC0 ->  Desktop ->   Command Prompt

          Give the IPv4 address of  PC1 with ping command.

          Type :
                          PC>  Ping 192.168.10.11

     

             


     

            Now your PCs are connected...........



        To Assign IPv6 addresses. 


1.   Create the structure as shown above.

2.   Configure PCs with IPv6 addresses.
 

       Make sure that both IP addresses are in same subnet.

                            Eg:
                                      For  PC0 -     IPv6 address :          2001:db8:cafe:1::10/64
                                                         
                                      For  PC1-      IPv6 address:           2001:db8:cafe:1::11/64

3.    Configure PC0

      Click on PC0  ->  Desktop -> IPv6 Configuration -> select Static

      Give the IPv6 address and the Mask.
      Provide the mask inside the separated cage.
                                 
             
                     


 4.      Configure PC1

      Click on PC1  ->  Desktop -> IPv6 Configuration -> select Static

      Give the IPv6 address and the Mask.
      Provide the mask inside the separated cage.
                                 

           
         



5.   Now ping both PCs.

          Pinging PC1 from PC0.
 
         Click on PC0 ->  Desktop ->   Command Prompt

          Give the IPv6 address of  PC1 with ping command.

          Type :
                          PC>  Ping  2001:db8:cafe:1::11

     
     

                Now your PCs are connected..........