Wednesday, January 11, 2012

integration frameworks

  • Apache Camel
Apache Camel is a powerful open source integration framework based on known Enterprise Integration Patterns with powerful Bean Integration.
http://camel.apache.org/

Saturday, January 7, 2012

Decision Making Skills

  • Using a DECISION MATRIX to help you to decide between alternatives:

SWOT analysis is a subjective method used to evaluate the STRENGTHS, WEAKNESSES, OPPORTUNITIES, and THREATS involved in trying to attain an objective


Reference:
http://www.kent.ac.uk/careers/sk/decisionmaking.htm#DECISION

  • PEST analysis (political, economic, social and technological) describes a framework of macro-environmental factors used in the environmental scanning component of strategic management. It is part of an external analysis when conducting a strategic analysis or doing market research, and gives an overview of the different macro-environmental factors to be taken into consideration. It is a strategic tool for understanding market growth or decline, business position, potential and direction for operations.
https://en.wikipedia.org/wiki/PEST_analysis


  • Identifying "Big Picture" Opportunities and Threats
Changes in your business environment can create great opportunities for your organization – and cause significant threats.PEST Analysis is a simple and widely used tool that helps you analyze the Political, Economic, Socio-Cultural, and Technological changes in your business environment. This helps you understand the "big picture" forces of change that you're exposed to, and, from this, take advantage of the opportunities that they present.PEST Analysis is often linked with SWOT Analysis [Add to My Personal Learning Plan] , however, the two tools have different areas of focus. PEST Analysis looks at "big picture" factors that might influence a decision, a market, or a potential new business. SWOT Analysis explores these factors at a business, product-line or product level.These tools complement one another and are often used together.
https://www.mindtools.com/pages/article/newTMC_09.htm

business analyst role

What are the challenges a BA may need to overcome to respond to the increased expectations of companies who hire business analysts not just to manage requirements, but

also to perform project management and participate on decision-making processes?


To be truly effective, a BA must consider the project requirements their primary concern, from the development of a product vision and scope to detailed user and

software requirements specifications and the change control processes that will be used to manage requirements during the lifetime of the proj


Reference:
http://www.bridging-the-gap.com/expanding-the-business-analyst-role-good-or-bad/

preparation

Top 5 Job Interview Tips
http://career-advice.monster.co.uk/job-interview/preparing-for-job-interviews/top-5-job-interview-tips/article.aspx


Marketing Yourself Successfully - Video Advice
http://career-advice.monster.co.uk/job-interview/job-interview-behaviour/marketing-yourself-successfully-video/article.aspx

What is the difference between an incremental backup and a differential backup?

An Incremental backup backs up only the selected files that have their archive bit set to ON, setting them back to OFF.
a backup of all files that are new or changed since the last backup whether it was a full or an incremental.
The advantage of an Incremental is that it takes the least amount of time and media of all the backup methods.
In the case of restoring with Incremental backups, all the Incremental backups since the last full backup plus the last full backup would be necessary.




A Differential backup backs up only the selected files that have their archive bit set to ON but does not set the archive bit back to OFF.
A Differential backup will back up all selected files that are new and changed since the last full backup.
at restore time; you'll need only the last full backup and the last differential to get a complete restore

Reference:
http://wiki.answers.com/Q/What_is_the_difference_between_an_incremental_backup_and_a_differential_backup


  • Continuous data protection (CDP), also called continuous backup or real-time backup, refers to backup of computer data by automatically saving a copy of every change made to that data, essentially capturing every version of the data that the user saves. In its true form it allows the user or administrator to restore data to any point in time

https://en.wikipedia.org/wiki/Continuous_Data_Protection


Simply stated, continuous data protection (CDP), also called continuous backup, is a storage system that backs up data whenever any change is made in it. In effect, CDP creates an electronic journal of complete storage snapshots, one for every instant in time that data modification occurs.

Why continuous data protection?
IT complexity: Continuous data protection helps ensure continuous availability of the varied, cross-platform environments.
Administrative capability:
Cost factor:Continuous data protection may prove to be a cheaper solution than traditional backup and recovery solutions. Software-based continuous data protection solutions today are easy to deploy and manage,
Data growth:  Remote users in geographically dispersed locations have access to email, core systems and other mission-critical applications. In such cases, continuous data protection makes perfect sense for enterprises with locations in multiple geographies.
Criticality of data:Continuous data protection technologies enable seamless backup and restore at the backend without affecting end users. Many continuous data protection solutions can recover data from any point in time within less than a minute.

Most of the challenges with continuous data protection emanate from the environment being targeted. A true continuous data protection solution will support real-time protection rather than scheduled snapshots. The change rate of the data sets that are being protected could pose challenges to the continuous data protection solution.
https://www.computerweekly.com/tip/Continuous-data-protection-Do-you-need-it

SQL JOIN

  • ChatGPT

SQL JOINs are used to combine rows from two or more tables based on a related column between them. Here’s an explanation of different types of SQL JOINs with Venn diagrams and examples:

1. INNER JOIN

Definition: An INNER JOIN returns records that have matching values in both tables. It retrieves only the rows that satisfy the join condition.

Venn Diagram:

  • A (left table) ∩ B (right table) = Intersection

