Chelsie  Towne

Chelsie Towne

1598777580

Docker: my questions from the first day

I recently started using Docker, and with that produced an absolute pile of questions. Scraping through Google and StackOverflow for answers, here is a compilation of what I can remember learning on the first day.


Images and Docker Hub

How do I see the actual docker file on Docker Hub?

Amazingly this isn’t a simple thing.

Docker Hub really just hosts the images, not the actual Dockerfile used to make them (assuming they were made from a Dockerfile). You can get lucky by heading to the page for the desired image on Docker Hub, and often you will find a link to a GitHub hosted Dockerfile.

#docker #programming #coding #ai #development

What is GEEK

Buddha Community

Docker: my questions from the first day
Felix Kling

Felix Kling

1683553906

Everything You Need to Know About CSS Variables

I'll be covering all you need to know about CSS variables. A complete guide To CSS Variables with examples. In this tutorial, we will explore what CSS variables are and how to use variables in CSS for creating beautiful responsive websites. 

Learn CSS Variables in 15 Minutes

In today's tutorial, I'll be covering all you need to know about CSS variables in 15 minutes. These include it's basic usage, combining it with the calc() function, fallback values and inheritence + psuedo classes.


A Complete Guide To CSS Variables [With Examples]

Variables are the basic building block of any software application. They reduce the redundant tasks for the developers in a program and hold values that have to be used in the entire program. Websites are a bit different. A novice in web programming may not be aware that variables exist at the front-end of web development as well as in CSS. Variables serve the same purpose as they serve when implementation is done using C++, Python, etc. Their work and complexities motivated us to come up with a dedicated blog on CSS variables.

CSS variables (also known as Custom Properties) is a modern CSS specification that is gaining prominence due to widespread browser support. It reduces coding and maintenance time and lets you develop cross browser compatible websites. It also helps in declaring values for reuse across a CSS file, which was previously possible only with preprocessors such as Sass and LESS.

In this blog, we will explore what CSS variables are and how to use variables in CSS for creating beautiful responsive websites. Finally, we will back it up with practical examples. So let’s begin!

What Are CSS Variables?

CSS variables are custom properties in which you can store a value and use it anywhere in the HTML code. They were introduced in Chrome 49 and have been extremely popular ever since. However, unlike programming languages that support simple initialization and substitution syntax, CSS variables need to be specifically defined whether they are being initialized or substituted. Hence, both of these things have their separate syntaxes.

CSS (4)

The initialization of the CSS variable is done by prefixing “–” to the variable name. For example, the following syntax initializes the variable “my_font” to 20px.

--my_font: 20px;

The “my_font” variable can now be used anywhere inside the code with a value of “20px”. Next comes the substitution part. The substitution of a property to the variable can be done only by the “var()” CSS property. Inside the “var(),” we spell the variable name as shown below:

selector {
    font-size : var(--my_font);
}

In the above syntax, the font size of the selector will become 20px due to the my_font variable. The “var()” takes another argument apart from the variable name – the fallback value. The fallback value works as a safety net in the variable substitution. In scenarios where the variable value is found to be inaccessible, the fallback value will be used in its place. The fallback value can be declared as shown below:

font-size: var(--my_font, 20px);

Fallback values work differently in different aspects. We will discuss this later in this post with some interesting illustrations related to web browsers.

Life Before CSS Variables – The SASS Preprocessor

Before understanding how to use variables in CSS and their importance in the website styling sheet, we need to understand what we used to do before variables in CSS. Before we had this awesome custom property to use, the web developers would use the SASS variables, which had similar intentions but were not smooth and flexible.

SASS variables work similarly to the backend languages where we copy-paste the variable name whenever substitution is required. The initialization, however, is done by prefixing the “$” to the variable name.

$my_font: 20px;

The substitution can be done as shown below:

font-size: $my_font;

The problem with SASS is that it is a preprocessor and not a custom property as a CSS variable. Therefore, any variable declared in SASS needs to be compiled before it can be executed. This makes the variable static and irresistible to change at runtime. A very common problem, therefore, arises when the developer tries to reinitialize the variable as follows.


$my_font: 20px;
 
selector1 {
 
   font-size: $my_font;
}
 
selector2 {
  
   $my_font : $my_font + 1;
   font-size: $my_font; 
  
}

This will now change the value of my_font to 21px. To reset the value back to 20px, we have to subtract one from it. This does not happen in CSS variables, as we get the advantage of the “calc” function, which we will cover later in this blog.

SASS Variables vs. CSS Variables

The following table will help you out to draw a clear picture between the two variables:

SASS VariableCSS Variable
Static allocationDynamic allocation
Media queries not supportedSupport for media queries
Requires preprocessorPreprocessor not required
An added layer of calculation and complexitySingle-layer and direct variable management

The SASS variables were commonly used before CSS variables. But the differences between them cannot be ignored. CSS variables are more useful as compared to SASS variables but also differ in many other aspects. Let’s see them in the next section.

Importance Of CSS Variables

Before we go ahead and understand how to use variables in CSS, let’s explore some of the benefits of using variables in CSS. As a web developer, you will be able to relate to it and retrospect on how your life would have been easier with them.

1. Remove Redundancy In Code

Variables remove the redundancy in the code. For example, let’s say we have a very small web page requirement with all the headings (the h tags) of the same “color: red.”

<html lang="en" dir="ltr">
    <head>
      <meta charset="utf-8">
      <title>CSS Variables</title>
      <style>
           h2 {
             color: red;
           }

           h3 {
             color: red;
           }

           h4 {
             color: red;
           }
      </style>
    </head>

    <body>
      <center>
      <h2>I am heading 2</h2>
      <h3>I am heading 3</h3>
      <h4>I am heading 4</h4>
    </center>
    </body>
  </html>

Up to this point, everything looks good, and we get the correct output on our webpage.

pasted image 0 (17)

Now let’s say the team decides to change the color to green for every heading. To do this, we have to go through “find and replace” three times on the page, which is acceptable. But what about constructing a real website where this would be done 100 times or more for just a single change

Variables in CSS eliminate this redundancy from the system where we would just need to change the color once – in the variable’s value.

--heading_color: red;
   h2 {
             color: var(--heading_color, black);
           }

           h3 {
             color: var(--heading_color, black);
           }

           h4 {
             color: var(--heading_color, black);
           }

In the above code, whenever a change arises, I just need to change the variable “heading__color” value from “red” to “green.”

2. No need For Preprocessors

Preprocessors are used for the compilation of variables. Now that we have variables in CSS, we can bid adieu to the processors and perform dynamic activities on the variables. So, in the above example, when I change the color from Red to Green or Cyan (or anything else), I don’t need to compile my page again. Instead, I just press F5, and the changes will be reflected on the web browser.

3. Super Flexible – Declare Anywhere

CSS variables are custom properties of CSS. Similar to other custom properties, you can use the variables in CSS wherever you want. Here is how you can use it with the style tag:

<style>
       h2 {
             color: var(--heading_color, black);
           }
      </style>

Using it inline can be another option:

< h2 style = "color: var(--heading_color, black)">I am heading 2</h2 >

4. Improved code readability

For developers, code readability is perhaps one of the most troubling pain points. Consider the following code where we apply color to the various elements on the web page:

h2 {
             color: rgb(194, 70, 48);
           }

           h3 {
             color: #c40808;
           }

           h4 {
             color: #8c1c06;
           }

Consider a case where 100 lines later, I choose the same h1 color for another paragraph because that was the team plan.

p {
             color: rgb(194, 70, 48);
           }

But is it predictable that the color used in this paragraph is the same as used in the heading? If color consistency is a point in your website development plan, you might have to look at both the values carefully and verify their similarities. This becomes a lot harder when we talk about maybe 10 or 20 such scenarios. Here is how you can improve the code readability and make it more predictable with variables in CSS:

:root {
        --heading_color: red;
        --other_color: rgb(194, 70, 48);
      }
           h2 {
             color: var(--heading_color, black);
           }

           h3 {
             color: var(--other_color, black);
           }

           p {
             color: var(--heading_color, black)
           }

Since the variable of “p” is similar to “h2”, they both have the same color. An add-on advantage of a readable code is that it becomes a lot easier to find typos. For example, let’s say later on you find out that “H2” and “p” were not supposed to be the same color?

To make them similar, you might have to go through the grilling task of finding and replacing the instances where you have read every value digit by digit. Instead, you can define CSS variables! In the above code, the class “root” defines the variables, which is one of the methods for defining variables in CSS.

CSS Variables and JavaScript

CSS variables can access the DOM of the web page, which is very helpful when dealing with JavaScript. This is a big advantage knowing that JavaScript can help us create awesome code by fetching the variable value and setting it to different values based on predefined conditions.

The end result (i.e., web page) is more dynamic, user-friendly, and gives a lot more control to the developer. The process and code for manipulating the variables with the help of JavaScript are defined in a separate section at the end of this blog.

Calc And CSS Variables

In the SASS variable section, I mentioned the calc function and how it gives the edge to variables in CSS. The calc function is a vital function for people who love to set things relative to each other. For example, if you are interested in fluid typography in web design, calc function would probably focus on your typography designs.

In addition, the calc function is a basic CSS function that lets us do calculations. For example, Calc functions are generally used to apply relative properties in HTML.

This is how I would make the heading to be 2.5 times larger than the paragraph’s font size.

font-size: calc(20 * 2.5)px;

But the problem here is that even though I have my requirements set properly, I still have to look at my paragraph size. This leads to redundancy in the source code. Variables in CSS can be used with the calc function just like any other property to minimize redundancy.

The approach described above can be replaced with the CSS variables as shown below:

:root {
        --paragraph_size: 20px;
      }
           h2 {
             font-size: calc(var(--paragraph_size) * 2.5);

Output:

pasted image 0 (16)

The second line is the original default font size of the “h2” tag. This code will be further discussed in the exceptions section to point out some of the common mistakes in CSS variables.

Scope In CSS Variables

In the implementation shown earlier, the root pseudo class (in which the variable is declared) and its significance in the CSS sheet look a bit questionable. However, this class is a part of “scopes,” and this section will highlight its importance in variables in CSS.

Global Scope – One declaration For All

The scope property is akin to a variable’s scope in the programming languages. The CSS variable’s scope is no different. This is how you can define a CSS variable under two scopes:

  • Global Scope – Accepted from the start till the end of the document
  • Local Scope – Accepted only within the selector

When a variable is defined with a global scope, its existence is defined in the complete document from the time of its declaration. But other programming languages like Python or C++ have an open field between functions where you have the option to define the global scope.

Unfortunately, CSS has no such area due to the lack of a preprocessor. Therefore, in CSS, we use the root pseudo class, which means that the variable is under the document’s root (i.e. global).

:root {
--my_variable: <value>
}

This variable can now be called in any of the selectors in the same document.


:root {
        --my_variable: <value>;
      }

div {

   <property>: var(--my_variable, fallback)

}

The root selector works because variables in CSS can access the DOM of the web app code. The root here represents the root of the DOM tree which passes the data to its branches (i.e., complete document).

Local Scope – Bounded By Selector Walls

The local scope of the variables in CSS is restricted by the boundaries of the selectors inside which it has been defined. For instance, in the below code, I have defined the background colour for a div box with id “first_div”:

div {
        width: 300px;
        height: 200px;
        color: white;
        font-weight: bold;
        font-size: 30px;
      }
      #first_div {
        --my_bg: #692a3c;
        background-color: var(--my_bg, black);
      }

  <body>
      <center>
      <div id = "first_div">I am a div</div>
    </center>
    </body>

Output:

pasted image 0 (14)

Let’s make another div and set the same background color as done with the above div.

#first_div {
        --my_bg: #692a3c;
        background-color: var(--my_bg, black);
      }
      #second_div {
        background-color: var(--my_bg, white);
      }
  <div id = "first_div">I am a div</div>
   <br><br>
   <div id = "second_div">I am a div too!!</div>

Output:

unnamed (1)

The fallback value is applied (i.e., black background color) to the second div. This happened because the scope of the variable “my_bg” is only within the #first_div tag. Thus, “my_bg” will not be accessible outside those brackets. Try rendering the same web page with “my_bg” defined in the root section and see how it looks!

Precedence And Inheritance

Now we know that when a variable is defined in the document’s root, it has a global scope and when defined inside any selector, it has a local scope. But, what if the same variable is declared at both places? Who takes the precedence, local or global CSS variable?

The following implementation demonstrates two different techniques to initialize the same CSS variable and its effect on the web page:

<style>
      :root {
        --my_bg : #692a3c;
      }
      div {
        width: 300px;
        height: 200px;
        color: white;
        font-weight: bold;
        font-size: 30px;
      }
      #first_div {
        --my_bg: #f42a3c;
        background-color: var(--my_bg, black);
      }

      #second_div {
        background-color: var(--my_bg, black);
      }

Output:

pasted image 0 (13)

None of the divs here has a black background color. This means none of the variables failed and fallback values were never used. Furthermore, if you read the code, the second div has used the global instance of the variable while the first div chose the local variable. Therefore, we can confirm that the local scope has precedence over the global scope in CSS variables.

As far as inheritance is concerned. CSS is infamous for inheritance, which confuses many web developers when things take values that were never defined within their scope. So, what does inheritance mean in CSS?

Inheritance is the relationship between elements that are nested in each other. For example, the following code shows a parent-child relationship:

<div>Hello, I am a parent
<div> Hello, I am a child</div>
</div>

Similarly, we can define other sibling relationships. But these relationships affect each other’s property (down the line from the top) when the value is either set to “inherit” or cannot be found. The following implementation demonstrates the parent-child relationship where the child does not have the CSS variable setting for its background color:

CSS:

#first_div {
        --my_bg: blue;
        background-color: var(--my_bg, black);
      }

      #second_div {
             background-color: var(--my_bg, black);
      }

      #third_div {
        --my_bg: green;
        background-color: var(--my_bg, black);
      }

      #fourth_div {
        background-color: var(--my_bg, black);
      }

HTML:

<div id = "first_div">
    <div id = "second_div">
      <div id = "third_div"></div>
      <div id = "fourth_div"></div>
    </div>
  </div>

If a variable is not found for the element, it inherits the variable value from its parent! Therefore, the above code will see the following background colors for all the div:

  • first_div: blue
  • second_div: blue – inherited from the parent.
  • third_div: green
  • fourth_div: blue – inherited from the parent that inherited from its parent.

All four values are predictable considering the inheritance logic in the above diagram.

Fallback Values In CSS Variables

Fallback values are the second argument used in the “var()” function, which denotes the substitution of a CSS variable. Fallback values take their name from the job they do – they are used when you fall back with the original variable values.

There are four possibilities through which a CSS variable goes during the substitution.

  • Browser does not support CSS variable property.
  • The browser supports the property, and the variable is set to correct values with scope.
  • The browser supports the property, but the variable is not set to any value.
  • The browser supports the property, and the variable is set to an invalid value.

What If The Browser Does Not Support CSS Variables?

If the browser does not support variables in CSS, the CSS line of code with “/var()” is ignored completely as the browser does not understand it. In such cases, the browser takes on the default values, i.e., transparent.

Let’s check the code on Google Chrome 46 that does not support the CSS variables.

<style>
      :root {
        --my_bg : #9e2e50;
      }
      div {
        width: 300px;
        height: 200px;
        color: black;
        font-weight: bold;
        font-size: 30px;
        background-color: var(--my_bg, black);
      }

      </style>
    </head>

    <body>
      <center>
  <div>
      I am a div box!!
  </div>
    </center>
    </body>
pasted image 0 (12)

The color I applied to the variable “my_bg” is not rendered on the div box. At the same time, the div box does exist here but only transparently.

pasted image 0 (11)