Example:

Consider two tables:







  • Employees

    IDName
    1Alice
    2Bob
    3Charlie
  • Departments

    IDEmployeeIDDepartment
    11HR
    22IT
    34Finance



  • SELECT Employees.Name, Departments.Department
    FROM Employees
    INNER JOIN Departments ON Employees.ID = Departments.EmployeeID;


    Result:

    NameDepartment
    AliceHR
    BobIT

    2. LEFT OUTER JOIN

    Definition: A LEFT OUTER JOIN returns all records from the left table and the matched records from the right table. If there is no match, the result is NULL on the side of the right table.

    Venn Diagram:

    • A (left table) ∪ (AB) = Left table plus the intersection
    SELECT Employees.Name, Departments.Department
    FROM Employees
    LEFT OUTER JOIN Departments ON Employees.ID = Departments.EmployeeID;


    3. RIGHT OUTER JOIN

    Definition: A RIGHT OUTER JOIN returns all records from the right table and the matched records from the left table. If there is no match, the result is NULL on the side of the left table.

    Venn Diagram:

    • B (right table) ∪ (AB) = Right table plus the intersection

    SELECT Employees.Name, Departments.Department
    FROM Employees
    RIGHT OUTER JOIN Departments ON Employees.ID = Departments.EmployeeID;

    4. FULL OUTER JOIN

    Definition: A FULL OUTER JOIN returns all records when there is a match in either left or right table. It combines the results of both LEFT OUTER JOIN and RIGHT OUTER JOIN.

    Venn Diagram:

    • A (left table) ∪ B (right table) = Union of both tables

    Example:

    SQL Query:



    SELECT Employees.Name, Departments.Department
    FROM Employees
    FULL OUTER JOIN Departments ON Employees.ID = Departments.EmployeeID;

    Summary

    • INNER JOIN: Retrieves only the rows with matching values in both tables (intersection).
    • LEFT OUTER JOIN: Retrieves all rows from the left table and matching rows from the right table (left table plus intersection).
    • RIGHT OUTER JOIN: Retrieves all rows from the right table and matching rows from the left table (right table plus intersection).
    • FULL OUTER JOIN: Retrieves all rows from both tables, with NULL where there are no matches (union of both tables).

    • The SQL JOIN clause is used whenever we have to select data from 2 or more tables.

    There are 2 types of SQL JOINS – INNER JOINS and OUTER JOINS.

    The INNER JOIN will select all rows from both tables as long as there is a match between the columns we are matching on.

    SQL OUTER JOIN and it has 2 sub-types called LEFT OUTER JOIN and RIGHT OUTER JOIN.


    The LEFT OUTER JOIN or simply LEFT JOIN (you can omit the OUTER keyword in most databases),
    selects all the rows from the first table listed after the FROM clause, no matter if they have matches in the second table.

    The RIGHT OUTER JOIN or just RIGHT JOIN behaves exactly as SQL LEFT JOIN, except that it returns all rows from the second table (the right table in our SQL JOIN statement).



    References:
    http://www.sql-tutorial.net/SQL-JOIN.asp
    http://www.quackit.com/sql/tutorial/sql_outer_join.cfm
    http://www.tizag.com/sqlTutorial/sqljoin.php
    http://www.sqltutorial.org/sqljoin-innerjoin.aspx




    • INNER JOIN
    Inner join shows matches only when they exist in both tables.this SQL will only give you result with customers who have orders. If the customer does not have order, it will not display that record
    SELECT Customers.*, Orders.* FROM Customers INNER JOIN Orders ON Customers.CustomerID =Orders.CustomerID

    There is another way to visualize the SQL INNER JOIN by using the Venn diagrams

    • LEFT OUTER JOIN
    Left join will display all records in left table of the SQL statement. In SQL below customers with or without orders will be displayed. Order data for customers without orders appears as NULL values
    SELECT Customers.*, Orders.* FROM Customers LEFT OUTER JOIN Orders ON Customers.CustomerID =Orders.CustomerID

    There is another way to visualize the SQL INNER JOIN by using the Venn diagrams

    • RIGHT OUTER JOIN
    Right join will display all records in right table of the SQL statement. In SQL below all orders with or without matching customer records will be displayed. Customer data for orders without customers appears as NULL values
    SELECT Customers.*, Orders.* FROM Customers RIGHT OUTER JOIN Orders ON Customers.CustomerID =Orders.CustomerID

    There is another way to visualize the SQL INNER JOIN by using the Venn diagrams

    • FULL OUTER JOIN
    Full outer join it will return all records from left table and from right table.
    There is another way to visualize the SQL INNER JOIN by using the Venn diagrams




    • JOIN SCHEMA



    • Using Cross Joins

    A cross join that does not have a WHERE clause produces the Cartesian product of the tables involved in the join. The size of a Cartesian product result set is the number of rows in the first table multiplied by the number of rows in the second table.

    The result set contains 170 rows (SalesPerson has 17 rows and SalesTerritory has 10; 17 multiplied by 10 equals 170).

    http://msdn.microsoft.com/en-us/library/ms190690%28v=sql.105%29.aspx


    The SQL CROSS JOIN produces a result set which is the number of rows in the first table multiplied by the number of rows in the second table, if no WHERE clause is used along with CROSS JOIN. This kind of result is called as Cartesian Product
    http://www.w3resource.com/sql/joins/cross-join.php




    • Cross join

    CROSS JOIN returns the Cartesian product of rows from tables in the join. In other words, it will produce rows which combine each row from the first table with each row from the second table



    CREATE TABLE department
    (
     DepartmentID INT,
     DepartmentName VARCHAR(20)
    );

    CREATE TABLE employee
    (
     LastName VARCHAR(20),
     DepartmentID INT
    );



    INSERT INTO department(DepartmentID, DepartmentName) VALUES(31, 'Sales');
    INSERT INTO department(DepartmentID, DepartmentName) VALUES(33, 'Engineering');
    INSERT INTO department(DepartmentID, DepartmentName) VALUES(34, 'Clerical');
    INSERT INTO department(DepartmentID, DepartmentName) VALUES(35, 'Marketing');

    INSERT INTO employee(LastName, DepartmentID) VALUES('Rafferty', 31);
    INSERT INTO employee(LastName, DepartmentID) VALUES('Jones', 33);
    INSERT INTO employee(LastName, DepartmentID) VALUES('Steinberg', 33);
    INSERT INTO employee(LastName, DepartmentID) VALUES('Robinson', 34);
    INSERT INTO employee(LastName, DepartmentID) VALUES('Smith', 34);
    INSERT INTO employee(LastName, DepartmentID) VALUES('John', NULL);

    Example of an explicit cross join:

    SELECT *
    FROM employee
    CROSS JOIN department;

    Example of an implicit cross join:

    SELECT *
    FROM employee, department;


    Inner join

    SELECT *
    FROM employee
    INNER JOIN department ON employee.DepartmentID = department.DepartmentID;

    The following example is equivalent to the previous one, but this time using implicit join notation:

    SELECT *
    FROM employee, department
    WHERE employee.DepartmentID = department.DepartmentID;


    Left outer join

    SELECT *
    FROM employee
    LEFT OUTER JOIN department ON employee.DepartmentID = department.DepartmentID;


    Right outer join

    SELECT *
    FROM employee
    RIGHT OUTER JOIN department ON employee.DepartmentID = department.DepartmentID;


    Full outer join

    SELECT *
    FROM employee
    FULL OUTER JOIN department ON employee.DepartmentID = department.DepartmentID;


    Self-join
    A self-join is joining a table to itself

    SELECT F.EmployeeID, F.LastName, S.EmployeeID, S.LastName, F.Country
    FROM Employee F
    INNER JOIN Employee S ON F.Country = S.Country
    WHERE F.EmployeeID < S.EmployeeID
    ORDER BY F.EmployeeID, S.EmployeeID;


    http://en.wikipedia.org/wiki/Join_%28SQL%29

    • JOIN Three Tables

    method 1

    SELECT Orders.OrderID, Customers.CustomerName, Shippers.ShipperName
    FROM ((Orders
    INNER JOIN Customers ON Orders.CustomerID = Customers.CustomerID)
    INNER JOIN Shippers ON Orders.ShipperID = Shippers.ShipperID);

    method 2
    SELECT tablo1.OrderID, tablo1.CustomerName, Shippers.ShipperName
    FROM (select * from Orders INNER JOIN Customers ON Orders.CustomerID = Customers.CustomerID) 
    as tablo1
    INNER JOIN Shippers ON tablo1.ShipperID = Shippers.ShipperID;

    https://www.w3schools.com/sql/sql_join_inner.asp




    Friday, January 6, 2012

    The Key Differences Between SAN, DAS, and NAS

    • Direct-Attached Storage(DAS)

    The most common form of server storage today is still direct attached storage.
    The disks may be internal to the server or they may be in an array that is connected directly to the server
    Either way, the storage can be accessed only through that server.
    An application server will have its own storage; the next application server will have its own storage;
    and the file and print servers will each have their own storage



    • Storage Area Networks(SAN)

    A SAN allows more than one application server to share storage.
    Data is stored at a block level and can therefore be accessed by an application, not directly by clients
    The physical elements of the SAN (servers, switches, storage arrays, etc.) are typically connected with Fibre-Channel – an interconnect technology that permits high-performance resource sharing
    Storage can be added without disrupting the applications, and different types of storage can be added to the pool.


    A storage area network (SAN) is a dedicated network that provides access to consolidated, block level data storage. SANs are primarily used to make storage devices, such as disk arrays, tape libraries, and optical jukeboxes, accessible to servers so that the devices appear like locally attached devices to the operating system. A SAN typically has its own network of storage devices that are generally not accessible through the local area network by other devices
    In storage networking terminology, a Storage Area Network (SAN) is a high-speed subnetwork of shared storage devices. A storage device is a machine that contains nothing but a disk or disks for storing data.

    A SAN's architecture works in a way that makes all storage devices available to all servers on a LAN or WAN. As more storage devices are added to a SAN, they too will be accessible from any server in the larger network. In this case, the server merely acts as a pathway between the end user and the stored data.

    Because stored data does not reside directly on any of a network's servers, server power is utilized for business applications, and network capacity is released to the end user.




    • Network Attached Storage(NAS)

    A NAS appliance is a simplified form of file server; it is optimized for file sharing in an organization.
    Authorized clients can see folders and files on the NAS device just as they can on their local hard drive
    NAS devices are frequently used to consolidate file services.
    To prevent the proliferation of file servers, a single NAS appliance can replace many regular file servers, simplifying management and reducing cost and workload for  the systems administrator.
    NAS appliances are also multiprotocol, which means that they can share files among clients using Windows® and UNIX®-based operating systems.

    Reference:
    http://smbtechconnect.securelement.com/2008/03/key-differences-between-san-das-and-nas.html


    • An optical jukebox is a robotic data storage device that can automatically load and unload optical discs, such as Compact Disc, DVD, Ultra Density Optical or Blu-ray disc and can provide terabytes (TB) and petabytes (PB) of tertiary storage.

    https://en.wikipedia.org/wiki/Optical_jukebox

    spring interview questions


    • What is IOC (or Dependency Injection)?


    The basic concept of the Inversion of Control pattern (also known as dependency injection) is that you do not create your objects but describe how they should be created
    You don't directly connect your components and services together in code but describe which services are needed by which components in a configuration file


    • What is Spring ?

    Spring is an open source framework created to address the complexity of enterprise application development.
    Spring is a lightweight inversion of control and aspect-oriented container framework.



    • What are the advantages of Spring framework?

    Spring has layered architecture.
    Use what you need and leave you don't need now.
    Spring Enables POJO Programming.
     POJO programming enables continuous integration and testability.
    Dependency Injection and Inversion of Control Simplifies JDBC


    • What are features of Spring ?
    Inversion of control (IOC):



    Loose coupling is achieved in spring using the technique Inversion of Control.
    The objects give their dependencies instead of creating or looking for dependent objects

    Aspect oriented (AOP):
    Spring supports Aspect oriented programming and enables cohesive development by separating application business logic from system services.

    MVC Framework:
    Spring comes with MVC web application framework, built on core Spring functionality.
    This framework is highly configurable via strategy interfaces, and accommodates multiple view technologies like JSP, Velocity, Tiles, iText, and POI.
    But other frameworks can be easily used instead of Spring MVC Framework.

    JDBC Exception Handling:
    The JDBC abstraction layer of the Spring offers a meaningful exception hierarchy, which simplifies the error handling strategy.
    Integration with Hibernate, JDO, and iBATIS:
    Spring provides best Integration services with Hibernate, JDO and iBATIS



    • What are the different modules in Spring framework?

    The Core container module
    Application context module
    AOP module (Aspect Oriented Programming)
    JDBC abstraction and DAO module
    O/R mapping integration module (Object/Relational)
    Web module
    MVC framework module

    Reference:
    http://www.developersbook.com/spring/interview-questions/spring-interview-questions-faqs.php
    http://www.javabeat.net/articles/103-spring-framework-interview-questions-1.html




    • Model-view-controller framework

    The Spring Framework features its own MVC web application framework, which wasn't originally planned. The Spring developers decided to write their own web framework as a reaction to what they perceived as the poor design of the (then) popular Jakarta Struts web framework,
    Like Struts, Spring MVC is a request-based framework
    MVC paves the way for cleaner front end code. All interfaces are tightly coupled to the Servlet API.
    This tight coupling to the Servlet API is seen by some as a failure on the part of the Spring developers to offer a high-level abstraction for web-based applications[citation needed].
    However, this coupling makes sure that the features of the Servlet API remain available to developers while offering a high abstraction framework to ease working with said API.
    http://en.wikipedia.org/wiki/Spring_Framework#Model-view-controller_framework



    • With desktop Java apps, you can have a single piece of 

    code that instantiates the container and gets beans
    • I.e., driver class that calls instantiates
    ClassPathXmlApplicationContext and calls getBean
    – With Web apps, each servlet wants access to beans
    • But you want to instantiate container once only


    bean scopes
    – Standard Spring supports singleton and prototypeStandard Spring supports singleton and prototype
    – Web apps also want request, session, and application


    Regular Web Apps
    Put bean definitions in WEB-INB/applicationContext.xml
    • request and session scope now supported• request and session scope now supported
    Declare two listeners in web.xml
    • Container will be instantiated when app is loaded

    JSF Apps
    Same approach for JAR files, bean defn file, and listenerspp , ,
    – Declare variable-resolver in faces-config.xml
    Can declare beans in applicationContext or faces-config



    applicationContext.xml
    – Put “empty” file (with header and py (
    <beans..></beans> only) in WEB-INF
    • Unlike in desktop apps, the filename matters. The
    standard loading utility assumes that name and location

    /WEB-INF/applicationContext.xml
    • If you want to change this default name/location, set a
    context param called contextConfigLocation to override it


    ContextLoaderListener
    – This listener runs when the app is firs
    instantiates the ApplicationContext (f
    WEB-INF/applicationContext.xml) and places aWEB INF/applicationContext.xml) an
    reference to it in the ServletContext
    You can retrieve this reference with the static
    tR i dW bA li ti C t t th d fgetRequiredWebApplicationContext method of
    WebApplicationContextUtils


    RequestContextListener
    – This listener is needed if you declare any of your beans to
    be request-scoped or session-scoped
    IWb itdfth lSi f• I.e., Web scopes instead of the usual Spring scopes of
    singleton or prototype


    Not good to call getBean
    – It would be technically legal to get the
    ApplicationContext and call getBean explicitly (probably
    from the backing bean’s action controller method). Butfrom the backing bean s action controller method). But
    this is a bad idea since JSF is geared around declaring
    beans in config files only



    JSF already supports dependency injection
    – The managed-property element lets you insert other beans
    inside newly created ones.inside newly created ones.
    • The only trick is to be able to refer to Spring beans



    Use DelegatingVariableResolver
    – Declare in faces-config.xml. Now, whenever JSF sees a
    bean name, it uses JSF rules first, then Spring rules next.



    Regular Web Apps
    • Two JAR files
    – Put Spring JAR files in WEB-INF/lib
    • Bean definition file
    PliiC liWEB INF– Put applicationContext.xml in WEB-INF
    • Scopes now include request and session in addition to
    singleton and prototype
    • Listeners
    – Two listener definitions in web.xml
    G tti b• Getting beans
    – Access ApplicationContext with static
    getRequiredWebApplicationContext method ofgetRequiredWebApplicationContext method of
    WebApplicationContextUtils
    – Call getBean normally



    JSF-Based Apps
    • Basic setup
    – Start with same setup as regular Web apps
    – Use normal JSF definition of FacesServlet in web.xml
    faces config xml• faces-config.xml
    – Declare DelegatingVariableResolver
    • Option 1• Option 1
    – Declare Spring beans in applicationContext.xml
    – Declare backing beans in faces-config.xmlg g
    • Refer to Spring beans with managed-bean-property
    • Option 2
    – Declare all beans in applicationContext.xml
    • Refer to other beans with ref and normal Spring syntax



    Gets the Spring bean called sampleLookupService
    and passes it to the setLookupService method of the
    JSF backing bean called formBean (i.e., injects it
    into the lookupService property).
    into the lookupService property).


    03-Spring-in-Web-Apps.pdf
    http://courses.coreservlets.com/Course-Materials/spring.html

    static scoping(lexical) vs dynamic scoping

    • ChatGPT

    Static Scoping vs. Dynamic Scoping

    Static Scoping (Lexical Scoping) and Dynamic Scoping are two different methods used to determine the scope and binding of variables in programming languages. Here's a detailed explanation with examples:


    1. Static Scoping (Lexical Scoping)

    Definition: In static scoping, the scope of a variable is determined by its position in the source code. The variable's binding is fixed at compile-time based on the program's structure.

    Characteristics:

    • Variable references are resolved based on the program's text structure.
    • The scope of a variable is determined by the block or function where it is defined.
    • A variable can be accessed only within the block or function where it is declared, and this relationship does not change regardless of the program's execution.

    int globalVar = 1;

    void foo() {
        int localVar = 2;
        print(globalVar); // prints 1
        print(localVar);  // prints 2
    }

    void bar() {
        print(globalVar); // prints 1
        // print(localVar); // Error: localVar not defined in this scope
    }

    int main() {
        foo();
        bar();
    }


    In this example:

    • globalVar is accessible throughout the program because it is declared in the global scope.
    • localVar is only accessible within foo() because it is declared within foo()'s local scope.

    2. Dynamic Scoping

    Definition: In dynamic scoping, the scope of a variable is determined by the call stack at runtime. The binding of a variable is based on the calling sequence of functions, not the structure of the code.


    Characteristics:

    • Variable references are resolved based on the execution call stack.
    • The scope of a variable is determined dynamically, depending on the function call hierarchy at runtime.
    • Variables are accessible in functions that are called within the context where the variable was defined.
    int globalVar = 1;

    void foo() {
        int localVar = 2;
        print(globalVar); // prints 1 (globalVar is accessible)
        print(localVar);  // prints 2
    }

    void bar() {
        print(globalVar); // prints 2 (globalVar is from foo's scope in dynamic scoping)
    }

    int main() {
        foo();
        bar();
    }

    In this example:

    • globalVar is set to 1 globally.
    • When bar() is called after foo(), dynamic scoping would cause globalVar to print 2 if bar() could access globalVar set in foo().

    Comparison

    • Static Scoping:

      • Variable scope is determined by the position of the variable in the source code.
      • More predictable and easier to understand because the scope does not change dynamically.
      • Example languages: C, Java, Python (mostly).
    • Dynamic Scoping:

      • Variable scope is determined by the runtime call stack.
      • Less predictable because the scope can change depending on function calls.
      • Example languages: Some Lisp dialects (like older versions of Emacs Lisp).
    Summary: Static scoping relies on the structure of the code to determine variable scope, making it more predictable. Dynamic scoping relies on the call stack and the sequence of function calls, making it more flexible but potentially less predictable.
    • ChatGPT

    To determine the output of the given pseudocode under both static (lexical) scoping and dynamic scoping, we need to understand how variable scopes are managed in each case.

    Pseudocode Analysis:

    int i
    main ()
    {
        i = 3
        S ()
        R ()
    }

    void S ()
    {
        print i // prints the value of i on the current line of output
        print " " // prints a blank space on the current line of output
    }

    void R ()
    {
        int i
        i = 2
        S ()
    }


    Static Scoping (Lexical Scoping)

    In static scoping, the scope of a variable is determined by its physical location in the code.

    1. In main: i is set to 3. The function S() is called first.

      • S() prints the value of i from main, which is 3.
      • S() then prints a blank space.
    2. In R: A new local i is created and set to 2.

      • When S() is called within R(), it refers to the i from main due to static scoping.
      • So S() prints the i from main, which is still 3, and then a blank space.

    Static Scoping Output:

    3 (from main)  // `S()` prints `3` from `main`

    (Blank space)  // `S()` prints a space

    3 (from main)  // `S()` prints `3` from `main` again in `R()`


    Output: 3 3


    Dynamic Scoping

    In dynamic scoping, the scope of a variable is determined by the call stack at runtime.

    1. In main: i is set to 3. The function S() is called.

      • S() prints the i from main, which is 3.
      • S() then prints a blank space.
    2. In R: A new local i is created and set to 2.

      • When S() is called within R(), it will print the i from R(), which is 2, because dynamic scoping looks up the variable from the most recent context in the call stack.

    Dynamic Scoping Output:


    3 (from main)  // `S()` prints `3` from `main`

    (Blank space)  // `S()` prints a space

    2 (from `R`)   // `S()` prints `2` from `R()`


    Output: 3 2

    Summary:

    • Static Scoping Output: 3 3
    • Dynamic Scoping Output: 3 2

    So the answers for the options provided are:

    • Static Scoping: Option D) 3 3 3 2
    • Dynamic Scoping: Option C) 3 3 2 2

    • Gemini

    Static vs. Dynamic Scoping: Understanding the Output
    Understanding Static and Dynamic Scoping

    Before we analyze the output, let's clarify the two scoping methods:

        Static Scoping (Lexical Scoping): The scope of a variable is determined by its position in the code, not by the calling function. This is the most common scoping method in modern programming languages.
        Dynamic Scoping: The scope of a variable is determined by the calling sequence of functions at runtime.

    Analyzing the Pseudocode

    Given Pseudocode:

    int i
    main ()
    {
    i = 3
    S ()
    R ()
    }
    void S ()
    {
    print i // prints the value of i on the current line of output
    print " " // prints a blank space on the current line of output
    }
    void R ()
    {
    int i
    i = 2
    S  

     ()
    }

    Static Scoping:

        The i in function S refers to the global i which is initialized to 3.
        The i in function R is a local variable and hides the global i.
        The output will be: 3 3 2

    Dynamic Scoping:

        The i in function S will refer to the most recently defined i.
        When S is called from R, the i in R is the most recent, so it will print 2.
        The output will be: 3 2 3

    Answer:

        Static Scoping: (C) 3 3 2 3
        Dynamic Scoping: (B) 3 3 2 2

    Explanation:

        The first 3 is printed from the main function.
        The second 3 is printed from function S, referring to the global i in static scoping, and the local i in R in dynamic scoping.
        The 2 is printed from function R.
        The last 3 is printed from function S again, referring to the global i in static scoping.

    This example demonstrates the difference between static and dynamic scoping. Static scoping is more predictable as it relies on the code structure, while dynamic scoping depends on the function call stack at runtime, which can lead to unexpected results.

    Statically typed languages check types at compile time
    The programmer ensures that parameter types are specified and the compiler ensures the programmers wishes will be followed.

    In a dynamically typed language (like ruby, javascript, etc), types are not checked until execution
    If an expression evaluates, then the type-checking worked. If not, it blows up to your error handling or the user

    Static Scoping – Variables can be bound at compile time without regards to calling code.

    Dynamic Scoping – Variable binding (context) can only be determined at the moment code is executed.



    Reference:
    http://hoolihan.net/blog-tim/2009/02/17/static-vs-dynamic-scope/
    http://en.wikipedia.org/wiki/Scope_%28programming%29




    • First, Lexical Scope (also called Static Scope), in C-like syntax:

    void fun()
    {
        int x = 5;
    
        void fun2()
        {
            printf("%d", x);
        }
    }
    Every inner level can access its outer levels.
    There is another way, called Dynamic Scope used by first implementation of Lisp, again in C-like Syntax:
    void fun()
    {
        printf("%d", x);
    }
    
    void dummy1()
    {
        int x = 5;
    
        fun();
    }
    
    void dummy2()
    {
        int x = 10;
    
        fun();
    }
    Here fun can either access x in dummy1 or dummy2, or any x in any function that call fun with xdeclared in it.
    dummy1();
    will print 5
    dummy2();
    will print 10

    The first one is called static because it can be deduced at compile-time, the second is called dynamic because the outer scope is dynamic and depends on the chain call of the functions.
    Dynamic scoping is like passing references of all variables to the called function.
    stackoverflow

    stack vs heap

    how the memory of the computer is organized for a running program
    When a program is loaded into memory, it is organized into three areas of memory, called segments:
    the text segment,
    stack segment,
    heap segment.

    The text segment (sometimes also called the code segment) is where the compiled code of the program itself resides
    This is the machine language representation of the program steps to be carried out, including all functions making up the program, both user defined and system.

    The stack is where memory is allocated for automatic variables within functions.

    The heap segment provides more stable storage of data for a program;
    memory allocated in the heap remains in existence for the duration of a program.
    Therefore, global variables (storage class external), and static variables are allocated on the heap.


    The stack is a place in the computer memory where all the variables that are declared and initialized before runtime are stored
    The heap is the section of computer memory where all the variables created or initialized at runtime are stored

    computer memory, it is organized into three segments:

    text (code) segment
    stack segment
    heap segment


    The text segment (often called code segment) is where the compiled code of the program itself resides. When you open some EXE file in Notepad, you can see that it includes a lot of "Gibberish" language, something that is not readable to human. It is the machine code, the computer representation of the program instructions.


    Heap and stack in Java
    When you create an object using the new operator, for example myobj = new Object();, it allocates memory for the myobj object on the heap.
    The stack memory space is used when you declare automatic variables.

    for example String myString;, it is a reference to an object so it will be created using new and hence it will be placed on the heap

    Reference:
    http://ee.hawaii.edu/~tep/EE160/Book/chap14/subsection2.1.1.8.html
    http://www.maxi-pedia.com/what+is+heap+and+stack





    • Stack memory

    -Size required determined at compile-time, so no need at run time to determine amount of memory to allocate at run time. This is obviously a performance advantage
    In contrast, the size of objects allocated on the stack, needs to be known at compile time

    -Automatic "clean-up"
    your program takes care of stack memory (allocating it & cleaning it up)

    -The most important thing about the stack is that you don't need to think much about it. Your program manages it.

    -The size of the stack is usually quite small because it's mostly used for local variables (variables that go out of scope pretty soon after they're finished with). The size of the stack is set at compile time and is small enough to be available on any computer, no matter how little RAM it's got

    -Stack is where variables declared before runtime are stored.





    • Heap memory

    -It's also used very frequently to allocate memory for things whose size is not known until run time. For example, if you had to open a file and read in the data, you don't know how much data exists until run time

    -The size of objects allocated on the heap is often not known to the compiler - therefore the programmer must allocate and release the memory specifically.

    -If a particular computer has a lot of RAM, why not make use of it?
    Therefore the heap consists of memory that can be allocated at run time

    -Heap memory is most often used for 'large' things (e.g. the contents of a file) - or for things that need to 'stay around' in memory so that different functions can share the data (in other words, for NON-local variables).

    -Heap is where variables created or initialized at runtime are stored.

    -On the other hand, heap is an area of memory used for dynamic memory allocation


    http://hep.ph.liv.ac.uk/~gwilliam/cppcourse/




    • When you look at your computer memory, it is organized into three segments:

    ?text (code) segment
    ?stack segment
    ?heap segment



    The text segment (often called code segment) is where the compiled code of the program itself resides. When you open some EXE file in Notepad, you can see that it includes a lot of "Gibberish" language, something that is not readable to human. It is the machine code, the computer representation of the program instructions. This includes all user defined as well as system functions.




    • What is stack?

    The two sections other from the code segment in the memory are used for data. The stack is the section of memory that is allocated for automatic variables within functions.

    Data is stored in stack using the Last In First Out (LIFO) method. This means that storage in the memory is allocated and deallocated at only one end of the memory called the top of the stack. Stack is a section of memory and its associated registers that is used for temporary storage of information in which the most recently stored item is the first to be retrieved.






    • What is heap?

    On the other hand, heap is an area of memory used for dynamic memory allocation. Blocks of memory are allocated and freed in this case in an arbitrary order. The pattern of allocation and size of blocks is not known until run time. Heap is usually being used by a program for many different purposes.

    The stack is much faster than the heap but also smaller and more expensive.









    Reverse a String

    A typical programming interview question is “reverse a string, in place”. if you understand pointers, the solution is simple. even if you don’t, it can be accomplished using array indices


    to reverse the string word by word, in place. for example if our string is “the house is blue”, the return value would be “blue is house the”. the words are reversed, but the letters are still in order


    initial: the house is blue
    reverse: eulb si esuoh eht
    wanted : blue is house the

    the solution can be attained by first reversing the string normally, and then just reversing each word.

    Reference:
    http://www.techinterview.org/post/526374214/reverse-a-string





    • 3-ways to reverse a string in java



    First Solution: StringBuffer
    The easiest way to reverse a String in Java is by using an instance of the StringBuffer class as it already contains a reverse() method.


    Second Solution: Reverse For Loop
    You can also reverse a String by traversing it from the end in a traditional for loop. For this approach you can either use a char array which would be somewhat more efficient than by creating a large String pool as a result of continuous concatenation to a String variable.

    Third Solution: Recursion

    http://www.brilliantsheep.com/3-ways-to-reverse-a-string-in-java/

    algorithms & data structures

    Understanding how to choose the best algorithm or data structure for a particular task is one of the keys to writing high-performance software
    If you start with the wrong algorithm, all the micro-level tuning in the world won't produce optimal results.


    • What is a data structure? What are the types of data structures?

    Data structures are used to store data in a computer in an organized fashion.


    • Different types of data structures are:


    1. Arrays: A set of homogeneous values
    2. Records: A set of fields, where each field consists of data belongs to one data type.
    3. Stack- Works in first in last out order. The element inserted first in stack is removed last.
    4. Queue- First in First out order. The element inserted first is removed first.
    5. Linked list- Stored data in a linear fashion.
    6. Trees- Stores data in a non linear fashion with one root node and sub nodes.A data structure where the data is organized in a hierarchical structure.This type of data structure follows the sorted order of insertion, deletion and modification of data items




    • Define a linear and non linear data structure

    Linear data
    Linked list is an example of linear data storage or structure.
    Linked list stores data in an organized a linear fashion. They store data in the form of a list.
    A linear data structure traverses the data elements sequentially, in which only one data element can directly be reached.
    Ex: Arrays, Linked Lists

    Non Linear data structure
    Tree data structure is an example of a non linear data structure.
    A tree has one node called as root node that is the starting point that holds data and links to other nodes.
    Every data item is attached to several other data items in a way that is specific for reflecting relationships.
    The data items are not arranged in a sequential structure.
    Ex: Trees, Graphs

    data structure is a way of organizing data that considers how items are stored and their relationship between them


    Reference:
    http://java.sun.com/docs/books/performance/1st_edition/html/JPAlgorithms.fm.html
    http://www.java2s.com/Code/Java/Collections-Data-Structure/CatalogCollections-Data-Structure.htm
    http://www.careerride.com/Data-Structure-Interview-Questions.aspx
    http://globalguideline.com/interview_questions/Questions.php?sc=Data_Structures_Interview_Questions_and_Answers_&page=1

    B+ tree

    In computer science, a B+ tree or B plus tree is a type of tree which represents sorted data in a way that allows for efficient insertion, retrieval and removal of records, each of which is identified by a key. It is a dynamic, multilevel index, with maximum and minimum bounds on the number of keys in each index segment (usually called a "block" or "node"). In a B+ tree, in contrast to a B-tree, all records are stored at the leaf level of the tree; only keys are stored in interior nodes.

    Reference:
    http://en.wikipedia.org/wiki/B%2B_tree



    • Consider the following B+ tree with degree d = 2,
    which means each node except the root has between 2 and 4 keys, as shown in Figure 1. We label
    each node as A0,B0,B1,C0,C1 ... so that you can redraw the tree easily

    (1)Different applications with different types of queries may require different indexes on a database
    in order to have high efficiency. What type of queries, which your application needs a lot, will
    make you choose a B+ tree index over a hash table index? Can you give an example of this type
    of queries.(2 points)

    Solution When an application needs a lot of range queries, a B+ tree index is preferred. For
    example, find all the data entries between 20 and 22

    (2)Show the B+ tree that would result from deleting the data entry with key 79 from the original
    tree. You MUST redraw the whole tree in your result. But you can use just the labels to denote
    those nodes that are unchanged. An example of deleting the data entry with key 6 from the original
    tree is shown in Figure 2. If you add descriptions about how the B+ tree is changed, you may get
    partial credits if your result drawing is not totally correct. (4 points)

    (3) Show the B+ Tree that would result from adding the data entry with key 10 from the original
    tree. You MUST redraw the whole tree in your result. But you can use just the labels to denote
    those nodes that are unchanged. If you add descriptions about how the B+ tree is changed, you
    may get partial credits if your result drawing is not totally correct. (4 points)


    webcache.googleusercontent.com/search?q=cache:8vRupC7L9OYJ:https://wiki.engr.illinois.edu/download/attachments/227743489/CS411-F2011-Final-Sol.pdf%3Fversion%3D1%26modificationDate%3D1380470739000+&cd=3&hl=tr&ct=clnk&gl=tr&client=firefox-a

    Thursday, January 5, 2012

    What's the difference between a hub, a switch, and a router?

    What's the difference between a hub, a switch,a bridge,a repeater and a router?


    • Hubs

    A hub is typically the least expensive, least intelligent, and least complicated of the three.
    It's job is very simple - anything that comes in one port is sent out to the others.
    Hub: Layer 1device, just a multi-port repeater and works on physical layer


    • Switches

    A switch does essentially what a hub does, but more efficiently.
    By paying attention to the traffic that comes across it, it can "learn" where particular addresses are.
    Switch: Layer 2 device, can work on data link layer


    • Routers

    A router is the smartest and most complicated.
    a router operates exactly as a switch, learning the location of the computers on its connections and routing traffic only to those computers
    Router: Layer 3 device, can work on physical, data and network layer


    • Bridge

    Bridge: Layer 2 device, can work on data link layer.

    Reference:
    http://ask-leo.com/whats_the_difference_between_a_hub_a_switch_and_a_router.html


    Switches, and Routers, and Hubs! Oh my!
    http://www.youtube.com/watch?v=reXS_e3fTAk&feature=related


    • 1- What is the difference between a hub and a switch?
    In the case of a hub, it broadcasts all data to every port. This can make for serious security and reliability concerns, as well as cause a number of collisions to occur on the network.
    Switches on the other hand create connections dynamically, so that usually only the requesting port can receive the information destined for it.

    http://resources.infosecinstitute.com/ramp-5-levels-top-50-network-administrator-interview-questions/