To demonstrate my web app, I have used an online cross browser testing platform LambdaTest. It provides 3000+ browsers and operating systems to test websites and web apps for cross browser compatibility issues.

Variable Is Set And Is In Scope!

If the variable is set to a valid value and is being called within its scope, it will be implemented correctly. So, for example, executing the above code on Google 47 and above will show correct results.

Variable Is Never Initialized

The next scenario comes when the variable is never initialized but is substituted in the code somewhere.

<style>
      div {
           background-color: var(--my_bg, black);
      }
   </style>

Output:

pasted image 0 (10)

The div box takes the fallback value in this case. The same thing happens when the variable is initialized but is called outside of its scope.

Variable Is Set To An Invalid Value

If the variable is set to an invalid value based on its usages, such as px or deg for color, the background becomes transparent.

 <style>
      :root {
        --my_bg : 20px;
      }
      div {
        background-color: var(--my_bg, black);
      }
      </style>

Output:/p>
pasted image 0 (9)

So the variable line is ignored by the browser.

Fallback values do not work every time the variable throws an error. Furthermore, it only works with a few of the scenarios that are described above. So, as a web developer, what can we do to manage the cross browser compatibility issues?

Implementing Two Fallbacks

The best method is to lay a safety net in the selector CSS code that can still place the value to the property in cases that the CSS variable fails.

<style>
      :root {
        --my_bg : #9e2e50;
      }
      div {
        background-color: #9e2e50;
        background-color: var(--my_bg, black);
      }

      </style>

If the variable is not initialized in the above code, the value will be taken from the first “background-color” initialization. However, if it is initialized, the value will be taken from the variable.

Although not necessarily a strict “fallback,” the variables in CSS can also perform fallback values for various exceptions using the cascading CSS variable methods.

background-color: var(variable_name, var(variable_name, fallback));

However, it has multiple layers of calculation and takes time to execute. This approach is therefore never recommended for a web developer.

Exceptions In CSS Variables

Once you know how to use variables in CSS, you will see it is flexible and easy to use. However, they do have a few exceptions that one should remember before declaring and substituting the variables.

Watch Cyclic Dependencies

Cyclic dependencies are explicit with their names. When dependencies are created with each other, the web developer should verify that the cycle is not created among the variables. If a cycle is created, the code execution could result in an infinite loop that can timeout the web page as it would never load completely.

--variable_name_1 : var(variable_name_2, fallback);
--variable_name_2 : var(variable_name_1, fallback);

A similar process will be seen when a variable will depend on itself during the time of initialization.

--variable_1 = var(variable_1, fallback);

Web developers should always take note of cyclic dependencies while initializing the variables.

CSS Variables Are Case-Sensitive

The CSS variables are case-sensitive. Therefore, the variables my_var and My_var are both different.

CSS Variable Cannot Be A Property Name

The CSS variable name cannot have a value as an existing property in CSS. So, for example, you cannot initialize a variable with the value “font-size.”

CSS Variables With JavaScript

One of the most attractive points for developers who love JavaScript is that variables in CSS can be handled and manipulated with the help of JavaScript easily. To use variables in CSS with JavaScript, you can fetch their current value similar to how JS handles other properties.

The following code fetches the CSS variable (used for the font size) and increases its font size to 40px as we press the button.

<html lang="en" dir="ltr">
    <head>
      <meta charset="utf-8">
      <title>CSS Variables</title>
      <style>
      :root {
      --fontSize: 20px;
      }

      div {
        width: 300px;
        height: 200px;
        color: white;
        font-weight: bold;
        font-size: var(--fontSize, 12px);
        background-color: #9e2e50;
      }
      </style>
      <script>
function changeFontSize() {
  var r = document.querySelector(':root');
  var rs = getComputedStyle(r);
  r.style.setProperty('--fontSize', '40px');
}
      </script>
    </head>

    <body>
      <center>
  <div>
      I am a div box!!
  </div>
  <br><br>
  <button onclick="changeFontSize()">Change Font Size</button>
    </center>
    </body>
  </html>

Output:

CSS_variables_with_Javascript

Browser Compatibility Of CSS Variables

CSS variables enjoy great support from every major browser. If you know how to use variables in CSS, you can ensure that exceptions and fallbacks are correctly working as per the code.

After implementing, you can use LambdaTest to perform browser compatibility testing to make sure it renders correctly on different browser versions and operating systems.

pasted image 0 (7)

How To Use LT Browser For Responsiveness Test Of CSS Variables

The most buzzed word of the web development world currently is responsiveness. With Google specifying the responsiveness wherever possible and multiple devices flooding the market, responsive web design has become a priority in itself.

Variables in CSS are not visual elements that can be tested with window resize functionality for responsiveness. But they do affect the components that are visual such as div, images, or anything else. Therefore, responsiveness test are important with the CSS media queries whether variables in CSS support them or not.

The following code implements the CSS media queries along with the CSS variables.

<html lang="en" dir="ltr">
    <head>
      <meta charset="utf-8">
      <title>CSS Variables</title>
      <style>
      :root {
        --my_color: red;
        --my_second_color: green;
      }


      @media only screen and (min-width: 641px) {
          #heading {
            color: var(--my_color);
          }
      }

      @media only screen and (max-width: 640px){
        #heading {
          color: var(--my_second_color);
        }
      }
      </style>
    </head>

    <body>
      <center>
      <h2 id = "heading">Wait for it!!!!</h2>
    </center>
    </body>
  </html>

Output:

media_queries_CSS_variables

The text is original of red color in the above code until the window size is greater than 640px. Else, the text color becomes green.

Performing a responsiveness test is not an easy job. You need various devices and owning or leasing every device is not a feasible approach. Instead, we need to choose smart solutions when dealing with responsiveness.

Conclusion

As a web developer, variables have always been a part of my styling sheet. I am sure after befriending them today, and you will start using them regularly too. Variables in CSS remove redundancy from the code, and the best thing is that they are just another property in CSS. However, after implementing CSS variables, you must perform a responsiveness test of your web design. You can follow the responsive web design checklist to ease up the entire responsiveness test process.

giphy

In this guide, we learned how to use variables in CSS from its implementation to responsiveness test. I hope variables in CSS are something that you enjoy and share with your fellow developers. If you have come across any interesting experiences with variables in CSS, please share them in the comment section below.

For your reference, check this out:
https://developer.mozilla.org/en-US/docs/Web/CSS/Using_CSS_custom_properties 

#css #webdevelopment

Iliana  Welch

Iliana Welch

1595249460

Docker Explained: Docker Architecture | Docker Registries

Following the second video about Docker basics, in this video, I explain Docker architecture and explain the different building blocks of the docker engine; docker client, API, Docker Daemon. I also explain what a docker registry is and I finish the video with a demo explaining and illustrating how to use Docker hub

In this video lesson you will learn:

  • What is Docker Host
  • What is Docker Engine
  • Learn about Docker Architecture
  • Learn about Docker client and Docker Daemon
  • Docker Hub and Registries
  • Simple demo to understand using images from registries

#docker #docker hub #docker host #docker engine #docker architecture #api

Top 130 Android Interview Questions - Crack Technical Interview Now!

Android Interview Questions and Answers from Beginner to Advanced level

DataFlair is committed to provide you all the resources to make you an android professional. We started with android tutorials along with practicals, then we published Real-time android projects along with source code. Now, we come up with frequently asked android interview questions, which will help you in showing expertise in your next interview.

android interview questions

Android Interview Questions – Get ready for your next interview

Android – one of the hottest technologies, which is having a bright future. Get ready to crack your next interview with the following android interview questions. These interview questions start with basic and cover deep concepts along with advanced topics.

Android Interview Questions for Freshers

1. What is Android?

Android is an open-source mobile operating system that is based on the modified versions of Linux kernel. Though it was mainly designed for smartphones, now it is being used for Tablets, Televisions, Smartwatches, and other Android wearables.

2. Who is the inventor of Android Technology?

The inventors of Android Technology are- Andry Rubin, Nick Sears, and Rich Miner.

3. What is the latest version of Android?

The latest version of Android is Android 10.0, known as Android Q. The upcoming major Android release is Android 11, which is the 18th version of Android. [Note: Keep checking the versions, it is as of June 2020.]

4. How many Android versions can you recall right now?

Till now, there are 17 versions of Android, which have their names in alphabetical order. The 18th version of Android is also going to come later this year. The versions of Android are here:

  • Android 1.0 – Its release is 23 September 2008.
  • Android 1.1 – Its release date is 9 February 2009.
  • Android 1.5 – Its name is Cupcake, Released on 27 April 2009.
  • Android 1.6 – Its name is Donut, Released on 15 September 2009.
  • Android 2.0 – Its name is Eclair, Released on 26 October 2009
  • Android 2.2 – Its name is Froyo, Released on 20 May 2010.
  • Android 2.3 – Its name is Gingerbread, Released on 06 December 2010.
  • Android 3.0 – Its name is Honeycomb, Released on 22 February 2011.
  • Android 4.0 – Its name is Ice Cream Sandwich, Released on 18 October 2011.
  • Android 4.1 – Its name is Jelly Bean, Released on 9 July 2012.
  • Android 4.4 – Its name is KitKat, Released on 31 October 2013.
  • Android 5.0 – Its name is Lollipop, Released on 12 November 2014.
  • Android 6.0 – Its name is Marshmallow, Released on 5 October 2015.
  • Android 7.0 – Its name is Nougat, Released on 22 August 2016.
  • Android 8.0 – Its name is Oreo, Released on 21 August 2017.
  • Android 9.0 – Its name is Pie, Released on 6 August 2018.
  • Android 10.0 – Its name is Android Q, Released on 3 September 2019.
  • Android 11.0 – As of now, it is Android 11.

5. Explain the Android Architecture with its components.

This is a popular android developer interview question

Android Architecture consists of 5 components that are-

a. Linux Kernel: It is the foundation of the Android Architecture that resides at the lowest level. It provides the level of abstraction for hardware devices and upper layer components. Linux Kernel also provides various important hardware drivers that act as software interfaces for hardwares like camera, bluetooth, etc.

b. Native Libraries: These are the libraries for Android that are written in C/C++. These libraries are useful to build many core services like ART and HAL. It provides support for core features.

c. Android Runtime: It is an Android Runtime Environment. Android Operating System uses it during the execution of the app. It performs the translation of the application bytecode into the native instructions. The runtime environment of the device then executes these native instructions.

d. Application Framework: Application Framework provides many java classes and interfaces for app development. And it also provides various high-level services. This complete Application framework makes use of Java.

e. Applications: This is the topmost layer of Android Architecture. It provides applications for the end-user, so they can use the android device and compute the tasks.

6. What are the services that the Application framework provides?

The Android application framework has the following key services-

a. Activity Manager: It uses testing and debugging methods.

b. Content provider: It provides the data from application to other layers.

c. Resource Manager: This provides users access to resources.

d. Notification Manager: This gives notification to the users regarding actions taking place in the background.

e. View System: It is the base class for widgets, and it is also responsible for event handling.

7. What are the important features of Linux Kernel?

The important features of the Linux Kernel are as follows:

a. Power Management: Linux Kernel does power management to enhance and improve the battery life of the device.

b. Memory Management: It is useful for the maximum utilization of the available memory of the device.

c. Device Management: It includes managing all the hardware device drivers. It maximizes the utilization of the available resources.

d. Security: It ensures that no application has any such permission that it affects any other application in order to maintain security.

e. Multi-tasking: Multi-tasking provides the users the ease of doing multiple tasks at the same time.

8. What are the building blocks of an Android Application?

This is a popular android interview question for freshers.

The main components of any Android application are- Activity, Services, Content Provider, and Broadcast Receiver. You can understand them as follows:

a. Activity- It is a class that acts as the entry point representing a single screen to the user. It is like a window to show the user interface.

b. Services- Services are the longest-running component that runs in the background.

c. Content Provider- The content provider is an essential component that allows apps to share data between themselves.

d. Broadcast receivers- Broadcast receiver is another most crucial application component. It helps the apps to receive and respond to broadcast messages from the system or some other application.

9. What are the important components of Android Application?

The Components of Android application are listed below:

  1. Widgets
  2. Intents
  3. Views
  4. Notification
  5. Fragments
  6. Layout XML files
  7. Resources

10. What are the widgets?

Widgets are the variations of Broadcast receivers. They are an important part of home screen customization. They often display some data and also allow users to perform actions on them. Mostly they display the app icon on the screen.

11. Can you name some types of widgets?

Mentioned below are the types of widgets-

a. Informative Widgets: These widgets show some important information. Like, the clock widget or a weather widget.

b. Collective Widgets: They are the collection of some types of elements. For example, a music widget that lets us change, skip, or forward the song.

c. Control Widgets: These widgets help us control the actions within the application through it. Like an email widget that helps check the recent mails.

d. Hybrid Widgets: Hybrid widgets are those that consist of at least two or more types of widgets.

12. What are Intents?

Intents are an important part of Android Applications. They enable communication between components of the same application as well as separate applications. The Intent signals the Android system about a certain event that has occurred.

13. Explain the types of intents briefly?

Intent is of three types that are-

a. Implicit Intents: Implicit intents are those in which there is no description of the component name but only the action.

b. Explicit Intents: In explicit intents, the target component is present by declaring the name of the component.

c. Pending Intents: These are those intents that act as a shield over the Intent objects. It covers the intent objects and grants permission to the external app components to access them.

14. What is a View?

A view is an important building block that helps in designing the user interface of the application. It can be a rectangular box or a circular shape, for example, Text View, Edit Text, Buttons, etc. Views occupy a certain area of the screen, and it is also responsible for event handling. A view is the superclass of all the graphical user interface components.

15. What do you understand by View Group?

It is the subclass of the ViewClass. It gives an invisible container to hold layouts or views. You can understand view groups as special views that are capable of holding other views, that are Child View.

16. What do you understand about Shared Preferences?

It is a simple mechanism for data storage in Android. In this, there is no need to create files, and using APIs, it stores the data in XML files. It stores the data in the pair of key-values. SharedPreferences class lets the user save the values and retrieve them when required. Using SharedPreferences we can save primitive data like- boolean, float, integer, string and long.

17. What is a Notification?

A notification is just like a message that shows up outside the Application UI to provide reminders to the users. They remind the user about a message received, or some other timely information from the app.

18. Give names of Notification types.

There are three types of notifications namely-

a. Toast Notification- This notification is the one that fades away sometime after it pops up.

b. Status Notification- This notification stays till the user takes some action on it.

c. Dialog Notification- This notification is the result of an Active Activity.

19. What are fragments?

A fragment is a part of the complete user interface. These are present in Activity, and an activity can have one or more fragments at the same time. We can reuse a fragment in multiple activities as well.

20. What are the types of fragments?

There are three types of fragments that are: Single Fragment, List Fragment, Fragment Transactions.

  1. Single Transactions can only show a single view for the user.
  2. List Fragments have a special list view feature that provides a list from which the user can select one.
  3. Fragment Transactions are helpful for the transition between one fragment to the other.

Frequently asked Android Interview Questions and Answers

21. What are Layout XML files?

Layout XML files contain the structure for the user interface of the application. The XML file also contains various different layouts and views, and they also specify various GUI components that are there in Activity or fragments.

22. What are Resources in Android Application?

The resources in Android Apps defines images, texts, strings, colors, etc. Everything in resources directory is referenced in the source code of the app so that we can use them.

23. Can you develop Android Apps with languages other than Java? If so, name some.

Yes, there are many languages that we can work with, for the development of Android Applications. To name some, I would say Java, Python, C, C++, Kotlin, C#, Corona/LUA.

24. What are the states of the Activity Lifecycle?

Activity lifecycle has the following four stages-

a. Running State: As soon as the activity starts, it is the first state.

b. Paused State: When some other activity starts without closing the previous one, the running activity turns into the Paused state.

c. Resume State: When the activity opens again after being in pause state, it comes into the Resume State.

d. Stopped State: When the user closes the application or stops using it, the activity goes to the Stopped state.

25. What are some methods of Activity?

The methods of Activity are as follows:

  • onCreate()
  • onStart()
  • onPause()
  • onRestart()
  • onResume()
  • onStop()
  • onDestroy()

26. How can you launch an activity in Android?

We launch an activity using Intents. For this we need to use intent as follows:

  1. ntent intent_name= new Intent(this, Activity_name.class);
  2. startActivity(intent_name);

27. What is the service lifecycle?

There are two states of a service that are-

a. Started State: This is when the service starts its execution. A Services come in start state only through the startService() method.

b. Bounded State: A service is in the bounded state when it calls the method bindService().

28. What are some methods of Services?

The methods of service are as follows-

  • onStartCommand()
  • onBind()
  • onCreate()
  • onUnbind()
  • onDestroy()
  • onRebind()

29. What are the types of Broadcast?

Broadcasts are of two types that are-

a. Ordered Broadcast: Ordered broadcasts are Synchronous and work in a proper order. It decides the order by using the priority assigned to the broadcasts.

b. Normal Broadcast: These are asynchronous and unordered. They are more efficient as they run unorderly and all at once. But, they lack full utilization of the results.

30. What are useful impotent folders in Android?

The impotent folders in an Android application are-

  1. build.xml- It is responsible for the build of Android applications.
  2. bin/ – The bin folder works as a staging area to wrap the files packages into the APK.
  3. src/ – The src is a folder where all the source files of the project are present.
  4. res/ – The res is the resource folder that stores values of the resources that are used in the application. These resources can be colors, styles, strings, dimensions, etc.
  5. assets/ – It provides a facility to include files like text, XML, fonts, music, and video in the Android application.

31. What are the important files for Android Application when working on Android Studio?

This is an important android studio interview question

There are following three files that we need to work on for an application to work-

a. The AndroidManifest.xml file: It has all the information about the application.

b. The MainActivity.java file: It is the app file that actually gets converted to the dalvik executable and runs the application. It is written in java.

c. The Activity_main.xml file: It is the layout file that is available in the res/layout directory. It is another mostly used file while developing the application.

32. Which database do you use for Android Application development?

The database that we use for Android Applications is SQLite. It is because SQLite is lightweight and specially developed for Android Apps. SQLite works the same way as SQL using the same commands.

33. Tell us some features of Android OS.

The best features of Android include-

  1. Multi-tasking
  2. Support for a great range of languages
  3. Support for split-screen
  4. High connectivity with 5G support
  5. Motion Control

34. Why did you learn Android development?

Learning Android Studio is a good idea because of the following-

  1. It has a low application development cost.
  2. It is an open-source platform.
  3. It has multi-platform support as well as Multi-carrier support.
  4. It is open for customizations.
  5. Android is a largely used operating system throughout the world.

35. What are the different ways of storage supported in Android?

The various storage ways supported in Android are as follows:

  1. Shared Preference
  2. Internal Storage
  3. External Storage
  4. SQLite Databases
  5. Network Connection

36. What are layouts?

Layout is nothing but arrangements of elements on the device screen. These elements can be images, tests, videos, anything. They basically define the structure of the Android user interface to make it user friendly.

37. How many layout types are there?

The type of layouts used in Android Apps are as follows:

  1. Linear Layout
  2. Relative Layout
  3. Constraint Layout
  4. Table Layout
  5. Frame Layout
  6. Absolute Layout
  7. Scrollview layout

38. What is an APK?

An APK stands for Android Package that is a file format of Android Applications. Android OS uses this package for the distribution and installation of the Android Application.

39. What is an Android Manifest file?

The manifest file describes all the essential information about the project application for build tools, Android operating system, and google play. This file is a must for every Android project that we develop, and it is present in the root of the project source set.

#android tutorials #android basic interview questions #android basic questions #android developer interview questions #android interview question and answer #android interview questions #android interview questions for experienced #android interview questions for fresher

Docker Architecture Overview & Docker Components [For Beginners]

If you have recently come across the world of containers, it’s probably not a bad idea to understand the underlying elements that work together to offer containerisation benefits. But before that, there’s a question that you may ask. What problem do containers solve?

After building an application in a typical development lifecycle, the developer sends it to the tester for testing purposes. However, since the development and testing environments are different, the code fails to work.

Now, predominantly, there are two solutions to this – either you use a Virtual Machine or a containerised environment such as Docker. In the good old times, organisations used to deploy VMs for running multiple applications.

So, why did they started adopting containerisation over VMs? In this article, we will provide detailed explanations of all such questions.

#docker containers #docker engine #docker #docker architecture

Cayla  Erdman

Cayla Erdman

1599914520

Apache/Airflow and PostgreSQL with Docker and Docker Compose

Hello, in this post I will show you how to set up official Apache/Airflow with PostgreSQL and LocalExecutor using docker and docker-compose. In this post, I won’t be going through Airflow, what it is, and how it is used. Please checktheofficial documentation for more information about that.

Before setting up and running Apache Airflow, please install Docker and Docker Compose.

For those in hurry…

In this chapter, I will show you files and directories which are needed to run airflow and in the next chapter, I will go file by file, line by line explaining what is going on.

Firstly, in the root directory create three more directories: dagslogs, and scripts. Further, create following files: **.env, docker-compose.yml, entrypoint.sh **and **dummy_dag.py. **Please make sure those files and directories follow the structure below.

#project structure

root/
├── dags/
│   └── dummy_dag.py
├── scripts/
│   └── entrypoint.sh
├── logs/
├── .env
└── docker-compose.yml

Created files should contain the following:

#docker-compose.yml

version: '3.8'
services:
    postgres:
        image: postgres
        environment:
            - POSTGRES_USER=airflow
            - POSTGRES_PASSWORD=airflow
            - POSTGRES_DB=airflow
    scheduler:
        image: apache/airflow
        command: scheduler
        restart_policy:
            condition: on-failure
        depends_on:
            - postgres
        env_file:
            - .env
        volumes:
            - ./dags:/opt/airflow/dags
            - ./logs:/opt/airflow/logs
    webserver:
        image: apache/airflow
        entrypoint: ./scripts/entrypoint.sh
        restart_policy:
            condition: on-failure
        depends_on:
            - postgres
            - scheduler
        env_file:
            - .env
        volumes:
            - ./dags:/opt/airflow/dags
            - ./logs:/opt/airflow/logs
            - ./scripts:/opt/airflow/scripts
        ports:
            - "8080:8080"
#entrypoint.sh
#!/usr/bin/env bash
airflow initdb
airflow webserver
#.env
AIRFLOW__CORE__SQL_ALCHEMY_CONN=postgresql+psycopg2://airflow:airflow@postgres/airflow
AIRFLOW__CORE__EXECUTOR=LocalExecutor
#dummy_dag.py
from airflow import DAG
from airflow.operators.dummy_operator import DummyOperator
from datetime import datetime
with DAG('example_dag', start_date=datetime(2016, 1, 1)) as dag:
    op = DummyOperator(task_id='op')

Positioning in the root directory and executing “docker-compose up” in the terminal should make airflow accessible on localhost:8080. Image bellow shows the final result.

If you encounter permission errors, please run “chmod -R 777” on all subdirectories, e.g. “chmod -R 777 logs/”


For the curious ones...

In Leyman’s terms, docker is used when managing individual containers and docker-compose can be used to manage multi-container applications. It also moves many of the options you would enter on the docker run into the docker-compose.yml file for easier reuse. It works as a front end "script" on top of the same docker API used by docker. You can do everything docker-compose does with docker commands and a lot of shell scripting.

Before running our multi-container docker applications, docker-compose.yml must be configured. With that file, we define services that will be run on docker-compose up.

The first attribute of docker-compose.yml is version, which is the compose file format version. For the most recent version of file format and all configuration options click here.

Second attribute is services and all attributes one level bellow services denote containers used in our multi-container application. These are postgres, scheduler and webserver. Each container has image attribute which points to base image used for that service.

For each service, we define environment variables used inside service containers. For postgres it is defined by environment attribute, but for scheduler and webserver it is defined by .env file. Because .env is an external file we must point to it with env_file attribute.

By opening .env file we can see two variables defined. One defines executor which will be used and the other denotes connection string. Each connection string must be defined in the following manner:

dialect+driver://username:password@host:port/database

Dialect names include the identifying name of the SQLAlchemy dialect, a name such as sqlite, mysql, postgresql, oracle, or mssql. Driver is the name of the DBAPI to be used to connect to the database using all lowercase letters. In our case, connection string is defined by:

postgresql+psycopg2://airflow:airflow@postgres/airflow

Omitting port after host part denotes that we will be using default postgres port defined in its own Dockerfile.

Every service can define command which will be run inside Docker container. If one service needs to execute multiple commands it can be done by defining an optional .sh file and pointing to it with entrypoint attribute. In our case we have entrypoint.sh inside the scripts folder which once executed, runs airflow initdb and airflow webserver. Both are mandatory for airflow to run properly.

Defining depends_on attribute, we can express dependency between services. In our example, webserver starts only if both scheduler and postgres have started, also the scheduler only starts after postgres have started.

In case our container crashes, we can restart it by restart_policy. The restart_policy configures if and how to restart containers when they exit. Additional options are condition, delay, max_attempts, and window.

Once service is running, it is being served on containers defined port. To access that service we need to expose the containers port to the host's port. That is being done by ports attribute. In our case, we are exposing port 8080 of the container to TCP port 8080 on 127.0.0.1 (localhost) of the host machine. Left side of : defines host machines port and the right-hand side defines containers port.

Lastly, the volumes attribute defines shared volumes (directories) between host file system and docker container. Because airflows default working directory is /opt/airflow/ we need to point our designated volumes from the root folder to the airflow containers working directory. Such is done by the following command:

#general case for airflow
- ./<our-root-subdir>:/opt/airflow/<our-root-subdir>
#our case
- ./dags:/opt/airflow/dags
- ./logs:/opt/airflow/logs
- ./scripts:/opt/airflow/scripts
           ...

This way, when the scheduler or webserver writes logs to its logs directory we can access it from our file system within the logs directory. When we add a new dag to the dags folder it will automatically be added in the containers dag bag and so on.

Originally published by Ivan Rezic at Towardsdatascience

#docker #how-to #apache-airflow #docker-compose #postgresql