Author: Amjad Izhar

  • Story of Musa & Khizer by Allama Javed Ghamdi

    Story of Musa & Khizer by Allama Javed Ghamdi

    The text presents interpretations of Surah Kahf, specifically focusing on the story of Musa and Al-Khidr. It explores the divine wisdom behind seemingly inexplicable events, emphasizing the importance of patience and trust in Allah’s plan. The text analyzes the reasons behind these trials, and highlights their context within the Sunnah. It suggests that these trials test faith and understanding and offers insights into Allah’s actions that extend beyond human comprehension. Moreover, the narrative explores how prophets receive and understand divine messages, drawing parallels with worldly events. Ultimately, the passage offers guidance on maintaining faith and trust in divine wisdom even when faced with life’s challenges.

    Wisdom in Surah Kahf: A Study Guide

    Quiz (Short Answer)

    Answer each question in 2-3 sentences.

    1. According to the text, what three types of reasoning are commonly found in the Holy Qur’an?
    2. What is the significance of patience in the context of the challenges faced by prophets?
    3. What are the two aspects that should be kept in mind sometimes when comforting someone or advising someone patience?
    4. What is the significance of the story of Khizr and Musa in Surah Kahf?
    5. How does the Qur’an describe the ways in which Allah conveys His message to the prophets, as summarized in Surah Shura?
    6. What are the two ways “intentions” or “observations” are shown to the prophets?
    7. What does the text suggest about the interpretation of dreams and visions experienced by prophets?
    8. What is the context of the story of Sayyiduna Musa’s journey?
    9. What was the moral of the episode regarding the killing of the boy?
    10. What does the text say about trusting in the sources of knowledge that God gave us?

    Answer Key (Quiz)

    1. The three types of reasoning are arguments from the self, arguments from the horizons (Afaq), and arguments from history. These types of arguments appear throughout the Holy Qur’an, though the level of detail varies in each argument.
    2. Patience is essential because results may not be immediately apparent, and it requires trusting in Allah’s wisdom even when outcomes are unclear. Prophets are advised to act with patience and wisdom, trusting in Allah’s wisdom, even when faced with accusations and criticism.
    3. When comforting or advising someone patience, keeping in mind that there is one age, one period that is fixed. And also that the Lord is the end of my nation, if guidance would have been given by you.
    4. The story of Khizr and Musa is not a historical narration, but rather, an explanation of the importance of patience and the wisdom of Allah. This includes patience in waiting for permission for migration and patience when trying to understand the purpose or reason for waiting.
    5. Allah speaks in their innermost being (thought takes the form of words) or something is heard with regular sounds (a voice felt from behind a hijab). The thought either speaks in sounds or dialogue occurs between them as instructions are told.
    6. Intentions are either shown in a dream (where the truth is shown through parables needing interpretation) or through observation in an awakened state. In the awakened state the ego begins to appear.
    7. Dreams and visions of prophets are true and not influenced by Satan, but they often require interpretation and are presented in the form of parables. For example, in Surah Yusuf, it is written that the dream of the person who misbehaved with the king was also true.
    8. The context of the story is to teach patience and wisdom and is intended to tell that permission for migration is not given until it is received. One must wait patiently and faith is necessary in the wisdom of Allah.
    9. It was feared that the boy might grow up and cause trouble for his parents with his disobedience and disbelief. Allah wanted to save his parents from his disbelief.
    10. If you look back it has been advised to act with patience and wisdom, trust in Allah, and trust in Allah remains only when a person is fully satisfied that the wisdom of my Lord works in everything and there is no covering of His wisdom. This is the lesson that has been given in this incident.

    Essay Questions

    1. Explore the concept of “Sunnah of Allah” as described in the text. How does understanding this concept influence a believer’s perspective on current events and personal challenges?
    2. The text outlines three methods for addressing problems: reasoning from the self, reasoning from the horizons (Afaq), and reasoning from history. Discuss how these methods can be applied to contemporary issues facing the Muslim community.
    3. Analyze the role of prophets as described in the text. How do they balance their human emotions and limitations with their divine calling and responsibilities? Use examples from the story of Musa and Khizr to illustrate your points.
    4. Discuss the importance of trusting in the sources of knowledge that God gave us. What can we do to avoid temptation that comes with greed or creating satanism?
    5. Examine the story of Musa and Khizr in Surah Kahf. In what ways does it contribute to a deeper understanding of divine wisdom, patience, and the limits of human knowledge?

    Glossary of Key Terms

    • Sunnah of Allah: The established and unchanging way or pattern of Allah’s actions and dealings with mankind.
    • Afaq: Horizons, realms, or the external world; arguments from Afaq refer to observing the signs and phenomena in the world around us.
    • Al-Mudat in Al-Qurba: Nearness or relationship; used to describe the prophet’s connection and love for his people.
    • Ijtihad: Independent reasoning or interpretation of Islamic sources to derive rulings on matters not explicitly covered in the Qur’an or Sunnah.
    • Tafsir: Interpretation or explanation, particularly of the Qur’an.
    • Dalal: Evidence or proof; used in the context of presenting historical events as evidence.
    • Hijab: A veil or barrier; in this context, it refers to a veil that separates humans from the direct perception of divine communication.
    • Ara: Observation; refers to divine visions or intentions shown to the prophets.
    • Majma Al-Bahreen: The meeting place of two rivers; a symbolic location in the story of Musa and Khizr.
    • Qada and Qadr: Divine decree and predestination; the belief that everything is predetermined by Allah.

    Stories of Wisdom: Understanding Divine Intentions in Surah Kahf

    Okay, here’s a briefing document summarizing the main themes and ideas from the provided excerpts from “Stories of Wisdom: Understanding Divine Intentions in Surah Kahf”:

    Briefing Document: “Stories of Wisdom: Understanding Divine Intentions in Surah Kahf”

    Overall Theme:

    The excerpts focus on understanding divine wisdom and intentions, particularly within the context of Surah Kahf in the Quran. A central argument is that seemingly random or negative events have underlying, often hidden, wisdom orchestrated by Allah. The excerpts emphasize the importance of patience, faith, and trust in Allah’s plan, even when the reasons behind events are not immediately apparent. The text addresses how prophets receive divine guidance and how believers should react when faced with trials and tribulations.

    Key Ideas and Facts:

    • The Sunnah of Allah is Unchangeable: The speaker emphasizes that what happened to past nations will happen again, serving as a warning. “It is the Sunnah of Allah and this Sunnah is unchangeable. There will never be any change in it, nor has it ever happened before, so be warned.” This establishes a pattern of divine justice and tests throughout history.
    • Prophets’ Role and Consolation: Prophets are human beings, and even they need comfort and reassurance. The text highlights the prophets’ longing for their people to believe. “Prophets are also human beings in the flesh, they are giving invitations, delivering messages, devoting their days and nights to their people… By Allah, the believers, I am still inviting you, still conveying the message, praying for you. My last wish is that you believe before I leave you.” When facing resistance, prophets are advised to be patient, as Allah has a plan and a fixed time for decisions. The surah itself provides consolation to the Prophet.
    • Arguments from Self, Horizons, and History: The Qur’an uses these three types of reasoning to convey its message. These methods of reasoning serve the overall function of giving “warning and observation.”
    • Arguments from self are more detailed sometimes
    • Arguments from Afaq are more detailed sometimes
    • Historical reasoning
    • The Story of Musa (Moses) and Khidr: This story is presented as an example of how divine wisdom operates beyond human understanding. Musa’s journey with Khidr is used to illustrate why one must be patient and trust in Allah’s plan, even when faced with events that seem unjust or incomprehensible.
    • Khidr’s actions (damaging the boat, killing the boy, repairing the wall) are explained as being divinely guided and serving a greater purpose.
    • The journey was not “to create an event or to narrate history,” but to comfort the Messenger of God and explain if results of da’wah do not come as expected, to understand the wisdom of Allah.
    • The story teaches about the importance of wisdom in actions.
    • The Nature of Prophetic Revelation (Intentions): The text delves into how prophets receive messages from Allah. It describes different methods:
    • Thought Speaking: Inner thoughts taking the form of words without actual sounds. “The thought speaks in their innermost being…the thought speaks, that is, as if I am talking or someone else is answering me, then here the thought has taken the form of words and the words have come out as sounds, but this does not happen in a dream or in a dream, in which words are sounds. They don’t come out of being, the thought speaks”
    • Hearing a Voice Behind a Veil: As with Musa and the burning bush.
    • “Intentions” (Ara’at): Showing the prophet a reality or vision, either in waking life or in a dream. These visions can be symbolic and require interpretation. “It means that there is no talk and no message has been given but the reality is being shown i.e. it has been observed…Paradise was shown to me as if it appeared at that time, but it is not clear whether they are asleep or in a state of sleep.”
    • Patience and Wisdom as Essential Virtues: The text emphasizes the necessity of patience and wisdom for human beings. “I think these two things are needed at every step by a human being, he should make a plan of action with wisdom, speak with wisdom, keep wisdom in mind in every action, and all goals and objectives should be discussed from the perspective of wisdom.” Patience is connected to faith in the fact that something is delayed, so if there is wisdom from Allah.
    • Limits of Human Knowledge: The passage acknowledges that human knowledge is limited. “What will be beyond your scope of knowledge, how can you even be patient with it, as if the Holy Qur’an has told me, forgive me. Man has a field of knowledge… the biggest mistake is that people do not know their field of knowledge.” The inability to grasp the full scope of Allah’s wisdom is a central reason for needing patience and trust. Humans must know and accept the limits of what they can know and trust in sources of knowledge Allah has given.
    • Everything Happens by Allah’s Permission: All things, including those that seem random or chaotic, happen under Allah’s permission, intention, and will. This should form the basis of a believer’s faith. “One is that everything that happens in this world is all by God’s permission and His intention. Occurs under will, that is, there is nothing that happens by yourself in this world.”
    • No Intention of Allah’s is Devoid of Goodness: Even if falsehood is allowed to exist, it does not mean that Allah loves falsehood. He nurtures good through the challenges.

    The Importance of Understanding Limits of Knowledge: Because not understanding the limits of knowledge causes many problems.

    Implications:

    • The excerpts provide a framework for understanding difficult or seemingly unjust events in life.
    • They encourage a deeper trust in Allah’s plan and a willingness to accept what is not immediately understandable.
    • They highlight the importance of seeking knowledge while acknowledging its limitations.
    • The surah aims to train patience and willingness.

    This briefing document captures the key themes and ideas presented in the provided text. Remember that it is a summary, and further reading and study of the source material are recommended for a more complete understanding.

    Stories of Wisdom in Surah Kahf

    Stories of Wisdom FAQ:

    1. What is the central message conveyed through the stories in Surah Kahf?

    The central message emphasizes the importance of patience and trusting in Allah’s wisdom, even when events seem perplexing or unjust. The stories illustrate that there is often a divine purpose behind occurrences that we may not immediately understand, urging believers to accept Allah’s plan with contentment. It highlights the immutability of Allah’s Sunnah, warning that patterns of past nations will repeat and to learn from them. The stories also point to the ways a messenger brings a message, by way of arguments from self, the horizons, and history.

    2. What three types of argument are presented in Surah Kahf?

    Three types of arguments are presented: arguments from the self, arguments from the horizons, and arguments from history. These methods are employed to convey warnings, observations, and ultimately, to offer consolation to both the prophets and the believers.

    3. How does Surah Kahf provide comfort and guidance to prophets facing difficulties?

    The Surah offers solace by reminding prophets that they are not alone in facing rejection and adversity. It highlights that prophets are also human. It assures them that Allah has a fixed time for decisions and a wisdom behind events, even when results are not immediately apparent. The stories encourage patience, emphasizing that Allah’s mercy and victory will eventually prevail, but haste and ego must be avoided. The message is one of perseverance and trust in Allah’s ultimate plan.

    4. What is the significance of the story of Musa (Moses) and Khidr (the wise servant) in the context of Surah Kahf?

    The story of Musa and Khidr serves as a practical illustration of the Surah’s core message. It demonstrates that there is divine wisdom behind actions that may seem incomprehensible or even morally wrong from a human perspective. Musa’s inability to understand Khidr’s actions initially underscores the limits of human knowledge and the need to trust in Allah’s greater plan. It illustrates that Allah uses observation, dreams and the unseen to communicate to prophets.

    5. In the story of Musa and Khidr, what do Khidr’s actions represent, and what lessons can be derived from them?

    Khidr’s actions, such as damaging the boat, killing the boy, and repairing the wall, represent Allah’s divine will and wisdom operating beyond human comprehension. The lessons include:

    • Trust in Allah’s wisdom: Even when events seem unjust, there is a greater purpose.
    • Limits of human knowledge: We cannot always understand Allah’s plan.
    • Patience: Understanding the divine plan requires patience.
    • Acceptance: We must accept Allah’s will and strive to learn from it.

    6. What different methods were used to communicate to the prophets?

    Several methods were used to communicate with the prophets including, inspiration or thoughts that speak within, direct sound behind a veil, visions presented in dreams (which require interpretation), and direct observations or “intentions” shown while awake.

    7. How does Surah Kahf address the problem of evil and suffering in the world?

    The Surah does not explicitly solve the problem of evil, but rather offers a perspective that acknowledges its existence while emphasizing the presence of a divine plan. It suggests that suffering and apparent evil may serve a greater purpose, even if we cannot always discern that purpose. It urges believers to trust that Allah’s wisdom and mercy will ultimately prevail.

    8. What practical advice does Surah Kahf offer for navigating life’s challenges and maintaining faith?

    The Surah provides several key pieces of practical advice:

    • Cultivate Patience (Sabr): Be patient during difficult times.
    • Trust in Allah’s Wisdom: Have faith that everything happens for a reason.
    • Act with Wisdom (Hikmah): Strive to understand situations from Allah’s perspective.
    • Avoid Haste and Ego: Do not rush to judgment or act out of pride.
    • Seek Knowledge: Strive to increase your understanding of the world and Allah’s plan.
    • Accept Allah’s Decisions: Be content with Allah’s will and trust in His ultimate plan.

    Understanding Allah’s Intentions and Wisdom in Events

    Allah’s intentions and wisdom are central themes in the sources, particularly in the context of understanding events and adhering to patience and faith. The sources emphasize that everything happens with Allah’s permission, intention, and will. This perspective is presented as a foundation of faith, suggesting that belief should extend beyond philosophical concepts into a practical understanding that Allah’s wisdom underlies all events.

    Key points related to understanding Allah’s intentions:

    • Unchangeable Sunnah The ways of Allah (Sunnah) are unchangeable, indicating a consistent and predictable pattern in how events unfold.
    • Arguments and reasoning Understanding Allah’s intentions involves recognizing arguments from the self, signs from the horizons, and lessons from history.
    • Patience and consolation Prophets are advised to practice patience, especially when outcomes seem unpromising. Consolation and patience are advised, coupled with wisdom, to understand the reasons behind Allah’s decisions, which are made according to a fixed time.
    • Wisdom behind events Believing in Allah’s wisdom is what gives a person patience. This requires trusting that Allah’s wisdom is at work in everything.
    • Limits of human knowledge Humans have limitations in their understanding, and should not try to exceed the scope of their knowledge.
    • Guidance and Knowledge The means by which Allah conveys messages, including thought, sounds, intentions, and dreams, all serve to provide guidance and knowledge.
    • Testing and Trust Allah tests people by presenting situations where they must use their intellect to understand what they can and trust in their Lord for what remains.
    • Goodness in intentions No intention of Allah is devoid of goodness and wisdom. Even when falsehood appears to thrive, it is part of a larger plan that nurtures a greater good.
    • Divine Scheme There is a divine scheme in place that governs the happenings of the world. Understanding this scheme completely is beyond human capability, but glimpses can be caught to provide insights.
    • Mercy and Grace Events that seem evil may still be acts of mercy from Allah, as demonstrated in the story of the boat.
    • Guidance in the Quran The Quran provides guidance, but some facts are beyond human grasp. Analogies are used to explain these concepts, but humans should not try to fully comprehend their reality.
    • Limits of Knowledge Humans should recognize the limits of their knowledge and not overstep them, as the basis of all knowledge comes from observation and experience.
    • Intention and Will Everything in the world occurs with God’s permission, intention and will, and that is the basis of faith.
    • Trust and contentment Humans should be content with Allah’s will and strive for the right results.

    The sources emphasize that while humans may not always understand the reasons behind events, trusting in Allah’s wisdom, mercy, and overarching plan is essential.

    Understanding Human Limitations: Knowledge, Senses, and Faith

    The sources discuss several limitations inherent in human understanding and knowledge, emphasizing the importance of recognizing these boundaries in the context of faith and wisdom.

    Key aspects of human limitations include:

    • Scope of Knowledge Human knowledge is limited, and there are matters beyond its scope. Humans should determine their field of knowledge, recognizing what lies within and beyond their grasp. People make a mistake when they do not know the scope of human knowledge.
    • Senses and Reflexive Knowledge Knowledge is created through a relationship with metaphysical information within, but it is limited by our senses. Senses connect individuals to both their inner selves and the external world, but these connections have limits.
    • Rationality and Moral Principles: Intellect and moral principles cannot fully dictate or govern the world, as the laws and regulations of the world operate differently. Moral questions arise based on external circumstances, but the causes of evil may not be known.
    • Inability to Grasp Divine Intentions Humans cannot fully grasp the wisdom of Allah’s intentions or all the mysteries behind His actions.
    • Limits of Senses Humans can increase the capacity of their senses to a degree; however, there are still limits.
    • Limits of Imagination While humans possess the ability to extract information and create a world of imagination, this world lacks inherent truth or reality.
    • Rational vs. Observational Human intellect does two things: it starts to know the things that are obligatory in the structure of consciousness and it creates possibilities that become the subject of research through observation.

    These limitations suggest a need for humans to trust in Allah’s wisdom and accept that not all events or divine intentions can be fully understood. Humans should be patient and thankful for the knowledge they have, and avoid exceeding the boundaries of their understanding. The source material indicates that this is the greatest blessing.

    Patience and Wisdom: Navigating Life’s Challenges

    Patience and wisdom are critical virtues discussed in the sources, particularly in the context of understanding Allah’s intentions and navigating life’s challenges. The sources emphasize that patience and wisdom are intertwined and necessary for those who seek to understand the world and act in accordance with divine guidance.

    Key aspects of patience and wisdom, as discussed in the sources, include:

    • Interdependence Human beings need both patience and wisdom at every step. A plan of action should be made with wisdom, speaking should be done with wisdom, and wisdom should be kept in mind in every action.
    • Source of Patience Faith in the wisdom of Allah gives a person patience.
    • Need for Patience Patience is advised when matters seem to be getting out of hand.
    • Patience in the face of adversity The sources advise patience and satisfaction, especially when the results of one’s efforts are not immediately apparent. Prophets, in particular, are encouraged to practice patience when faced with criticism and accusations, understanding that the timing and outcomes are determined by Allah.
    • Connection to Allah’s Wisdom Patience is essential for those who want to align themselves with Allah’s wisdom and understand the divine plan. It involves recognizing that Allah’s wisdom underlies everything and trusting in His decisions, even when they are not immediately comprehensible.
    • Wisdom as a guide Wisdom involves planning and acting in accordance with Allah’s law, recognizing that everything has an appointed time. It requires a comprehensive understanding of goals and objectives from a wise perspective.
    • Learning Patience and Wisdom The story of Musa (Moses) is presented as a lesson in patience and wisdom, teaching that one must wait patiently for Allah’s permission and have faith in the wisdom behind delays.
    • Wisdom and Knowledge: It is necessary to tell the wisdom of Allah, especially when one cannot see the real facts.
    • Wisdom as a Test: Prophets are tested on how they make decisions with their existing knowledge.
    • Benefits of Patience and Wisdom: Taking patience and wisdom in terms of results is the greatest blessing in this world.

    The sources suggest that by combining patience and wisdom, individuals can navigate the complexities of life with a deeper understanding of Allah’s intentions and a greater sense of inner peace. Patience allows one to endure challenges, while wisdom provides the insight to discern the divine purpose behind them.

    Understanding the Quran: Context, Reasoning, and Wisdom

    The sources discuss several aspects of interpreting the Quran, emphasizing the importance of understanding its context, recognizing different forms of reasoning, and acknowledging the limits of human knowledge.

    Key points related to Quran interpretation, according to the sources:

    • Arguments and Reasoning Understanding the Quran involves recognizing arguments from the self, signs from the horizons, and lessons from history. These arguments are sometimes detailed and sometimes not.
    • Historical Context Historical reasoning is important in understanding the Quran. Historical events, including the stories of prophets and their nations, are used to illustrate principles and provide guidance.
    • Patience and Wisdom The story of Musa (Moses) and Al-Khidr (mentioned in a tradition and adopted in Tafsir books) is presented as a lesson in patience and wisdom, teaching the importance of waiting for Allah’s permission and recognizing the wisdom behind delays. This story advises acting with patience and wisdom, and trusting in Allah.
    • Context and Circumstance Quranic verses and stories should be understood in the context of the situation in which they were revealed or the purpose they serve. The context of an event is important for understanding the message.
    • Dreams and Visions Dreams and visions mentioned in the Quran, particularly those of prophets, are true but may require interpretation. These visions can be shown in the form of parables and may be interpreted to reveal deeper meanings.
    • Intention and Observation Understanding the Quran involves recognizing the importance of intentions and observations.
    • Limits of Knowledge Humans have limitations in their understanding, and should not try to exceed the scope of their knowledge. There is a need to understand the limits of one’s knowledge when interpreting the Quran.
    • Trust and Contentment Humans should be content with Allah’s will and strive for the right results.
    • Guidance and Mercy: The Quran provides guidance, but some facts are beyond human grasp. Analogies are used to explain these concepts, but humans should not try to fully comprehend their reality.
    • Recognizing Allah’s Wisdom The ultimate goal of Quran interpretation is to recognize Allah’s wisdom and mercy in all matters.

    The sources suggest that interpreting the Quran requires a combination of intellectual reasoning, historical awareness, and spiritual insight, as well as an acknowledgement of the limits of human understanding. It is a process of seeking guidance and understanding Allah’s intentions, while remaining humble and patient in the face of the unknown.

    Prophet Musa: Patience, Wisdom, and Divine Knowledge

    The sources discuss Prophet Musa (Moses) primarily in the context of his journey to learn patience and wisdom, as well as to illustrate key principles of Quranic interpretation.

    Key aspects of the discussion regarding Prophet Musa, according to the sources:

    • The Journey for Knowledge: The story of Musa’s journey with a disciple to meet Al-Khidr (a servant of Allah) is a central theme. Musa seeks to gain knowledge from Al-Khidr, but is warned that he will not be able to be patient.
    • Patience and the Wisdom of Allah: The narrative serves to teach patience and to highlight the wisdom of Allah. Musa is advised to be patient and trust in Allah’s wisdom, even when events seem inexplicable or unjust.
    • Testing of Musa: Musa’s character, particularly his tendency to question events, is evident throughout the story. The journey can be seen as a test for Musa, intended to educate him.
    • Limitations of Human Knowledge: The story emphasizes the limitations of human knowledge. Musa’s inability to understand Al-Khidr’s actions underscores the idea that humans cannot fully grasp the divine wisdom behind all events.
    • Events during the Journey: The journey includes several notable events that test Musa’s patience:
    • The damaged boat: Al-Khidr damages a boat belonging to poor sailors.
    • The slain boy: Al-Khidr kills a young boy.
    • The repaired wall: Al-Khidr repairs a collapsing wall in a village where they were denied hospitality.
    • Explanations and Divine Intentions: Al-Khidr eventually explains the reasons behind these actions, revealing the divine intentions and wisdom that were hidden from Musa. These explanations illustrate that seemingly negative events can have positive purposes and are part of Allah’s plan.
    • Lessons from the Story: The story of Musa is presented as a parable, teaching believers to trust in Allah’s wisdom, accept the limits of human knowledge, and be patient in the face of adversity. It also highlights the importance of acting with wisdom and aligning oneself with Allah’s laws.
    • The Meeting Place of Two Rivers: The location where Musa meets Al-Khidr is described as the meeting place of two rivers. The exact location is debated, with some suggesting it could be near Khartoum, where the Blue Nile and White Nile converge. Others suggest it is not important to know the physical location.
    • Determined Journey: Musa expresses his determination to continue his journey until he reaches the meeting place of the two rivers, even if it takes years.
    📑 SERIES: Story MUSA & KHAZIR | موسی اور خضر کا واقعہ | AL Bayan – Al-KAHF | JAVED AHMAD GHAMIDI

    The Original Text

    کہ یہ کوئی نئی بات نہیں اور نہ ہی یہ نئے رسول ہیں، جس طرح اللہ تعالیٰ پہلی امتوں میں اپنے رسول بھیجتا رہا ہے، وہ بھی وہی ہیں جیسے پہلے رسولوں کی امتیں اس قانون کے تحت آئیں جس کا ذکر یہاں کیا گیا۔ آپ بھی اسی طرح اس سے متاثر ہونے جا رہے ہیں۔ اب وہی باتیں ہونے جا رہی ہیں۔ یہ اللہ کی سنت ہے اور یہ سنت ناقابل تغیر ہے۔ اس میں کبھی کوئی تبدیلی نہیں آئے گی اور نہ ہی اس سے پہلے کبھی ہوئی ہے، لہٰذا خبردار رہیں۔ میں نے سب سے پہلے نفس کے دلائل کو بیان کیا، افق کے آثار کی طرف توجہ دلائی، کچھ واقعات کی طرف اشارہ کیا، اس کے بعد بالآخر تنبیہ اور مشاہدہ کے موضوع پر یہ سلسلہ پایہ تکمیل کو پہنچا۔ انبیاء بھی جسم میں انسان ہوتے ہیں، دعوت دیتے ہیں، پیغام پہنچاتے ہیں، اپنے دن رات اپنی قوم کے لیے وقف کرتے ہیں۔ کیا تم قرآن پاک میں دیکھتے ہو کہ کیسی تمنا اور کیسی محبت کا اظہار کیا گیا ہے کہ میں تم ہوں۔ میں تجھ سے کوئی صلہ نہیں مانگتا، یعنی میں نے کوئی مطالبہ نہیں کیا، مجھے تجھ سے کوئی دلچسپی نہیں، سوائے القرباء میں المدت کے، میں تجھ سے تعلق رکھتا ہوں، اس کی محبت مجھے مجبور کرتی ہے کہ میرا رب کہتا ہے: لاالہ نفسک۔ اللہ کی قسم اے ایمان والو، میں اب بھی تمہیں دعوت دے رہا ہوں، پیغام پہنچا رہا ہوں، تمہارے لیے دعا کر رہا ہوں۔ میری آخری خواہش یہ ہے کہ میں تمہیں چھوڑنے سے پہلے یقین کر لو۔ عمل یا اس رویے کا اثر ہوگا۔ قرآن کریم کا شعر دیکھیں تو کہتا ہے کہ اگر نفس سے دلیلیں ہیں، افق سے دلیلیں ہیں تو تاریخ سے بھی دلیل ہوگی۔ بعض اوقات نفس سے دلائل زیادہ مفصل ہوتے ہیں۔ کبھی آفاق کے دلائل زیادہ مفصل ہوں گے، کبھی تاریخی استدلال، جیسے سورہ اعراف میں، کئی حصوں پر پھیلا ہوا ہو گا، بلکہ پوری سورت، لیکن یہ تین طرح کے استدلال ہیں، نفس سے، آفاق سے، اور تاریخ سے اسی طرح جب مضمون تحدید یا مشاہدہ کا مضمون، مضمون اس مقام تک پہنچتا ہے، جہاں یہ مضمون پہنچتا ہے، تو یہ مضمون بھی انسان کو پہنچتا ہے، وہ بھی سکون ہوتا ہے۔ اسے تسلی ہے. یہ تبدیلی تین یا چار آیات میں ہوتی ہے، یعنی اوپر جو کچھ بیان کیا گیا ہے اس کی وجہ سے وضاحت کی گئی ہے، پھر ایک دو آیات میں ایک تاریخی واقعہ کی طرف اشارہ کیا گیا ہے، اور آخر میں قرآن کریم یا رسول اللہ سے متعلق تسلی دی گئی ہے۔ مضمون آگے بڑھے تو کئی جگہ ایسا ہوتا ہے، جیسے ابواب ترتیب دیتے وقت، اس میں بھی کبھی کبھی یہ حالات یکے بعد دیگرے پیش آتے ہیں اور قوم کی طرف سے یہی رد عمل سامنے آتا ہے، تو مثلاً سورۃ الضحی یا سورۃ الم نشرح میں تسلی کی صورتیں ظاہر ہوتی ہیں، پھر اس باب کا وہ حصہ تکمیل کو پہنچتا ہے، یہاں بھی اللہ تعالیٰ نے نصیحت فرمائی ہے، چنانچہ اللہ تعالیٰ نے فرمایا: صبر صبر کی تلقین اسی وقت کی جاتی ہے جب نتیجہ نکلتا دکھائی دے کہ معاملہ ہاتھ سے نکلتا جا رہا ہے۔ نبی کا معاملہ اپنی امت کے بارے میں یہ نہیں ہے کہ وہ مطمئن ہو کر بیٹھ جائے اور یہ کہے کہ اگر اچھا عذاب آئے تو اسے چھوڑ دو۔ سیدنا نوح نے فرمایا کہ لم یلد الفجرا کفارہ۔ عام طور پر، نبی چاہتا ہے کہ اس کی قوم ایمان لائے اور اللہ تعالی کی رحمت سے سرفراز ہو، لیکن وہ مرحلہ کھو جاتا ہے . ان رسولوں کے باب میں جنہوں نے اللہ کی اجازت کے بغیر ہجرت کی، یہ طے ہے کہ ان کی ہجرت کا فیصلہ اللہ ہی کرتا ہے، وہ یہ فیصلہ خود نہیں کر سکتے، وہ اپنے اجتہاد سے نہیں کر سکتے۔ ان کا تذکرہ کرتے ہوئے فرمایا گیا کہ اگر تم مچھلی کے آدمی کی طرح جلد بازی میں نہ بیٹھو تو صبر کا وہ مرحلہ آئے گا جس میں اللہ کی رحمت نازل ہوگی اور اللہ تمہیں اپنی فتح سے کامیابی عطا کرے گا لیکن اس سے پہلے ایک مشکل وقت آئے گا۔ مرحلہ انا کا ہے، اس میں جلد بازی نہیں کرنی چاہیے، لہٰذا اب صبر و تحمل کے ساتھ سکون اور سکون کا معاملہ ہے۔ ہمارے لحاظ سے ہم انسان ہیں، کبھی ہمیں چند قدم کے فاصلے پر نظر آتا ہے اور کبھی ہم آگے دیکھتے ہیں اگر آپ اصل حقائق کو نہیں دیکھ سکتے تو اللہ کی حکمت بتانا ضروری ہے، تو اکثر موضوع یہ ہوتا ہے کہ جب تسلی دینا چاہتے ہیں تو کبھی نتیجہ بتا دیا جاتا ہے، اور کبھی پردے کے پیچھے حکمت کام کرتی ہے۔ یہ رہا ہے، یعنی مضمون میں اس کی وضاحت ہو چکی ہے، کیا ایسا نہیں، کہ ایک عمر ہے، ایک مدت ہے، وہ مقرر ہے، وہ جو کچھ کرتے ہیں، کبھی کبھی ہو جاتا ہے، جو رہ گیا ہے، رب، اب ان کی کہانی ختم ہو جائے، یہ خیال بھی پیدا ہوتا ہے۔ اور یہ بھی کہ رب میری امت کی انتہا ہے، اگر آپ کی طرف سے ہدایت ہوتی تو ان دونوں پہلوؤں کو سامنے رکھتے ہوئے کبھی سکون، کبھی صبر، کبھی اطمینان اور ایسی باتیں بھی نصیحت کی جاتی ہیں اور پھر کوئی حکمت یہ بھی بتائی جاتی ہے کہ ایسا کیوں ہے کہ ہم نے ہر چیز کا ایک وقت مقرر کر رکھا ہے، ہمارے فیصلے کیسے ہوتے ہیں، اس بات کو یہاں بیان کر دیا گیا ہے، تاریخ کا ایک واقعہ بھی ہے، تاریخ کا ایک واقعہ بھی ہے۔ انبیاء اور ان کی قوموں کی تاریخ۔ ایسا بھی ہوتا ہے اور عموماً قرآن کریم اسے موضوع بناتا ہے لیکن بعض اوقات اس کے علاوہ بھی دلال میں کچھ واقعات اس طرح پیش کیے جاتے ہیں۔ میں صاحب سے ملا ہوں۔ یہاں اس کا کوئی نام نہیں ہے۔ چونکہ یہ نام روایت میں آیا ہے اس لیے اسے ہم نے کتب تفسیر میں اختیار کیا ہے۔ اس کا تلفظ خضر ہے اور اسے ہمارے شاعروں نے باندھا ہے، اس لیے اسے اختیار کیا جاسکتا ہے۔ اس کا کوئی مطلب نہیں ہے۔ واضح رہے کہ اصل تلفظ ایک ہی ہے۔ اب یہ قصہ قرآن کریم نے پیش کیا۔ اور اب اگلا مضمون اس کے پیچھے ہے جس کی پابندی یا نشاندہی کی گئی ہے یا تنبیہ کی گئی ہے اور جس طرح آخر میں اس نے اپنے قانون کا حوالہ دیا ہے اور خاص طور پر بتایا ہے کہ ہر چیز کے پیچھے ایک حکمت ہوتی ہے۔ اور ہر چیز کے لیے ایک وقت مقرر ہے، اس لیے اسے سامنے رکھ کر استدلال کیا گیا ہے، پس واقعہ اور واقعہ کے پس پردہ موضوع کے درمیان تعلق کو اس طرح واضح کیا گیا ہے کہ اے نبیؐ، ان پر صبر کرو، یعنی اگر ایسا ہی ہو۔ وہ اس مقام پر پہنچ چکے ہیں اور کوئی بات سننے کو تیار نہیں ہیں، اس لیے ٹھیک ہے کہ فیصلہ ہو جائے گا، اس کا وقت مقرر ہو چکا ہے، لیکن اس فیصلے کا آپ کو صبر سے انتظار کرنا پڑے گا۔ اے پیغمبر ان پر صبر کرو اور اس کے لیے اس واقعہ کو سامنے رکھو واقعہ کو سامنے رکھو یہ معلوم ہے کہ عام طور پر جب واقعات بیان ہوتے ہیں تو قرآن کریم فعل متعین کرتا ہے، یہاں بھی ایسا ہی ہوا، یعنی فعل ہے لیکن اس کے پیچھے کوئی فعل نہیں ہے، اس لیے فعل لفظ کے لحاظ سے استعمال ہوتا ہے۔ ہم خود سمجھتے ہیں کہ کبھی ایسا ہوتا ہے، یاد رکھنا، کبھی ایسا ہوتا ہے، یاد دلانا، یاد دلانا، اور بعض اوقات صرف نبی ہی ہوتا ہے جو مخاطب ہوتا ہے، اسے اپنے سامنے رکھو، ذہن میں رکھو، وہ اسے الفاظ کے لحاظ سے نکالتے ہیں، ان کے مقابلے میں اپنے دل میں صبر کرو۔ اے نبی صلی اللہ علیہ وسلم اپنے سامنے موسیٰ فتح کا واقعہ رکھو جب موسیٰ نے اپنے شاگرد سے کہا تھا کہ میں نے بیان کر دیا ہے۔ اس سے واضح ہوتا ہے کہ اس کا مقام صرف ایک خادم کا نہیں بلکہ ایک نوجوان ساتھی اور طالب علم کا ہے۔ اس لحاظ سے دیکھا جائے تو لفظ شاگرد کا ترجمہ بہت موضوعی ہو گا، یعنی یہ لفظ بعض اوقات عام ہوتا ہے، لیکن موقع لفظ ہمیں بتاتا ہے کہ یہ لفظ یہاں کس پہلو سے استعمال ہوا ہے، لہٰذا اگر اردو زبان میں لفظ نوجوان کے استعمال کو بھی دیکھیں یا بوڑھے استعمال کر رہے ہوں، تو ان تمام پہلوؤں میں یہ لفظ استعمال ہوتا ہے۔ سے ہم کسی ایسی چیز کا ترجمہ اور اختیار کر سکتے ہیں جو اب منظر عام پر آ رہی ہے۔ اس واقعہ کے بارے میں ایک اہم بحث یہ پیدا ہوتی ہے کہ آیا یہ ایک واقعہ ہے جیسا کہ ہم اس کا تجربہ کرتے ہیں۔ یا خواب میں کچھ حقائق اس لیے دکھائے گئے ہیں کہ ہمارا وقت ختم ہو گیا ہے، اس لیے ہم اس پر اگلی نشست میں بات کریں گے اور پھر دیکھیں گے کہ یہ واقعہ کیا ہے، اس میں کیا پیش کیا گیا ہے اور یہ کس پہلو سے ہے۔ کہی گئی باتوں سے اس کا کیا تعلق ہے ؟ اللہ مجھ پر رحم فرمائے ، الحمدللہ۔ بات اس سے شروع ہوتی ہے کہ میں نے واضح کیا کہ خضر کا نام قرآن میں نہیں ہے، کیا کسی حدیث میں مذکور ہے، اسی وجہ سے وہ ہمارے درمیان مشہور ہوئے۔ ایسا لگتا ہے کہ جس طرح واقعات رونما ہوتے ہیں، اسی طرح ہمیں اپنے ساتھ پیش آنے والے واقعات کا سامنا کرنا پڑتا ہے۔ اسی طرح کی بات یہ بھی ہے۔ ایک بار پھر ہم وضاحت کرتے ہیں کہ ہجرت کا معاملہ اس طرح پیش آیا، نبی صلی اللہ علیہ وسلم کی سیرت کا بیان اور اسی طرح دوسرے انبیاء کی سیرت کا بیان بھی اسی طرح ہوا ہے۔ وہ بھی ان کے ہیں یا دکھائے جاتے ہیں۔ جب ہم کسی نبی کی زندگی کو بیان کریں گے تو اس کو اس طرح بیان کیا جائے گا جس طرح دنیوی زندگی میں پیش آنے والے واقعات، اگر ان پر کوئی بات نازل ہوئی یا ان پر کوئی مشاہدہ کیا گیا تو۔ ہو چکا ہے اور بیان بھی کیا جائے گا۔ یہ نبی کی سیرت ہے اور نبی کا مفہوم یہ ہے کہ اللہ تعالیٰ نے ایک شخص کو خطاب کے لیے چنا ہے، اسے چن کر یہ ذمہ داری دی گئی ہے۔ کہ وہ اللہ کا پیغام دوسروں تک پہنچائے۔ اس لیے اللہ تعالیٰ اپنا پیغام اس تک پہنچاتا ہے۔ اس کے لیے جو طریقے استعمال کیے گئے ہیں ان کا خلاصہ سورہ شوریٰ میں کیا گیا ہے۔ بتایا گیا ہے کہ دو سورتیں ہیں۔ خیال ان کے باطن میں بولتا ہے، جسے ایک شاعر نے کندراں بہارف می روئی کلام کہا ہے۔ بلکہ خیال بولتا ہے، یعنی گویا میں بات کر رہا ہوں یا کوئی اور مجھے جواب دے رہا ہے، تو یہاں خیال نے الفاظ کی شکل اختیار کر لی ہے اور الفاظ آواز بن کر نکلے ہیں، لیکن ایسا خواب یا خواب میں نہیں ہوتا، جس میں الفاظ آواز ہوتے ہیں۔ وہ وجود سے نہیں نکلتے، خیال بولتا ہے، یعنی یہ بولتا ہے، ہم اسے سنتے ہیں، سمجھتے ہیں، اور اسی طرح جب ہم بیدار ہوتے ہیں، اگر ہم نے کوئی بات کہی ہے تو ہم اسے دہرا سکتے ہیں، اگر یاد رہے تو مجھے یہ جواب ملا۔ فلاں نے جواب دیا، “لیکن اگر کبھی سوچو اور پیچھے مڑ کر دیکھو تو اس میں آوازیں اس طرح سنائی نہیں دیتی تھیں جیسی کہ اب سنی جاتی ہیں، اس میں فکر نے ایسی زبان اختیار کی ہے جو سنی اور سمجھی جاتی ہے۔” یہ وہاں ہے، لیکن اس میں کوئی آواز نہیں ہے۔ ایک بات یہ ہے کہ انسان کو اس طرح کچھ سننے کی صلاحیت دی گئی ہے۔ وہ خیال پر اثر انداز ہوتے ہیں اور پھر وہ خیال بولنا شروع کر دیتے ہیں۔ دوسرا طریقہ یہ ہے کہ کوئی چیز باقاعدہ آواز کے ساتھ سنی جاتی ہے۔ ایک حجاب ہے جیسے درخت کو اللہ تعالیٰ نے سیدنا موسیٰ علیہ السلام سے بات کرنے کے لیے پردہ کیا ہے، حجاب کے پیچھے سے آواز آتی ہے۔ یہ آواز اسی طرح کی ہے جس طرح ہم آواز سنتے ہیں۔ اور بندہ اسے سنتا ہے، اس کی حقیقت کو سمجھتا ہے، پھر جب حضرت موسیٰ کو دیا گیا تو کون سا مکالمہ ہوا، قرآن نے پورا مکالمہ نقل کیا ہے، انہیں اس میں کوئی عجب محسوس نہیں ہوا، وہ جواب دے رہے ہیں۔ وہ سوالات سن رہے ہیں، انہیں ہدایات دی جارہی ہیں، انہیں بتایا جارہا ہے کہ انہیں کون سا کام سونپا گیا ہے، جو مسائل انہیں درپیش ہیں، ان کے سامنے رکھے گئے ہیں، ان کا حل بتایا گیا ہے، تو ایک مکالمہ کی طرح۔ جیسا کہ ہوتا ہے مکالمہ ہوا لیکن جیسا کہ میں نے عرض کیا ہے خیال کو لفظوں میں ترجمہ کرنا پڑتا ہے خیال بولتا ہے اس میں حروف اور آواز نہیں ہوتی بلکہ کہنے والا بولتا ہے اور سننے والا سنتا ہے۔ اس کے ساتھ انبیاء کو سکھانے کے لیے ایک اور طریقہ اختیار کیا جاتا ہے، وہ ہے نیت کا طریقہ۔ اس کا مطلب یہ ہے کہ نہ کوئی بات ہوئی ہے اور نہ کوئی پیغام دیا گیا ہے بلکہ حقیقت دکھائی جا رہی ہے یعنی مشاہدہ کر لیا گیا ہے۔ اس کی دو نمایاں مثالیں حدیث میں بیان ہوئی ہیں۔ نبی کریم صلی اللہ علیہ وسلم نے فرمایا کہ جب مجھے اسرائیل کا رویا دکھایا گیا اور میں نے صبح کو کہا کہ مجھے بیت المقدس لے جایا گیا ہے۔ لوگوں نے اس پر طرح طرح کے اعتراضات کرنے شروع کر دیے، چنانچہ جس مجلس میں یہ معاملہ بیان کیا جا رہا تھا، وہاں قریش کے کچھ رہنما بھی موجود تھے۔ جب وہ سوال پوچھنے لگے تو میں گھبرا گیا۔ کسی چیز کو اپنی مرضی سے یا کسی کی توجہ سے دیکھا جاتا ہے، پھر جو کچھ وہاں دکھایا جاتا ہے اور خواب میں ہم عام مشاہدہ کرتے ہیں۔ اگر آپ دکھا دیں کہ یہاں کتنے جال لگے ہوئے ہیں تو انہوں نے اسی طرح کے سوالات کرنا شروع کر دیے، اس حقیقت کے پیش نظر کہ رسول اللہ صلی اللہ علیہ وسلم کی دعا کا انکار کیا جاتا ہے۔ گھبراہٹ یہ پیدا ہوئی کہ مجھ سے یہ ممکن نہ ہو، وہ باتیں گزر گئیں، اگر اس وقت میرے ذہن میں ہوتی تو اب وہ مجھ سے ان تفصیلات کے بارے میں پوچھیں گے، تو میں انہیں کیسے بیان کروں گا، پھر وہ منظر میرے سامنے آنے لگا، یعنی پھر سے گویا ایک قسم کی آرت شروع ہوگئی۔ اب وہ یہاں گم نہیں، خوابوں کا علم نہیں، چیزیں اسی طرح دیکھی جا رہی ہیں، تو اس نے کہا کہ میں اسے دیکھتا تھا، جو سوال کرتا تھا، ویسا ہی منظر سامنے آتا اور میں اسے بیان کرتا چلا جاتا۔ تو یہ ایک مثال ہے۔ دوسری مثال وہ ہے جس میں رسول اللہ صلی اللہ علیہ وسلم نماز پڑھا رہے تھے۔ انہوں نے کہا کہ جب میں نماز کے لیے کھڑا ہوا تو مجھے جنت اس طرح دکھائی گئی جیسے اس وقت دکھائی دی لیکن یہ واضح نہیں کہ وہ سوئے ہوئے ہیں یا نیند کی حالت میں۔ میں نے محسوس کیا کہ میں اسے توڑ سکتا ہوں، اس لیے میں نے اپنا ہاتھ آگے کیا، یعنی یہ شکل بنائی گئی۔ یہ نیتوں کا ایک پہلو ہے۔ ایک پہلو وہ ہے جس میں خواب میں کوئی چیز یا مشاہدہ ہوتا ہے۔ خواب میں کوئی چیز دکھائی جاتی ہے، یعنی نبی صلی اللہ علیہ وسلم سو رہے ہیں، پھر دکھایا جاتا ہے۔ ان میں جو کچھ دکھایا گیا ہے وہ حقیقت ہے، اس میں شیطان کے دخل کا سوال نہیں ہے اور نہ ہی روح کے دخل کا کوئی سوال ہے، بلکہ وہ تمثیلوں کی صورت میں دکھائے گئے ہیں، اس لیے سورہ یوسف میں ان کی تشریح کی گئی ہے۔ قرآن نے واضح کر دیا ہے کہ انبیاء کو دکھائے گئے یا ان سے متعلق لوگوں کو دکھائے گئے خواب اگر ان سے متعلق کوئی نتیجہ نکالیں تو وہ سچے ہیں، چنانچہ بادشاہ کا خواب بھی سچا تھا۔ جس شخص نے اس کے ساتھ بدتمیزی کی اس کا خواب بھی سچ تھا۔ ان کا خواب بھی سچا تھا اور سیدنا یوسف کا خواب بھی، جس سے یہ نکلا کہ باپ نے گیارہ ستاروں اور سورج اور چاند کو اپنے سامنے سجدہ کیا۔ اگر میں دیکھ رہا ہوں تو یہ سب سچے خواب ہیں، لیکن تعبیر کے محتاج ہیں، یعنی تعبیر ہو جائے گی، اس لیے جب نیند میں کوئی چیز اس طرح دکھائی جائے تو اس واقعہ کی تعبیر بھی ہو سکتی ہے۔ عام طور پر، اس کی تشریح کی ضرورت ہے. اس دیباچے میں میں نے یہ ساری باتیں اس لیے بیان کی ہیں کہ پچھلی بار میں نے یہ واقعہ بیان کیا تھا جو آگے بیان کیا جا رہا ہے۔ یہ خواب بھی ہو سکتا ہے اور یہ ایک حقیقی واقعہ ہے، یعنی ایسا ہی واقعہ سیدنا موسیٰ علیہ السلام کے کسی سے ملنے کے وقت ہوا، جس کی مزید تفصیل بیان کی جا رہی ہے، اور یہ خواب کا واقعہ بھی ہو سکتا ہے۔ اسرائیل کا خواب بھی اسی طرح بیان کیا گیا ہے۔ سورہ بنی اسرائیل کے شروع میں ایک لفظ بھی ایسا نہیں ہے جس سے معلوم ہوتا ہو کہ یہ واقعہ خوابیدہ ہے۔ اسی لیے لوگ اب تک اس پر بحث کر رہے ہیں، یعنی اگر واقعہ سبحان الذی یسرہ بابدا لیل من المسجد الحرام المسجد المجید البرکانہ حول پڑھیں تو اس پوری آیت کو عربی زبان میں پڑھیں، ترجمہ میں پڑھیں، مزید پڑھیں۔ بعد میں اسی سورت میں فرمایا کہ یہ جاگنے کا واقعہ نہیں تھا بلکہ ایک خواب تھا، خواب دکھایا گیا تھا۔ کیونکہ یہ اللہ تعالیٰ کی طرف سے واقعات ہیں، یعنی ان کی تاویل کی ضرورت ہے، لیکن وہ واقعات ہیں، ان کو اس وضاحت کی ضرورت نہیں۔ لہٰذا لفظ نیت سے مراد یہ ہے کہ جو معاملات انبیاء علیہم السلام کے ہوتے ہیں وہ وحی کے معاملات ہیں، یعنی کوئی بات سنی جاتی ہے، سنی جاتی ہے، اس کی صورتیں بیان کی جاتی ہیں، اسی طرح کچھ چیزیں دکھائی جاتی ہیں، یہ آراء ہے۔ اور دکھانے کے لیے دونوں طریقے استعمال کیے جاتے ہیں۔ بیداری میں انا ظاہر ہونے لگتی ہے۔ یہ ”عراق” کا ایک پہلو ہے اور دوسرا یہ کہ اسے خواب میں دکھایا جائے۔ یا بیداری میں دکھایا گیا ہے، البتہ اگر اس کی حقیقت کو مزید کسی بحث میں بیان کرنا ہو تو بتایا جاتا ہے۔ میں نے ان چیزوں کو اپنے سامنے رکھ کر سمجھا دیا ہے اور اس میں لکھا ہے۔ ہم واقعہ پڑھنے جا رہے ہیں۔ میں پہلے بھی کہہ چکا ہوں کہ یہ واقعہ یہاں سیاق و سباق کے لحاظ سے آیا ہے، یعنی صبر اور حکمت کی تعلیم دینے کے لیے۔ یہ بتانا مقصود ہے کہ اب ہجرت کی اجازت اس وقت تک نہیں دی جاتی جب تک کہ وہ موصول نہ ہو جائے، صبر سے انتظار کرنا پڑتا ہے اور انتظار کے لیے اس بات پر یقین ہونا ضروری ہے کہ کسی چیز میں تاخیر ہو رہی ہے، اس لیے اگر اس میں اللہ کی طرف سے کوئی حکمت ہے تو اللہ کیا کرتا ہے؟ حکمتیں ہیں اور ان حکمتوں کو سمجھنے کے لیے انسان کو صبر کیوں کرنا چاہیے۔ اس حقیقت کو بیان کرنے کے لیے یہ واقعہ بیان کیا گیا ہے۔ خواب خواب بھی ہو سکتا ہے کیونکہ انبیاء علیہم السلام کے خواب سچے ہوتے ہیں یعنی ان میں غلطی کا سوال ہی پیدا نہیں ہوتا۔ چونکہ انبیاء کے نظارے سچے ہیں، اس لیے قرآن اور بائبل دونوں سے یہ بات واضح ہے کہ بعض اوقات ان کو بالکل اسی طرح بیان کیا جاتا ہے جس طرح دنیا کی بیداری کے واقعات ہوتے ہیں۔ بیانات اس لیے بنائے جاتے ہیں کہ وہ سچے ہیں، اس لیے جب اللہ تعالیٰ ان کو بیان کرتا ہے تو عہد نامہ قدیم میں اور قرآن میں بھی کچھ بیانات ہیں، وہ اسے اسی طرح بیان کرتے ہیں جس طرح کوئی واقعہ بیان کیا جا رہا ہے، یعنی اللہ کا۔ نقطہ نظر سے دیکھیں تو دونوں چیزیں دکھائی دے رہی ہیں۔ یعنی قرآن اور بائبل کی بعض اوقات بالکل اسی طرح تشریح کی جاتی ہے جس طرح روشن خیال علماء نے سورہ بنی اسرائیل میں واقعات کو بیان کیا ہے۔ اسراء کے واقعہ کو دیکھیں تو سورہ بنی اسرائیل کی ابتدا اسی واقعہ کی تفصیل سے ہے اور کہا گیا ہے کہ پاک ہے وہ جو اپنے بندے کو راتوں رات مسجد حرام سے مسجد حرام تک لے جائے۔ اب ان الفاظ میں ایسی کوئی بات نہیں کہ اس کی اصل میں وضاحت کیسے ہوئی؟ آئیے سورت کی تلاوت کرتے ہیں، پھر آگے بڑھیں اور وضاحت کریں کہ یہ خواب تھا۔ یہ اس لیے نہیں تھا کہ بتانا تھا، اس لیے نہیں کہ ایک مسئلہ زیر بحث تھا جس میں حوالہ دینا تھا، اس لیے وہاں یہ بیان کیا گیا ہے کہ وما نے جھوٹا کہا ہے کہ جو رویا ہم نے آپ کو دکھایا وہ اوپر بیان کر دیا ہے۔ ان لوگوں نے اسے فتنے میں بدل دیا ہے اس لیے اس کا اس طرح ذکر کرنا پڑا تو اس کی حقیقت واضح ہو گئی۔ اگر آپ سورہ بنی اسرائیل کو دیکھیں تو اسرائیل کا واقعہ اسی طرح بیان کیا گیا ہے، لیکن اسی سورت میں مزید قرآن نے واضح کیا ہے کہ یہ ایک خواب تھا جو رسول اللہ صلی اللہ علیہ وسلم کو دکھایا گیا تھا۔ واقعہ ہو یا خواب، ہر شخص اس میں اپنی ترجیح قائم کر سکتا ہے۔ میں نے اپنی ترجیح بیان کی ہے، تاہم، میں دوسرے امکان کی نفی نہیں کرتا۔ جگہ ایک ہی ہو سکتی ہے۔ اس میں دو دریاؤں کے ملنے کی جگہ کا ذکر ہے۔ اسے عربی میں مجمع البحرین کہتے ہیں۔ مصر میں اور سوڈان میں اس علاقے میں اسے مجمع البحرین کہا جاتا ہے۔ اسی لفظ کا اوپر ذکر ہوا ہے۔ تاہم اگر اسے عالمی بیداری کا واقعہ سمجھا جائے تو دو دریاؤں کے ملنے کی جگہ ایک ہی ہوسکتی ہے، یعنی اگر یہ واقعہ ہماری دنیا جیسا ہے۔ میں نے دیکھا ہے کہ یہ کوئی خواب نہیں ہے، اس لیے اس میں البحرین کی مجلس کا ذکر ہے، یعنی دو دریاؤں کے ملنے کی جگہ، ظاہر ہے، پھر مسئلہ پیدا ہوتا ہے کہ یہ کون سی جگہ ہے، یعنی سیدنا موسیٰ مصر میں ٹھہرے، بعد میں وہاں سے چلے گئے۔ وہ 40 سال صحرائے سینا میں رہے اور وہ فلسطین نہ پہنچ سکے۔ یہ واقعہ کب ہوا؟ بائبل میں اس کا کوئی ذکر نہیں ہے۔ یہ معاملہ کہاں ہوا؟ اگر آپ خواب کو مان لیں گے تو ان سے کچھ پیدا نہیں ہوگا۔ کسی سوال کی ضرورت نہیں۔ اگر بیداری کے واقعہ پر یقین کیا جائے تو دونوں دریاؤں کے ملنے کی جگہ وہی ہو سکتی ہے جہاں دریائے نیل کی دو بڑی شاخیں بحرالبائز اور بحرال الازرق موجودہ شہر خرطوم کے قریب آپس میں ملتی ہیں۔ یہ شاخوں میں بٹ جاتا ہے اور وہ دونوں شاخیں وہاں مل جاتی ہیں، ایک کا نام البحر البیز، سفید دریا اور دوسرا ازرق یعنی نیلا دریا ہے۔ اور میں نے عرض کیا کہ اگر خواب تھا تو اس سوال پر تحقیق کی ضرورت نہیں۔ قرآن کے صحابی فرحیح نے بالکل صحیح لکھا ہے کہ جن علاقوں میں حضرت موسیٰ نے اپنی پوری زندگی گزاری وہاں اس ایک جگہ کے علاوہ کوئی جماعت نہیں ہے۔ بحرین نہیں ملتا، یعنی جہاں دو دریا آپس میں ملتے ہیں اور کوئی جگہ نہیں ہے، تو ہمیں یہ ماننا پڑے گا کہ واقعہ وہیں پیش آیا، اور اسی طرح بحرین کی اس ایک مجلس کے علاوہ واقعہ میں بیان کردہ تمام چیزوں کا ذکر نہیں ہے، کیونکہ بائبل میں اس کا کوئی ذکر نہیں ہے۔ اگر ایسا ہوا تو سوال باقی ہے کہ یہ واقعہ آخر کیوں پیش آیا، وہ سفر پر نکلے اور ان کے ساتھ ان کا ایک شاگرد بھی تھا، پھر تاریخ میں اس کا ذکر کیوں نہیں کیا گیا؟ یہ سوال ان لوگوں کے لیے بھی اہم ہے جو اسے ایک واقعہ سمجھتے ہیں، اسے بصیرت کی دنیا کا معاملہ سمجھتے ہیں، اس سوال کی کوئی ضرورت نہیں، البتہ یہ معاملہ ہے، اب اس میں کہا گیا ہے کہ اے نبیؐ، ان کے سامنے صبر کرو، یہ واقعہ کا سیاق و سباق ہے۔ اے نبی صلی اللہ علیہ وسلم ان پر صبر کرو اور وہ واقعہ ان کے سامنے رکھ دو۔ یہ شروع ہوتا ہے کہ موسیٰ ( علیہ السلام ) اپنے شاگرد کے ساتھ چل رہے ہیں۔ وہ کہتے ہیں کہ چل رہا ہوں، یہ ایک لمبا سفر ہے، اور کوئی منزل نہیں، تو کہتے ہیں کہ مجھے چلتے رہنا چاہیے، یعنی جب تک میں دو دریاؤں کے ملنے کی جگہ نہ پہنچ جاؤں، مجھے چلتے رہنا ہے، یعنی یہ میری منزل کی طرح ہے۔ جب تک مجمع البحرین دو دریاؤں کا ملاپ ہے، میں اپنا سفر نہیں روکوں گا، میں چلتا رہوں گا۔ جب تک میں دو دریاؤں کے ملنے کی جگہ نہ پہنچ جاؤں یا برسوں یونہی چلتا رہوں، یعنی نہیں رکوں گا، مجھے منزل تک جانا ہے، کیا ایسا نہیں ہے کہ کسی نے کہا ہو کہ جہاں دو دریا ملتے ہیں، تم ایسے ہی چلتے رہو۔ جہاں دو دریا ملتے ہیں وہ منزل ہے تو وہ کہے گا کہ میں چلتا رہوں گا چاہے برسوں چلتے رہوں اس سفر میں نہیں رکوں گا۔ یہ عزم و حوصلے اور جذبے کا اظہار ہے اور یہ لفظ بہ لفظ ٹپک رہا ہے۔ استاد امام لکھتے ہیں کہ وہ کہتے ہیں کہ یا تو میرا مطلب ہے کہ سیدنا موسیٰ علیہ السلام کہتے ہیں کہ میں یا تو مجمع البحرین میں اس جگہ پہنچوں گا جہاں پہنچوں گا۔ کیونکہ مجھے ہدایت دی گئی ہے۔ مجھے کچھ بتانے کے لیے بلایا گیا ہے، اس لیے میں اب نہیں رکوں گا، میں اس مقام تک پہنچنے تک چلتا رہوں گا، اور اگر وہ منزل برسوں نہ آئی تو برسوں چلتا رہوں گا۔ ورنہ یہ شخص بہرحال اس محبوب سفر پر جا رہا ہے اور اس عزم کے ساتھ روانہ ہو رہا ہے کہ یا تو اس کی منزل مقصود ہے یا وہ مرنا چاہتا ہے، یعنی اس سفر کے لیے مجھے اپنا سب کچھ قربان کرنا ہے، تو گویا یہ عزم ہی ہے کہ اس نے خواب میں یا کسی حقیقی واقعہ میں اپنے شاگرد پر ظاہر کر کے کہا کہ میں جاری رکھوں گا، جب وہ مچھلیوں سے ملاقات کے لیے دریائے مچھلی کے پاس پہنچے تو وہاں پہنچ گئے۔ ان کا ناشتہ. وہ چلتے وقت اپنے ساتھ کچھ لے گیا تھا، وہ بھول گیا۔ شاگرد نے اسے اٹھایا ہوگا۔ جب وہ ندیوں کے جلسہ گاہ پر پہنچا تو ناشتے میں تلی ہوئی مچھلی بھول گیا۔ میں نے وضاحت کی ہے کہ اس کے لیے لفظ “فوری گلینڈ” استعمال ہوا ہے۔ یہ لفظ کسی بھی طرح بغیر بھنی ہوئی یا زندہ مچھلی کے لیے موضوع نہیں ہے، اس لیے یہ اس بات کا واضح ثبوت ہے کہ مچھلی بھنی ہوئی ہے۔ زندہ مچھلی لے کر اتنے لمبے سفر پر جانے اور پھر اسے ناشتہ کہنے کی کوئی وجہ نہیں ہے۔ اس سے صاف معلوم ہوتا ہے کہ یہ تلی ہوئی مچھلی تھی، چنانچہ جب وہ دریاؤں کے جلسہ گاہ پر پہنچے تو وہ اپنے ناشتے میں تلی ہوئی مچھلی بھول گئے اور اس نے اسے وہیں رکھ لیا۔ کرےگا نے مڑ کر دیکھا کہ بھنی ہوئی مچھلی درد کے ساتھ باہر نکل کر دریا میں چلی گئی۔ وہ مچھلیاں جاتے ہوئے دریا میں چلی گئیں جب وہ جلسہ گاہ پر پہنچا تو وہ اپنے ناشتے میں تلی ہوئی مچھلی بھول گیا اور اس نے راستہ بنانے کے لیے دریا میں ایک سرنگ کھودی۔ انہیں ایک نشانی بتائی گئی کہ ایسا ہو جائے گا، پھر وہیں رک جاؤ، یعنی جب دو دریاؤں کے ملنے کی جگہ پر پہنچو گے تو ایک واقعہ ہو جائے گا، یہی تمہارا مقدر ہے۔ پھر جب آگے بڑھے تو موسیٰ نے اپنے شاگرد سے کہا، قل فتح، اتنا کھانا بھائی، وہ ہمارا ناشتہ کھاتے ہیں، جو پیک کیا ہوا تھا، وہ کھاتے ہیں۔ ذرا ناشتہ لے آؤ اور جیسے ہی ان کے کہنے پر کھا پی لو۔ حیرت کی بات ہے کہ کوئی اپنی بات بڑی ہچکچاہٹ سے کہتا ہے۔ ہوا تھا کہ وہ دونوں دریا کہاں سے شروع ہوتے ہیں جب ہم اس چٹان کے پاس ٹھہرے ہوئے تھے تو میں نے کچھ دیر تک مچھلی کے بارے میں نہیں سوچا یعنی میں اس منظر میں گم ہو گیا اس وقت میں نے مچھلی کے بارے میں نہیں سوچا اور حضرت کیا کہوں، یہ شیطان ہی تھا جس نے مجھے یاد کرنا بھلا دیا اور اس نے عجیب طریقے سے دریا میں اپنا راستہ تلاش کیا۔ میری سمجھ میں نہیں آیا کہ کیا ہوا۔ لیکن جیسے ہی میں نے دیکھا، مچھلی نے چھلانگ لگائی اور وہ زندہ ہو کر دریا میں چلی گئی۔ تو گویا اس طالب علم نے نہایت واضح الفاظ میں اپنی معذرت کا اظہار کیا ہے کہ یہ واقعہ پیش آیا ہے، اب میں کیا کروں، اگر آپ اس پر غور کریں، اگر آپ عربی زبان اور اس کے ادب سے واقف ہیں۔ ایک ایک لفظ رک کر بولا گیا اور قرآن نے اسے بالکل اسی طرح بیان کیا ہے، یعنی گویا کوئی بات جھجکتے ہوئے کہی جارہی ہے۔ ہم نے اسی رعایت کے ساتھ ترجمہ کیا ہے۔ میرے پاس معاوضے کی کوئی صورت نہیں تھی۔ میں اسے لے گیا اور اب وہ مچھلی دریا میں چلی گئی ہے۔ اس نے معافی مانگ لی ہے۔ یہ کہانی ابھی تک چل رہی ہے۔ ہمارا وقت ختم ہو گیا ہے۔ اللہ کے نام سے جو بڑا مہربان نہایت رحم والا ہے، خواتین و حضرات، ہم سورہ کہف کی آیت نمبر 64 کے سبق میں پناہ لے رہے ہیں۔ سیدنا موسیٰ علیہ السلام کے سفر کا واقعہ زیر بحث ہے۔ نیز، وہ کوئی واقعہ تخلیق کرنے یا تاریخ بیان کرنے کا ارادہ نہیں رکھتے۔ یہاں سورہ کے سیاق و سباق میں رسول اللہ صلی اللہ علیہ وسلم کو تسلی دی گئی ہے اور بتایا گیا ہے کہ اگر دعوت کے نتائج اس کی توقع کے مطابق نہ آئے۔ اس لیے اللہ کی حکمت پر نگاہ رکھیں۔ اللہ دنیا کا نظام چلا رہا ہے۔ اس میں جو کچھ ہوتا ہے وہ بڑی حکمت کے تحت ہوتا ہے۔ اللہ کی حکمت پر ایمان ہی انسان کو صبر عطا کرتا ہے۔ یہ انبیاء کے لیے بہت بڑا امتحان ہے۔ وہ اپنی دعوت کو پوری خوش اسلوبی کے ساتھ پیش کرے، لوگوں کے سامنے اسے ہر لحاظ سے واضح کرے، ان کے اعتراضات کا جواب دے، لیکن لوگ سننے کو تیار نہیں، اس پر الزام لگاتے ہیں، ہزار طرح سے اس پر تنقید کرتے ہیں۔ ایسے موقعوں پر خود کو نشانہ بنایا جاتا ہے، انسان تو انسان ہے، اس کی فطرت بھی رد عمل ظاہر کرتی ہے۔ قرآن کریم نے ایسے تمام مواقع پر یہ نصیحت کی ہے اور کہا ہے کہ جو ذمہ داری تمہیں دی گئی ہے اسے خود ادا کرو۔ ہجرت کا موقع کب آئے گا ؟ قوم کو چھوڑنے کا وقت کب ہے؟ کارروائی کا وقت کب ہے؟ انجام طے ہے، یہ سارے فیصلے آپ کے کرنے کے نہیں، اللہ تعالیٰ کرے گا، اس لیے پیچھے مڑ کر دیکھیں تو صبر سے کام لینے کی تلقین کی گئی ہے۔ میرے خیال میں انسان کو ہر قدم پر ان دو چیزوں کی ضرورت ہوتی ہے، اسے حکمت کے ساتھ لائحہ عمل بنانا چاہیے، حکمت سے بات کرنی چاہیے، ہر عمل میں حکمت کو ذہن میں رکھنا چاہیے، اور تمام اہداف و مقاصد کو حکمت کے نقطہ نظر سے زیر بحث لانا چاہیے۔ اور اللہ کے قانون کے مطابق چونکہ یہ طے ہے کہ ہر چیز کا ایک وقت مقرر ہے جس طرح اللہ نے میرے اور تمہارے لیے ایک وقت مقرر کیا ہے جب ہماری مہلت ختم ہو جائے گی اور ہمیں واپس بلایا جائے گا۔ جس طرح قوموں کے لیے ایک ڈیڈ لائن ہے، اسی طرح اللہ تعالیٰ اگر کسی کو کوئی مشن سونپتا ہے تو اس کے لیے بھی ایک ڈیڈ لائن ہے۔ مجھے صبر اور حکمت کا طریقہ اختیار کرنا چاہیے، اللہ پر بھروسہ رکھنا چاہیے اور اللہ پر بھروسہ اسی وقت باقی رہتا ہے جب انسان کو یہ اطمینان ہو کہ میرے رب کی حکمت ہر چیز میں کام کرتی ہے اور اس کی حکمت کا کوئی پردہ نہیں ہے۔ اس واقعہ میں یہی سبق دیا گیا ہے۔ کہا جاتا ہے کہ سیدنا موسیٰ کو اللہ تعالیٰ نے دیکھا۔ یہ مشاہدہ براہ راست تھا یا خواب میں۔ کہ وہ سفر پر ہیں، ان کا کوئی خادم یا ان کا کوئی شاگرد ان کے ساتھ ہے اور وہ کہہ رہے ہیں کہ میں اس وقت تک چلتا رہوں گا جب تک کہ وہ مجمع البحرین یعنی دو دریاؤں کے ملنے کی جگہ نہ پہنچ جائیں۔ وہ دو دریاؤں کے سنگم تک نہیں پہنچ پاتے، وہ اس عزم کا اظہار کرتے ہیں کہ چاہے مجھے برسوں چلنا پڑے، میں چلتا رہوں گا، جو کچھ مجھے بتایا گیا ہے اس کے حصول کے لیے میں اس سفر کو نہیں روکوں گا۔ وہ بڑے عزم کے ساتھ اس وقت تک اپنے عزم کا اظہار کرتے ہیں جب تک کہ وہ جگہ ختم نہ ہو جائے۔ کافی دیر وہاں رہنے کے بعد معلوم ہوا کہ رسی کے ساتھ کچھ لے جایا جا رہا ہے، وہ بھول گئے اور آگے کا سفر کرنے لگے۔ غالباً یہ سوچ کر کہ میں ایسی عجیب بات کا ذکر کروں گا تو سیدنا موسیٰ کیا مانیں گے اور یہ میری طرف سے غلطی تھی، میں نے انہیں یہ نہیں بتایا۔ کہنے لگا کہ ہم اس سفر سے بہت تھک گئے ہیں اس لیے وہ ناشتہ لے آؤ اور ہمیں کھانے دو۔ اور یہ شیطان ہی تھا جس نے مجھے اس کو یاد کرنا بھلا دیا اور اس نے عجیب طریقے سے دریا میں اپنا راستہ پایا، یعنی میرے لیے یقین کرنا مشکل تھا کہ تلی ہوئی مچھلی بندھے ہوئے تھی، اچانک وہ باہر نکل آئی اور اس نے نکل کر دریا میں سرنگ بنا دی، اس لیے میں ایسا نہ کر سکا۔ مجھے اپنے آپ پر افسوس ہوا کہ مجھ سے غلطی ہو گئی۔ موسیٰ نے کہا کہ ہمارا ارادہ یہی ہے، انہیں بتایا گیا کہ جب وہ دو دریاؤں کے سنگم پر پہنچیں گے تو مچھلی ایک سرنگ بنا کر دریا میں کود جائے گی، یہ اشارہ تھا۔ تو جیسے ہی شاگرد نے اسے یہ خبر سنائی تو اس نے کہا کہ یہ ہماری منزل تھی، اس کا مطلب ہے کہ ہم اپنی منزل پر پہنچ چکے ہیں، ہم جہاں جانا چاہتے تھے وہاں پہنچ گئے، وہ اپنے قدموں کی طرف دیکھتے ہوئے، یعنی فوراً بولا۔ ہم وہیں سے آئے ہیں، مجھے اس جگہ لے چلیں جہاں مچھلی کے ساتھ یہ معاملہ ہوا، ہم وہاں جائیں گے۔ وہ سنگم جسے عربی زبان میں دو دریاؤں کے ملنے کی جگہ کہا جاتا ہے مجمع البحرین میں کہتے ہیں کہ جب تم وہاں پہنچو تو سانس لینے کے لیے کسی چٹان کے پاس رک جاؤ، جیسا کہ مسافر عموماً کچھ دیر آرام کرتے ہیں، کہیں رک جاتے ہیں، پھر اپنا سفر جاری رکھتے ہیں، یعنی کچھ دیر ٹھہرنے کے بعد۔ جب اس نے دوبارہ سفر شروع کیا تو شاگرد مچھلی کو اپنے ساتھ لے جانا بھول گیا، تھوڑا آگے چلنے کے بعد اسے یاد آیا تو وہ اسے لینے کے لیے واپس لوٹ آیا، لیکن جب وہ وہاں پہنچا تو دیکھا کہ ناشتے کے لیے تلی ہوئی مچھلی مر کر پانی میں جا رہی تھی۔ یہ واقعہ اس قدر عجیب تھا کہ شاید اس کے شاگرد نے اس خوف سے حضرت موسیٰ کو نہیں بتایا کہ کہیں وہ اس کی بات پر یقین نہ کریں اور ناراض بھی ہو جائیں۔ یہ بھی ہو سکتا ہے، یعنی ایسا مشاہدہ جو کیا گیا تھا۔ موسیٰ علیہ السلام نے فوراً فیصلہ کر لیا کہ ہم واپس جائیں گے، چنانچہ وہ اپنے قدموں کو دیکھتے ہوئے واپس لوٹے، یعنی جس راستے پر وہ آئے تھے، جب وہ اس چٹان پر پہنچے تو اب کیا دیکھیں گے؟ انہیں وہاں ہمارا ایک نوکر ملا۔ قرآن کریم کہتا ہے کہ ہمارے بندوں میں اس بندے کا معاملہ یہ تھا کہ وہ سب سے زیادہ مہربان علماء تھے جن پر ہم نے خاص طور پر رحم کیا۔ میں نے وضاحت کی ہے کہ یہ شخص کون تھا، اگرچہ روایات میں اس کا نام آیا ہے، لیکن اردو میں اس کا تلفظ خضر کے نام سے جانا جاتا ہے۔ نام موجود ہے اور یہ عربی زبان میں صحیح تلفظ ہے۔ اس کے کچھ کام پہلے بیان کیے جا چکے ہیں۔ اسے بتایا گیا کہ وہ یہاں کسی سے ملے گا۔ یہی ان کی منزل ہے، چنانچہ وہ طالب علم کی بات سن کر پرجوش ہو گیا اور کہا کہ میں اسے ڈھونڈ رہا ہوں، اور وہ شخص مل گیا۔ ان سے معلوم ہوا کہ وہ غالباً کچھ فرشتے تھے یعنی اللہ تعالیٰ نے اپنے ایک فرشتے سے ملاقات کی جو انسانی شکل میں موسیٰ علیہ السلام سے ملے اور اللہ تعالیٰ نے انہیں اسی قسم کا کام سونپا۔ اس دنیا کی مذکورہ بالا ترتیب کے بارے میں جو اللہ تعالیٰ نے قائم کیا ہے، قرآن کریم نے ہمیں بتایا ہے کہ اس ترتیب میں فرشتوں کو مختلف ذمہ داریاں دی گئی ہیں اور وہ اللہ تعالیٰ کے لیے اپنی ذمہ داریاں ادا کرتے ہیں۔ جن باباؤں نے کام کیا ہے، یہ مادی دنیا ہمارے سامنے ہے، جس میں انسان کا سانچہ تیار ہوا ہے، وہ اس دنیا کو اپنے حواس سے سمجھ سکتا ہے، اس کے حواس بیرونی ہوں یا اندرونی، اس کا علم یہیں سے شروع ہوتا ہے۔ لیکن اس سے آگے بھی بہت سی حقیقتیں ہیں۔ اللہ تعالیٰ نے بتایا ہے کہ آپ کے علاوہ دو اور مخلوقات بھی ہیں جن کے پاس فرشتوں اور جنوں جیسی مرضی اور اختیار ہے اور ان میں سے بالخصوص فرشتوں کے بارے میں قرآن کہتا ہے: مجید نے نہ صرف تمام تفصیلات بیان کی ہیں بلکہ انہیں ہمارے ایمان میں شامل کیا ہے، یعنی ان پر ایمان لانا ضروری ہے، ایمان لانا ضروری ہے۔ اگر وہ ان کو انجام دے رہے ہیں تو اللہ نے کچھ دیر کے لیے پردہ اٹھایا ہے اور بتایا ہے کہ وہ کیسے کام کر رہے ہیں۔ اللہ تعالیٰ نے اپنے ایک فرشتے کو سیدنا موسیٰ علیہ السلام کی تربیت کے لیے بھیجا۔ جب وہ ان سے ملے تو موسیٰ علیہ السلام نے ان سے درخواست کی کہ آپ مجھے اس شرط پر اپنے پاس رہنے کی اجازت دیں کہ جو علم آپ کو دیا گیا ہے اس میں سے کچھ آپ مجھے سکھائیں گے۔ اس کا استعمال آپ سے اللہ تعالیٰ کی نسبت میں ہوا ہے۔ ظاہر ہے کہ وہ چلا گیا اس کائنات کے اسرار کا علم فرشتوں کو بھی دیا جاتا ہے جس طرح انبیاء کو بھی کچھ علم دیا جاتا ہے اسی طرح ان کو بھی دیا جاتا ہے اور ان کی ذمہ داریوں کی نوعیت بھی وہی ہے تو موسیٰ نے اس سے درخواست کی۔ کہ آپ مجھے کچھ سکھائیں، میں بھی اس علم کا کچھ حصہ حاصل کرنا چاہتا ہوں، میں بھی اسے سمجھنا چاہتا ہوں، چچا تسیبہ نے کہا، انہوں نے جواب دیا، یہ خواہش اچھی ہے، لیکن آپ مجھ سے صبر نہیں کر پائیں گے، آپ صبر کیوں نہیں کر سکتے؟ کیونکہ ہمارے ارد گرد اس دنیا کے قوانین بالکل مختلف ہیں۔ یہ دنیا آزمائش کے قانون پر قائم ہے۔ اس میں ہمیں اخلاقی شعور دیا گیا ہے۔ اسے برتر رکھیں۔ وہ اخلاقی شعور قدم قدم پر سوالات اٹھاتا ہے۔ انسان کو جو خاص امتیازات حاصل ہیں وہ تین ہیں۔ وہ ایک عقلی وجود ہے۔ اسے ایک غیر معمولی شعور دیا جاتا ہے۔ اس کے ذریعہ وہ غیر معمولی ایجادات کرنے کے قابل ہے اس کے ذریعہ وہ اپنے حواس کی صلاحیتوں کو بڑھانے کے قابل ہے۔ وہ حکم دیتا ہے کہ چیزیں صحیح ہیں، غلط ہیں، اخلاقی طور پر غلط ہیں، اور اسے جمالیات کا ایک حصہ دیا جاتا ہے۔ اگر وہ ناپسندیدگی کا اظہار کرے تو انسان ہر وقت ان تینوں صلاحیتوں کے ساتھ ہوتا ہے، وہ ان خصوصیات کو ترک نہیں کر سکتا۔ کہا جاتا ہے کہ جس میں فرشتے کام کر رہے ہیں، جس میں دنیا کی حکومت ہو رہی ہے، اس کی نوعیت بالکل مختلف ہے، اس کے قوانین مختلف ہیں، اس کے ضابطے مختلف ہیں، نہ یہ عقل اسے اس طرح حکم دے سکتی ہے اور نہ یہ ہمارے اخلاقی اصول۔ وہ تابع رہ سکتا ہے اور ہم اپنی جمالیات کی بنیاد پر اس کے بارے میں کوئی فیصلہ نہیں کر سکتے۔ وہ ہمارے وجود سے باہر کی دنیا ہے۔ اس کے قوانین مختلف ہیں، اس لیے اس کے سامنے رکھ کر آپ نے سیدنا موسیٰ علیہ السلام کو جواب دیا کہ میں آپ پر صبر نہیں کر سکتا اور اس کی وجہ وقوف تسبر مہتہ ہے اور جو آپ کے علم سے باہر ہے، آپ اس پر بھی صبر کیسے کر سکتے ہیں، گویا قرآن کریم نے مجھے بتایا ہے کہ مجھے معاف کر دیں۔ انسان کے پاس علم کا ایک شعبہ ہے۔ پہلی چیز جس کا تعین کیا جانا چاہئے وہ یہ ہے۔ فلسفہ کی ڈھائی سے تین ہزار سال کی تاریخ پر نظر ڈالیں، سائنس کی تاریخ دیکھیں تو سب سے بڑی غلطی یہ ہے کہ لوگوں کو اپنے علمی شعبے کا علم نہیں۔ یہ اس بات کا تعین نہیں کرتا کہ انسان کے علم کا دائرہ کیا ہے، اس کو سب سے بڑھ کر جو چیز عطا کی گئی ہے، جس کے ذریعے اس کا علم سے تعلق پیدا ہوتا ہے، وہ اس کے حواس ہیں، اس کے حواس خارجی بھی ہیں، اس کے حواس اندرونی بھی ہیں۔ اس کو جو حواس عطا کیے گئے ہیں ان کا تعلق ظاہری دنیا سے ہے، وہ کچھ دیکھتے ہیں، کچھ سنتے ہیں، اسی طرح وہ اپنے نفس کے اندر دیکھتے ہیں اور اس کے نفس کے اندر کے حالات سے واقف ہیں۔ میں محسوس کرتا ہوں کہ میں اپنے غم سے واقف ہوں میں اپنے جذبات کو دیکھ سکتا ہوں میں انہیں کسی کو نہیں دکھا سکتا اسی طرح میرے حواس باہر کی دنیا میں چیزوں کو دیکھتے ہیں تو میرے اندر ایک اضطراری علم ہے یعنی میرے اندر حقیقی معنوں میں علم۔ اس کا تعلق بیرونی دنیا سے ہے، اس لیے وہ چیزوں کو نام دیتا ہے، ان کے درمیان تفریق پیدا کرتا ہے، ان کو الگ کرتا ہے اور ان کی درجہ بندی کرتا ہے، اور جب وہ درجہ بندی کرتا ہے تو ان کے ضروری عقلی نتائج بھی نکالتا ہے۔ وہ دیکھتا ہے کہ انسان کا علم اپنا سفر جاری رکھے ہوئے ہے، اس لیے انسان کے علم کا دائرہ یہ ہے کہ وہ اس سے پیچھے نہیں رہ سکتا، وہ مطمئن نہیں ہوسکتا، نہ اس سے آگے بڑھ سکتا ہے، اس کے پیچھے کے معاملات اس کے علم سے باہر ہیں۔ اس سے آگے کے معاملات اس کے علم سے باہر ہیں، اس لیے جو اس کے علم میں نہیں ہے، جس کا احاطہ نہیں کر سکتا، وہ کہتے ہیں کہ صبر کیسے ہو گا، سوال کرے گا، یعنی اسے خاموش نہیں رکھا جا سکتا جب کہ اس کے پاس علم کے دائرے سے باہر کوئی چیز آئے گی تو وہ اسے آسانی سے قبول نہیں کرے گا، وہ تو دوسری دنیا کا آدمی ہے، اس لیے اللہ کے اس فرشتے نے اسے خبر دی کہ اگر تم انسان کے علم میں اتنا صبر نہ کر سکو گے، تو تم اس کے علم میں نہیں رہ سکتے۔ یہ اللہ کے رسولوں کے ساتھ بھی ہوتا ہے کہ وہ اپنے لیے بھی یہی مسئلہ پیدا کرتا ہے کہ یہ آپ کے لیے مشکل ہے۔ اس سے آگے آپ کے علم کا دائرہ۔ یہی ہو گا، تم صبر نہ کرو گے، سوال اٹھاؤ گے، ساتھ چلنا مشکل ہو جائے گا، انشاء اللہ۔ موسیٰ نے کہا انشاء اللہ آپ مجھے صابر پائیں گے۔ مجھے اجازت دیجئے اور میں کسی معاملے میں آپ کی نافرمانی نہیں کروں گا، یعنی آپ جو کہیں گے میں مانوں گا، لیکن ذرا حجاب اٹھا کر مجھے اپنے علم سے روشناس کرائیں۔ میں یہ علم سیکھنا چاہتا ہوں، میں جاننا چاہتا ہوں، میں نے عرض کیا ہے۔ قرآن نے جس تناظر میں یہ واقعہ بیان کیا ہے، اس میں یہ سکھایا جا رہا ہے کہ دنیا میں جو کچھ پیش کیا جاتا ہے اس کے پیچھے کیا حکمت کارفرما ہو سکتی ہے، کیونکہ دنیا کے معاملات میں خواہ وہ دین کی طرف دعوت کا معاملہ ہو، ہمارے سیاسی معاملات ہوں یا معاشی معاملات، صبر لازم ہے، اور صبر کے لیے اللہ تعالیٰ کی رضا پر لازم ہے۔ وہ ہے، یہ ان حواس کی گرفت میں آجاتا ہے اور یہ آپ کا علم ہے، لیکن اس کے پیچھے ایک دنیا ہے، یہ اپنا کام کر رہی ہے، تو انہوں نے وعدہ کیا۔ ایک بات قابل غور ہے کہ میرے ساتھ رہو، اس نے کہا، پھر اگر تم میرے ساتھ رہنا چاہتے ہو تو مجھ سے اس وقت تک کچھ مت پوچھو جب تک میں خود تم سے اس کا ذکر نہ کروں۔ دیکھتے رہیں کہ کیا ہوتا ہے اور اپنے سوالات پوچھتے رہیں۔ میں تمہیں ایک موقع دوں گا۔ میں آپ سے پوچھوں گا کہ آپ کیا جاننا چاہتے ہیں۔ تم یہ وعدے کرو گے، منتیں کی گئیں، آخرکار وہ دونوں چلے گئے، یعنی اللہ کا وہ بندہ اور موسیٰ علیہ السلام، دونوں چلے گئے، دن کے آخر تک، وہ دونوں چلے یہاں تک کہ ایک جگہ ایک کشتی میں سوار ہو گئے، یعنی وہ چلے گئے۔ ایک دریا اوپر آیا اور اسے عبور کرنے کے لیے کشتیاں تھیں۔ انہوں نے ایک کشتی کرایہ پر لی اور اس میں سوار ہو گئے۔ جیسے ہی وہ بیٹھ گئے، اس شخص نے جو ان کے ساتھ اللہ کا بندہ تھا، کشتی میں سوراخ کر دیا۔ انہوں نے اسے توڑ دیا، موسیٰ صبر نہ کر سکے، یعنی ظاہر ہے کشتی میں بیٹھے ہیں۔ کشتی میں سوراخ کرنا بہت خطرناک چیز ہے۔ کھڑکتا موسیٰ نے کہا کہ تم نے اس میں سوراخ کیا تاکہ تمام کشتی والوں کو غرق کردے، تم نے کیا کیا ؟‘‘ اس نے صرف سوال کیا لیکن احتجاج کیا اور جب آپ موسیٰ کا کردار قرآن میں اور بالخصوص بائبل میں دیکھتے ہیں تو یہ بات بالکل واضح ہوجاتی ہے کہ یہ ان کے لیے کوئی آسان کام نہیں تھا اور لگتا ہے کہ اللہ تعالیٰ نے انہیں قبر کی تعلیم کے لیے ان کے ساتھ بھیجا تھا۔ اس نے بیٹھ کر کیا کیا؟ اس نے بیٹھتے ہی کشتی میں سوراخ کیا۔ اب اس نے سوچا کہ لوگ اس طرح کے مسائل پیش کریں گے تو مجھے کیا ضرورت ہے؟ میں ان سے سوال کروں گا۔ پیچھے جو ہو رہا ہے ہم آپ کو دیں گے، اسی طرح سمجھیں۔ ایسی کوئی وجوہات نہیں ہیں جو بنیامین کو روک سکیں۔ جس طرح موسیٰ (علیہ السلام) کو یہاں ایک خاص صورت حال کا سامنا ہے، وہی صورت حال یوسف (علیہ السلام) کو بھی درپیش ہے۔ کوئی صورت حال نہیں ہے۔ اور اس میں کوئی غیر اخلاقی بات نہیں تھی، سب کچھ قاعدے کے مطابق ہوا، لیکن اس کے اسباب تھے جن کے نتیجے میں ان کا روکنا ممکن ہوا، چنانچہ وہاں بھی یہی سبق دیا گیا ہے کہ اللہ تعالیٰ کبھی کبھی مداخلت کرتا ہے، اس لیے ہم اسے اس طرح کہتے ہیں۔ پھر معاہدہ ہوا، پھر وہی ہوا۔ جو شخص کشتی کا مالک ہے وہ سمجھے گا کہ یہ کشتی ہے، اس میں تختیاں ہیں، یہ ٹوٹتی ہے، یہ ٹوٹتی ہے، یعنی اسے یہ معاملہ نظر نہیں آتا، یہ سب اس کے سامنے نہیں ہو رہا، یہ اسی طرح ہو رہا ہے جس طرح دنیا ہے۔ سیدنا موسیٰ علیہ السلام نے سخت احتجاج کیا اور کہا کہ آپ نے اس میں سوراخ کر دیا تاکہ تمام کشتی والے ڈوب جائیں۔ نہیں، اس نے سب کچھ کیا۔ اب اس نے جواب دیا، اس نے کہا، میں نے یہ نہیں کہا تھا کہ تم میرے ساتھ صبر نہیں کرو گے، یہ وہ مشکل ہے، جس کی وجہ سے میں نے تم سے کہا تھا کہ تم صبر نہیں کرو گے۔ اور یہ ہو گا۔ اب سیدنا موسیٰ کو احساس ہوا کہ یہ میری غلطی تھی۔ موسیٰ علیہ السلام نے کہا کہ جو کچھ میں بھول گیا ہوں اس پر مجھ سے مواخذہ نہ کرو اور میرے معاملے میں مجھ پر سختی نہ کرو ۔ اعتراض کیا تھا، اسی طرح عاجزی سے معافی مانگ لی، مجھ سے غلطی ہوئی، میں نے اس پر توجہ نہیں دی، جو بھول گیا، وہ دونوں طرف سے ہوتا ہے، قرآن پاک میں اس کے استعمال کی مثالیں موجود ہیں اور ہم اپنی زبان میں بھی اسی طرح استعمال کرتے ہیں۔ اس کا مطلب یہ ہے کہ کوئی چیز یاداشت سے نکل گئی، اور یہ بھی کہا جاتا ہے کہ وہ چیز حافظے میں تھی، لیکن اس قدر نیچے چلی گئی تھی کہ جب کوئی صورت پیدا ہوئی تو اس کا خیال تک نہ رہا، اس کے لیے وہی فعل استعمال ہوتا ہے۔ کہا جاتا ہے کہ جو میں بھول گیا ہوں اس پر مجھے مت پکڑو، ولا ترحق من امری اسرا اور میرے معاملے میں مجھ پر زیادہ سختی نہ کرو۔ جو بتایا گیا ہے، بتایا گیا ہے کہ تیرے لیے یہ حال ہے کہ ایک کشتی تیرے حواس کی گرفت میں آرہی ہے، وہ ایک دریا ہے، آپ نے اسے عبور کرنا ہے، کشتی کو اپنا بالغ مل گیا، آپ بیٹھ گئے، اب یہ آپ کا ہے۔ خواہش یہ ہونی چاہیے کہ کشتی بحفاظت پار ہو جائے۔ اگر بورڈ اچانک ٹوٹ جائے، چھید جائے تو یہ حادثہ ہے۔ ظاہر ہے کہ آدمی یہی کرے گا، کیا گردن اٹکانے سے نہیں ؟ کیا کر رہے ہو؟ یہ ہماری دنیا ہے، جس میں وہ چیزیں ہو رہی ہیں جو ہمارے حواس کی گرفت میں آتی ہیں یا ہمارے اخلاقی حادثے کی زد میں آتی ہیں۔ حکم دیا گیا ہے اور اس کے پیچھے اللہ تعالیٰ کی حکمتیں ہیں۔ اب اللہ تعالی ان کو واضح کر دے گا۔ یہ سلسلہ ابھی تک جاری ہے۔ ہمارا وقت ختم ہو گیا ہے۔ الحمدللہ الحمدللہ رب العالمین وصلی اللہ علیہ وسلم علی محمد الامین آواز باللہ من الشیطان الارجم بسم اللہ الرحمن الرحیم خواتین و حضرات سورہ کہف کی آیت نمبر 74 سے یہ سبق جنم لے رہا ہے کہ سیدنا معاویؓ کا واقعہ زیر بحث ہے۔ طالہ کیا ہم نے اس واقعے کا کچھ حصہ پڑھا، اس کا تعلق ایک غریب ملاح کی کشتی سے تھا۔ آپ نے ایسا کام کیا ہے کہ اس کے نتیجے میں کشتی کے تمام مسافر پریشان ہو جائیں گے۔ سیدنا موسیٰ علیہ السلام نے فرمایا کہ تم یہ بتانے اور بتانے کے لیے اس سفر پر جارہے ہو کہ اللہ تعالیٰ کی حکمت کیا کام کر رہی ہے، لہٰذا اس پر سوال نہ کرو، اس نے معذرت کی اور دونوں کو ساتھ چلنے کی اجازت دی، اب اس نے کہا کہ فان تلکا تو دونوں آگے بڑھے، یعنی سفر شروع ہوا، کیا وہ یہ ہوتا ہوا دیکھ رہے ہیں یا یہ ان کا براہ راست مشاہدہ ہے جو لڑکا اس کے پاس سے گزرتا ہوا دیکھ رہا تھا۔ اس نے اسے ہلاک کیا ، یہ معاملہ مزید ہلاک ہوگیا ، کسی کی جان کو جان سے مارا جانا چاہئے یہ کہا ہے کہ تم نے ایک آدمی کی کشتی کو چھیدا اب تم نے ایک اور کارنامہ انجام دیا ہے۔ آپ نے ایک معصوم لڑکے کو راستے میں قتل کر دیا ہے۔ اگر ہم اس کے بارے میں سوچیں تو یہی ہو رہا ہے، یعنی جب چیزیں ہمارے سامنے آتی ہیں تو دسیوں سوالات پیدا کر دیتی ہیں۔ اگر یہ چیزیں ہمارے سامنے لائی جائیں تو ہم اسی طرح پوچھیں گے کہ یہ جانور کس چیز سے بنا ہے؟ یہ کر لیں، بچوں کو جتنی تکلیف ہو رہی ہے ایسے کیسز ہوتے ہیں جن میں کوئی چیز بری لگتی ہے، اسے دیکھنے کے بعد انسان کے ذہن میں یہ وہ سوالات اٹھنے چاہئیں۔ اللہ یہ واضح کرتا ہے کہ وہ کہاں سے کام کر رہا ہے، وہ آپ کو بتاتا ہے کہ جس نے اس کائنات کی ترتیب کو پیدا کیا ہے اس کے معاملات اور آپ کے علم کا آپس میں کیا تعلق ہے۔ ایک سوال پیدا ہوتا ہے اور یہ جواب ہے۔ تعلیم ہی نہیں سارے راز کھلے ہیں۔ وہ نہیں کر رہا ہے۔ رشتے طے ہوتے ہیں اور آپ انہیں سمجھ نہیں سکتے لیکن اگر آپ کو اپنی حدود کا علم ہے تو آپ کم از کم اندازہ لگا سکتے ہیں کہ آپ کو رب کے بارے میں نیند نہیں آنی چاہیے۔ یہ ہے تعلیم اور نتائج کے لحاظ سے صبر۔ صبر اور حکمت سے کام لینا چاہیے۔ یہ اس دنیا کی سب سے بڑی نعمت ہے۔ اگر کوئی نعمت ہے تو دن رات اس کے لیے رب کا شکر ادا کرنا چاہیے۔ اس نے کہا کہ تم نے ایک بے گناہ کی جان لے لی حالانکہ اس نے کسی کا خون نہیں بہایا تھا، تم نے بہت برا کام کیا ہے، تمہیں ایسا ہی سوچنا چاہیے تھا، یہی سوال پس منظر میں پوچھنا چاہیے تھا، انہوں نے جس پر اعتراض کیا، وہی اعتراض ہر ذہین آدمی اٹھائے گا۔ جس دنیا میں ہم رہتے ہیں، ہمارا حادثہ ان چیزوں کا حکم دیتا ہے جو اخلاقی ہیں۔ وہ علم کے ساتھ چیزوں کے بارے میں جاننا چاہتا ہے، وہ حکم دینا چاہتا ہے، وہ فیصلہ دینا چاہتا ہے، اگر وہ اپنے علم کی حدود میں چیزوں کے بارے میں سوچتا ہے تو وہ بھی پوری دنیا ہے۔ یہ وہی دنیا ہے جس میں سائنسی ذہن نے بہت سی ایجادات کی ہیں۔ ایسی سہولتیں پیدا کر دی ہیں کہ بجائے خود عجائبات کا کارخانہ بن گئے ہیں اور جس طرح انسان کی بہتری کے آلات ہیں اسی طرح غور و فکر کے بھی بڑے اوزار ہیں۔ اپنے علم اور اپنی ذہانت اور اپنی صلاحیتوں کو استعمال کرتے ہوئے، سمجھنے کی اہم بات یہ ہے کہ جب بھی ہم کسی چیز کے بارے میں سوچتے ہیں، جب ہم کسی چیز کے بارے میں رائے قائم کرتے ہیں۔ اگر آپ کسی معاملے میں فیصلہ دیں تو پہلی بحث علم کی بحث ہے، باقی اس کے بعد۔ میرا علم کہاں سے شروع ہوتا ہے، میرا علم کہاں ختم ہوتا ہے؟ جس پہلو سے آپ اپنے وجود کو تحلیل کرتے ہیں وہ یہ ہے کہ ہمارا علم ہماری مابعد الطبیعاتی معلومات سے شروع ہوتا ہے جو ہمارے اندر ہے، ہمارے حواس بھی ہمارے باطن سے رابطہ پیدا کرتے ہیں اور ان کی کچھ حدود ہوتی ہیں۔ حواس ہمیں بیرونی دنیا یا بیرونی دنیا سے جوڑتے ہیں۔ ان کی بھی کچھ حدود ہیں۔ کچھ چیزیں معلوم ہوئی ہیں اور اگر ہم ان کے اندر جھانکیں تو وہ حواس کی صلاحیت میں اضافے کا نتیجہ ہیں۔ یہ عقلی سوالات بھی پیدا کرتا ہے اور کچھ عقلی نتائج ہمارے سامنے رکھتا ہے، ان میں سے کچھ فرض کے درجے میں ہیں، وہ ناگزیر ہیں، ان سے بچنے کا کوئی راستہ نہیں ہے، اور کچھ نتائج کا امکان ہے۔ یہ بھی ممکن ہے، یہ بھی ممکن ہے، یہ بھی ممکن ہے کہ ہم انہیں جیسے ہیں پیش کریں اور پھر ان کی تحقیق کریں یہاں تک کہ کوئی چیز ہمارے تجربے اور مشاہدے میں اس طرح آجائے کہ ہمیں اس کے بارے میں کچھ معلوم نہ ہو۔ نتیجہ اخذ کرنے کے لیے، یہ ہمارا علم دراصل کام کرنے کا طریقہ ہے، اور یہ ایک ایسی دنیا تخلیق کرتا ہے جس کے نتیجے میں ہم آگے بڑھتے ہیں۔ پھر وہ اپنے تخیلات کو استعمال کرتے ہیں اور انہیں امکانات کے طور پر پیش کرنے کے بجائے انہیں حقائق کے طور پر پیش کرنا شروع کر دیتے ہیں۔ دوسری بات یہ ہے کہ وہ اس کے پیچھے جا کر اپنے ہی حواس کی دنیا کو چیلنج کرنے لگتے ہیں۔ جو کچھ ہم سن رہے ہیں وہ حقیقی ہے، حقیقی ہے یا غیر حقیقی، ہمارا علم وہیں سے شروع ہوتا ہے، ہمارے پاس اس کے پیچھے جانے کا کوئی ذریعہ نہیں ہوتا، اس لیے باری وہاں پہنچ جاتی ہے، اور پھر ہمارا اپنا وجود بھی تحقیق کا ہدف ہوتا ہے۔ ہو جاتا ہے اور بندہ یہاں کھڑا کہتا ہے کہ میرا خیال ہے اس لیے میں ہوں، اس سے آگے جانا ممکن نہیں، اس لیے اللہ تعالیٰ نے ہمیں جو تعلیم دی ہے وہ یہ ہے کہ ہم اپنے علم پر اپنے حواس پر بھروسہ کرنا سیکھیں۔ دنیا اللہ رب العزت نے بنائی ہے، اگر ہم اس علم کے ذرائع پر بھروسہ کریں جو اس نے ہمیں عطا کیے ہیں تو اس سے کچھ نہ کچھ بڑھے گا۔ یہ اعتماد اسی سطح کا ہونا چاہیے جس حد تک ہم ان حواس اور اپنے اندر کے اضطراری علم سے ہم آہنگ ہیں۔ معلومات سے رشتہ پیدا ہوتا ہے اور علم کا عمل شروع ہوتا ہے۔ اعتراض کر رہے ہیں اور ان پر اعتراض ہونا چاہیے، پھر یہاں بھی انہوں نے بالکل بجا طور پر اعتراض کیا ہے کہ جب اخلاقی طور پر یہ طے ہو جائے کہ انسان کی جان کی حرمت ہے تو کسی انسانی جان کو بلا وجہ نہیں لیا جا سکتا۔ اگر اللہ تعالیٰ نے جان لینے کا حق اپنی کتابوں میں دیا ہے یا اپنی شریعت میں جان لینے کا حق دیا ہے تو اس کی حدیں بالکل ٹھیک بیان فرما دی ہیں۔ انہوں نے بتایا کہ کسی کی جان اس وقت تک نہیں لی جاسکتی جب تک کہ وہ کسی اور کی جان نہ لے، یا اگر وہ لوگوں کی جان و مال لے کر مصیبت پیدا کرے، یہ وہ دو صورتیں ہیں جن میں جب کوئی سڑک پر چلتے لڑکے کی جان لے لے تو کوئی وجہ نہیں تھی، نہ اس لڑکے نے کسی کو مارا تھا، نہ اس نے کوئی ہنگامہ کیا تھا، نہ ہی لوگوں کی جان کو خطرہ تھا۔ ہوا تو پھر جان کیوں لی؟ ظاہر ہے، اس سوال کو واپس لے لیں۔ اللہ نے ہمیں کاغذ کا ایک ٹکڑا دیا ہے۔ وہ ہمارے ساتھ کھیل رہا تھا۔ ہمارے درمیان بہت پیار کا رشتہ تھا۔ اگر کوئی قتل کرنے والا ہے تو وہ اعتراض کر رہا ہے، لیکن اس قتل کے بارے میں سوچیں تو یہ روزانہ ہو رہا ہے، پریشانیاں ہیں، ہم ان کے سبب اور اثر کے درمیان تعلق قائم نہیں کر پا رہے، مصیبتیں آسمان سے برس رہی ہیں۔ وہ اپنی وجہ کا تعین نہیں کر سکتے، یعنی اخلاقی سوالات خارجی حالات کی بنیاد پر پیدا ہوتے ہیں، اس کی تعریف برائی کا مسئلہ ہے، یعنی برائی کے اسباب معلوم نہیں ہوتے۔ کہا جا رہا ہے کہ اس کے پیچھے کسی عالم اور عقلمند کی تدبیر ہے، اس سکیم کو پوری طرح سمجھنا کسی کے بس میں نہیں، البتہ کچھ حجاب اٹھا کر یہ کہا جا سکتا ہے کہ کن چیزوں کا اندازہ ہو سکتا ہے، یعنی گویا اس نے سوچا کہ نظر کا ایک دانہ ہے جو ذائقے کے لیے دیا گیا ہے اور پھر کہا کہ اب یہ بات کیوں سمجھے یا اس کے علم پر آدمی کا قیاس کیوں ہے۔ اگر ایسا ہے تو وہ عقلی استدلال کے ذریعے اسے کلی میں بدل دیتا ہے۔ یہ سفر بتانے اور سمجھانے کے لیے کیا جا رہا ہے۔ اس نے کہا میں نے تمہیں نہیں کہا تھا کہ تم مجھ سے صبر نہیں کرو گے میرا مطلب ہے یہ دیکھو وہ بار بار جملہ دہرا رہے ہیں مجھ سے صبر مت کرو۔ آپ سیکھیں گے، کیونکہ جس دنیا میں میں کام کر رہا ہوں، وہ آپ کے علم سے نہیں پکڑ سکتا، اس میں کیا ہو رہا ہے، کیسے ہو رہا ہے، کن اصولوں کے مطابق ہو رہا ہے، یہ آپ کی سمجھ سے باہر ہے، اس لیے آپ صبر نہیں کر رہے۔ آپ اسے کرنے کے قابل ہو جائیں گے. یہ صرف زجر کا جملہ نہیں ہے یعنی کوئی تنبیہ نہیں ہے۔ وہ ایک سچی کہانی کیا سنا رہے ہیں کہ یہ کوئی آسان کام نہیں ہے۔ اسی لیے میں نے تم سے کہا تھا کہ ایمان لاؤ جب اللہ نے تمہیں بتایا کہ میرے گزرنے کے بعد تمہیں کچھ علم ملے گا، اس لیے اس علم کے لیے صبر ضروری ہے۔ اس نے کہا میں نے تم سے یہ نہیں کہا تھا کہ تم میرے ساتھ صبر نہ کرو۔ آپ صبر کریں گے۔ بعد میں صاحب موسیٰ علیہ السلام کو تنبیہ کی گئی۔ اس نے سمجھا کہ یہ میرا معاملہ ہے اور میں صبر نہیں کر پا رہا، اس لیے اسے بھی درد ہے اور اگر وہ یہ کہہ رہے ہیں تو اسے بھی تکلیف ہے۔ اس نے کہا، ٹھیک ہے۔ اس کے بعد موسیٰ علیہ السلام نے فرمایا کہ اگر میں تم سے کچھ پوچھوں تو تم مجھے بھر دو، یعنی جتنا علم مجھے درکار ہے اتنا ہی میں نے حاصل کر لیا ہے۔ تو اس کے بعد یہ صحبت بھی ختم ہو جائے گی، اگر میں تم سے کچھ پوچھوں تو مجھے اپنے ساتھ نہ رکھنا۔ جتنا آپ نے مجھے بتانا تھا، میں نے وہی سیکھا جو مجھے سیکھنا تھا۔ اب اس سفر میں اگر میں مزید صبر نہ کروں تو ٹھیک ہے۔ آپ کا عذر بھی ٹھیک ہے اور مجھے بھی اب جانا چاہیے۔ میں نے کر دیا اور یہ بھی کہا کہ تم میری طرف سے عذر کی حد کو پہنچ گئے ہو، یعنی اب تم سے کوئی شکایت نہیں رہے گی، اب تم سے کوئی شکایت نہیں ہو گی، چیزیں واضح ہو گئی ہیں۔ یہ ہو گیا، چلو بات کرتے ہیں، دونوں آگے بڑھے، کہنے لگے اچھا ہے، اگر تم جانے کے لیے تیار ہو تو چلتے ہیں، لیکن واضح ہوا کہ یہ آخری موقع ہے، اس کے بعد دونوں الگ ہو جائیں گے۔ دونوں آگے بڑھے، اسی پر ایک اور واقعہ پیش آیا، دونوں آگے بڑھے، یہاں تک کہ جب ایک گاؤں پہنچے تو وہاں کے لوگوں سے کہا کہ انہیں کھانا کھلاؤ۔ یہ ایک عام روایت تھی جب لوگ سفر کر رہے تھے۔ کہا گیا کہ وہ یہیں اس ہوٹل میں ٹھہریں گے اور یہاں سے کھانا خریدیں گے۔ اس زمانے کی روایت یہ تھی کہ اگر مسافر ہوتے تو بستی کے لوگ ان کے لیے کھانے کا انتظام کرتے، یعنی ایک جگہ سے دوسری بستی جاتے۔ وہ تیسری بستی میں اسی طرح گئے جس طرح لوگ سفر کرتے تھے۔ انہوں نے اپنے ساتھ تھوڑا سا اور سفر کیا ہے، چلے گا، ورنہ یہ ہے کہ وہ بستی کی مسجد میں گئے جہاں وہ اترے اور سو گئے یا اس دوران کسی اور جگہ پہنچ گئے۔ وہ گاؤں کے باہر حلقے بنا کر بیٹھ جاتے تھے۔ لوگ دیکھتے کہ شام کا وقت ہے، کھانے کا وقت ہے اور کوئی مسافر ہے جو رات گزارنے جا رہا ہے۔ میں نے جا کر وہاں کے لوگوں سے درخواست کی کہ ہم مسافر ہیں اگر وہ ہمیں کھانا دے دیں لیکن انہوں نے ان کی میزبانی کرنے سے انکار کر دیا۔ وہ اتنے اچھے لوگ تھے ورنہ عام طور پر ایسا نہیں ہوتا۔ میں نے گزارش کی ہے کہ اگر واقعہ کے نقطۂ نظر سے دیکھیں تو بھی ایک تاثر پیدا ہوتا ہے اور اگر خواب کی نگاہ سے دیکھیں تو معاملات بس اسی طرح چل رہے ہیں۔ کہنے لگے لیکن انہوں نے میزبانی سے انکار کر دیا، اب یہ سلوک بستی میں ہوا۔ وہ بستی چھوڑ کر جا رہے تھے۔ پھر انہوں نے وہاں ایک دیوار دیکھی۔ گرہ مطلوب تھی، مطلب معلوم تھا کہ دیوار ابھی گری یا کل، یہی حال تھا۔ جو ان کے ساتھ تھے انہوں نے گرتی ہوئی دیوار کو دیکھا تو اسے دوبارہ بنانا شروع کر دیا۔ فقامہ کا مطلب ہے دوبارہ تعمیر کرنا یا اس کی تائید کرنا۔ دیا، وہ دیوار کو گرانا چاہتی تھی، لیکن اب انہوں نے اسے ٹھیک کر دیا۔ موسیٰ نے کہا کہ آپ کو گاؤں والوں سے اس پر بحث کرنی چاہیے تھی، یعنی یہاں صورتحال یہ ہے کہ کھانے کو کچھ نہیں۔ وہ جاری ہیں، انہوں نے آپ کو کھانا بھی نہیں دیا۔ اگر آپ دیوار کو ٹھیک کرنا چاہتے ہیں تو آپ گاؤں والوں سے کہہ دیں کہ آپ ہمیں مہمان بنا کر کھانا نہیں دے رہے ہیں تو ہم آپ کی دیوار کو انعام کے طور پر ٹھیک کر دیں گے۔ اگر آپ ہمیں کھانا دیتے تو یہ معقول بات ہوتی۔ ہمارے یہاں حالات خراب ہوتے جا رہے ہیں۔ موسیٰ نے دیوار بنائی اور کہا اگر تم چاہتے تو اس پر مزدوری رکھ سکتے تھے یعنی اتنا غریب گاؤں تمہاری میزبانی کے لیے تیار نہیں ہے تم نیکی کرنے کا سوچ رہے ہو نیکی کے مواقع موجود ہیں اس وقت ہم بھوکے ہیں۔ ان کے لیے کچھ ہونا چاہیے تھا۔ اگر وہ میزبانی کے لیے تیار نہ ہوتے تو مزدوری لیتے۔ آپ چاہتے تو اس کے لیے مشقت لے سکتے تھے۔ انہوں نے ہماری درخواست پر ہمیں کھانا کھلانے سے انکار کر دیا، لیکن آپ نے اس کے باوجود ان کی دیوار کو ٹھیک کر دیا۔ تم نے ان کمینوں کے لیے یہ محنت کیوں برداشت کی ؟ وہ اس کے مستحق نہیں تھے۔ آپ ان سے کچھ مزدوری لے سکتے تھے، جس سے ہم کھانا خرید لیتے۔ یعنی اگر وہ میزبانی کے لیے تیار نہ ہوتے اور مہمانوں کو مہمان ماننے کے لیے تیار نہ ہوتے تو ہم پیسے دے کر ان سے کھانا لے لیتے، لیکن یہ کام آپ نے کیا۔ اب جب اس نے یہ اعتراض اٹھایا تو فرمایا کہ یہ تمہارے اور میرے درمیان جدائی ہے اور وہ نیکی برابر نہیں ہے، یعنی جیسا کہ ہم نے ماضی میں دیکھا کہ برائی آجاتی ہے، کسی غریب کی کشتی ٹوٹ جاتی ہے، آدمی کا جوان لڑکا چلا جاتا ہے، یہ وہ چیزیں ہیں کہ ایک علم اس طرح زندگی میں سوال اٹھتے ہیں، اسی طرح کبھی کبھی نیکی، نیکی، ثمرات نہیں ہوتے۔ وہ اخلاقی حدود کی پرواہ نہیں کرتے، لیکن احسانات ہوتے رہتے ہیں، یعنی ان کی دیواریں پختہ ہوتی رہتی ہیں، تو یہ وہ تصویر ہے جو اس دنیا میں آئے روز سامنے آتی ہے، اس شکل میں سامنے آئی کہ انہوں نے اس کی دیوار کو ٹھیک کیا۔ اب اس نے کہا کہ یہ جدائی بینک اب ہمارے لیے الگ ہونے کا موقع ہے، اب ہمیں الگ ہونا چاہیے، لیکن صبر سے الگ ہونے سے پہلے اب میں تمہیں ان باتوں کی حقیقت بتاؤں گا جو تم برداشت نہیں کر سکتے۔ جواب نہیں دیا تھا، واقعات ہوتے رہے اور تینوں یکے بعد دیگرے وقوع پذیر ہوتے رہے اور میں نے عرض کیا کہ یہ تینوں نمائندہ واقعات ہیں ان سوالات کے لحاظ سے جو ہماری دنیاوی زندگی میں پیدا ہوتے ہیں، یعنی برائی پیدا ہوتی ہے اور وجہ سمجھ میں نہیں آتی۔ اچھائی آتی ہے اور ان تک پہنچتی ہے جو اس کے مستحق نہیں کیونکہ وہ وجہ نہیں سمجھتے۔ اس نے کوئی جواب نہیں دیا لیکن اب جب وہ الگ ہو رہے ہیں اور اسی لیے انہیں بھیجا تو اس نے کہا کہ اب میں ان باتوں کی حقیقت بتاؤں گا۔ ہوا یہ کہ حضرت موسیٰ کی شہادت تو ختم ہو گئی لیکن جس مقصد کے لیے یہ سفر کیا گیا وہ بھی حاصل ہو گیا۔ اللہ نے جس سکیم کے تحت یہ سفر کیا تھا وہ پورا ہوا۔ یہ بھی معلوم ہوا کہ اس دنیا میں ہم سے جو چیز مطلوب ہے وہ اللہ کی معرفت پر ایمان کا تقاضا ہے، اللہ کی حکمت پر ایمان کا تقاضا، اللہ کے فیصلوں پر بھروسہ کا تقاضا، اللہ تعالیٰ کے پیدا کردہ نتائج پر بھروسہ کا تقاضا ہے۔ اس کا تقاضا یہ ہے کہ وہ تمام تقاضے جو ہم سے بنائے گئے ہیں، جو ہمارے دین نے بنائے ہیں، جن پر اللہ تعالیٰ قائم ہے، ہر ایک کے وہ تمام تقاضے ہیں، جن کا اندازہ اس سطح پر ہو کہ وہ جس سطح پر اٹھتے ہیں، اس کا مطلب یہ ہے کہ ہر چیز پر سوالات ختم نہیں ہوتے۔ جواب نہیں ملے گا۔ اللہ تعالیٰ چند چیزیں ہمارے سامنے رکھ کر ہمیں امتحان میں ڈال رہا ہے۔ امتحان یہ ہے کہ ہم اپنی عقل کو استعمال کریں اور ان چند چیزوں پر قیاس کریں جو ہم نے باقی کے بارے میں سمجھی ہیں۔ اپنے رب پر بھروسہ رکھیں۔ یہ ایک امتحان ہے۔ پھر وہ ہمیں اس کشتی کے بارے میں کیا بتائیں؟ وہ ایک ایک کر کے لے گئے۔ اس کشتی کا مسئلہ یہ ہے کہ یہ کچھ غریب لوگوں کی تھی۔ وہ مزدوری کرتے تھے، یعنی کشتیاں اسی طرح چلاتے تھے اور اپنی محنت سے کچھ حاصل کرتے تھے، اس لیے میں نے اسے عیب دار بنانا چاہا، یعنی میں نے اس کے بارے میں یہ فیصلہ کیا۔ اسے عیب دار بنانے کا مطلب یہ ہے کہ کشتی عام استعمال کے لیے موزوں نہیں ہے۔ میں نے اس میں ایک بورڈ توڑ دیا۔ آخر میں کیا وہ مجھے بتاتے ہیں کہ میں نے اس میں اپنی رضامندی سے کچھ نہیں کیا، میں نے اللہ کے حکم سے کیا، اگلی وضاحت یہ ہے کہ انہوں نے اللہ کے حکم سے کیا، لیکن یہاں اس کے مقابلے میں یہ ان کی طرف ہے۔ قیاس کیا گیا ہے کہ حکم غالباً صرف بادشاہ کے غضب سے کشتی کو بچانے کے لیے تھا، اس لیے اس نے خود فیصلہ کیا کہ اس کے لیے کیا کیا جائے، اس لیے اسے بھی اپنی طرف منسوب کیا، یعنی فرشتوں کو ہدایت دینے والا اللہ۔ اور کہتے ہیں کہ فلاں فلاں کام ہونا چاہیے، پھر پورا پلان پہلے بتانے کی ضرورت نہیں۔ وہ ذہین مخلوق ہیں، وہ اپنے فیصلے خود کرتے ہیں۔ چنانچہ یہاں اوپر سے صرف حکم آیا کہ کشتی کو بادشاہ کے قبضے سے بچایا جائے، یہ کشتی ان غریبوں کے پاس رہے کیونکہ ان کی روزمرہ کی زندگی اسی پر منحصر ہے، یہ بادشاہ کے پاس گئی، اس لیے یہ معلوم نہیں کہ کب واپس آئے گی۔ اس میں یہ غریب لوگ بھوک سے مر جائیں گے، اس لیے آپ اس کشتی کو بچا لیں، تو وہ کہتے ہیں کہ میں نے اس کو توڑنے کا منصوبہ بنایا تھا، اب یہ جائے گی، کشتی پکڑنے والے وہاں آئیں گے، وہ دیکھیں گے کہ ظاہر ہے کہ جو کشتیاں کام کرنے کے قابل ہوں گی اسے لے جائیں گے اور چھوڑ دیں گے، اس لیے یہ منصوبہ ہے جو میں نے اختیار کیا ہے۔ اس کے پیچھے یہی حکمت تھی۔ یہ وہی ہے جو انہوں نے پہلی چیز کے بارے میں بتایا۔ مزید یہ کہ اس میں کچھ اور حقائق بھی بیان کیے ہیں اور پھر ظاہر کیے ہیں جن میں سے ایک چیز کو سمجھنا ہے اور وہ ہے علم کے امتحان میں کامیابی کے لیے ہماری ضرورت جو ہمارے سامنے رکھی گئی ہے۔ وقت ختم ہو گیا اور کلام یہ ہے، اور خدا نے مجھے معاف کر دیا۔ ہم آپ کو خوش آمدید کہتے ہیں۔ الحمدللہ ، الحمدللہ، رب العالمین وعلیکم السلام۔ محمد الامین، فوز باللہ، من من الشیطان ، تمام غضب، بسم اللہ، رحمن الرحیم۔ خواتین و حضرات، ہم سورہ کہف کی آیت 79 سے ایک سبق تخلیق کر رہے ہیں۔ یہ واقعہ قرآن میں کیوں بیان ہوا، اس کا سیاق و سباق کیا ہے ؟ اور انہوں نے تینوں سے سوال کیا، وہ اپنے وعدے کے مطابق صبر نہ کر سکے، وہ بار بار ایک ہی بات کہتے، یہ کیوں ہوا، یہ کیسے ہوا، اگر آپ غور کریں تو انہیں یہی کرنا چاہیے تھا۔ ہم عقلی مخلوق ہیں، ہمارے اندر اخلاقی جز ہے۔ اللہ رب العزت نے ہمیں حسن کا ایک حصہ دیا ہے۔ یہ ممکن نہیں کہ انسان کے سامنے بہت بدصورت چیز کو خوبصورت کہا جائے اور وہ سوال نہ کرے۔ یہ ممکن نہیں کہ جھوٹ اور بے ایمانی ہو۔ یہ ممکن نہیں کہ کسی بے گناہ کو قتل کیا جائے اور وہ اس پر اعتراض نہیں کرتا۔ عقلی ہستی اپنے ظہور سے باز نہیں رہ سکتی۔ وہ وہی کرے گا۔ چنانچہ سیدنا موسیٰ نے بار بار سوال کیا۔ یہاں تک کہ موقع پیدا ہوا کہ ان کے سامنے یہ بات رکھ دی گئی کہ یہ جدائی اب جدائی کا موقع ہے، تو میرے سارے کام ایک جیسے ہوں گے، ان میں ظاہر کچھ ہوگا اور باطن کچھ اور ہوگا۔ اللہ رب العزت نے دنیا کو پیدا کیا ہے اور ہم پر ظاہر کرنے کے لیے اس اسکیم میں کام کیا ہے، قانون ہمارے لیے اخلاقی اصول ہیں جو متعین کیے گئے ہیں اور یہ فتنہ کے لیے لازمی تقاضا ہے۔ اللہ تعالیٰ اپنے احکام اور طریقوں کے مطابق کام کرتا ہے اور اس کے فرشتے اس کے حکم پر چلتے ہیں۔ سوال ہوں گے تو اللہ کے فرشتے نے جس سے ملاقات کی اس نے صاف کہہ دیا کہ مجھے بھی ایسے ہی کام کرنے ہیں، ہر قدم پر وہی سوال ہوں گے۔ مجھے کچھ سمجھانا تھا، میں نے سمجھا دیا، اب اس کے بارے میں اندازہ لگا لو اور باقی تمام معاملات کو خود سمجھ لو، اب تمہارے اور میرے درمیان جدائی کا وقت آگیا ہے، اس لیے بہتر ہے کہ ہم ابھی الگ ہو جائیں، لیکن جدائی سے پہلے میں تمہیں ان سب باتوں کے بارے میں بتاؤں گا۔ میں آپ کو وہ سچ بتاتا ہوں جس پر آپ صبر نہ کر سکے۔ یہ وہ پس منظر ہے جس میں انہوں نے ہر کیس کو لے کر سچ کہا ہے۔ سب سے پہلے انہوں نے کشتی کا معاملہ لیا۔ اس کا اہتمام کیا گیا کہ وہ کہتے ہیں اما سفینہ فقانت مسکین، اس کشتی کا معاملہ یہ ہے کہ یہ کچھ غریبوں کی تھی، یعنی تم نے اللہ کو دیکھا، مسافروں کو دیکھا، لیکن ہمیں معلوم تھا کہ یہ غریبوں کی کشتی ہے، یہ یملون کیا کر رہے ہیں۔ سمندر میں جو لوگ دریا میں محنت مزدوری کرتے تھے، یعنی کشتیاں چلاتے تھے، مسافروں کو لاتے تھے، وہ چار پیسے کما لیتے تھے، یہی ان کا رزق تھا، یہی ان کا روزگار تھا۔ میں نے اس کی وضاحت کی ہے، یعنی میں اپنی ایک جنگی مہم کے لیے زبردستی اس پر قبضہ کر رہا تھا۔ ہمارے زمانے میں ایسے واقعات ہوتے تھے کہ شہر بھر سے اچھی اچھی گاڑیاں اس لیے لی جاتی تھیں کہ ایک بڑی کانفرنس ہو رہی تھی جس میں بادشاہ اور حکمراں موجود تھے۔ حکومت کو لاہور میں اس کی ضرورت تھی۔ مجھے معلوم ہے کہ کچھ گھر اسی طرح خالی کرائے گئے تھے اور بڑے لوگوں کے گھر تھے، انہیں دوسری جگہ جانے کو کہا گیا تھا اور وہ گھر گیسٹ ہاؤسز میں تبدیل ہو گئے تھے۔ مہم کے لیے تمام کشتیاں ضبط کی جائیں۔ ایسی ضرورت کا اندازہ ہی لگایا جا سکتا ہے۔ اس کے پیش نظر کشتیوں کو زبردستی لے جایا جا رہا تھا یعنی جہاں کشتی کو پہنچنا تھا وہاں بادشاہ کے اہلکار کھڑے تھے اور وہ کشتیاں ضبط کر لی گئیں۔ وہ کہہ رہے تھے کہ یہ حالت دیکھ کر اللہ تعالیٰ نے حکم دیا کہ کشتی کو بچایا جائے، چنانچہ وہ کہتے ہیں کہ میں نے جو طریقہ اختیار کیا وہ یہ ہے کہ میں نے کشتی کو ناکارہ بنا دیا۔ مجھے جو منصوبہ کرنا تھا وہ حکم دیا گیا، چنانچہ میں نے اس کو عیب دار بنانے کا ارادہ کیا، اس لیے میں نے چاہا کہ اسے عیب دار کر دوں، کیونکہ ان سے پہلے ایک بادشاہ تھا جو ہر کشتی کو زبردستی چھین لیتا تھا، کہتا تھا کہ یہ چیز اگر آپ کو نظر ہوتی تو آپ نے بظاہر دیکھا کہ کشتی خراب ہو گئی ہے، کشتی کا تختہ ٹوٹ گیا ہے، اس لیے آپ کا یہ اعتراض قطعی طور پر درست ہے کہ اس کشتی کے ٹوٹنے کا اندیشہ بالکل درست ہے۔ اس میں پانی بھر جائے گا اور نتیجتاً اگر کشتی ڈوب جائے تو مسافروں کو بھی یہ حشر بھگتنا پڑے گا اور اگر غریب آدمی کی کشتی خراب ہو جائے تو وہ کام نہیں کر سکے گی، اور اب اسے مرمت کرنا پڑے گا۔ انہیں غصے سے بچانے کے لیے وہ انہیں زبردستی نہیں لے جا سکتے تھے۔ کشتی میں ایک چھوٹی سی خرابی کو ٹھیک کیا جائے گا اور اسے ٹھیک کیا جائے گا۔ تمام باتوں کو مدنظر رکھتے ہوئے ہم نے یہ طریقہ اختیار کیا تو اس نے پہلی بات سمجھائی اور یوں بتایا کہ جس طرح باہر سے چیزیں ہوتی ہیں اللہ تعالیٰ اندر سے کچھ کیوں نہیں ہونے دیتا، حادثہ کیوں ہوتا ہے۔ کوئی کیوں راستے میں آتا ہے؟ یہ کیا چیزیں ہیں ؟ لڑکا مارا گیا اور لڑکا بچ گیا۔ اس کے والدین دونوں مومن تھے یعنی اللہ تعالیٰ نے انسان کو جو مہلت دی ہے اس سے لڑکے کے والدین نے خوب فائدہ اٹھایا۔ صلوٰۃ کی زندگی اہل ایمان نے اختیار کر لی تھی۔ یہاں مومنین کو ایک جامع تشریح کے طور پر استعمال کیا گیا ہے۔ لڑکا لڑکا ہی رہا، اس کے ماں باپ دونوں مومن تھے، اور ہمیں ڈر تھا کہ کہیں وہ بڑا ہو کر ان کو اپنی نافرمانی اور کفر سے تنگ نہ کر دے۔ کرائے کا مطلب یہ ہے کہ وہ اس عمر کو پہنچ گیا تھا کہ اس میں نشانات نظر آنے لگے تھے کہ اس میں بغاوت ہے، اس میں بغاوت ہے، وہ چیزوں کو دائیں طرف سے نہیں دیکھتا، اللہ نے اس کی فطرت میں جو نور رکھا ہے وہ اسے بجھانا ہے۔ جب یہ واضح ہو گیا تو اب اس خوف سے کہ یہ بڑا ہو کر ماں باپ کی نافرمانی اور کفر سے مصیبت بن جائے گا۔ بچوں کے معاملے میں جنہیں قرآن نے فتنہ قرار دیا ہے، وہ بڑی غلطیاں کرتے ہیں۔ ہم جانتے ہیں کہ بچوں کی محبت، بیوی کی محبت، عائزہ کی محبت کچھ فیصلوں پر کیسے اثر انداز ہوتی ہے، اس لیے انسان ہر حال میں یہی چاہتا ہے۔ کہ میرے بچے خیریت سے ہوں خواہ وہ کچھ بھی ہوں لیکن اللہ تعالیٰ نے مستقبل کو دیکھتے ہوئے انہیں نافرمانی اور کفر سے بچانے کا فیصلہ فرمایا۔ یہ لڑکا زندہ نہ رہے، اس لیے وہ لڑکا مر گیا، یعنی اللہ تعالیٰ نے اس کی موت کر دی۔ اس نے کہا کہ وہ میں ہوں اور ہم نے فیصلہ کیا کہ اب اسے زندہ نہیں رہنا چاہیے، اس لیے ان کا کہنا ہے کہ لڑکے کے معاملے میں اصل بات یہ تھی کہ وہ یہ تھا کہ ہم نے یہ معاملہ اس کے سامنے رکھا۔ کیا ہمیں اندیشہ تھا کہ کہیں وہ کافر نہ ہو جائے، میں نے اس پر حاشیہ لکھا ہے۔ یہاں بھی وہی حال ہے جیسا کہ اوپر بیان ہوا کہ انہیں صرف حکم دیا گیا تھا کہ یہ لڑکا کافر ہو گا، اس لیے اسے قتل کرنے کا مطلب یہ ہے کہ ہدایت صرف اتنی تھی، انہوں نے اس سے یہ اندازہ لگایا کہ اللہ تعالیٰ نے اس کے والدین پر احسان کیا ہے، یعنی دنیا میں یہ دستور نہیں کہ جو کافر ہونے والا ہو اسے قتل کر دیا جائے، اس لیے اب وہ سمجھے کہ اس کے ماں باپ بھی اتنے اچھے ہیں کہ اس کے لیے وہ لوگ ماننے والے ہیں اور وہ بھی اپنے لیے اچھے فیصلے کرنے والے ہیں۔ . جو کافر ہونا چاہے قتل کر دے۔ سوال یہ ہے کہ اس کے کفر سے کون متاثر ہوتا ہے اور اس کی نافرمانی سے کون متاثر ہوتا ہے۔ اگر یہ دوسرے لوگوں کو متاثر کر رہا ہے، تو ان دوسرے لوگوں کا حال۔ یہ کیا ہے؟ کیا وہ مومن ہیں؟ کیا ان کا اللہ سے حقیقی تعلق ہے؟ لیکن اللہ تعالیٰ مجموعی صورت حال دیکھتا ہے اور فیصلہ کرتا ہے کہ انہیں اس امتحان میں ڈالنا ہے یا نہیں، چنانچہ انہوں نے یہ قیاس کیا کہ اللہ تعالیٰ نے یہ حکم دیا ہے یہ سوچ کر انہوں نے اس سے یہ اندازہ لگایا کہ اللہ تعالیٰ نے ان کے والدین پر احسان کیا ہے کہ جب وہ بڑے ہو جائیں تو ان کو اپنی نافرمانی اور کفر سے تکلیف نہ پہنچائیں، اس لیے ان کے لیے خوشینہ کا لفظ استعمال کیا گیا۔ اس کے لیے انہوں نے جمع کا استعمال کیا ہے اس کی وجہ یہ ہے کہ مجھے ڈر ہے کہ بجائے اس کے کہ ہم ڈر رہے ہیں کہ یہ الفاظ کیوں استعمال ہوئے ہیں، وجہ یہ ہے کہ وہ یہاں اس پوری جماعت کی نمائندگی کر رہے ہیں۔ جن کارکنوں کو قضا اور قدر کے کاموں پر مامور کیا گیا ہے یعنی وہ یہ کام کر رہے ہیں اور موسیٰ علیہ السلام اللہ کے دس اور فرشتوں کو بھی اسی طرح کا کام کرتے ہوئے دیکھ رہے ہیں۔ انہوں نے وہاں اپنے زمرے یا اپنی جماعت کی طرف اشارہ کیا ہے، جیسا کہ عام طور پر قانون نافذ کرنے والے ادارے ایسے مواقع پر ایسی تشریح کرتے ہیں، اس لیے انہوں نے اپنے زمرے کی رعایت کے ساتھ، یعنی اپنی جماعت کی رعایت کے ساتھ ایسا کیا۔ جمع کا استعمال ہماری زبان میں بھی عام ہے، ہم بھی کرتے ہیں، تو گویا اس نے کہا کہ اللہ تعالیٰ اس کے والدین کو اس کے کفر سے بچانا چاہتا ہے۔ اس میں مصلحت کیا ہے؟ انہوں نے اللہ کے حکم کی تعمیل کی تو ایسا ہی ہوا۔ پھر کہتے ہیں ربا خیر من۔ پس ہم نے چاہا کہ ان کا رب انہیں اپنی جگہ خیر من اور زکوٰۃ جیسی اولاد عطا کرے۔ اس سے بہتر ہے اور اس سے بڑھ کر ہمدردی اور محبت میں، یعنی یہ ختم ہو گیا ہے، لیکن اب ہماری نظر میں یہی چیز ہے کہ رب ان والدین پر رحم کرے اور ان والدین کو اولاد سے محروم نہ کرے، یعنی اب ان کے ہاں اچھا بچہ پیدا ہوگا۔ اللہ عزوجل عطا فرمائے، وہ چاہے گا تو ہو جائے گا۔ اس کا مطلب یہ بھی ہے کہ مہلت دی جائے گی۔ ان تمام پہلوؤں کا تذکرہ کرنے کے بعد فرمایا کہ یہاں بھی آپ کو یہ سبق سیکھنا چاہیے کہ جو کچھ ظاہری طور پر ہو رہا ہے وہ بالکل مختلف پہلوؤں سے اندرونی طور پر ہو رہا ہے، یعنی اللہ اندر ہے۔ عقل کیا کام کرتی ہے، انسان کے سامنے نہیں ہوتا، اس نے بچے دیے، کیا ہوا جب بچہ ماں کے پیٹ سے چلا گیا، اس نے ابھی آنکھ بھی نہیں کھولی تھی، فرشتہ بچپن میں مر گیا، پڑھایا، لکھا، کھیلا ، اس کے سامنے چھلانگ لگاتا رہا۔ ماں باپ کی آنکھوں کی ٹھنڈک ہے۔ اللہ تعالیٰ نے اسے لیا اور فرمایا کہ یہ سب کچھ کسی مصلحت کے تحت ہوتا ہے، یعنی ہم نے موت کا وقت مقرر نہیں کیا۔ کہ انسانوں کو یہ نہیں بتایا گیا کہ وہ فلاں عمر میں اس دنیا سے چلے جائیں گے۔ اس سے پہلے موت نہیں آئے گی۔ موت ہر مرحلے پر آتی ہے اور جب آتی ہے تو اللہ کے سامنے فضیلت ہے کیونکہ جو مرے گا وہ مرے گا۔ کسی کی اولاد ہوگی، کسی کے ہاں بیٹا ہوگا، کسی کی بیٹی ہوگی۔ یہ رشتے رشتے ہیں۔ یہ ظاہر ہے کہ وہ صدمے کا سبب بنتے ہیں۔ بڑی نعمتیں لیتے ہیں اور چھین لیتے ہیں۔ ایسی حالت میں صبر کرنا آسان نہیں اس لیے بتایا گیا کہ عموماً یہ سارے معاملات آپ کے فائدے کے لیے ہیں۔ اللہ تمہیں نافرمانی، کفر، سرکشی سے بچانا چاہتا ہے اور یہی اللہ ہے۔ وہ حکمتیں اور مصلحتیں ہیں جو اس وقت آپ کے سامنے نہیں ہیں۔ اگر ایسا ہوتا تو آپ خود دیکھ لیتے۔ البتہ قیامت کے دن ہم پردہ اٹھا کر وہاں اسی طرح دکھائیں گے جس طرح ہم یہاں دکھا رہے ہیں۔ خدا کی حکمت اور مشیت سے اس نے حجاب اٹھایا اور ان سے کہا کہ یہ صورت حال ہے، معاف کیجئے گا، اور پھر تیسری صورت اور مدینہ منورہ میں دیواروں والے یتیموں کا کام۔ ایک دیوار بھی تھی۔ یہ اصل میں شہر کے دو یتیم لڑکوں کی ملکیت تھی۔ معاف کیجئے گا۔ تاویل مست۔ صابرہ۔ دیوار کا معاملہ یہ ہے کہ یہ شہر کے دو یتیم لڑکوں کی تھی۔ وہ اس کے نیچے دب گئے۔ باپ نیک آدمی تھا یعنی دو یتیم لڑکے تھے۔ باپ دنیا سے رخصت ہو چکا تھا۔ اس کے والد نے اس دیوار کے نیچے اپنے بچوں کی تدفین کی جگہ رکھی تھی۔ جب وہ جا رہا تھا، ہم چاہتے تھے کہ وہ محفوظ رہے اور اس کے لیے یہ انتظام کیا۔ وہ یہ نہیں چاہتے تھے، یعنی آپ کا رب نہیں چاہتا تھا کہ یہ دوسرے لوگوں کے ہاتھ لگ جائے، تاکہ وہ اسے اس طرح چھپا سکیں۔ ایسا کرنا ضروری تھا، دیوار ٹیک ہوئی تھی، وہ کسی بھی لمحے گر سکتی تھی، ہم نے اسے کھڑا کیا، یہ کیسے ہوا، اس کی وضاحت یہاں نہیں ہے، ظاہر ہے، کچھ اینٹیں ہٹا کر واپس رکھ دی گئیں، یا دیوار جیسا کہ فرشتے کر سکتے ہیں۔ انہوں نے اسے بنایا ہے۔ پھر کیا ہوا، آپ کے رب نے چاہا کہ وہ اپنی جوانی کو پہنچ جائیں اور اپنے پیچھے ان کی قبر کھودیں جس کے پیچھے سیدنا موسیٰ علیہ السلام نے فرمایا کہ اگر انہوں نے مشقت لی تو اس سے معلوم ہوتا ہے کہ گویا کچھ بگڑ گیا ہے۔ مثلاً کسی جگہ سڑک ٹوٹی ہوئی دیکھ کر اللہ کا بندہ بغیر کسی اجر کے کھڑا ہو کر اس کی مرمت شروع کر دیتا ہے، یا اس طرح کی کوئی اور چیز ہو تو اسے ٹھیک کر دے تو واضح ہے۔ کہ گاؤں کے لوگ یہ بھی دیکھ رہے تھے کہ یہاں کچھ لوگ ہیں جو ایک دیوار کی مرمت کر رہے ہیں، انہوں نے کہا کہ یہ اچھی بات ہے کہ دیوار گرنے والی تھی اور انہوں نے اس کی مرمت کر دی کیونکہ وہ کہتے ہیں کہ مزدوری اور کم از کم روٹی تو مانگ لیتے۔ اگر ہم اسے نہ کھلاتے تو وہی خرید لیتے، اس سے اندازہ ہوتا ہے کہ کوئی ظاہری عمل بھی ہوا، اس لیے آپ کے رب نے چاہا کہ وہ اپنی جوانی کو پہنچیں اور اپنی تدفین خود کھودیں۔ لیکن ہم چاہتے تھے، ہم ڈرتے تھے۔ یہاں اللہ تعالی کی طرف براہ راست حوالہ ہے۔ میں نے اصل الفاظ لکھے ہیں ربک۔ نیت کا عمل براہِ راست اللہ تعالیٰ کی طرف ہوتا ہے، یعنی جب حکم دیا گیا تو اس نے کس نزاکت کا مشاہدہ کیا اور اپنی طرف سے کوئی اجتہاد کیے بغیر اس پر عمل کیا۔ دیا گیا، وہاں تعلق بھی اللہ تعالیٰ کی طرف سے ہے اور جہاں خلاصہ حکم دیا گیا، یعنی حاصل کیا جائے، یہ نتیجہ نکلے، والدین کو بچے کی سرکشی سے بچایا جائے یا اسے قتل کر دیا جائے، لیکن یہ نہیں بتایا گیا کہ مصلحت کیا ہے، پھر اگر وہ اپنی طرف سے اس مصلحت کو بیان کرتے ہیں، تو وہ جمع کو استعمال کرتے ہیں، اور اگر وہ خود بیان کرتے ہیں، تو اس کو بھی استعمال کرتے ہیں۔ جمع شکل. یہ یہاں واضح ہے۔ کہ سارا معاملہ کچھ یوں تھا، اس نے کہا کہ وہ اپنی جوانی تک پہنچیں اور اپنی تدفین خود کھودیں۔ اعتراض یہ تھا کہ ہمارے ہاں پوری دنیا میں ایک اچھی روایت ہے کہ اگر کوئی مسافر اس طرح اجنبی ہو تو اسے کھانا کھلایا جائے اور ہم نے خود اس کی درخواست کی لیکن وہ اس کے لیے تیار نہ ہوئے۔ فقیروں اور کمینوں کا اعتراض یہ تھا کہ آپ نے دیوار کی مرمت کی کہ یہ احسان ان غریبوں کو نہیں دیا گیا جو ایک مہمان کو کھانا کھلانے کے لیے بھی تیار نہیں تھے، بلکہ دیوار گرنے کی وجہ سے دو یتیموں کو دیا گیا تھا۔ اس کا خزانہ ان بدمعاشوں کے ہاتھ نہ لگ جائے اور ایسا اس لیے کیا گیا کہ اس کے والد نیک آدمی تھے یعنی نیک انسان تھے۔ یہ ان کا کام ہے۔ ہم نے اس کی حفاظت کا فیصلہ کیا۔ اگر دیوار گر جاتی تو تدفین اس بستی کے لوگوں کے ہاتھ میں ہوتی۔ چنانچہ ہم نے دیوار کی مرمت کی۔ اب یہ کھڑا رہے گا۔ اس لحاظ سے وہ اسے ہٹا دیں گے جیسا کہ پرانے زمانے میں ہوا کرتا تھا، چنانچہ انہوں نے اس کی حکمت بیان کی اور پھر کہا، رحمت من ربک، یہ آپ کے رب کے فضل سے ہوا، یعنی ان میں سے کوئی بھی عمل ایسا نہیں ہے۔ میں نے جو کچھ اپنی مرضی سے کیا ہے، جو کچھ میں نے اپنی رائے کے مطابق کیا ہے، میں نے امتیصل کو معاملے کے لیے حکمت عملی کے طور پر اختیار کیا ہے، یا میں نے کسی جگہ اس کی حکمت کو اپنی سمجھ میں لیا ہے۔ یہ اللہ تعالیٰ کا طریقہ ہے۔ ایک چیز ہمیں بتاتی ہے کہ اللہ تعالیٰ معاملات سے کیسے نمٹتا ہے۔ قرآن پاک میں بعض مقامات پر وہ ہمارے سامنے حکم دیتا ہے۔ ہمارا غور فکر کرنا چھوڑ دیا جاتا ہے، لیکن بعض جگہ احکام کو اس طرح دہرایا جاتا ہے یا مختلف چیزوں پر اس طرح لاگو کیا جاتا ہے کہ وہ چیز بہت نمایاں ہو جاتی ہے، چنانچہ ان کے یہاں بھی یہ سب کچھ ہوا ہے۔ دوسرے لفظوں میں اللہ تعالیٰ فرشتوں کے ساتھ اسی طرح پیش آتا ہے۔ بعض جگہ اس نے حکم بھی دیا ہے۔ اس نے حکم بھی دیا ہے۔ بعض جگہ اس نے حکم دیا ہے۔ اس نے مصلحت کو ان کے اندازوں پر چھوڑ دیا ہے۔ اس میں اگر آپ ان جگہوں کو غور سے پڑھیں تو ان کا استعمال کردہ لفظ آپ کو بتاتا ہے کہ یہاں کیا صورتحال ہے، اس لیے میں نے ہر جگہ اسے واضح کرنے کی کوشش کی۔ اگر کچھ ہوا، یعنی لڑکا مارا گیا تو تیرے رب کی رحمت، اگر اس لائم بستی کے لیے یہ دیوار دوبارہ بنائی گئی تو تیرے رب کی رحمت ہو، اور اگر کشتی میں کوئی ظاہری خرابی پیدا ہوگئی جو بظاہر کوئی برائی معلوم ہوتی ہے۔ لیکن تیرے رب کی رحمت، تو انہوں نے اس سے کہا کہ اگر تیرا رب ایسا مہربان رب نہ ہوتا تو اپنی حکمت کے مطابق معاملات کو چھوڑ دیتا۔ کہا جاتا ہے کہ یہ تیرے رب کے فضل سے ہوا، رحمت من ربک وما فلت امری اور کبھی یہ نہ سوچنا کہ میں نے یہ کام اپنی رائے سے کیا ہے یا میں بھی ایک ہستی ہوں۔ میں نے وہی کیا جو مجھے اوپر کہا گیا ہے اس کے سلسلے میں کرنے کا حکم دیا گیا ہے۔ یہ بیان کیا گیا کہ یہ مشاہدہ کیوں کیا گیا، بتانے کا مقصد کیا تھا، سیدنا موسیٰ کی تربیت کیا تھی اور یہاں میں بیان کر چکا ہوں کہ اس سورت کے تناظر میں رسول اللہ صلی اللہ علیہ وسلم اور مسلمانوں کو بتایا گیا کہ اس وقت آپ کو جن حالات کا سامنا ہے، ان میں فکر کرنے کی کوئی بات نہیں، اس کے پیچھے اللہ کی حکمت ہے۔ جبکہ وہ حکمتیں بھی سامنے لائی جاتی ہیں، پھر یہ قصہ یہیں ختم ہوتا ہے، اس کے بعد ایک اور سوال ہے، ذوالقرنین کے بارے میں پوچھا گیا۔ قرآن نے جو سوال مناسب سمجھا اسے موضوع کے طور پر لیا اور پھر تفصیل سے جواب دیا، میں نے اس کہانی کے آخر میں ایک مفصل نوٹ لکھا ہے۔ کہانی کیا ہے، اس میں علم و حکمت کا خزانہ ہے، جو ہمارے سامنے آتا ہے، تو یہ چند آیات، چند سطریں، ایک قصہ، ایک واقعہ، اس میں تین باتیں بیان کی گئی ہیں، لیکن اگر غور کیا جائے تو یہ گنج گرام مایا ایک بھاری خزانہ ہے، ایک غیر معمولی خزانہ ہے، اس کے لیے صبر و استقامت کی تربیت، صبر و استقامت کا واضح ترین اصول ہے۔ اس دنیا میں انسان اپنے اندر جو خوبی پیدا کر سکتا ہے وہ صبر اور آمادگی ہے، یعنی ایک ثابت قدم انسان۔ اسے چلنے دو، اسے اپنی آزادی میں سلب نہ کرنے دو، اسے انعام نہ دینے دو، اسے پیش آنے والے واقعات سے کوئی پریشانی نہ ہونے دو، وہ اللہ کے فیصلوں پر مطمئن ہو کر صحیح نتائج کے لیے جدوجہد کرتا رہے، پھر یہ ساری چیز سب سے بڑی چیز ہے۔ اس دنیا میں انسان جو کچھ حاصل کر سکتا ہے اسے صبر اور اطمینان کی تربیت حاصل کرنی چاہیے۔ معلوم ہوا کہ اس ساری کہانی کا سبق کیا ہے، میں نے اس کے بہت سے پہلوؤں کی نشاندہی کی، اب ان کو ایک ترتیب سے دیکھا جائے، ایک یہ کہ اس دنیا میں جو کچھ ہوتا ہے، وہ سب اللہ کے حکم اور اس کی مشیت سے ہوتا ہے۔ مرضی کے تحت ہوتا ہے، یعنی اس دنیا میں خود سے کچھ نہیں ہوتا، حالانکہ ایک خودکار نظام کام کر رہا ہے، وہ خودکار نظام کچھ اصولوں پر کام کر رہا ہے، لیکن یہ خود کار طریقے سے یا اس میں کام کرتا ہے۔ کسی بھی قسم کی مداخلت خدا کی اجازت اور اس کی مشیت اور اس کی مرضی سے ہو، یعنی چاہے وہ خودکار ہی کیوں نہ ہو، خدا کی مرضی اور اس کی مرضی کے تحت ہے۔ یہ نہیں کیا جا سکتا۔ یہ ہمارے ایمان کی بنیاد ہونی چاہیے۔ اس سے ایمان کی مٹھاس ملتی ہے۔ اگر کسی شخص کو ہر چیز میں اللہ تعالی کی نیت اور مرضی نظر نہیں آتی تو اس کا مطلب یہ ہے کہ ایمان اس کے لیے محض ایک فلسفیانہ تصور ہے۔ اس نے اسے لے کر کہیں چھوڑ دیا ہے۔ ایمان جب حقیقی زندگی سے تعلق رکھتا ہے تو اس چیز کو پیدا کرتا ہے، یعنی انسان کی پوری زندگی اللہ تعالیٰ کی رضامندی اور ہر چیز میں اس کی مرضی اور حکمت و حکمت پر استوار ہے۔ ہمارا دیکھ کر راضی ہونے کا وقت ختم ہوگیا، اب اس کے مختلف نکات زیر بحث آئیں گے۔ اس کے بعد خضر کا واقعہ آیت 82 پر ختم ہوا، اس واقعہ میں علم و حکمت کی کیا دولت پوشیدہ ہے۔ استاد امام امین احسن اصلاحی نے اسے نکات کی صورت میں بیان کیا ہے۔ میں نے اس کا حوالہ دیا ہے۔ انہوں نے لکھا ہے کہ ایک یہ کہ اس دنیا میں جو کچھ بھی ہوتا ہے اس کی حقیقت میں سب سے پہلی بات جو قرآن نے اس کہانی کو بیان کر کے واضح کی ہے وہ یہ ہے کہ اس دنیا میں جو کچھ ہوتا ہے وہ خدا کے حکم اور اس کی مرضی اور مرضی سے ہوتا ہے۔ اور مقصد ایک عارضی دنیا ہے، دنیا کا مادّہ بنایا گیا ہے، لیکن اسے وسیع و عریض جگہوں پر بکھیر دیا گیا ہے اور ایک چھوٹا سا علاقہ چنا گیا ہے، جسے ہم زمین کہتے ہیں، اور اس میں لوگ بستے ہیں، جنہیں اللہ نے بنایا ہے۔ خدا کے قوانین اپنی جگہ پر ہیں، یہ سب خود کار طریقے سے کام کرتے ہیں، اور بعض اوقات ان میں دخل اندازی ہوتی ہے، اور پردے کے پیچھے فرشتے بھی اپنے فرائض انجام دیتے ہیں۔ ایسا نہیں ہے جو اللہ تعالیٰ کی اجازت کے بغیر ہو اور وہ نہیں جانتا کہ اس کائنات میں اس کی مشیت اور رہنمائی کے بغیر کیا ہوا یا ہو سکتا ہے۔ یہ سب چیزیں اسی نے پیدا کی ہیں۔ اس کے سامنے ایک سکیم رکھی گئی ہے اور اس سکیم کے اجزا کا تعین کر دیا گیا ہے اور پھر جس نے اس میں اختیار دیا ہے وہ اس کی اجازت سے اپنا اختیار استعمال کر رہا ہے۔ اس نے کہاں مداخلت کا فیصلہ کیا ہے، اس کی اپنی حکمت کے تحت کیا ہے، پھر ہر چیز میں اللہ تعالی کام کرتا ہے اور اس کی نیت، کوئی چیز اس کی گرفت سے باہر نہیں ہے اگر ہم اپنے اختیار کو استعمال کرتے ہوئے غلطی کر بیٹھیں۔ مجھے اس میں کوئی شک نہیں کہ وہ اپنا اختیار استعمال کرتے ہوئے کرتے ہیں، اس لیے وہ اس کے ذمہ دار اور جوابدہ ہیں، لیکن اگر یہ اختیار ہمارے رب نے نہ دیا ہوتا تو ہمیں کہیں سے بھی حاصل نہ ہوتا۔ سب کچھ ہوچکا ہے، اس لیے ہر چیز کو اس کی اجازت ملتی ہے، پھر عمل ہوتا ہے، اس کی اجازت اور مشیت کے بغیر ایک ذرہ بھی اپنی جگہ سے نہیں ہل سکتا۔ یہ پہلی چیز تھی۔ یعنی اس کی نیت اس کی حکمت کے ساتھ ہوتی ہے، اس سے کوئی برائی وجود میں نہیں آتی، وہ جو کچھ بھی کرتا ہے وہ سراسر اچھا ہوتا ہے، لعنت نیکی ہوتی ہے اور اس کے ہر فیصلے میں حکمت ہوتی ہے۔ اس وجہ سے اس کی کوئی نیت نیکی اور حکمت سے خالی نہیں ہے۔ اگر وہ اہل باطل کو چھوڑ دیتا ہے تو اس کی وجہ یہ نہیں کہ وہ باطل سے محبت کرتا ہے یا اس کے سامنے بے بس اور مجبور ہے۔ وہ بھلائی کی پرورش کرتا تھا یعنی لگتا ہے کہ جھوٹ کو مہلت دی گئی ہے، جھوٹ زمین پر بکھر رہا ہے، جھوٹ لوگوں کے گلے کاٹ رہا ہے، جھوٹ فساد برپا کر رہا ہے۔ اس کا مطلب یہ ہے کہ وہ ابھی تک گرفت میں نہیں آ رہا ہے، کیونکہ دنیا فتنہ کے اصول پر بنی ہے، اس لیے اس نے موقع دیا ہے، لیکن اس موقع کے دینے کا یہ مطلب بھی نہیں کہ اللہ تعالیٰ کو کچھ عرصے کے لیے باطل سے محبت ہو گئی ہے یا وہ اس باطل سے بے نیاز ہے۔ بس اتنا ہے کہ اس کا ہاتھ نہیں پکڑ سکتا، لیکن اس کے اندر بھی وہ ایک عظیم نیکی کو پالتا ہے، یعنی ایک بہت بڑی نیکی ظاہر ہوتی ہے، جو ظاہر ہے برسوں بعد بعض مواقع پر سامنے آتی ہے اور بعض مواقع پر خود قیامت۔ میں ظاہر کروں گا کہ اس میں کیا حکمت پوشیدہ تھی۔ یہ سب اس کی طرف سے اچھا ہے۔ اسی طرح اگر وہ اہل حق کو مصائب و آلام میں مبتلا کرتا ہے تو انبیاء کرام کو مصائب اور انبیاء کو اللہ تعالیٰ کے اعلان میں مصائب کا سامنا کرنا پڑا۔ جن بندوں سے اس نے اپنی کتابوں میں اپنی محبت کا اظہار کیا ہے، ان پر آزمائش اور آزمائش کی گھڑیاں گزر چکی ہیں۔ ایسا کیوں ہوتا ہے؟ وہ حق کے دکھوں میں دلچسپی رکھتا ہے، یعنی انہیں مصیبت میں ڈالنا چاہتا ہے۔ وہ ایسے امتحانوں سے گزرتا ہے، چنانچہ سب سے بڑا گروہ، جسے اللہ تعالیٰ نے خود ایک اچھی قوم کہا، وہ گروہ ہے جو اللہ کے رسول صلی اللہ علیہ وسلم پر ایمان لائے، جسے ہم صحابہ کہتے ہیں۔ میں نے بیان کیا ہے کہ اللہ ان سے راضی ہوا، یعنی انہوں نے اللہ کی بیعت کی، اور ان کے مجموعی طرز عمل کی بنا پر اس پوری جماعت کے بارے میں کہا گیا ہے کہ تم بہترین جماعت ہو۔ پھر کہا گیا کہ یہ وہ بہترین گروہ ہے جس کو میں نے آخری زمانے میں ذمہ داری دی ہے کہ اب جاؤ اور دنیا والوں کو پیغام پہنچا دو۔ ان سب نے کہا اور ان سب کے باس نے ان کے بارے میں کہا کہ من الخفین من الفارہ کہ جس عہدے پر تم فائز ہو اس کے تقاضوں کے مطابق امتحانات اور آزمائشوں کا ایک سلسلہ شروع ہونے والا ہے وہ امتحانات میری طرف سے ہوں گے اور میں تمہیں فلاں فلاں میں آزماؤں گا، اس میں بھوک کا ذکر ہے، اس میں خوف کا ذکر ہے، اس میں دنیا کے خوف کا ذکر موجود ہے۔ گڑیا ، دولت ، یہ دیکھنے کے لئے کہ آپ کو یہ عظیم مقام دیا گیا ہے ، جب تک کہ یہ بات آپ کے پاس نہیں ہے۔ ایمان کا اظہار کریں، وہ اپنے رب کے ساتھ اپنے تعلق کا اظہار کریں گے، اور ان کو امتحان میں نہیں ڈالا جائے گا، ایک اچھی امت ہے اور میں نے انہیں مقام دیا ہے۔ یہ انبیاء ہیں، یہ شہداء ہیں، یہ صالحین ہیں، اب ان کے لیے بخشش ہے۔ کیونکہ عظیم بھلائی کا راستہ کھلنا ہے، اس لیے انہوں نے اس دنیا میں جو مقام حاصل کیا، جس طرح وہ ہمارے لیے نمونہ بن گئے، جیسا کہ اب ہم انہیں دینی رہنمائی کے نمونے کے طور پر دیکھتے ہیں اور جس طرح انہیں اللہ کے رسول صلی اللہ علیہ وسلم نے سکھایا تھا۔ یہ سند ملی کہ اگر کسی چیز کے بارے میں فیصلہ کرنا ہو کہ وہ صحیح ہے یا غلط، تو دیکھو کہ ما انا الیہ والصحابی اور میرے صحابہ کا رویہ کیا تھا، ان کا طریقہ کیا تھا، تو یہ اتنا بڑا وقت ہے کہ اللہ تعالیٰ نے انہیں دنیا میں ایک عظیم سلطنت عطا فرمائی، روم و ایران کی بڑی سلطنتیں آپ کے سامنے پروں کی طرح اڑ گئیں۔ آپ اس کا اندازہ نہیں لگا سکتے، لیکن اس دنیا میں جو آزمائشیں اور فتنوں کا سامنا کرنا پڑتا ہے وہ وہ آزمائشیں اور فتنے ہیں جن کے ذریعے انسان کی تربیت ہوتی ہے، وہ جنت کی ابدی زندگی میں اللہ رب العزت کی اسکیم کا حصہ بننے کے لیے تیار ہوتا ہے۔ علم میں خیر ہے۔ دنیا میں یہ ممکن ہو سکتا ہے۔ یہ میری کائنات میں ممکن ہے۔ اس علم کا ایک بڑا حصہ ہے جو میں نے تم لوگوں کو دیا ہے، من علم القلیلہ، یعنی یہ علم جسے ہم پسند کرتے ہیں، جس کے نتائج دیکھ کر لوگ حیران رہ جاتے ہیں۔ یہاں تک کہ ہمارے شاعر کا کہنا تھا کہ میں سوچتا ہوں کہ دنیا کیا بنے گی، یہ علم جو انسان کو قوی بناتا ہے اس کا موازنہ اللہ کے علم سے کیا جاتا ہے، اللہ کے فرشتوں کے علم سے اور علم کا موازنہ ایک ذرہ سے زیادہ نہیں، اسی لیے اسے اس طرح بیان کیا گیا ہے، ایک جگہ کہا گیا ہے کہ من العلما چھوٹا ہے، یہی وجہ ہے کہ انسان کو علم نہ سمجھنے کی وجہ سے بڑی نعمت ہوتی ہے۔ اور اس کی تربیت کے لیے قرآن میں ہی اللہ تعالیٰ نے فرمایا کہ میں نے اس قرآن کو نازل کیا ہے، پھر میں نے اس میں دین کی وضاحت کی ہے، اس کے حصے یہ ہیں، یعنی ان میں کوئی چیز مخفی نہیں ہے، نہ یہ عام ہے، نہ کوئی راز ہے، ہر چیز جملے سے نکلی ہے، ہر چیز جملے سے نکلی ہے۔ بیان کیا تو فیصلہ کن ہو گیا، اس میں کوئی ابہام نہیں، وہ اپنی رہنمائی کو آخری درجے تک پہنچا دیتا ہے، لیکن اس ہدایت کا ایک حصہ وہ ہے جس میں آپ اپنے علم کی حدود سے باہر کے علم سے بھی واقف ہوں۔ دیا جاتا ہے، یعنی بتایا جاتا ہے کہ اس کائنات کا رب کیسے کام کرتا ہے۔ بتایا جاتا ہے کہ اس دنیا کا کارخانہ بعض مواقع پر کیسے کام کرتا ہے۔ آنے والا جس میں آپ کی پرورش کی جائے گی اس میں نئے نوام اور نئے قوانین ہوں گے۔ اس دنیا میں کیا نعمتیں ہوں گی ؟ کتاب میں کوئی ابہام نہیں ہے، لیکن یہ حقائق ایسے ہیں کہ آپ اس دنیا میں ان کی گرفت نہیں کر سکتے۔ یہ بتانا بھی ضروری ہے کہ جنت کیا ہو گی اور یہ بتانا بھی ضروری ہے کہ جنت کے دوست کیسے وجود میں آئیں گے۔ بتاتے ہوئے زیادہ سے زیادہ علم دینے کے لیے ہم نے تشبیہات کا طریقہ اختیار کیا ہے، یعنی آپ کی دنیا میں موجود چیزوں سے مشابہت۔ اس طرح ہم نے خود شناسی کا ایک راز کھول دیا، یعنی جب کوئی چیز اس دنیا میں ہمارے سامنے ظاہر ہوتی ہے اور اسے ہمارے حواس گرفت میں لے لیتے ہیں، خواہ وہ ظاہری حواس ہوں یا اندرونی حواس، تو عقل کی ایسی سمجھ۔ ہم دولت لائے ہیں کہ اگر اس سے کوئی اصول نکلتا ہے تو فرعون تک پہنچتا ہے، فرعون سامنے ہو تو اصول تک پہنچ جاتا ہے۔ نتائج سامنے آنے لگتے ہیں۔ یہ ہمارے علم کی عظیم نعمت ہے، وہ عظیم دولت جو ہمیں عطا کی گئی ہے، لیکن یہ عظیم دولت اور یہ عظیم نعمت کیا ہے جو لامحدود ہے۔ آپ تصور کر سکتے ہیں کہ یہ ایک غیر معمولی صلاحیت ہے جو آپ کو دی گئی ہے، اس لیے ہم نے اس کا آپ کی دنیا سے موازنہ کیا ہے اور آپ کو کچھ ایسے حقائق بتائے ہیں جو آپ کے حواس کی گرفت یا آپ کی عقل کی گرفت سے باہر ہیں۔ یہ بھی بتایا اور ان کی دوبارہ تلقین کی گئی ہے کہ علم کے وارث، علم میں اثر رکھنے والے کبھی بھی ان تشبیہات کے دروازے پر نہیں آتے، یعنی اب مجھے ان کی حقیقت کا علم ہو جائے گا اور میں اس میں ہوں۔ وہ اسے کبھی بھی اپنے اندازوں کا ہدف نہیں بناتے بلکہ جتنا علم انہیں دیا جاتا ہے۔ ہمیں ان کی طرف سے یہ اطلاع ملی ہے کہ ہم ان کی حقیقت کے سامنے کبھی نہیں ہوں گے اور پھر لوگوں کو متنبہ کیا کہ جو لوگ ان کی حقیقت کے سامنے ہیں یعنی ان کے علم کی حد سے باہر چیزوں کی حقیقت دو ہیں۔ وہ لالچ سے اس دنیا میں اترتے ہیں، اس دلدل میں اترتے ہیں، یا فتنہ فتنہ کیا ہے؟ ان کے خیال میں ایک فتنہ پیدا کرنا ہوگا۔ یہ شیطانیت اور تاویل کی ابتداء کو جنم دیتے ہیں کہ فطری تجسس اس حد سے آگے نکل جاتا ہے کہ ہمیں ان چیزوں کو بھی سمجھنا ہوگا۔ ان کو سمجھے بغیر ہم کیسے مطمئن ہو سکتے ہیں ؟ انہوں نے کہا کہ جو لوگ ان دو چیزوں کو اپناتے ہیں جو ہمارے دلوں میں ہیں انہیں اپنے باطن کو جھانک کر دیکھنا چاہیے کہ دوسری چیز اپنے آپ میں بری نہیں ہے لیکن دل کی کجی کے بغیر نہیں رہ سکتی۔ یہ بتایا گیا ہے کہ آپ کے علم کی حدود کیا ہیں تو استاد امام یہاں اس کی وضاحت کرتے ہیں۔ جہاں تک وہ اپنے حواس کو تیز کر سکتا ہے، وہ بھی محدود ہے کیونکہ اس کے علم کی رسائی محدود ہے، اس لیے وہ اس دنیا میں، یعنی یہاں خدا کے ہر ارادے کی حکمت نہیں جان سکتا۔ باتیں ایک حد تک معلوم ہوتی ہیں، یہی وجہ ہے کہ ان تینوں واقعات میں اٹھنے والے سوالات کو موضوع نہیں بنایا گیا، لیکن تھوڑا سا پردہ اٹھا کر ہم نے بتایا ہے کہ ہم اس دنیا میں کیا کر رہے ہیں، بظاہر وہ برائی آپ کو نظر آتی ہے۔ اس کے پیچھے کیا خوبی ہے؟ آپ اس کے پیچھے اچھائی دیکھ سکتے ہیں۔ اس کے پیچھے کیا حکمت ہے؟ پھر یہ بات بتائی گئی ہے کہ ہم یہ سب اس طرح کر رہے ہیں۔ اس لیے یہ خدا کے ہر ارادے کی حکمت ہے۔ اس کے ارادوں کے سارے اسرار اس دنیا میں نہیں جان سکتے، یعنی اللہ نے یہ کیوں چاہا، یہ کیوں چاہا، اس نے دنیا کو ایسا کیوں بنایا، اس میں یہ اصول کیوں رکھے، اس کے قوانین ایسے کیوں ہیں، اس میں یہ برائی کیوں پیدا ہوئی؟ اس میں خیر ہے۔ ہم کبھی کبھار کیوں مغلوب ہو جاتے ہیں؟ ایسے حالات کیوں پیدا ہوتے ہیں؟ ہماری خواہشات اور تمنائیں ادھوری کیوں رہتی ہیں؟ ہزاروں سوال۔ لیکن خدا اپنے بندوں پر اپنے ارادے ظاہر نہیں کرتا، اس کے ارادوں کے تمام اسرار آخرت میں ہی کھلیں گے۔ تمام فیصلوں پر اپنا فرض ادا کرو، یعنی اگر علم کسی حد تک دیا جائے تو اس پر صبر اور شکر کرو۔ اگر اسے حد کے اندر رکھا جائے تو اس میں بھی صبر اور شکر کرنا، وہی راسخون فی العلماء کمال کا کلمہ ہے، یعنی فرمایا کہ جو لوگ ان چیزوں کی تلاش میں ہیں، وہ اپنے آپ کو عالم سمجھتے ہیں، جب کہ ان کا علم مطلع علم ہے۔ ایسا ہوتا ہے کہ وہ اپنے علم کی حد سے تجاوز کر رہے ہیں۔ وہ ایسی چیزوں کی تلاش میں ہیں جو انسان کی سمجھ سے باہر ہیں۔ ان کے ساتھ پھر یہی ہوتا ہے، پھر فرمایا کہ وہ انہیں صبر اور شکر کرنے کی اجازت نہیں دیتا اور ان جہانوں میں جانے کے بعد یہ سمجھتے ہیں کہ ہم نے علم کے اسرار دریافت کر لیے ہیں، جب کہ راسخون فی علم وہ نہیں جو یہ کہتے ہیں، کل آدمی سے مراد وہ ہے جو اپنے علم کی حدود کو پہچان کر صحیح سرحد پر کھڑا ہو اور اس سے آگے قدم نہ بڑھائے۔ ہماری حدود یہ ہیں۔ ہم اس دور تک جائیں گے۔ واضح طور پر تجزیہ کریں اور سمجھیں کہ انسانی علم کی حدود دراصل کیا ہیں۔ میرے اور آپ کے درمیان علم کی حدیں زیر بحث نہیں آتیں۔ ہو سکتا ہے کہ مجھے کمتر علم ہو۔ ہو سکتا ہے آپ زیادہ علم والے ہوں۔ علم اور علم میں فرق یہ ہے کہ علم کی حدود کا مطلب ہے انسان بحیثیت انسان، علم کی حدود کا تعین ہونا چاہیے۔ عمر وہ ہے جس میں وجود کی حقیقت جاننے کے لیے ایک قدم بھی آگے نہیں بڑھایا جا سکتا۔ جب چیزیں وجود میں آئی ہیں، وہ وجود میں آگئی ہیں، تب ہم ان کا علم حاصل کر سکتے ہیں، کسی حد تک ہم اس سے آگے نہیں بڑھ سکتے، پھر دنیا نے اس سے توبہ کر لی، اس لیے اب علم کا چرچا ہے۔ یہ ایک مفید بحث ہے ، اور اس سے بہت اچھے نتائج برآمد ہوئے ہیں۔ انسان نے علم کی حدیں جان لی ہیں۔ جب دنیا پیدا ہوئی تو گویا علم کی حدود جاننے کا عمل شروع ہو گیا۔ اس میں عرض کر رہا ہوں کہ جیسے ہی آپ اس کی تعریف کریں گے، اس کے بعد آپ کو علم میں اصل اثر ملے گا۔ ان کی تعریف یہ ہے کہ ہمارے تمام علم کی بنیاد دراصل ہمارے حواس کا مشاہدہ اور تجربہ ہے۔ یہاں ہر دلیل کو اپنی بنیاد تلاش کرنی پڑتی ہے۔ اس سے آگے، جب ایک چھلانگ لگائی جائے گی، تو آپ اپنی حدوں سے باہر ہو جائیں گے۔ جو علم ہم اپنے حواس کے ذریعے حاصل کرتے ہیں وہ ہماری بنیاد ہے، پھر اللہ۔ ہمیں عقل دی ہے کہ جو علم ہم اپنے حواس سے حاصل کرتے ہیں، اس علم کو اپنے شعور کی ساخت میں متعین کرنا، اسے ممتاز کرنا، اسے نام دینا، درجہ بندی کرنا، یہ تمام صلاحیتیں موجود ہیں، یعنی یہ کیسا علم ہے؟ ہمارے حواس سے جو کچھ حاصل ہوتا ہے اس کے بعد ہماری عقل دو کام کرتی ہے: یا تو وہ ان چیزوں کو جاننا شروع کر دیتی ہے جو ہمارے شعور کی ساخت میں واجب ہوتی ہیں، مثلاً ہم جانتے ہیں کہ فعل بغیر کسی مضمون کے نہیں۔ ہو سکتا ہے کہ ہم نے فعل کو دیکھا ہو اور اس کا مشاہدہ کیا ہو، ہمارے باطن میں ہمارے شعور کی ساخت اسے عقلی طور پر لازم کر دیتی ہے کہ اب اس کا بھی مضمون ہونا چاہیے یا اثر دیکھا ہے تو سبب بھی ہونا چاہیے۔ اگر ہم اثر کو دیکھیں تو اثر ہونا چاہیے۔ گویا فرض عقلی ہے۔ عقل نے اسے واجب کر دیا۔ دوسری بات کیا ہے؟ وجہ امکانات پیدا کرتی ہے۔ یہ ایک امکان ہے۔ یہ ہے ارباب تصوف نے جسے زوال سے تعبیر کیا ہے یا جسے افلاطون نے عالمگیر مثال قرار دیا ہے۔ یہ دراصل عقلی امکانات کا اظہار ہے۔ اسی طرح جدید سائنس نظریہ ارتقاء کو بیان کرتی ہے۔ یہ عقلی امکانات کا اظہار ہے۔ عقلی امکانات تحقیق کا موضوع ہیں۔ یہ مشاہدے سے بنایا جائے گا یا بنایا جائے گا۔ عمل ایک جیسا ہو گا۔ اسے الگ نہیں کیا جا سکتا۔ یہ ہمارے علم کی آخری حد ہے۔ اس سے بڑھ کر علم کا کوئی دوسرا ذریعہ نہیں ہے۔ اس سے آگے جو کام ہے وہ دراصل وہ کام ہے جسے کرنے کی انسان میں ایک اور صلاحیت ہے۔ یہ دیا جاتا ہے کہ وہ حقائق سے چیزیں نکالتا ہے اور اس کی بنیاد پر وہ تخیل کی دنیا بناتا ہے، پھر تخیل کی دنیا دیکھنے میں اتنی ہی خوبصورت ہوتی ہے جتنی کہ کوئی بے نظیر ناول پکڑتا ہے۔ اس میں کوئی حقیقت نہیں ہے اگر حقیقت نہیں ہے تو یہ علم کی حد ہے، چنانچہ اس کو سمجھایا کہ اس دنیا میں انسان کے لیے صحیح رویہ یہ ہے کہ وہ صبر و تحمل کے ساتھ خدا کے تمام فیصلوں پر شکر ادا کرتے ہوئے اپنا فرض ادا کرے اور اس بات پر مطمئن رہے کہ روح افزا جام کی لکیروں میں جو مٹھاس چھپی ہوئی ہے وہ کل ظاہر ہو جائے گی، انشاء اللہ یہ دعا ایمان اور ایمان کے ساتھ زندہ باد۔ واقعہ اس لیے کیوں بیان کیا گیا ہے تاکہ اللہ کے رسول اور صحابہ کرام جو اس وقت موجود ہیں اللہ کے فیصلوں، اللہ کے ارادوں، اللہ کے اعمال اور اللہ کی سنت کے بارے میں دیے گئے علم کو بھی سمجھ سکیں اور اس سے؟ اگر وہ سمجھ جائیں تو ان کے لیے ذلت کا کوئی امکان نہیں لیکن اگر وہ اس حد سے تجاوز کریں تو اللہ کا فتویٰ وہی ہے۔ فی قلوبیت سے مراد وہ لوگ ہیں جن کے دلوں میں کجی ہے، پھر وہ اسے اپنی دنیا، اپنی عزت، اپنا امتیاز بنا لیتے ہیں اور پھر کہتے ہیں کہ علم ایسا ہے، چیزوں کو اس طرح سمجھا جاتا ہے، اس کی کوئی حقیقت نہیں، بالکل ایک ہے۔ وہ سمجھتے ہیں کہ آپ نے لکڑی کی ٹانگ بنائی ہے اور یہ سوچ رہے ہیں کہ آپ اس پر کھڑے ہیں کسی چیز پر نہیں۔

    By Amjad Izhar
    Contact: amjad.izhar@gmail.com
    https://amjadizhar.blog

  • Humanity’s Conscious Efforts: A Legacy of Greatness

    Humanity’s Conscious Efforts: A Legacy of Greatness

    The text explores the contrast between the unchanging aspects of nature and the achievements of human consciousness, particularly highlighting the impact of philosophers and scientists throughout history. It emphasizes the significance of human effort in shaping societies and creating advancements, using the Turkish Revolution of 1924 under Atatürk as a prime example of a successful, lasting societal transformation. The writing also touches on the tension between religious fervor and secular progress within Muslim societies, examining how religious leaders sometimes prioritized personal gain over societal advancement. Finally, the text advocates for a reevaluation of intellectual heritage and urges a move toward modernization and democracy, inspired by Atatürk’s legacy

    Study Guide: Exploring Human Consciousness, Revolutions, and Intellectual Heritage

    Quiz

    Answer each question in 2-3 sentences.

    1. According to the text, what is the difference between nature’s processes and human-made divisions of time?
    2. What does the text suggest is the primary source of the wonders and masterpieces in the universe beyond natural landscapes?
    3. Who does the text identify as truly deserving of gratitude for their contributions to humanity’s progress?
    4. What is the significance of the UN and the UN Human Rights Charter, as mentioned in the text?
    5. What is meant by the phrase “fake paradise” as opposed to “earthly paradise” in this context?
    6. What was the most impactful event of 1979, according to the text, and why?
    7. How did the author view Kamal Ataturk’s 1924 revolution in Turkey?
    8. According to the text, what was the British government’s motive for suppressing Communist movements in India?
    9. How did the “architects” of the Pakistani nation view Ataturk’s revolution, according to the text?
    10. What does the author suggest regarding the future of the Turkish Revolution?

    Quiz Answer Key

    1. The text states that nature’s processes like the rising and setting of the sun are eternal and beyond human control, while human-made divisions of time, like months and years, are a product of human consciousness and not relevant to nature itself.
    2. The text suggests that the primary source of wonders and masterpieces in the universe, beyond natural landscapes, is the pure human struggle and the efforts of human consciousness, not the work of gods or transcendent forces.
    3. The text identifies great philosophers and scientists as truly deserving of gratitude because they have made miraculous contributions to humanity that even those claiming divine power could not achieve.
    4. The UN and the UN Human Rights Charter are presented as concrete examples of human progress, showing that humanity has not only advanced through innovative inventions but also intellectually and consciously, establishing a platform for global human rights.
    5. “Fake paradise” likely refers to the promise of a blissful afterlife, while “earthly paradise” signifies that true happiness and fulfillment are found in the real-world, through human achievement and struggles.
    6. The most impactful event of 1979 was the rise of madujis which highlighted the importance of the Indian Ocean, however, 1979 was the year that the text writer became most impressed by the revolution of Kemal Ataturk in 1924.
    7. The author views Ataturk’s 1924 revolution in Turkey as an amazing one that cut the roots of the caliphate system based on personal dictatorship and moved its direction towards democracy and an elected parliament.
    8. The British government suppressed Communist movements in India out of a need to counter their influence and prevent their spread, using the idea of “special combinations” in order to entangle the communist ideas with other religious zealotry and slogans.
    9. The “architects” of the Pakistani nation, despite using religion for personal and political gain, still admired Ataturk’s revolution and recognized its intellectual greatness and the blessings of the revolution, even in the midst of the Caliphate movement.
    10. The author suggests that even after the Turkish Revolution has suffered many conservative attacks, it will eventually rise again with a new climate and shine as a role model for other Muslim nations, as envisioned by Iqbal.

    Essay Questions

    1. Discuss the author’s perspective on the relationship between nature, human consciousness, and the creation of “masterpieces” in the universe.
    2. Analyze the significance of Kamal Ataturk’s revolution in 1924, according to the author, and its implications for Muslim nations.
    3. Explore the concept of “earthly paradise” presented in the text, and how it differs from traditional notions of heaven or spiritual salvation.
    4. Evaluate the author’s critique of religious institutions and their role in hindering or promoting human progress.
    5. Considering the text’s perspective, how might one interpret the call for a reevaluation of intellectual heritage, and what are its implications for national identity?

    Glossary of Key Terms

    • Human Consciousness: The state of being aware of and responsive to one’s surroundings; the collective awareness and understanding of humanity.
    • Eternity: Infinite or unending time; a state that is timeless and without beginning or end.
    • Caliphate: The rule or reign of a caliph; the political-religious leadership of a Muslim state.
    • Kayapult: A term from the text meaning “revolution” or “upheaval,” often referring to a fundamental shift or change in society or thinking.
    • Intellectual Heritage: The cumulative body of knowledge, ideas, and traditions passed down through generations within a specific group or society.
    • Rabbani: A term used in the text, possibly meaning divine, sacred, or of the Lord.
    • Jawar Bhata: A term used in the text, possibly referring to the ebb and flow or tides; a significant or impactful occurrence.
    • Madujis: A term used in the text with no explicit definition but seems to refer to specific notable events or people in relation to the Indian Ocean in the year 1979.
    • Tehreek Caliphate: A movement focused on the revival or establishment of the caliphate.
    • Moderate Revolution: Used in reference to the Turkish Revolution; a revolution promoting moderate views or a middle path of social reform.

    Atatürk’s Revolution: A Model for Modernity

    Okay, here’s a briefing document summarizing the key themes and ideas from the provided text:

    Briefing Document: Analysis of “Pasted Text”

    Date: October 26, 2023

    Subject: Analysis of a philosophical and historical reflection on nature, human consciousness, and societal progress with particular emphasis on the Ataturk revolution.

    Executive Summary:

    This text presents a multi-faceted reflection on the nature of reality, human achievement, and the importance of intellectual and societal progress. It contrasts the immutable laws of nature with the transformative power of human consciousness and effort. The author celebrates human achievements, particularly in science and philosophy, while critiquing the reliance on outdated religious systems. The text culminates in a strong endorsement of Mustafa Kemal Atatürk’s revolution in Turkey as a model for other Muslim nations, emphasizing secularism, modernization, and patriotic identity over outdated religious concepts. The text is a passionate plea for intellectual re-evaluation and progress.

    Key Themes and Ideas:

    1. Nature vs. Human Consciousness: The text establishes a stark contrast between the indifferent, cyclical nature of the universe and the dynamism of human consciousness.
    • Nature’s Passivity: “Nature or nature has nothing to do with when which day, month or year comes and when it passes…”. The text emphasizes that nature operates without purpose or concern for human constructs like calendars or anniversaries. Events like birth, death, and revolutions are just part of its ongoing cycle.
    • Human Agency: Human achievements are presented as a direct result of conscious effort and struggle: “The wonders and masterpieces that have been created in this universe through pure human struggle…”. The text highlights human contributions in science, philosophy, and societal advancement.
    1. Critique of Religious Mysticism and “Fake Paradise”: The author implicitly critiques religious beliefs that focus on a heavenly afterlife, arguing they distract from the pursuit of earthly improvement and progress.
    • “Fake Paradise”: The text implicitly contrasts a heaven-focused worldview with the possibility of achieving a “real heaven on earth” through human effort and good deeds. It suggests that a focus on mystical beliefs leads to a passive acceptance of difficulties, rather than striving for real improvement.
    • Value of Philosophers and Scientists: “The real and truly deserving of our gratitude are those great philosophers and scientists of the world who have done miracles in the universe…”. This directly contrasts the text’s view with any idea of divine or transcendental power, praising instead tangible human achievements.
    1. Emphasis on Intellectual and Moral Struggle: The author highlights the importance of intellectual and moral struggles for human advancement.
    • “Humanitarian Deeds and Struggles”: The author emphasizes that the world can be improved through positive human action. This contrasts with accepting difficult circumstances as a predetermined fate.
    • Quote from “Sargasht Adam”: The lines “Mila mood swings, I did not say anything under the sky. I removed stone idols from Kaaba and sometimes I made idols into Haram” imply a constant reevaluation of ideas and a challenging of outdated beliefs. The text is advocating for action to achieve change, even if it means upending tradition.
    1. The Ataturk Revolution as a Model: The author praises the secular and modernizing revolution led by Mustafa Kemal Atatürk in Turkey.
    • Secularism and Democracy: “the amazing revolution of the world’s greatest man Kamal Ataturk in 1924, which has forever cut the root of the caliphate system… and moved its direction to democracy.” This is presented as a definitive break from outdated theocratic systems towards a more progressive governance structure.
    • Patriotic Identity: “…your real nationality is not an outdated, conceptual and spiritual nationality but a patriotic nationality like other civilized nations.” This emphasizes a civic identity rooted in national belonging over religious identification.
    • A Model for Muslim Nations: The author suggests that the Ataturk revolution is a paradigm for other Muslim-majority nations seeking modernization and self-determination. The text encourages readers to learn from the Turkish example: “We too, like the Turks, will have to reevaluate our rational and conscious heritage one day.”
    1. Re-evaluation of Intellectual Inheritance: The author calls for a critical assessment of established beliefs and traditions.
    • Call to Readers: The author urges “friends who are interested in the knowledge and research of Darwish” to consider what “intellectual and conscious heritage of ours” needs reevaluation, connecting the ideas to a specific intellectual tradition.
    • Iqbal’s Influence: The text repeatedly refers to Iqbal’s desire to re-evaluate the intellectual and religious heritage of his time: “Whose Iqbal wanted to re-evaluate like the Turks??” and “The foundation of Reconstruction Of Religous Thought in Islam is the modern kayapult of Ata Turk and Turks”.
    1. Critique of Religious Manipulation for Political Gain: The text is critical of figures who use religion for their own political ends, even if they cannot deny the value of the Ataturk revolution: “What an interesting and amazing story it is for the Pakistani nation that each of its two architects kept using religion as much as political and social for their personal or national interests… but… the voices of their conscience did not let them deny the intellectual greatness of Ataturk…”.

    Conclusion:

    The text is a powerful and impassioned call for human progress driven by reason, conscious effort, and a rejection of outdated religious dogmas. It promotes the Ataturk revolution as a historical turning point and a model for achieving a more just, modern, and prosperous society. The author encourages self-reflection, critical reevaluation of established beliefs, and active participation in shaping a better future. The text makes a case for a “real heaven on earth” achievable through hard work and dedication to ideals of secularism, democracy, and patriotism.

    Human Ingenuity and the Turkish Revolution

    Frequently Asked Questions

    1. What is the text’s perspective on the role of nature versus human effort in shaping our world?
    2. The text emphasizes a stark contrast between nature’s indifference and the significance of human consciousness and struggle. It argues that natural phenomena like the changing of seasons are simply consistent, while human constructs such as calendars, festivals, and even political revolutions are the products of deliberate human effort. The text credits human ingenuity, specifically scientific and philosophical achievements, as the main force behind progress, while nature provides a neutral background.
    3. According to the text, what are some examples of human achievements that deserve gratitude?
    4. The text expresses gratitude for the contributions of great philosophers, scientists, thinkers, and political leaders who have shaped human consciousness. It specifically praises advancements from Greek philosophy to modern scientific achievements, as well as the creation of human rights frameworks like the UN Charter. These achievements, it argues, are responsible for improving living conditions and intellectual understanding. The text values accomplishments that lead to a better earthly experience, rather than solely focusing on otherworldly rewards.
    5. How does the text view the concept of “heaven” and its relation to human action?
    6. The text contrasts a “dream-like” heaven after death with the potential for an “earthly paradise” created through human actions. It suggests that focusing on real-world achievements and humanitarian deeds provides a more meaningful and tangible form of satisfaction. The text implicitly criticizes the idea of relying solely on the promise of an afterlife and encourages readers to focus on improving our current existence.
    7. What are the main ideas conveyed by the lines from “Sargasht Adam” quoted in the text?
    8. The lines from “Sargasht Adam” suggest a theme of intellectual and spiritual independence and iconoclasm. The speaker claims to have challenged established norms, removing idols from holy places and advocating for new perspectives. The lines also reflect a journey of intellectual exploration, from Greek thought to various Eastern cultures. The speaker emphasizes their commitment to seeking truth and wisdom, suggesting that true progress comes from challenging and reshaping societal norms. The last lines reference a commitment to the honor of “this earth.”
    9. What significance does the text place on the Turkish Revolution of 1924 led by Kemal Ataturk?
    10. The text regards the Turkish Revolution of 1924 as an incredibly important event that fundamentally changed the Islamic world by abolishing the Caliphate system and establishing a democratic, secular state with an elected parliament. The text views Ataturk’s revolution as a model for other Muslim nations, emphasizing its modern, progressive nature and the shift from spiritual nationalism to patriotic nationalism. It celebrates its impact on the national identity of Turks and its shift from an old, autocratic structure to a new, modern system.
    11. Why does the text criticize the Caliphate system?
    12. The text portrays the Caliphate system as an outdated and dictatorial form of personal rule that is detrimental to Muslim societies. It contrasts it with the democratic ideals of the Turkish Revolution, highlighting the latter’s emphasis on elected parliaments and patriotic nationalism. The text criticizes any system that is rooted in personal dictatorship rather than democracy, suggesting the Caliphate had failed its people due to its outdated nature.
    13. How does the text view the role of religion in politics?
    14. The text portrays the architects of Pakistan using religion for political purposes to increase their power, acknowledging their success, but also highlights that their consciences recognized Ataturk’s intellectual greatness as well as the blessings of the Turkish Revolution. It critiques the use of religious fervor for political ends, viewing it as a means to personal or national gain rather than a genuine attempt to improve the condition of society. The text advocates for a separation of religion and politics.
    15. What is the core message of the text regarding the intellectual and political legacy that should be reevaluated?
    16. The text advocates for a reevaluation of the intellectual and rational heritage within Muslim societies, drawing inspiration from the Turkish Revolution, which prioritized progress and democracy over outdated religious systems. The text implies that Muslim societies should critically examine their inherited traditions and political structures, encouraging a move toward modernity, rationality, and democratic principles. It calls on its readers to be intellectually honest and to recognize the legacy of progress in the world, like the Turkish Revolution, while critiquing the legacy of outmoded authoritarian theocracies.

    Atatürk’s Revolution and the Future of Islam

    Okay, here is a timeline and cast of characters based on the provided text:

    Timeline of Main Events

    • Ancient Times (Unspecified): The text reflects on the nature of time and the universe, contrasting nature’s unchanging rhythms with human constructs like calendars and festivals. It posits that human consciousness and struggle are the sources of advancements and meaning.
    • Ancient Greece (Unspecified): Greek philosophers are mentioned as foundational figures in the progression of human thought.
    • 1924: Mustafa Kemal Atatürk leads a revolution in Turkey, abolishing the Caliphate and establishing a secular, democratic state. This is presented as a pivotal event with lasting significance.
    • Pre-1947: The text references the destruction in India in 1947.
    • 1979: The year 1979 is noted as significant for the author’s personal experiences, witnessing the importance of various events in relation to the Indian Ocean.
    • Time of the Caliphate Movement in India: The Caliphate Movement, led by the Ali brothers, is described as a time of religious fervor and political maneuvering in India. The author notes that despite the religious fervor, some leaders admired Ataturk’s revolution.
    • Present (Time of writing): The author reflects on the legacy of Atatürk’s revolution in Turkey, noting ongoing attempts to undermine it by conservative elements, while predicting a resurgence of the revolution’s principles. The author also calls for a reevaluation of intellectual heritage in Islamic nations similar to what Turkey undertook.
    • Future (Implied): The author anticipates that Turkey’s secular, democratic revolution will serve as a model for other Muslim nations in the future, which is also presented as Iqbal’s wish.

    Cast of Characters

    • Nature: Not a person, but a force representing the unchanging universe and the source of physical phenomena, contrasted with human-made concepts.
    • Great Philosophers and Scientists: A general group encompassing thinkers throughout history, particularly from ancient Greece, who advanced human knowledge and understanding.
    • Western Scientists, Thinkers, and Political Leaders: A broad group credited with transforming humanity through innovations and establishing concepts like the UN and human rights, but specifically not Ghalib who is mentioned later in the text.
    • Ghalib: Mentioned in the context of a poet, he is used as a contrasting example, someone whose “hobbies” are inconsequential compared to great leaders and thinkers. His poetry is referenced with a specific poem to highlight the contrast between worldly and heavenly concerns.
    • “Sargasht Adam”: The title of the poems from which excerpts are provided. His poetry explores themes of rebellion, questioning established religions, and spreading wisdom, with imagery of travel and struggle. He seems to be a symbol of humanistic thought.
    • Kamal Ataturk: The central figure of the text. The leader of the Turkish Revolution in 1924. He is portrayed as a great visionary who abolished the Caliphate, established a secular state, and is presented as a positive model for other Muslim nations.
    • Iqbal: A figure who admired the Turkish Revolution and desired for a similar reevaluation of intellectual heritage in other Muslim nations. The text notes that Iqbal’s wish has yet to be fulfilled. He wrote the “Hindi Anthem.”
    • The Ali Brothers: Leaders of the Caliphate Movement in India. They are described as experiencing emotional distress due to the abolition of the caliphate in Turkey, though the author stresses that they did not express sympathy for the system.
    • Conservative Spokesman of the Turks: A collective group representing those attempting to undermine Atatürk’s revolution in contemporary Turkey. They are described as opposing the secular and democratic nature of the revolution.
    • “Two Architects” of Pakistan: Implied to be political leaders of Pakistan. The text suggests that they used religion for their personal and political gain but that they secretly admired Ataturk and the Turkish Revolution.
    • Darwish: The author himself. A person interested in human history and philosophy, and concerned about the intellectual heritage of Muslim nations.

    Let me know if you have any other requests!

    Atatürk’s Legacy and the Modernization of Turkey

    The text explores the contrast between the unchanging aspects of nature and the achievements of human consciousness, particularly highlighting the impact of philosophers and scientists throughout history. It emphasizes the significance of human effort in shaping societies and creating advancements, using the Turkish Revolution of 1924 under Atatürk as a prime example of a successful, lasting societal transformation. The writing also touches on the tension between religious fervor and secular progress within Muslim societies, examining how religious leaders sometimes prioritized personal gain over societal advancement. Finally, the text advocates for a reevaluation of intellectual heritage and urges a move toward modernization and democracy, inspired by Atatürk’s legacy.

    Human Consciousness: Shaping Our World

    Human consciousness is presented as a powerful force that has shaped the world, responsible for the creation of culture, and for the advancements of human civilization [1]. The sources contrast the works of human consciousness with the natural world, and suggest that nature is indifferent to human constructs of time and events [1, 2].

    Here are some key aspects of human consciousness discussed in the sources:

    • Creation of Culture: Human consciousness is responsible for the creation of systems like months, years, days, festivals, and anniversaries [1]. These are seen as human efforts to create structure and meaning [1].
    • Human Struggle and Progress: The sources emphasize the “greatness of human conscious efforts and human struggle” and the wonders that have been created through it [1]. Without human endeavors, life would be difficult and desolate [1].
    • Intellectual and Scientific Achievements: The text highlights the importance of philosophers, scientists, thinkers, and political leaders who have advanced human consciousness and have led to significant changes in human life [3].
    • Reversal of Humanity’s Shape: Through innovative inventions, intellectual and conscious platforms, and human rights charters, humanity’s shape has been reversed and improved [3].
    • A Source of Pride: The accomplishments of human consciousness are presented as something humanity can be proud of [1]. The source contrasts these achievements with the desolate state of existence that would exist without these advancements [1].
    • Influence on Religion: The text discusses how some leaders have used religion for political and social purposes, but also acknowledges that their conscience led them to respect the intellectual achievements of others, such as Ataturk [4].
    • Reevaluation of Intellectual Heritage: The need for reevaluating the intellectual and conscious heritage is highlighted [4]. This is tied to the idea of progress and the need to question established norms and ideas [4].
    • A Distinction from Nature: The sources emphasize a clear distinction between nature and human consciousness. Nature is portrayed as a force that is indifferent to the passage of time and the events in human history [2]. In contrast, human consciousness is a driving force of change and progress [1].
    • Earthly Paradise: The idea of creating a “real heaven on earth” through humanitarian efforts and struggles is presented as a goal that surpasses seeking a dreamlike heaven [5].

    Nature’s Indifference to Humanity

    Natural processes are depicted in the sources as separate from and indifferent to human constructs and events [1, 2]. Here’s a breakdown of how the sources discuss natural processes:

    • Nature’s Timelessness: Nature is presented as being unconcerned with the passage of time, including days, months, and years, and with human events like births, deaths, and revolutions [1]. The sources say that nature has “nothing to do with when which day, month or year comes and when it passes” [1]. The rotation of days and the changing of days and nights are described as “masterpieces of nature, which have been the same since eternity” [1].
    • Indifference to Human Events: Nature is depicted as being unaffected by human activities and structures such as festivals and anniversaries [2]. The sources state that “it doesn’t matter to nature… if none of these happens” [2]. This suggests that natural processes operate independently of human concerns and calendars.
    • Celestial Cycles: The rising and setting of the sun, and the phases of the moon, are given as examples of natural phenomena that are constant and independent of human perception. The moon is described as appearing sometimes small and sometimes full, but in fact it is neither, just as the sun neither rises nor sets [1]. These celestial cycles are presented as “masterpieces of nature” that occur without human influence [1].
    • Contrast with Human Consciousness: The sources present a distinct contrast between natural processes and the creations of human consciousness [2]. While nature operates according to its own timeless rhythms, human consciousness is responsible for creating culture, structure, and meaning. The sources also suggest that nature’s beauty exists independently from human structures and that only human conscious efforts have the power to bring about change [2].

    In summary, the sources portray natural processes as consistent, timeless, and unaffected by human actions, existing in contrast to the dynamic and transformative power of human consciousness [1, 2].

    Human Achievement: Conscious Effort and Progress

    Human achievements are portrayed in the sources as the result of conscious effort and struggle, and they are contrasted with the natural world, which is presented as indifferent to human activity [1]. The sources suggest that human accomplishments are a source of pride and have fundamentally altered the course of human existence [1, 2].

    Here are some key areas of human achievement discussed in the sources:

    • Cultural Constructs: The creation of systems like months, years, days, festivals, and anniversaries are described as “a masterpiece of the efforts of human consciousness” [1]. These constructs are seen as ways that humans have created structure and meaning in the world, in contrast to the timelessness of nature [1, 3].
    • Scientific and Intellectual Progress: The sources emphasize the contributions of philosophers, scientists, thinkers, and political leaders [2]. These individuals are credited with doing “miracles in the universe” and leading humanity to its current heights through innovative inventions and intellectual advancements [2].
    • Political and Social Advancements: The establishment of the United Nations and the UN Human Rights Charter are highlighted as significant political achievements that have had a positive impact on humanity [2]. The sources suggest these accomplishments have provided platforms for intellectual and conscious growth and have reversed the “shape of humanity” [2].
    • Overcoming Desolation: The sources suggest that without the achievements of human consciousness, life would be “difficult, desolate” [1]. The implication is that human struggle and achievement are necessary to overcome a bleak existence and to find satisfaction [1].
    • Creating an Earthly Paradise: The text speaks of creating a “real heaven on earth” through humanitarian deeds and struggles [4]. This suggests that human effort can lead to tangible improvements in life, offering a different perspective than relying on the promise of a heavenly afterlife [4].
    • Reevaluation of Heritage: The sources advocate for a reevaluation of intellectual and conscious heritage, suggesting that progress requires questioning and updating established norms and ideas [5]. This is linked to the idea of constant improvement and a forward-looking approach [5].
    • Examples of Transformative Leadership: The sources present Mustafa Kemal Ataturk as an example of a transformative leader whose revolution in Turkey led to modernization and a shift towards democracy [6]. Ataturk’s revolution is portrayed as a model for other Muslim nations [5, 7].

    In summary, the sources present human achievements as a testament to the power of consciousness and a driving force for progress. These accomplishments are not merely material but include intellectual, cultural, political, and social progress, all of which contribute to a richer, more meaningful existence [1, 2, 4]. The sources also underscore the importance of continually reevaluating and building upon the achievements of the past to further advance human civilization [5].

    Atatürk’s Revolution: A Model for Muslim Nations

    Ataturk’s revolution is presented in the sources as a significant and transformative event that serves as a model for other Muslim nations [1, 2]. The revolution is described as having modernized Turkey and shifted its direction towards democracy [1]. Here’s a breakdown of key aspects of Ataturk’s revolution, as presented in the sources:

    • Overthrowing the Caliphate System: The revolution is credited with cutting the root of the caliphate system, which was based on personal dictatorship, from the world of Islam [1]. This move is portrayed as a crucial step towards a more democratic and modern society [1].
    • Establishment of Democracy: Ataturk’s revolution shifted Turkey’s governance towards an elected parliament, which is seen as a major advancement for the nation and a model for other Muslim nations [1]. This change is linked to a broader movement towards modernity and progress.
    • Promoting Patriotic Nationality: The revolution promoted a patriotic nationality, as opposed to an outdated, conceptual, and spiritual nationality [1]. This suggests a shift towards a more secular and civic-based identity, aligning with the norms of other civilized nations [1].
    • Intellectual Greatness: Even those who used religion for political and social purposes were unable to deny the intellectual greatness of Ataturk and the blessings of the Turkish Revolution [2].
    • A Role Model: The revolution is presented as a role model for other Muslim nations, with the sources suggesting that these nations should re-evaluate their intellectual heritage like the Turks [2, 3].
    • Enduring Impact: The revolution is described as having been established on its foundations for a century, despite attempts to undermine it by conservative elements within Turkey [4]. The sources predict that the moderate revolution will continue to rise with new lights and serve as a role model for other Muslim nations as per Iqbal’s wishes [3, 4].
    • Contrast with Traditional Systems: The revolution is implicitly contrasted with the “rotten” Caliphate system, which the source notes even staunch supporters of that system could not defend [2].
    • Significance for Iqbal: The sources suggest that the foundation of the book Reconstruction Of Religious Thought in Islam is based on the modern revolution of Ataturk and the Turks. Iqbal’s desire to reevaluate intellectual heritage, as the Turks did, is also emphasized [2].
    • Relevance for Pakistani Nation: The sources note that both of the architects of Pakistan, despite using religion for their political and social aims, could not deny the intellectual greatness of Ataturk [2]. The sources suggest that the Pakistani nation has an interesting and amazing story in the context of Ataturk’s revolution, given the actions and ideas of its founders [2].

    In summary, Ataturk’s revolution is presented as a pivotal moment in the history of Turkey, marked by the overthrow of the Caliphate, the establishment of a democratic system, and the promotion of a patriotic national identity. The revolution’s legacy is portrayed as an inspiration and a model for other Muslim nations, with its enduring impact and transformative nature still relevant today [2, 3]. The source emphasizes its importance as a key example of human achievement and progress [1].

    Atatürk’s Revolution and Modern Political Ideologies

    Political ideologies are discussed in the sources primarily through the lens of nationalism, democracy, and the rejection of personal dictatorship, particularly in the context of Ataturk’s revolution. The sources also touch on the use of religion for political purposes and the tension between traditional and modern systems of governance.

    Here’s a breakdown of the political ideologies and concepts discussed in the sources:

    • Patriotic Nationalism: The sources promote the idea of patriotic nationality as a modern and progressive concept, contrasting it with outdated notions of spiritual or religious nationality [1, 2]. The Turkish revolution is presented as an example of a movement that successfully shifted its focus to a patriotic identity, with the idea that Turks should have Turkish nationality and Arabs should have Arab nationality [2]. This is framed as aligning with other civilized nations and as a break from older, more religiously-defined systems of identity [1, 2]. The source suggests that even Hindi Muslims should embrace a Hindi patriotic nationality [2].
    • Democracy and the Rejection of Dictatorship: The sources strongly support democracy and the idea of elected parliaments, portraying them as significant advancements in governance [1]. Ataturk’s revolution is specifically praised for cutting the roots of the caliphate system, which is described as a form of personal dictatorship [1]. This demonstrates a preference for systems of government that involve the representation of the people and a rejection of autocratic rule [1].
    • Secularism: The emphasis on patriotic nationality and the rejection of the caliphate system indicate a leaning towards secularism, where political identity is separated from religious or spiritual identity [1, 2]. The sources suggest that modern, civilized nations have moved away from religiously-defined identities towards more civic-based ones [2].
    • Use of Religion for Political Purposes: The sources acknowledge that some leaders use religion for political and social purposes [3]. However, the sources also point out that even these leaders often recognize the intellectual greatness of those who promote more modern and secular ideas, like Ataturk [3]. The use of religion to manipulate political discourse is shown as a tool to gain support and advance personal or national interests [3].
    • Clash of Traditional and Modern Systems: The sources discuss a clear contrast between traditional, outdated systems of governance, such as the caliphate, and modern systems, such as democratic republics [1]. The caliphate is referred to as a “rotten system” [3]. The sources favor modern systems, highlighting the importance of progress, innovation, and intellectual advancement [1, 3].
    • The British Government’s Role: The source notes that the British government used “jihadi slogans” to counter communist influence, which is mentioned as an example of political maneuvering for national interests [2].
    • Iqbal’s Perspective: The source presents the views of Iqbal, who is shown as supporting the reevaluation of intellectual heritage like the Turks and admiring the modernizing influence of Ataturk’s revolution [3].

    In summary, the sources advocate for a move away from religiously-based political systems and towards more secular, democratic, and patriotic forms of government. The sources present Ataturk’s revolution as a key example of successful modernization and a model for other nations to follow. The role of political leaders using religion is also addressed, while emphasizing the importance of intellectual and conscious advancements over outdated systems of governance.

    Nature vs. Human Creation

    The sources present a distinct contrast between natural phenomena and human constructs, emphasizing that nature operates independently of human activity while human creations are the result of conscious effort and struggle [1, 2].

    Here’s how the sources differentiate between the two:

    • Nature’s Timelessness vs. Human-Made Time: The text describes nature as being constant and unaffected by human concepts of time [1]. The rising and setting of the sun and the phases of the moon are cited as examples of natural phenomena that occur without regard for human calendars [1]. In contrast, the division of time into months, years, days, and the establishment of festivals and anniversaries are described as “a masterpiece of the efforts of human consciousness” [2]. This highlights that these constructs are human inventions to create structure and meaning [2].
    • Nature’s Indifference vs. Human Consciousness: The sources suggest that nature is indifferent to human activities, with the text stating that “it doesn’t matter to nature or nature if none of these happens, goes or comes” [2]. This implies that nature functions according to its own laws, regardless of human existence or constructs. On the other hand, the sources portray human constructs as deliberate and purposeful, resulting from the application of “human conscious efforts” [2].
    • Natural Landscapes vs. Human Infrastructure: The sources contrast the “beautiful landscapes or deserts” of nature with human infrastructure [2]. It is suggested that apart from natural beauty, there is little that humanity can be proud of without human efforts [2]. This further emphasizes that human achievements are distinct from the natural world and are a result of deliberate effort.
    • Nature’s Desolation vs. Human Achievement: The text suggests that without human constructs, life would be “difficult, desolate,” implying that human achievement is essential to improve life beyond the natural state [2]. This is juxtaposed with the idea that nature does not offer inherent meaning or satisfaction, so humans must actively create these.
    • Human Effort as a Source of Pride: The sources suggest that the “wonders and masterpieces” created through human struggle, as well as intellectual and conscious effort, are things that humanity can be proud of [2, 3]. This is implicitly contrasted with nature, which is presented as lacking any intention and agency, which is what humans bring to the world and what creates purpose.
    • Real Heaven on Earth: The sources suggest that humans can create a “real heaven on earth” through their efforts, contrasting this with a heavenly afterlife that is detached from the physical world [4]. This indicates that human actions and constructs are capable of generating meaning, satisfaction and paradise, rather than relying on nature or a divine plan.

    In summary, the sources draw a clear distinction between the natural world and human-made constructs. Nature is depicted as timeless, indifferent, and constant, while human constructs are portrayed as conscious, deliberate, and transformative. The text suggests that human achievements are what make life meaningful, providing purpose and direction in contrast to the indifference of the natural world.

    1979: A Year of Reflection

    The year 1979 is significant in the text as a point of reflection for the author, marking a time of learning and observation of important events [1]. Here’s a breakdown of its significance:

    • Madujis and the Indian Ocean: The year 1979 is noted for the emergence of “madujis” which highlighted the importance of the “Jawar Bhata” (likely referring to tidal phenomena or some other event related to water levels) of the Indian Ocean [1]. This suggests that the year was marked by particular occurrences that drew attention to the natural world and its influence.
    • Destruction and Historical Context: The author notes that the region of India was torn apart by destruction in 1947 and that the “sparks” of this destruction are still felt by new generations [1]. This provides historical context for the year 1979, situating it in a broader timeline of regional conflict and its lasting impacts, implying that the events of 1979 should be understood through the lens of this historical trauma.
    • The Impact of the 1924 Revolution: The author contrasts the events of 1979 with the revolution led by Kamal Ataturk in 1924, which is described as having a significant positive impact [1]. The 1924 revolution is presented as a model of positive change, a point of comparison for assessing the events of 1979 and other historical moments. The 1924 revolution established a democracy and cut the root of the caliphate system from the world of Islam [1].
    • Personal and Cultural Significance: The author highlights that, personally and as a Muslim, the revolution of Kamal Ataturk impressed him the most, specifically the shift towards democracy and the rejection of the caliphate system. This underscores how the author’s personal experiences and cultural background shape his perception of historical and political events and provides another lens for understanding the significance of 1979 [1]. The author calls the revolution “amazing.”
    • Reflection on Intellectual Inheritance: The author uses the observations of 1979 to prompt reflection on the intellectual and conscious heritage of the author’s culture. This connects the personal experience of the year with the broader theme of intellectual progress and self-evaluation [2]. The author states, “We too, like the Turks, will have to reevaluate our rational and conscious heritage one day” [2]. This highlights the idea that historical moments, such as those of 1979, should prompt societies to reflect on and improve their own intellectual foundations.

    In summary, the year 1979 is presented as a significant year for the author, marked by specific events and observations that prompt reflection on both personal and historical experiences. The events of 1979 serve as a point of comparison for both the negative impact of the destruction of 1947 and the positive changes of Ataturk’s revolution, and they highlight the importance of evaluating cultural and intellectual heritage. The author’s cultural and personal experiences contextualize his reflections on the significance of 1979 and other historical events.

    Religion, Politics, and Modernity in Turkey

    Religion plays a complex and multifaceted role in the events described in the sources, acting as both a source of conflict and a tool for political and social change. Here’s a breakdown of the role of religion:

    • Critique of Religious Authority: The sources critique traditional religious systems, specifically the caliphate, which is described as a form of “personal dictatorship” [1]. The text praises the Turkish Revolution for cutting the roots of this system, framing it as a positive move towards democracy [1]. This indicates a rejection of religious authority in political governance. The sources emphasize that a “rotten system” based on religion should not be supported. [2]
    • Religion as a Tool for Political Gain: The text suggests that some leaders use religion for political and social purposes, exploiting religious sentiments to gain support [2]. However, the sources also note that these leaders often recognize the intellectual achievements of those who promote secular and modern ideas [2]. This points to a manipulative use of religion to further personal or national interests.
    • Rejection of Spiritual Nationality: The sources advocate for a shift away from spiritual or religious nationality to a more patriotic nationality [1]. The text presents this shift as a move toward progress and civilization, implying that religiously-defined national identities are outdated and problematic [1]. The author notes that “your real nationality is not an outdated, conceptual and spiritual nationality but a patriotic nationality like other civilized nations.” [1]
    • Religious Conflict and Division: The sources briefly allude to the British government’s use of “jihadi slogans” to counter communist influence, highlighting how religion can be manipulated to fuel conflict [3]. The text also notes that the region of India was torn apart in 1947, suggesting religious conflict might have contributed to the destruction, though this is not explicitly stated [1].
    • The Caliphate Revival: The sources describe the “Tehreek Caliphate” as a religious movement that caused grief to the Ali brothers, who were leaders in the movement [2]. The text notes that despite the religious fervor of this movement, figures like the Ali brothers did not show sympathy for the caliphate system, demonstrating a critique of the religious system [2].
    • The Contrast with Modernization: The sources present Ataturk’s revolution as a model of modernization and secularism, contrasting it with religious systems of governance. The revolution is praised for moving the direction of the country to democracy, and it serves as an example of how a nation can successfully modernize while moving away from religious authority [1]. The author indicates that Ataturk’s revolution is the only one of its kind that has lasted for a century, even with attacks from conservatives [4].
    • Iqbal’s Viewpoint: The text suggests that Iqbal, despite using religion for political means, admired the Turkish Revolution and wanted a similar reevaluation of intellectual heritage [2]. The sources state that Iqbal’s “Reconstruction Of Religious Thought in Islam” was based on the modern kayapult of Ata Turk and Turks. [2]

    In summary, the role of religion in the described events is complex. While it is portrayed as a powerful force capable of mobilizing people and influencing political outcomes, it is also critiqued for its potential to be used for personal gain and to maintain outdated systems of governance. The sources favor a move towards secular, democratic, and patriotic forms of identity, while acknowledging that religion can have significant impacts on the political landscape, even for people who oppose such religiously-defined systems. The author’s personal experiences are shown to be influenced by these various uses of religion, shaping his perspective on the events he describes.

    Rethinking National Identity: A Turkish Model

    The author urges a reevaluation of the intellectual and conscious heritage of his own culture, specifically in light of the reforms enacted by the Turkish Revolution [1, 2]. This reevaluation is prompted by the author’s observations and reflections on historical events, particularly the revolution led by Kamal Ataturk in 1924 and the events of 1979 [1]. The author’s desire to reevaluate their intellectual heritage is directly inspired by the Turkish experience of modernizing and secularizing their nation [2].

    Here’s a breakdown of what this intellectual heritage entails, according to the sources:

    • Rejection of outdated systems: The author suggests that their intellectual heritage must be examined in light of the need to move beyond outdated systems, such as the caliphate, and embrace modern, democratic values [1, 2]. The caliphate is described as a form of “personal dictatorship” [1]. This indicates a need to reject systems of governance based on religious authority.
    • Shift from spiritual to patriotic nationality: The author calls for a move away from a “conceptual and spiritual nationality” to a “patriotic nationality” [1]. This implies a reevaluation of how national identity is defined, advocating for a more secular, civic-based approach rather than one rooted in religious or spiritual affiliations. This is something the Turks have done and that the author believes is necessary.
    • Modernization and progress: The author views the Turkish Revolution as a model of modernization [1, 2]. This suggests that the intellectual heritage must be reevaluated to align with progress, innovation, and the principles of democracy [1]. The author highlights the Turkish shift to an elected parliament, which offers an alternative to religious forms of governance [1].
    • Secular values: The text highlights the importance of secularism and the separation of religious and political powers [1, 2]. The Turkish Revolution is presented as a positive example of secularism, and this implies that the author’s intellectual heritage must be reevaluated to incorporate secular values and institutions [1].
    • Conscious and Rational Heritage: The author specifically refers to the need to reevaluate their “rational and conscious heritage,” which suggests a move towards a more logical, evidence-based, and self-aware understanding of their culture and traditions [2]. This is presented in contrast to outdated religious ideas.
    • Iqbal’s Influence: The author references Iqbal’s desire for a similar reevaluation, suggesting that even figures who used religion for political means recognized the importance of the Turkish model [2]. The author calls Iqbal’s book, The Reconstruction of Religious Thought in Islam as being based on the modern shift in thought that came from Ataturk’s revolution [2].

    The author urges his readers to consider “what is that intellectual and conscious heritage of ours? Whose Iqbal wanted to re-evaluate like the Turks?” This indicates that the author’s intellectual heritage includes religious and traditional political thought that must be critically examined [2]. The author suggests that just as the Turks reevaluated their heritage to modernize, so too must his culture reconsider its intellectual inheritance to promote progress and a more relevant and forward thinking national identity [1, 2]. The author’s focus is on a conscious and rational reevaluation that moves away from outdated, spiritually-defined concepts towards modern and secular forms of governance [1, 2].

    Earthly Paradise vs. Fake Paradise

    The author contrasts the concept of a “fake paradise” with an “earthly paradise” to emphasize the importance of human effort and achievement in the real world, as opposed to relying on religious promises of an afterlife [1, 2]. Here’s how the author differentiates between the two:

    • “Fake paradise”: This concept refers to the traditional religious idea of heaven as a reward after death, often presented as a place of eternal bliss and satisfaction [1]. The author implies that this notion of paradise is a “dream-like dream,” suggesting that it is not grounded in reality and does not require any action or effort in the present world [3]. The author uses the term “fake paradise” to indicate that the promise of a heaven after death is not as valuable or meaningful as the achievements that humans can accomplish on earth [2]. The author also suggests that the notion of heaven after death can be used to distract from real issues in this life [1].
    • “Earthly paradise”: This refers to the idea that a fulfilling and meaningful existence can be created in the real world through human effort and consciousness [1, 2]. This “earthly paradise” is achieved through concrete actions and the application of human intellect, such as the advancements in science, philosophy, and politics [4]. The author also suggests that an “earthly paradise” is achieved through humanitarian deeds and struggles [3]. The text suggests that the wonders created through human struggle make life meaningful and offer real satisfaction, whereas relying on the idea of heaven after death leads to a desolate existence [1]. The author indicates that the “earthly paradise” is a “masterpiece of greatness and human consciousness” [2].

    The author contrasts these two ideas by highlighting that the “earthly paradise” is achievable through human efforts and tangible actions that produce concrete results, while the “fake paradise” is merely a hope or a dream with no foundation in reality [1-3]. The text suggests that true progress and satisfaction come from working to improve the world and achieve real-world goals rather than waiting for a promised afterlife [1, 4].

    The author uses the contrast between the “fake paradise” and the “earthly paradise” to emphasize the value of human struggle and achievement [1]. The author’s emphasis on human actions and the importance of the real world align with his admiration of the Turkish Revolution, which is presented as a model of progress through human consciousness [2, 4]. He also emphasizes that the true path to a fulfilling life is found in active participation in the world, creating an “earthly paradise” through real achievements, rather than waiting passively for a “fake paradise” after death [1, 3].

    Atatürk’s Revolution: A Model for Modern Muslim Nations

    Ataturk’s revolution is presented as a highly significant event in the sources, serving as a model for modernization and a rejection of outdated systems [1, 2]. The revolution’s importance is highlighted through several key points:

    • Rejection of the Caliphate: The revolution is praised for cutting the roots of the caliphate system, which is described as a “personal dictatorship,” from the world of Islam [1]. This act is viewed as a move toward democracy and a rejection of religious authority in political governance [1]. The author sees this as a crucial step for any Muslim nation seeking progress [2].
    • Shift to Democracy: The revolution moved the country towards an elected parliament, emphasizing a move from traditional, religiously-based governance to a modern, democratic system [1]. This shift to a more secular and representative form of government is a crucial aspect of the revolution’s significance [1]. The text suggests this transition is essential for progress and civilization [1, 3].
    • Model for Modernization: Ataturk’s revolution is presented as a model of modernization and secularism for other Muslim nations [1, 4, 5]. The author emphasizes that other Muslim societies should follow this example and re-evaluate their own “intellectual inheritance” [2]. The revolution provides a concrete example of how a nation can modernize while moving away from religious authority [1, 2].
    • Inspiration for Intellectual Reevaluation: The revolution inspired figures like Iqbal to call for a reevaluation of their own intellectual and conscious heritage [2]. The author notes that Iqbal’s book The Reconstruction of Religious Thought in Islam was based on the modern shift in thought that came from Ataturk’s revolution [2]. This reevaluation includes a shift from a spiritual to a patriotic nationality, which is viewed as a move toward progress and civilization [1-3].
    • Enduring Legacy: Despite attacks from conservative elements, the revolution has endured for a century, demonstrating its strength and importance [4]. The author suggests the revolution’s enduring nature proves its validity as a model for other nations [4, 5]. The text notes that intellectuals who wish to overthrow this revolution are being pushed out of cultural centers, suggesting its continuing influence and popular support [4].
    • Contrast with “Fake Paradise”: The revolution is aligned with the concept of an “earthly paradise” by emphasizing the importance of human effort and achievement in the real world, as opposed to relying on the idea of a “fake paradise” in the afterlife [1, 6]. This reinforces that Ataturk’s revolution is about creating a better life through real world, tangible actions [6].

    In summary, Ataturk’s revolution is significant because it represents a shift towards democracy, secularism, and modernization for Muslim societies. The author uses the revolution as a lens through which to critique traditional religious systems and emphasize the importance of human agency and achievement. The revolution serves as a concrete example of how a nation can successfully modernize while moving away from outdated systems and religious authority, and is presented as an ideal model for other Muslim nations to follow [5].

    Atatürk’s Revolution: A Legacy Contested

    The sources present a clear contrast in viewpoints regarding Ataturk’s legacy in Turkey, specifically highlighting the tension between supporters of his modernizing reforms and those who seek to undermine them [1]. Here’s a breakdown of the contrasting views:

    • Positive View: Modernization and Progress [1-4]
    • Ataturk’s revolution is seen as a positive force for modernization, secularism, and democracy [2, 3].
    • His actions, such as abolishing the caliphate and establishing an elected parliament, are viewed as essential steps towards progress and civilization [2].
    • The revolution is considered a model for other Muslim nations seeking to modernize and move away from outdated systems [4].
    • The enduring nature of the revolution, even a century later, is presented as evidence of its strength and importance [1].
    • The revolution is aligned with the concept of an “earthly paradise,” emphasizing the importance of human effort and achievement in the real world [2].
    • Negative View: Conservative Opposition [1]
    • Conservative elements within Turkey have been actively trying to undermine Ataturk’s revolution for the last quarter century [1].
    • These groups seek to overturn the liberal, secular, and democratic aspects of the revolution [1].
    • They are described as trying to “dig the foundations” of the revolution and “topple it down,” suggesting a fundamental opposition to Ataturk’s vision [1].
    • These opposing viewpoints are not supported by the educated classes, in major cultural centers like Istanbul and Ankara, and are being pushed out [1].

    Key Points of Conflict:

    • Secularism vs. Religious Authority: At the heart of the contrasting viewpoints is the tension between the secular principles of Ataturk’s revolution and the desire of some groups to reassert religious authority in governance [1, 2].
    • Modernization vs. Traditionalism: The conflict also highlights a clash between the forces of modernization and those who are clinging to traditional, outdated systems and values [2, 3].
    • Democracy vs. Dictatorship: Ataturk’s revolution is praised for dismantling the caliphate system, described as a “personal dictatorship,” and establishing a democratic parliament. The opposing viewpoint would therefore favor a return to autocratic forms of governance [1, 2].

    Overall:

    The sources emphasize that despite the ongoing attacks, Ataturk’s revolution and legacy are enduring. The text suggests that the positive view of Ataturk’s legacy is supported by the educated classes and is aligned with the forces of progress. The conflict highlights the ongoing struggle between different visions for Turkey’s future, but the text implies the liberal, secular, and democratic elements of the Turkish Revolution will ultimately prevail [1].

    Atatürk’s Revolution: A Model for Muslim Nations

    The author has a strongly positive perspective on Atatürk’s legacy, viewing his revolution as a crucial and transformative event for Turkey and a model for other Muslim nations [1-3]. Here’s a breakdown of the author’s perspective:

    • Admiration for Modernization and Secularism: The author admires Ataturk’s revolution for its commitment to modernization and secularism [1, 3]. The revolution is seen as a rejection of the outdated caliphate system, which is described as a “personal dictatorship” [1]. This rejection is viewed as a step towards democracy and a move away from religiously-based governance [1].
    • Emphasis on Democracy and Progress: The author praises Ataturk for establishing an elected parliament, emphasizing a shift towards a modern and representative form of government [1]. This move is seen as crucial for progress and civilization, aligning with the author’s view that an “earthly paradise” is achievable through human effort [1, 4].
    • Atatürk as a Model for Muslim Nations: The author explicitly presents Ataturk’s revolution as a model for other Muslim nations to follow [2, 3, 5]. The revolution is presented as a concrete example of how a nation can modernize and move away from religious authority [1, 2]. The text suggests that Muslim societies should re-evaluate their own “intellectual inheritance” in light of Ataturk’s achievements [2].
    • Rejection of Conservative Opposition: The author notes that there are conservative elements within Turkey that have been trying to undermine Ataturk’s revolution for the last quarter century [3]. However, the author makes it clear that these groups do not represent the educated classes and are being pushed out of cultural centers [3]. This suggests the author believes that the revolution’s ideals are ultimately stronger and will prevail [3].
    • Alignment with “Earthly Paradise”: The author’s view of Ataturk’s legacy is closely linked to the concept of an “earthly paradise” [1]. By emphasizing the importance of human effort and achievement in the real world, the author sees Ataturk’s revolution as creating a better life through tangible actions and progress, rather than relying on the idea of a “fake paradise” in the afterlife [1, 4].
    • Enduring Significance: The author highlights the enduring nature of Ataturk’s revolution, noting that it has lasted for a century despite attacks [3]. This longevity underscores its importance and relevance, suggesting that its principles of liberalism, secularism, and democracy will ultimately triumph [3].

    In summary, the author views Ataturk as a visionary leader whose revolution was a pivotal moment in the history of the Muslim world, offering a path towards modernization, democracy, and progress. The author admires the revolution’s secular and humanistic values, contrasting them with traditional systems of religious authority and viewing them as a way to achieve an “earthly paradise” [1, 4]. The author makes it clear that he believes Ataturk’s revolution will endure and serve as a continuing model for other Muslim nations [3, 5].

    Atatürk’s Revolution: A Model for Modern Muslim Societies

    The author has a strongly positive assessment of Atatürk’s 1924 revolution, viewing it as a pivotal moment of modernization and progress, particularly for the Muslim world [1-3]. The author sees the revolution as a crucial step away from outdated systems and towards a more enlightened future [1, 2].

    Here are the key points of the author’s assessment:

    • Rejection of the Caliphate: The author praises the revolution for dismantling the caliphate system, which is described as a “personal dictatorship,” and replacing it with a more democratic system [1, 2]. This move is viewed as essential for progress and a move away from religiously-based governance [1, 2].
    • Shift to Democracy: The revolution’s establishment of an elected parliament is seen as a significant step towards a modern and representative form of government [1, 2]. The author emphasizes the importance of this transition for the advancement of society [1, 2].
    • Model for Modernization: The author presents Ataturk’s revolution as an ideal model for other Muslim nations seeking to modernize [1-3]. The revolution provides a concrete example of how a society can move away from religious authority and towards a secular, democratic system [1-3].
    • Inspiration for Intellectual Reevaluation: The revolution inspired figures like Iqbal to call for a reevaluation of their own intellectual and conscious heritage [2]. The author notes that Iqbal’s book The Reconstruction of Religious Thought in Islam was based on the modern shift in thought that came from Ataturk’s revolution [2].
    • Enduring Legacy: The author highlights that the revolution has endured for a century despite attacks from conservative elements [3]. The author also notes that intellectuals who wish to overthrow this revolution are being pushed out of cultural centers [3]. This suggests that the revolution’s ideals are ultimately stronger and will prevail [3].
    • Alignment with “Earthly Paradise”: The author’s view of Ataturk’s revolution is closely linked to the concept of an “earthly paradise” [1]. By emphasizing the importance of human effort and achievement in the real world, the author sees Ataturk’s revolution as creating a better life through tangible actions and progress, rather than relying on the idea of a “fake paradise” in the afterlife [1].
    • Contrast with Traditional Systems: The author contrasts Ataturk’s revolution with the “rotten” system of the caliphate, emphasizing the revolution’s modern, forward-thinking nature [2]. The author suggests that the revolution’s rejection of outdated systems is essential for the progress of Muslim nations [2, 3].
    • Rejection of Conservative Opposition: The author makes it clear that the conservative opposition within Turkey is not aligned with the educated classes, who support the revolution’s values of liberalism, secularism, and democracy [3].

    In summary, the author views Atatürk’s 1924 revolution as a transformative event that embodies the ideals of modernization, democracy, and secularism. The author believes it serves as an important model for other Muslim nations to follow in order to move away from outdated systems and create a better future through human effort and progress [1-3]. The author believes that the revolution will endure despite opposition and continue to serve as an inspiration for other Muslim societies [3, 4].

    Atatürk’s Revolution and the End of the Caliphate

    Atatürk’s 1924 revolution had a profound and decisive impact on the caliphate, effectively dismantling it and fundamentally altering the political landscape of the Muslim world [1, 2]. The sources highlight the following key points regarding the revolution’s impact on the caliphate:

    • Abolition of the Caliphate: The revolution is credited with definitively cutting “the root of the caliphate system” based on personal dictatorship [1]. This action is portrayed as a major step towards modernity and progress, signaling a clear break from the traditional system of religious authority [1, 2].
    • Rejection of Personal Dictatorship: The caliphate system is described as a form of “personal dictatorship” [1, 2]. By dismantling this system, Atatürk’s revolution aimed to establish a more democratic and representative government [1, 2].
    • Shift Towards Democracy: The revolution replaced the caliphate with an elected parliament, moving the country towards a more modern, secular, and democratic structure [1]. This shift is emphasized as a critical step for the advancement of society [2].
    • End of Religious Governance: The revolution is presented as a rejection of religiously based governance, with a focus on the importance of establishing a secular state [2]. This transition marked a significant change from the traditional role of the caliphate in Islamic societies [2].
    • Inspiration for Modernization: The dismantling of the caliphate by Atatürk’s revolution is presented as an inspirational model for other Muslim nations seeking to modernize [1, 2]. It demonstrated a move away from outdated systems and towards a more progressive future [2].
    • Contrast with “Rotten System”: The author contrasts Ataturk’s revolution with the “rotten” system of the caliphate, emphasizing the revolution’s modern, forward-thinking nature [2].
    • Criticism of Caliphate Supporters: The author notes that during the time of the Caliphate revival movement in India, leaders like the Ali brothers were deeply affected by the caliphate’s weakening. However, the author points out that these leaders never showed sympathy for the system but rather opposition and contempt for it [2].

    In summary, Atatürk’s 1924 revolution had a revolutionary impact on the caliphate by abolishing it entirely and replacing it with a secular, democratic system [1, 2]. This action is viewed as a pivotal moment in the history of the Muslim world, setting an example for other nations seeking to modernize and move away from religious rule and personal dictatorships [1, 2]. The revolution is portrayed as a definitive break from the past, with the caliphate system seen as an outdated and oppressive system that was rightly overthrown [1, 2].

    Iqbal and Atatürk’s Revolution

    The sources suggest that Iqbal viewed Atatürk’s revolution as a significant and positive event, particularly in its implications for other Muslim nations. Here’s a breakdown of Iqbal’s perspective as presented in the sources:

    • Inspiration for Reevaluation: Iqbal was inspired by Atatürk’s revolution to call for a reevaluation of the intellectual and conscious heritage of Muslim societies [1]. This suggests that Iqbal saw the revolution as a catalyst for critical self-reflection and change within the Muslim world.
    • Model for Modernization: The author indicates that Iqbal saw the Turkish revolution as a model for other Muslim nations [2]. This suggests that Iqbal believed that Atatürk’s actions offered a concrete path for Muslim societies to modernize and move beyond outdated systems.
    • Rejection of Outdated Nationalism: Iqbal’s famous “Hindi Anthem” is mentioned in the context of rejecting outdated, conceptual and spiritual forms of nationality in favor of a more patriotic, civic nationalism [3]. This aligns with Atatürk’s revolution which rejected the caliphate in favor of a modern, secular, and democratic state and is presented by the author as a model for other Muslim nations to follow.
    • Foundation for Intellectual Work: The author notes that Iqbal’s book, The Reconstruction of Religious Thought in Islam, was based on the modern shift in thought that came from Atatürk’s revolution [1]. This suggests that Iqbal saw the revolution as a pivotal moment of change that had far-reaching intellectual and philosophical implications.
    • Emphasis on National Identity: Iqbal’s view that “Hindi Muslims have Hindi patriotic nationality” [3] aligns with the idea of a modern, secular state, a concept promoted by Ataturk’s revolution. This reinforces the idea that Iqbal saw the revolution as a means for Muslim societies to reframe their national identities in a modern context.
    • Role Model for Muslim Nations: According to the author, Iqbal wished for other Muslim nations to see the Turkish revolution as a role model [2, 4]. This desire underscores the significant influence that Iqbal believed the Turkish revolution had on the future direction of the Muslim world.
    • Admiration for the Revolution: The author implies that Iqbal admired the revolution [1], and that Iqbal’s son considered the foundation of Reconstruction of Religious Thought in Islam to be rooted in the kayapult (modern shift in thought) of Ataturk and the Turks [1].

    In summary, Iqbal, as portrayed in the sources, saw Atatürk’s revolution as a pivotal event that called for a reevaluation of Muslim societies’ intellectual and national identities. Iqbal believed the revolution offered a model for modernization and progress, advocating for a move away from outdated systems and toward a more secular and democratic future for other Muslim nations [1, 2]. He viewed the revolution as a source of inspiration and intellectual renewal that could guide Muslim societies toward a more progressive future.

    Atatürk’s Enduring Revolution

    The text assesses Atatürk’s lasting impact as profound and enduring, particularly in the context of his 1924 revolution and its implications for both Turkey and the wider Muslim world. Here’s a breakdown of the text’s assessment:

    • Enduring Revolution: The text emphasizes that Atatürk’s revolution has stood firm for a century despite attempts by conservative elements to undermine it [1]. This highlights the strength and resilience of the revolution’s foundations. The author notes that the revolution continues to be a source of inspiration for reform, and this enduring legacy is a key aspect of its lasting impact [1, 2].
    • Model for Other Nations: The text suggests that Atatürk’s revolution was intended to serve as a role model for other Muslim nations seeking to modernize and break free from outdated systems [1-3]. The author notes that Iqbal hoped that other Muslim nations would see the Turkish revolution as a model for reform [2]. This underscores the revolution’s broader impact beyond Turkey’s borders.
    • Rejection of Conservatism: The text notes that, even a century later, conservative elements in Turkey have tried to dismantle the revolution but have been largely unsuccessful [1]. The author observes that intellectuals who wish to overthrow the revolution are being pushed out of major cultural centers [1]. This suggests that the core values of the revolution, namely liberalism, secularism, and democracy, continue to hold sway and exert a lasting influence [1].
    • Intellectual and Conscious Heritage: The text highlights that the revolution prompted a reevaluation of intellectual and conscious heritage, not just in Turkey, but also in other Muslim societies [3]. This lasting intellectual impact is attributed to the revolution’s progressive principles.
    • Continued Relevance: Despite the passing of time, the text indicates that the revolution’s impact is far from diminished, and that it will likely continue to be a guiding force in the future [1]. The text suggests that the revolution will rise again with new lights and ultimately serve as a role model as Iqbal hoped [1, 2]. The author implies that the revolution’s ideals will continue to be relevant and influential [1, 2].

    In summary, the text’s assessment of Atatürk’s lasting impact is that his 1924 revolution has been a transformative event with an enduring legacy. The revolution continues to serve as a model for other Muslim nations, while its core values of secularism and democracy remain resilient in Turkey. The text makes it clear that the revolution will continue to be a source of inspiration and influence in the years to come.

    The Future of the Turkish Revolution

    The author views the Turkish Revolution’s future with optimism and confidence, despite past and present challenges [1]. Here’s a breakdown of the author’s perspective on the revolution’s future, drawing from the sources and our conversation history:

    • Resilience and Endurance: The author emphasizes that the revolution has endured for a century despite attempts by conservative elements to undermine it [1]. This demonstrates the revolution’s strong foundations and its ability to withstand opposition [1]. This suggests that the revolution’s core principles are deeply ingrained and will likely persist.
    • Rejection of Conservative Opposition: The author notes that intellectuals who wish to dismantle the revolution are being pushed out of major cultural centers [1]. This indicates that the revolution’s values of liberalism, secularism, and democracy continue to hold significant sway and that those who oppose these values are losing influence [1].
    • Renewal and Reemergence: The author believes that the revolution will “rise again with new lights,” suggesting that it will experience a resurgence and continue to be a guiding force in the future [1]. This implies that the revolution’s ideals are not static, but rather will evolve and adapt to new contexts while still maintaining its core values.
    • Model for Muslim Nations: The author believes that the revolution will ultimately serve as a role model for other Muslim nations in their respective territories, as was Iqbal’s wish [1, 2]. This demonstrates the author’s conviction that the revolution’s impact is not limited to Turkey but extends to the wider Muslim world [2].
    • Iqbal’s Vision: The author states that the revolution’s future aligns with Iqbal’s desire for other Muslim nations to follow Turkey’s example [1, 2]. This connects the revolution’s future with a broader vision of progress and reform in the Muslim world, giving it a sense of purpose that transcends national borders.
    • Positive Trajectory: The author implies that the revolution’s future trajectory is positive, with the expectation that it will not only endure but also gain renewed strength and influence [1]. The author’s tone is optimistic and projects a sense of confidence in the revolution’s ability to overcome current challenges.

    In summary, the author’s view of the Turkish Revolution’s future is highly optimistic. They believe that despite facing challenges from conservative forces, the revolution will not only endure but will also experience a renewal, reemerging with greater strength and influence. The author sees it as a continued source of inspiration and a model for other Muslim nations, thus emphasizing its lasting and widespread impact [1, 2].

    By Amjad Izhar
    Contact: amjad.izhar@gmail.com
    https://amjadizhar.blog

  • Al Riyadh Newspaper, March 11, 2025 : Islamic Schools, Diplomacy, and National Pride

    Al Riyadh Newspaper, March 11, 2025 : Islamic Schools, Diplomacy, and National Pride

    These articles from the Al Riyadh newspaper cover a variety of topics, with a significant focus on Saudi Arabia’s celebration of its national Flag Day, highlighting its historical significance and cultural importance. The sources also report on various local and international events, including sports news, cultural initiatives like the Saudi Film Festival and King Abdulaziz Library’s efforts to empower women, and regional developments such as humanitarian aid in Jordan and Tanzania, and the ongoing situations in Palestine and Syria. Furthermore, there are articles discussing economic trends, specifically fluctuations in oil prices, and social initiatives, such as mosque renovations and efforts to combat animal cruelty. Finally, some articles provide local news and features related to Ramadan activities and market developments in Saudi cities.

    The Saudi National Flag: A Symbol of Unity and History – Study Guide

    I. Core Concepts and Significance:

    • Historical Roots: Trace the origins of the Saudi flag back to the establishment of the First Saudi State in 1727 and its connection to the Islamic call for unity.
    • Religious Symbolism: Explain the meaning and significance of the Shahada (“There is no god but Allah; Muhammad is the messenger of Allah”) as the central element of the flag.
    • The Sword: Describe the addition of the sword and its symbolism of justice and strength. Note the direction of the sword’s blade.
    • Color Significance: Detail the meaning and importance of the green color of the flag in Islamic tradition and its representation of growth and prosperity.
    • National Identity: Analyze how the flag serves as a powerful emblem of Saudi national identity, unity, pride, and belonging for its citizens, both within the Kingdom and abroad.
    • Evolution of the Flag: Outline the key changes and modifications the flag has undergone throughout the history of the Saudi states, including the reign of King Abdulaziz Al Saud.
    • Respect and Protocol: Explain the regulations and restrictions surrounding the use and display of the Saudi flag, emphasizing the prohibition of lowering or disrespecting it due to its sacred inscription.
    • International Representation: Describe the role of the flag in representing the Kingdom in international forums, embassies, and diplomatic events, highlighting its significance in asserting sovereignty and projecting influence.
    • Cultural Influence: Discuss how the flag has become a source of inspiration in Saudi culture, poetry, and artistic expression, embodying national sentiments and values.
    • Modern Significance: Understand the contemporary relevance of the flag as a symbol of the Kingdom’s enduring values, historical depth, and aspirations for the future, as reflected in Vision 2030.

    II. Key Events and Figures:

    • 1727: Establishment of the First Saudi State and the early use of a green flag with the Shahada.
    • Imam Muhammad bin Saud: His role in establishing the First Saudi State and the initial flag.
    • 1744: Date associated with the consolidation of the First Saudi State and its religious mission.
    • King Abdulaziz Al Saud: His crucial role in unifying the Kingdom and the modifications made to the flag during his reign, including the addition and positioning of the sword.
    • 1902: King Abdulaziz’s recapture of Riyadh and the raising of the Shahada flag with a new addition.
    • 1926: Unification of Hejaz and the return to a rectangular green flag with the white Shahada.
    • 1932: Official establishment of the Kingdom of Saudi Arabia and the adoption of the current flag design.
    • 1357 AH (1938 AD): Formal regulations issued by King Abdulaziz concerning the raising of the Saudi flag.
    • 1393 AH / 1973 AD: Official system of the flag issued, specifying its dimensions and details.
    • Ali al-Qarni and Rayanah Barnawi: Their 2023 space mission and raising of the Saudi flag in space.

    III. Quiz:

    1. What is the central inscription on the Saudi national flag and what does it signify?
    2. Describe the symbolism of the sword on the Saudi flag and when it was formally added.
    3. Why is the Saudi flag always green, and what does this color traditionally represent?
    4. Explain why the Saudi flag is never flown at half-mast, even during periods of national mourning.
    5. How did King Abdulaziz Al Saud contribute to the evolution of the Saudi national flag during his reign?
    6. What is the historical significance of the year 1727 in relation to the Saudi national flag?
    7. In what ways does the Saudi national flag represent the national identity and unity of Saudi Arabia?
    8. Describe the protocol that Saudi embassies follow regarding the display of the national flag in foreign countries.
    9. How has the Saudi national flag served as a source of inspiration in Saudi poetry and culture?
    10. What is the significance of the Saudi flag being raised at international conferences and summits?

    IV. Quiz Answer Key:

    1. The central inscription is the Shahada: “There is no god but Allah; Muhammad is the messenger of Allah.” It is the fundamental declaration of Islamic faith and signifies the religious foundation of the Kingdom.
    2. The sword symbolizes justice, strength, and the defense of the Islamic faith and the nation. A single sword below the Shahada was formally added by King Abdulaziz Al Saud to represent a new era of unity and sovereignty.
    3. The Saudi flag is always green because green is a color of great significance in Islam, often associated with Paradise, growth, and prosperity. It also historically represented the banners of early Islamic states.
    4. The Saudi flag is never flown at half-mast because the Shahada inscribed upon it is considered sacred and must always be flown at its full height as a sign of respect for the Islamic creed.
    5. King Abdulaziz Al Saud played a key role in the flag’s evolution by standardizing its design. He initially used a square green flag with the Shahada and a sword, later adopting the rectangular shape and the specific positioning of the sword below the Shahada.
    6. The year 1727 marks the establishment of the First Saudi State. The sources indicate that a green flag bearing the Shahada was used during this early period, signifying the foundational link between the flag and the origins of the Saudi nation.
    7. The Saudi flag embodies national identity by visually representing the Kingdom’s core values: Islam, unity, justice, and historical heritage. It serves as a focal point for national pride and a symbol of belonging for all Saudi citizens.
    8. Saudi embassies around the world raise the Saudi flag prominently to symbolize the Kingdom’s sovereignty, independence, and diplomatic presence. It underscores Saudi Arabia’s standing and influence on the international stage.
    9. The Saudi national flag has inspired numerous expressions of national sentiment in Saudi poetry and culture, serving as a potent symbol of patriotism, loyalty to the leadership, and the nation’s historical journey.
    10. Raising the Saudi flag at international conferences and summits confirms the Kingdom’s presence and influence as a significant political and economic power on the global stage, reflecting its active participation in international affairs and organizations.

    V. Essay Format Questions:

    1. Analyze the evolution of the Saudi national flag from the establishment of the First Saudi State to its current design, discussing the key historical events and symbolic changes that shaped its form and meaning.
    2. Evaluate the significance of the religious symbolism embedded in the Saudi national flag, particularly the Shahada, and discuss how this symbolism influences national identity, values, and international relations.
    3. Discuss the ways in which the Saudi national flag serves as a unifying symbol for the diverse population of Saudi Arabia, both within the Kingdom and among Saudis living abroad, considering its historical, religious, and cultural resonance.
    4. Examine the regulations and cultural protocols surrounding the use and display of the Saudi national flag, explaining the rationale behind these rules and their importance in upholding the flag’s sanctity and national significance.
    5. Assess the role of the Saudi national flag in representing the Kingdom on the international stage, particularly in diplomatic relations, international organizations, and global events, and discuss how it projects Saudi Arabia’s image and influence.

    VI. Glossary of Key Terms:

    • Shahada: The Islamic declaration of faith: “There is no god but Allah; Muhammad is the messenger of Allah.” It is the central tenet of Islam and the inscription on the Saudi flag.
    • Tawhid: The concept of the oneness of God in Islam. The Shahada is a declaration of Tawhid.
    • Sovereignty: Supreme power or authority; in this context, the flag symbolizes the Kingdom’s independent authority and control over its territory and affairs.
    • National Identity: A sense of belonging to a nation, sharing common values, culture, history, and often language. The flag is a key visual representation of this identity.
    • Allegiance (Wala’): Loyalty and devotion to the leadership and the nation, a sentiment deeply connected to the national flag.
    • Unity (Talahum/Wahda): The state of being united or joined as a whole. The flag symbolizes the unification of the different regions into the Kingdom of Saudi Arabia.
    • Justice (Adl): Fairness and moral integrity, symbolized by the sword on the flag.
    • Strength (Quwwa): The capacity to exert force or resist opposition, also symbolized by the sword.
    • Historical Depth (Al-Umq al-Tarikh): The long and significant history of the Saudi state, reflected in the evolution of the flag.
    • National Pride (Iftikhar bil-Hawiyya al-Wataniyya): A feeling of satisfaction and esteem associated with one’s national identity, often evoked by the sight of the national flag.

    Briefing Document: Analysis of “Al Riyadh” Newspaper Excerpts (March 11, 2025)

    This briefing document summarizes the main themes and important ideas presented in the provided excerpts from the March 11, 2025 issue of the Saudi Arabian newspaper “Al Riyadh.” The analysis focuses on key events, social and cultural discussions, economic updates, international relations, and sports news highlighted in the selected articles.

    1. National Identity and “Flag Day”

    • Theme: The prominent theme across several articles is the significance of the Saudi national flag, particularly in commemoration of “Flag Day.” The flag is presented as a deeply symbolic representation of national unity, the Islamic faith, historical roots, and the Kingdom’s values.
    • Key Ideas/Facts:Flag Day commemorates the establishment of the first Saudi state in 1139 AH (1727 AD), rooted in the values of unity and Islam.
    • The flag’s green color, the “Shahada” (declaration of faith: “There is no god but Allah; Muhammad is the messenger of Allah”), and the sword symbolize unity, justice, strength, and the Kingdom’s historical journey.
    • The current design of the flag was officially adopted in 1393 AH (1973 AD), featuring a green rectangle, the “Shahada” in white, and a drawn sword beneath it pointing towards the flagstaff.
    • The flag’s history traces back to the banner of the first Saudi state, which was green with the “Shahada.” The sword was later added during the reign of King Abdulaziz to symbolize strength and justice during the unification of the Kingdom.
    • The flag is more than just a symbol; it embodies national identity, sovereignty, and a rich history. As stated, “The Saudi flag is not just a flag waving in the sky, but a deep-rooted and noble message that carries within it the identity of faith, sovereignty, and ancient history.”
    • There are strict regulations regarding the use and handling of the flag to preserve its sanctity and respect. “The Ministry of Interior has previously warned against prohibitions on the use of the flag of the Kingdom, including: raising the flag of the Kingdom faded or in a bad condition, when it becomes old from use that does not permit its continued use.”
    • The flag is a source of pride for Saudi citizens, representing their belonging, love, and loyalty to the leadership and the nation. “Every citizen, male and female, cherishes in their hearts the flag bearing the ‘Shahada of Tawhid,’ taking pride in the national identity, and expressing feelings of cohesion, love, and loyalty stemming from the spirit of belonging and allegiance to the leadership and the homeland.”

    2. International Relations and Diplomacy

    • Theme: The excerpts touch upon Saudi Arabia’s active role in international diplomacy, particularly in the Middle East and the ongoing conflict in Ukraine.
    • Key Ideas/Facts:Meeting with Ukrainian President: Crown Prince Mohammed bin Salman received Ukrainian President Volodymyr Zelenskyy in Jeddah, underscoring the Kingdom’s interest in peace efforts. Zelenskyy acknowledged Saudi Arabia’s “pivotal role” in the Middle East and the world.
    • Diplomatic Presence: The Saudi flag is raised high at Saudi embassies worldwide, symbolizing the Kingdom’s sovereignty, independence, and diplomatic presence on the international stage. “In all parts of the world, Saudi embassies raise the Saudi flag high to be a witness to the Kingdom’s sovereignty and independence, reflecting its diplomatic presence and confirming its strength and standing on the international arena.”
    • Role in International Organizations: The Saudi flag is present at international conferences and summits of organizations such as the United Nations (UN), G20, Organization of Islamic Cooperation (OIC), and the Gulf Cooperation Council (GCC), highlighting the Kingdom’s influence as a political and economic power.
    • Humanitarian Aid: The Saudi flag serves as a symbol of hope and trust in humanitarian aid efforts. Dr. Khalid Al-Subaan of the “Amal” volunteer program noted that the presence of the Saudi flag reassures beneficiaries and enhances the sense of responsibility among Saudi volunteers, projecting a positive national image internationally.

    3. Cultural Significance and the Arts

    • Theme: The excerpts explore the deep cultural significance of the national flag and the role of art, particularly poetry and cinema, in reflecting and promoting national identity.
    • Key Ideas/Facts:Flag in Poetry: Saudi poetry is rich with verses expressing national belonging, pride, and loyalty, often featuring the flag as a central symbol. “The Saudi flag is considered a symbol of identity and homeland, while poetry is a mirror for expressing feelings, and therefore we find that national poems carry many verses that express feelings of belonging, pride, and many deep meanings…”
    • Cinema and National Identity: The Saudi film festival, with the theme “Stories Seen and Told,” aims to showcase cinematic creations and highlight Saudi stories, reflecting the Kingdom’s cultural identity. The festival saw significant participation, indicating a growing interest in filmmaking.
    • Preservation of Heritage: There is a recognition of the importance of preserving and showcasing Saudi Arabia’s rich history and heritage through various initiatives, including the development of historical mosques and the focus on authentic details in Ramadan cultural events.

    4. Economic Updates and Investment

    • Theme: The excerpts provide a glimpse into economic trends, investment strategies, and the oil market.
    • Key Ideas/Facts:Stock Market Performance: The Saudi stock market experienced a decline, marking its lowest closing since the beginning of December 2024. Analysts advise investors to stay informed, diversify their portfolios, and focus on companies with strong fundamentals.
    • Oil Market Volatility: Oil prices declined due to concerns about slowing global demand, the impact of US customs duties on China, and increased production from OPEC+. There is continued volatility expected in the oil market.
    • Investment in Qassim Region: A meeting reviewed the investment strategy in the Qassim region, emphasizing partnerships between the public and private sectors to achieve sustainable development in line with Vision 2030.
    • “Alec” Company’s Growth: The construction and contracting company “Alec” reported significant annual growth in revenue and workforce, reflecting its strategic expansion in Saudi Arabia and the UAE.

    5. Social Initiatives and Community Development

    • Theme: The excerpts highlight various social initiatives focused on community service, supporting people with disabilities, and preserving Islamic values.
    • Key Ideas/Facts:Philanthropic Efforts: The Al-Fawzan family is recognized for their extensive charitable work, including supporting social programs, mosque architecture, and establishing centers for autism and comprehensive rehabilitation.
    • Support for People with Visual Impairments: A successful conclusion of the Ramadan Games for the Visually Impaired was reported, demonstrating the Kingdom’s commitment to inclusivity and sports for all.
    • Distribution of Quran Copies: Thousands of copies of the Holy Quran were distributed to Umrah pilgrims at King Abdulaziz International Airport in Jeddah, reflecting the Kingdom’s dedication to serving pilgrims.
    • Development of Historical Mosques: A project led by Crown Prince Mohammed bin Salman aims to develop historical mosques across the Kingdom, preserving their architectural heritage and religious significance in line with Vision 2030’s focus on cultural heritage.

    6. Sports News

    • Theme: The sports section covers local and international football competitions, rallying events, and achievements of Saudi athletes.
    • Key Ideas/Facts:AFC Champions League: Al-Nassr secured a spot in the quarter-finals of the AFC Champions League, while Al-Taawoun is aiming to advance. Al-Ahli Jeddah is also competing.
    • European Football: Liverpool gained an advantage in their Champions League tie against Paris Saint-Germain, while Bayern Leverkusen faces a tough challenge against Bayern Munich.
    • Rally Dakar: Saudi rally champion Yazeed Al-Rajhi proudly raised the national flag at the Dakar Rally 2025.
    • Achievements of Saudi Athletes: Saudi athletes have achieved significant success in various Asian Games, winning numerous medals and raising the national flag on international podiums. The flag is seen as a symbol and motivator for all Saudi athletes. “The flag is in the core of every athlete, but it is a symbol and a great motivator for all athletes during their participation in international and continental championships, and at all levels and in all sports, for raising the flag on the podium remains the dream of every athlete and a goal that everyone aspires to…”

    7. Other Notable Points:

    • Kafrit Agreement: A proposed bill in the Israeli Knesset aims to cancel the Oslo Accords, a development with potential implications for the Palestinian territories.
    • Humanitarian Situation in Gaza: Concerns are raised about the dire humanitarian situation in Gaza following the cutting of electricity supply by Israel.
    • Increased European Reliance on US Arms: European countries are increasingly relying on US arms imports, driven by the desire to strengthen their defense capabilities.
    • Critique of Ramadan Drama Series: An opinion piece critiques some Saudi Ramadan drama series for prioritizing visual spectacle over strong narratives and historical accuracy, potentially alienating discerning viewers.

    Conclusion:

    The selected excerpts from “Al Riyadh” on March 11, 2025, present a snapshot of a dynamic Saudi Arabia actively engaged on multiple fronts. The commemoration of “Flag Day” underscores the deep significance of national identity and unity. The Kingdom continues to play a notable role in regional and international affairs, while also focusing on cultural preservation, economic diversification, and social development in line with its Vision 2030. The sports section highlights the achievements and aspirations of Saudi athletes, further contributing to national pride. Overall, the newspaper conveys a sense of national pride, progress, and engagement with both domestic and global issues.

    Saudi National Flag: Symbolism and Significance

    Frequently Asked Questions about the Saudi National Flag

    1. What is the significance of the Saudi National Flag and when did its origins begin? The Saudi National Flag is a deeply significant symbol of national identity, sovereignty, historical depth, and religious commitment for the Kingdom of Saudi Arabia. Its origins trace back to 1727, coinciding with the establishment of the first Saudi state. The flag is rooted in the value of the nation’s knowledge and commemorates the unity and Islamic principles upon which the state was founded.
    2. How has the design of the Saudi National Flag evolved throughout history? The flag’s design has evolved over the centuries alongside the establishment and unification of the Saudi states. The first Saudi flag during the first Saudi state was green with the words “There is no god but Allah; Muhammad is the messenger of Allah” inscribed on it. Later, during the reign of King Abdulaziz Al Saud, a sword was added below the inscription, symbolizing strength and justice. The flag became rectangular and its dimensions were standardized in 1973.
    3. What are the key elements of the current Saudi National Flag and what do they symbolize? The current Saudi National Flag is a green rectangle with a width equal to two-thirds of its length. Across the center is the Islamic creed, the shahada (“There is no god but Allah; Muhammad is the messenger of Allah”) written in white in Thuluth script. Below the shahada is a white, unsheathed sword pointing towards the hoist (flagpole) with its hilt facing downwards. The green color symbolizes growth, vitality, and prosperity. The shahada represents the foundational Islamic belief of the kingdom. The sword embodies justice, strength, and the sacrifices made to unify and defend the nation.
    4. Why is the Saudi National Flag treated with such high respect, and what are some prohibitions regarding its use? The Saudi National Flag holds a sacred status due to its bearing of the shahada, a fundamental tenet of Islam. This religious significance, combined with its representation of national unity and sovereignty, necessitates utmost respect. Prohibitions include lowering the flag to half-mast (as a sign of mourning), allowing it to touch the ground or water, using it in a worn or faded condition, or any use deemed disrespectful to its symbolic value.
    5. Beyond its national symbolism, how does the Saudi Flag function in international contexts such as diplomacy and global organizations? The Saudi National Flag is a powerful tool in Saudi Arabia’s diplomacy and its presence in global organizations. Flown at Saudi embassies worldwide, it signifies the Kingdom’s sovereignty, independence, and diplomatic presence, fostering a sense of belonging for Saudi citizens abroad. Its raising at international conferences and summits, such as the United Nations and the G20, underscores Saudi Arabia’s political and economic influence and its commitment to global issues.
    6. What is the significance of ” يوم العلم ” (National Flag Day) in Saudi Arabia? “يوم العلم” (National Flag Day), celebrated on March 11th, marks the historical significance of the Saudi flag and its enduring value to the nation. It commemorates the day the first Saudi state was founded in 1727, highlighting the flag as a symbol of unity, pride in national identity, and the strong bond between the leadership and the people, rooted in loyalty and belonging.
    7. How is the Saudi National Flag reflected in Saudi culture, arts, and sports? The Saudi National Flag is deeply ingrained in Saudi culture and serves as a source of inspiration across various domains. In poetry, it evokes strong nationalistic sentiments, loyalty, pride, and belonging. In sports, raising the flag at international competitions is the ultimate aspiration of Saudi athletes, representing national achievement and unity. Even in volunteer work and humanitarian aid, the presence of the Saudi flag fosters a sense of responsibility and pride, reinforcing the Kingdom’s values on a global scale.
    8. Can the Saudi National Flag ever be lowered to half-mast, and what is the significance of it being raised in space? Due to the sacred inscription of the shahada, the Saudi National Flag is unique in that it is never lowered to half-mast as a sign of mourning. This unwavering display reflects the enduring principles it represents. The raising of the Saudi flag in outer space in 2023 by Saudi astronauts Ali Al-Qarni and Rayanah Barnawi was a historic moment symbolizing the nation’s ambitions, achievements, and the dedication of its citizens to reach new heights, while still holding their national identity aloft.

    Saudi National Flag and Day of the Flag

    The sources provided discuss the significance of the Saudi national flag and the designation of March 11th as ‘يوم العلم’ (Day of the Flag) in Saudi Arabia. This day, corresponding to the 27th of Dhul Hijjah, 1355 AH (March 11th, 1937 AD), marks the day when the flag was adopted during the reign of King Abdulaziz Al Saud.

    The establishment of ‘يوم العلم’ (Day of the Flag) by a royal decree issued on the 9th of Sha’ban, 1444 AH (March 1st, 2023), emphasizes the profound importance of the national flag. It is seen as a manifestation of the state, its power, unity, national cohesion, and sovereignty. The flag serves as a symbol of the Kingdom’s history, which extends back to its foundation in 1139 AH (1727 AD).

    The Saudi national flag is unique and highly revered:

    • It bears the Shahada (Islamic declaration of faith): ‘لا إله إلا الله محمد رسول الله’ (There is no god but Allah; Muhammad is the messenger of Allah). This central tenet of Islam, symbolizing Tawhid (Islamic monotheism), is fundamental to the Kingdom’s foundation.
    • Out of deep respect for the Shahada, the Saudi flag is never lowered, even during times of mourning. This distinguishes it from most other national flags.
    • Its use for commercial or decorative purposes is prohibited to prevent any unintended disrespect towards the sacred inscription. This underscores its esteemed position and sanctity within Saudi society.

    The flag embodies enduring national values, stands as a testament to the unification of the nation, and reflects its Islamic identity. Every Saudi citizen holds the flag with the Shahada in their hearts with pride in their national identity.

    In recognition of the flag’s significance, the Ministry of Culture issued a guidance manual for its use following the royal decree that designated March 11th as ‘يوم العلم’ (Day of the Flag). This manual details the history of the flag, its applications, protocol, the ‘Saudi Dress of Honor’, and information on other Saudi flags. The establishment of this day and the guidelines for its use highlight the flag’s role as a crucial symbol of national identity and sovereignty.

    The Symbolism of the Saudi National Flag

    The Saudi national flag holds profound symbolism deeply rooted in the Kingdom’s history, values, and identity. It is far more than just a piece of cloth; it represents the core tenets and aspirations of the Saudi nation.

    Key aspects of the flag’s symbolism include:

    • The Shahada (Islamic declaration of faith): The inscription “لا إله إلا الله محمد رسول الله” (There is no god but Allah; Muhammad is the messenger of Allah) is central to the flag’s meaning [previous turn, 4]. It symbolizes Tawhid (Islamic monotheism), the fundamental principle upon which the Kingdom is founded [previous turn, 6]. The deep respect for this sacred inscription is evident in the fact that the flag is never lowered, even in mourning, a unique characteristic among national flags [4, previous turn].
    • Unity: The flag is a “منارة الهوية ورسالة الوحدة” (beacon of identity and message of unity). It has been a “شاهداً على تاريخ المملكة” (witness to the history of the Kingdom) and carries the “مسيرة توحيدها” (journey of its unification). It remains a “رمزاً لوحدة الوطن” (symbol of the nation’s unity).
    • National Identity: The Saudi flag “يعد رمزاً أساسياً للهوية الوطنية” (is considered a fundamental symbol of national identity). It reflects the “الهوية السعودية” (Saudi identity) and the meanings of “االنتماء” (belonging) and “الوالء” (loyalty). Seeing the flag abroad evokes a sense of pride and connection to their homeland for Saudi citizens.
    • Sovereignty and Power: The flag is a “manifestation of the state, its power, … and sovereignty” [previous turn]. It enjoys “احترام واسع” (wide respect) due to its “رمزيتها الدينية والسيادية” (religious and sovereign symbolism). It also signifies “تحقيق القوة، والعزة، والأنفة” (the achievement of power, honor, and pride).
    • Historical Continuity: The flag’s design has remained consistent over the ages, reflecting the “ثبات مبادئها في المملكة” (steadfastness of its principles in the Kingdom) since its establishment. King Abdulaziz’s adoption of his ancestors’ banner as the national flag further underscores this historical link.
    • Core Values: The flag embodies enduring national values and the lofty principles upon which the state was founded, including “العدل والتوحيد والقوة” (justice, monotheism, and power), as well as “السلام، والإسلام، والعدل” (peace, Islam, and justice).
    • Religious Significance: Beyond the Shahada, the flag’s religious symbolism contributes to its high level of respect, making it “أحد أكثر الأعلام الموقرة عالمياً” (one of the most respected flags globally). It represents the “الوحدة الأساسية للعقيدة” (fundamental unity of creed).
    • Respect and Protocol: The prohibition of using the flag for commercial or decorative purposes highlights its sanctity. The traditions surrounding its use, such as never being lowered and swords being brandished under it in military parades, further emphasize its revered status.
    • Aspiration and Future: On ‘يوم العلم’ (Day of the Flag), the hopes of the nation’s sons for the continuation of the march towards platforms of honor are renewed under the banner of the flag. It is a “راية التوحيد العزة والعلو والمكانة” (banner of monotheism, honor, highness, and status).

    In essence, the Saudi national flag serves as a powerful and multifaceted symbol that encapsulates the Kingdom’s foundational religious beliefs, its journey towards unification, its enduring national identity and values, its sovereignty and strength, and its aspirations for the future.

    History of the Saudi Arabian Flag

    The history of the Saudi flag is deeply intertwined with the establishment and evolution of the Saudi state, dating back several centuries [previous turn, 5].

    • Early Origins (circa 1727 AD): The first Saudi flag emerged with the foundation of the first Saudi state in 1139 AH (1727 AD) during the reign of Imam Muhammad bin Saud [5, 29, previous turn]. This early flag was green with a white area near the hoist and a component included. This basic design reportedly carried through the first and second Saudi states.
    • The Unification Era under King Abdulaziz: During the period of the modern Kingdom’s establishment, King Abdulaziz Al Saud initially carried a square-shaped green flag. This flag featured the phrase “نصر من الله وفتح قريب” (Victory from Allah and an imminent conquest) inscribed on it, along with a sword underneath. Later, this design was modified to include two crossed swords beneath the Shahada (“لا إله إلا الله محمد رسول الله“), which was positioned in the center of the green flag. This design persisted until 1926 AD.
    • Post-Hijaz Unification (1926 AD): Following the unification of Hijaz, the flag returned to a rectangular shape. It became solid green with the Shahada written in white across its center, without any additional symbols.
    • The Modern Flag (1938 AD): The flag underwent its final modification in 1357 AH (1938 AD) during the reign of King Abdulaziz. This is the flag that remains in use today. Its dimensions were set with the width equaling two-thirds of its length. The white Shahada remains in the center, and a white, unsheathed sword is placed below it, with its tip pointing towards the left (fly side) and its hilt towards the bottom (hoist side). This addition of the sword symbolized strength and justice. It’s also noted that King Abdulaziz’s flag was based on the banner of his ancestors.

    Throughout these historical developments, the green color has been a constant feature of the Saudi flag. The inclusion of the Shahada from the early stages highlights the foundational Islamic identity of the state [5, 29, previous turn]. The enduring nature of the flag’s core elements reflects the “ثبات مبادئها في المملكة” (steadfastness of its principles in the Kingdom) [8, previous turn]. The current design, finalized in 1938, stands as a powerful “رمزاً لوحدة الوطن وهويته وتاريخه العريق” (symbol of the nation’s unity, identity, and ancient history).

    Saudi National Flag Regulations

    The Saudi national flag is subject to strict regulations that underscore its sanctity and significance. These regulations aim to prevent any disrespect or misuse of the Kingdom’s most important symbol.

    Key regulations regarding the Saudi flag include:

    • Prohibition of Lowering (Never Half-Mast): The Saudi flag is never lowered to half-mast, even during periods of mourning [6, 8, 12, previous turn]. This unique regulation is a mark of deep respect for the Shahada (Islamic declaration of faith) it bears.
    • Ban on Commercial and Decorative Use: The use of the Saudi flag for commercial, decorative, or advertising purposes is strictly prohibited [6, 9, 12, previous turn]. This is to avoid any unintended disrespect towards the sacred inscription and to maintain the flag’s dignified status. This includes not printing the flag on merchandise such as shoes or carpets.
    • Respect in International Settings: The Saudi flag is treated with great care and respect in international events and forums. When displayed alongside other national flags, meticulous attention is paid to ensure no unintended offense occurs.
    • Legal Protection: The Saudi flag is protected by strict laws within the Kingdom. Additionally, other nations also adhere to protocols to protect the Saudi flag during official events.
    • Proper Display: The national flag is hoisted at all times on all government buildings and public institutions within the Kingdom and at its diplomatic missions abroad, including during official holidays. Considerations of international courtesy are taken into account regarding its use.
    • Disposal of Damaged Flags: If a flag becomes faded or is in poor condition, it is not simply discarded. Instead, it must be sent to the official authorities for proper disposal, which involves burning it in a specific procedural manner.
    • Guidance Manual for Use: The Ministry of Culture has issued a guidance manual for the proper use of the national flag [11, previous turn]. This manual was created following the royal decree designating March 11th as ‘يوم العلم’ (Day of the Flag) and provides comprehensive information on the flag’s history, applications, and protocol.
    • Avoiding Disrespectful Contact: It is ensured that the flag does not touch the ground during official events. Similarly, it should not be printed on clothing or products in an inappropriate manner.

    These regulations collectively emphasize the profound respect and reverence accorded to the Saudi national flag as a symbol of the nation’s core identity, unity, and faith. The detailed guidelines and legal protections underscore its unique and esteemed position.

    The Profound Significance of the Saudi National Flag

    The علم (flag), specifically the Saudi national flag, holds immense significance for several profound reasons, as discussed in the sources and our conversation history.

    Firstly, the flag’s most prominent feature, the Shahada (“لا إله إلا الله محمد رسول الله”), imbues it with deep religious significance [previous turn, 4]. This declaration of faith is the cornerstone of Islam and symbolizes Tawhid (Islamic monotheism), the fundamental principle upon which the Kingdom of Saudi Arabia was founded [previous turn, 6]. The profound respect for this sacred inscription is underscored by the unique regulation that the Saudi flag is never lowered to half-mast, even in times of mourning [6, 8, 12, previous turn].

    Secondly, the flag serves as a powerful symbol of national unity. It is referred to as a “منارة الهوية ورسالة الوحدة” (beacon of identity and message of unity) and a “رمزاً لوحدة الوطن” (symbol of the nation’s unity) [previous turn]. The flag’s history is intertwined with the “مسيرة توحيدها” (journey of its unification), and it stands as a constant reminder of the Kingdom’s cohesion [previous turn].

    Thirdly, the علم is a fundamental symbol of Saudi national identity. It “يعد رمزاً أساسياً للهوية الوطنية” (is considered a fundamental symbol of national identity) [previous turn]. For Saudi citizens, seeing the flag, especially abroad, evokes a strong sense of pride (“فخر واعتزاز”) and belonging (“انتماء”) to their homeland [previous turn, 22].

    Furthermore, the flag represents the sovereignty and power of the Saudi state [previous turn, previous turn]. It is seen as a “manifestation of the state, its power, … and sovereignty” [previous turn]. Its religious and sovereign symbolism grants it “احترام واسع” (wide respect), both domestically and internationally, making it “أحد أكثر الأعلام الموقرة عالمياً” (one of the most respected flags globally) [7, previous turn].

    The history of the Saudi flag reflects the Kingdom’s evolution and the steadfastness of its core principles [6, 8, previous turn]. From its early origins to the final design adopted during the reign of King Abdulaziz in 1938 AD, the consistent presence of the color green and the Shahada highlights the enduring Islamic identity and historical continuity of the nation [previous turn]. King Abdulaziz’s choice to base the flag on the banner of his ancestors further emphasizes this historical connection [8, previous turn].

    The strict regulations governing the use of the flag further underscore its significance [previous turn]. The prohibition of commercial and decorative use [6, 9, 12, previous turn], the protocols for its proper display [8, previous turn], and the specific procedures for disposing of damaged flags [8, previous turn] all demonstrate the profound respect and sanctity accorded to it. The issuance of a guidance manual for its use following the designation of March 11th as ‘يوم العلم’ (Day of the Flag) highlights its crucial role as a symbol of national identity and sovereignty [11, previous turn]. ‘يوم العلم’ itself serves as a dedicated occasion to celebrate the flag’s value and its representation of the Kingdom’s long history since its foundation in 1727 AD [9, previous turn].

    In essence, the Saudi national flag is far more than a mere emblem. It is a deeply revered symbol that encapsulates the Kingdom’s foundational religious beliefs, its journey toward unity, its enduring national identity and values, its sovereignty and strength, its rich history, and its aspirations for the future. It is a powerful representation of what it means to be Saudi.

    By Amjad Izhar
    Contact: amjad.izhar@gmail.com
    https://amjadizhar.blog

  • C# Programming: Syntax, Variables, Iteration, and Core Concepts by Bob Tabor

    C# Programming: Syntax, Variables, Iteration, and Core Concepts by Bob Tabor

    The text is a comprehensive C# programming course designed for beginners. It initiates with Visual Studio installation, progresses to basic “Hello World” applications, and incrementally introduces concepts like variables, data types, operators, and control flow statements. The course then transitions to object-oriented programming, covering classes, objects, methods, properties, and their lifecycle management. Furthermore, it explores the .NET Framework Class Library, assemblies, namespaces, and external libraries, providing guidance on accessing and utilizing them in projects. The course also covers data structures like arrays, lists, and dictionaries, as well as LINQ for data manipulation and querying. Finally, it concludes with an overview of important software development concepts like debugging and design patterns.

    C# Programming Fundamentals Study Guide

    Quiz

    Answer each question in 2-3 sentences.

    1. What is the purpose of the Console.ReadLine() method in C#?
    2. Explain the difference between a variable declaration and variable initialization.
    3. What is the difference between the Console.Write() and Console.WriteLine() methods?
    4. What is an integer data type, and what range of values can it typically hold in C#?
    5. Describe the purpose of an if statement in C# and how it controls the flow of execution.
    6. What is the difference between a single equal sign (=) and a double equal sign (==) in C#?
    7. What is a “for loop” used for in programming and explain the three parts of a for loop.
    8. What is an array in C#?
    9. What is a class in C#?
    10. What is a method in C#?

    Quiz Answer Key

    1. The Console.ReadLine() method is used to read a line of text entered by the user from the console window. It pauses the program’s execution until the user enters text and presses the Enter key, then returns the entered text as a string.
    2. Variable declaration is the process of naming a variable and defining its data type, while variable initialization is the process of assigning an initial value to a previously declared variable.
    3. Both methods output text to the console, but Console.Write() leaves the cursor at the end of the output, while Console.WriteLine() moves the cursor to the beginning of the next line after the output.
    4. An integer is a whole number (without any decimal or fractional part). In C#, the int data type can typically hold values between approximately -2.147 billion and +2.147 billion.
    5. An if statement is a conditional statement that executes a block of code only if a specified condition is true. If the condition evaluates to false, the code block is skipped.
    6. A single equal sign (=) is an assignment operator used to assign a value to a variable. A double equal sign (==) is a comparison operator used to check if two values are equal, returning a Boolean value (true or false).
    7. A for loop iterates through a code block for a specified number of times. 1: Initialization(where you declare and initialize variables), 2: Condition(the condition for the loop to continue running), and 3: Increment(where you increment or decrement the loop variables).
    8. An array in C# is a data structure that stores a fixed-size, sequential collection of elements of the same data type. Each element in the array can be accessed by its index.
    9. A class is a blueprint for creating objects that define data (fields) and actions (methods). Classes define the properties and behaviors of the objects that will be created from them.
    10. A method is a block of code that performs a specific task and can be called by name from other parts of the program. Methods can accept input parameters and return a value.

    Essay Questions

    1. Explain the importance of understanding data types in C# and how choosing the correct data type can impact the performance and accuracy of a program. Provide examples of common data types and scenarios where each would be most appropriate.
    2. Discuss the role of decision statements (if, else if, else) in programming logic. Provide a detailed example of a scenario where multiple decision statements are used to handle different conditions, and explain how these statements control the flow of execution.
    3. Describe the concept of variable scope in C# and explain how it affects the accessibility and lifetime of variables. Provide examples of local, class-level, and global variables, and discuss the implications of each scope.
    4. Explain the purpose and benefits of using loops (for, while, do-while) in programming. Provide a detailed example of a scenario where a loop is used to iterate through a data structure, perform calculations, and output results, and discuss the different types of loops that could be used in that scenario.
    5. Discuss the key principles of Object-Oriented Programming (OOP) such as encapsulation. Explain how using classes and objects can improve code organization and maintainability.

    Glossary of Key Terms

    • Class: A blueprint or template for creating objects, defining their properties (fields) and behaviors (methods).
    • Console: A system output window where a program can display text and receive input from the user.
    • Data Type: Specifies the type of data a variable can hold (e.g., integer, string, boolean).
    • Declaration: The process of naming a variable and defining its data type.
    • Expression: A combination of operands and operators that evaluates to a single value.
    • Field: A variable that is a member of a class or struct.
    • For Loop: A control flow statement for specifying iteration, which allows code to be executed repeatedly.
    • If Statement: A conditional statement that executes a block of code if a specified condition is true.
    • Initialization: Assigning an initial value to a variable when it is declared.
    • Integer: A whole number without any fractional or decimal parts.
    • IntelliSense: A code completion feature in Visual Studio that suggests code elements as you type.
    • LINQ: Language Integrated Query, is a feature in C# that provides a unified way to query data from various sources.
    • Method: A block of code that performs a specific task and can be called by name.
    • Object: An instance of a class, created from a blueprint or template.
    • Operand: A value or variable on which an operator acts.
    • Operator: A symbol that performs an operation on one or more operands.
    • Property: A member of a class that provides a flexible mechanism to read, write, or compute the value of a private field.
    • Scope: The region of a program where a variable is accessible.
    • Semicolon: A character (;) used at the end of a C# statement to indicate the end of the statement.
    • Statement: A complete instruction in C#, often ending with a semicolon.
    • String: A sequence of characters.
    • Variable: A named storage location in memory that can hold a value of a specific data type.

    C# Programming Fundamentals with Visual Studio: A Beginner’s Guide

    Here’s a detailed briefing document summarizing the key themes and ideas from the provided source excerpts.

    Briefing Document: C# Programming Fundamentals with Visual Studio

    Overview:

    This document summarizes a series of instructional excerpts focused on teaching fundamental C# programming concepts using Visual Studio. The excerpts cover a range of topics, from setting up Visual Studio and creating basic “Hello World” applications, to declaring variables, using decision statements (if/else), understanding operators, working with iteration (for loops), arrays, LINQ, enums and switch statements, methods and debugging techniques. The material is designed for beginners with little to no prior programming experience. The instructor, Bob Tabor, emphasizes hands-on learning and provides practical examples.

    Key Themes and Ideas:

    1. Basic Workflow and Environment Setup:
    • Custom Installation of Visual Studio: The course begins by guiding users through a custom installation of Visual Studio. The narrator explains the selection and installation process, including the option to review license terms for each software component.
    • Creating a New Project: The initial lessons focus on establishing a basic workflow in Visual Studio. This includes creating new projects using templates (e.g., Console Application). “To begin, we’re going to create a new project. There are a number of different ways to do this, but I’m going to keep it simple and go to ”File” ”New” ”Project””.
    • “Hello World” Application: The course begins with building a “Hello World” application. The purpose is to familiarize the student with the basic steps of coding such as creating a new project, writing code, testing the application, saving the project, and debugging any errors.
    1. Variables and Data Types:
    • Variables as Buckets: Variables are explained as “buckets” in computer memory that hold data. “A variable is simply under the hood, a bucket. I guess you could call it in the computer’s memory and you put things in buckets and you dump things out of buckets”.
    • Declaring Variables: The importance of declaring variables and specifying the correct data type is emphasized. “We have to declare our variables, we have to create those buckets and then give them some label that we can refer to them with from that point on.”
    • Data Types Covered: int (integers), string (text), and others. The course highlights the importance of choosing the right data type for the data being stored.
    • Variable Initialization: The course explains how to initialize the value to variables upon declaration. “What I’m doing here is not only declaring the variable, but then I’m initializing its value to whatever we retrieve when we call Read Line. This is called initialization, and initialization is important because you want to give your variables a value as quickly as possible”.
    1. Decision Statements (if/else):
    • Conditional Logic: The course covers the use of if statements to execute code blocks based on conditions. “The if statement is called the decision statement because we will decide whether to execute any of the code inside of this inner code block based on this evaluation that we’re going to do after the if keyword”.
    • Comparison Operators: The use of double equal signs (==) for evaluation of “true or false” is covered and how to differentiate this from assignment operator using only one equal sign.
    • else if and else: The course includes the use of else if for additional conditions and else for “catch-all” scenarios.
    • Nested Decisions: The course also discusses how to nest ‘if’ statements within each other.
    1. Operators, Expressions, and Statements:
    • Building Blocks of Code: The course defines statements as complete thoughts, expressions as parts of statements, and operators and operands as components of expressions. “Statements are what you call complete thoughts in C#. Typically, one line of code. A statement is made up of one or more expressions and expressions are made up of one or more operators and operands”.
    • Types of Operators: Mathematical operators (+, -, *, /), assignment operators (=), equality operators (==), comparison operators (>, <, >=, <=), logical operators (&&, ||), and the inline conditional operator (?:) are described.
    1. Iteration (for Loops):
    • Looping Constructs: The course introduces for loops for iterating through code blocks a specified number of times.
    • Increment Operator: The i++ increment operator is explained.
    • break Statement: The break statement is introduced as a way to exit a loop prematurely.
    • Code Snippets: Code snippets are a pre-built piece of code to help users construct more complex code without needing to remember syntax perfectly. “To do this it’s real easy. If you can remember I need a for iteration statement just type in the word for. You’ll see that it pops up in the IntelliSense”.
    1. Debugging Techniques:
    • Breakpoints: The use of breakpoints to pause code execution and examine variables is explained. “To make this work, what I’m going to do is actually set a breakpoint here on this line of code.”
    • Stepping Through Code: The process of stepping through code line by line to understand the flow of execution is also covered.
    • Variable Monitoring: The ability to monitor variable values during debugging is highlighted.
    1. Arrays:
    • Storing Collections of Data: The course addresses how to create arrays to store multiple related values.
    • Array Declaration and Initialization: The method of declaring the array and initializing the array elements are both discussed.
    • Array Operations: The discussion covers how to retrieve values from an array using indexing, as well as how to utilize a for loop to print out the values in an array.
    1. LINQ (Language Integrated Query):
    • Querying Collections: The course discusses using LINQ to query and manipulate collections of data (like arrays or lists).
    • Extension Methods: Discusses method syntax and query syntax available in LINQ.
    • var Keyword: The use of the var keyword to allow the compiler to infer the data type of a variable is explained, especially in the context of LINQ queries. “The var keyword is essential to help us to be able to create these very complex queries, and not have to worry about what the data type of it is that’s returned.”
    • Anonymous types: The course discusses anonymous types and how those get used as part of a LINQ query.
    1. Enums and Switch Statements
    • Enumerations: Enumerations are a data type that limits and constrains all possible values to only those that are valid and have meaning within the system.
    • Switch Statement:. The course includes the introduction of a switch statement as an easier decision statement to read for situations with many different potential cases.
    1. Methods:
    • Defining Reusable Code Blocks: Methods are introduced as reusable blocks of code. “What we’re going to do now is create and talk about methods. Methods are essentially a way to take a series of code statements, give them a name, and then re-execute them over and over again throughout our applications.”
    • Method Parameters and Return Types: The course explains the use of input parameters and return types for methods.
    • Overloading Methods: Overloading is the method of creating two methods with the same name but different methods signatures is discussed.
    1. Understanding Scope
    • Scope of Variables: This section explains how the location where a variable is declared impacts its accessibility within the code. “Whenever you declare variable inside of a block of code, that variable is only alive for the life of that code block and any of the interior code blocks or code blocks inside of that code block.”
    • Accessibility Modifiers: The difference between public and private is touched upon.
    1. Assemblies and Namespaces
    • .NET Assemblies: A discussion about how the .NET framework splits the code into multiple files. “These code files are called.NET assemblies. In fact, even the applications that we build, they’re ultimately compiling into.NET assemblies.”
    • .Namespaces: Used to be able to tell one class from a different class. “The creators needed a way to be able to tell one class from a different class and so they introduced the notion of name spaces and name spaces are like last names for your classes”.
    1. Working with Strings
    • .Formatting Strings: How to use formatting codes to represent strings (e.g. as a percentage) are discussed.
    • .Manipulating Strings: Several functions are described such as Substring, ToUpper, Replace, and Trim.
    1. Creating Classes
    • .Properties: A class contains the data and functionality related to one “thing” in your code and a property is the actual data point.
    • .Objects: After defining the class, you can create instances of that class.
    1. Events
    • .Events Handlers: Used for the situations when you want more than one event handler to execute whenever the event is raised

    Instructor’s Style:

    • Beginner-Friendly: The instructor aims to simplify complex topics and use analogies to make them more understandable.
    • Emphasis on Practice: The course encourages viewers to type code along with the instructor to reinforce learning.
    • Problem-Solving Focus: The instructor emphasizes the importance of developing problem-solving skills by identifying differences in code and debugging errors.
    • IntelliSense Reliance: The course also highlights how software developers rely on IntelliSense (Visual Studio’s code completion feature) to help them write code quicker.

    Target Audience:

    The material is designed for individuals who are new to programming and want to learn C# using Visual Studio. No prior programming experience is assumed.

    Conclusion:

    These excerpts provide a structured introduction to C# programming, covering essential concepts and practical skills for beginners. The instructor’s clear explanations and hands-on approach make the material accessible and engaging for novice programmers.

    Visual Studio and C# Development: FAQ

    Visual Studio and C# FAQ

    • How do I perform a custom installation of Visual Studio 2015?
    • After clicking the “Next” button in the installer, you will see a screen displaying all the different items you have selected. By clicking “Install”, you agree to the license terms for all selected software components. You can click on each item to view its specific license terms. Once you are satisfied, clicking the “Install” button begins the installation of all chosen components.
    • What is the basic workflow for creating a simple C# application (like “Hello World”) in Visual Studio?
    • The basic workflow involves creating a new project by going to File -> New -> Project and selecting “Templates” then “C#”. Choose “Console Application,” rename the project (e.g., “HelloWorld” using CamelCase). Type your C# code within the innermost set of curly braces in the program.cs file. Test your application by running it, and save your project frequently.
    • What are variables in C# and how do I declare them?
    • Variables are like “buckets” in the computer’s memory that hold data. To declare a variable, you must specify its data type (e.g., int for integers, string for text) and give it a name (e.g., int x;, string myName;). This tells the compiler to allocate the appropriate amount of memory for that type of data.
    • What is the difference between the assignment operator (=) and the equality operator (==) in C#?
    • The single equal sign (=) is the assignment operator. It assigns the value on the right-hand side to the variable on the left-hand side (e.g., x = 7;). The double equal sign (==) is the equality operator. It compares the values on both sides and returns a boolean value (true if they are equal, false otherwise) (e.g. if (userValue == “1”)).
    • What is an “if” statement and how does it work?
    • An if statement is a decision statement that allows you to execute a block of code only if a certain condition is true. It can be followed by else if statements to check additional conditions, and an else statement to execute a block of code if none of the conditions are true.
    • What are operators and operands in C#?
    • Operators are symbols that perform actions on operands. Operands are the data that operators act upon. For example, in x = 7 + 3;, + is the addition operator, = is the assignment operator, and x, 7, and 3 are operands. Operators can perform arithmetic, comparisons, logical operations, and more.
    • What is a “for” loop and how do I use it?
    • A for loop is an iteration statement that allows you to repeatedly execute a block of code a specific number of times. Its syntax typically includes an initialization (declaring a variable), a condition (determining when to stop looping), and an increment/decrement (modifying the variable after each iteration). (e.g. for (int i = 0; i < 10; i++) { Console.WriteLine(i); })
    • What are classes and objects in C# and why are they important?
    • A class is a blueprint for creating objects. It defines the properties (data) and methods (actions) that an object of that class will have. An object is an instance of a class. Classes and objects are fundamental to object-oriented programming, allowing you to organize code into reusable and manageable units. They help in modelling real-world entities and their interactions within your program.

    Customizing Your Visual Studio Installation

    A custom installation of Visual Studio allows you to select the specific features, languages, and tools that you want to install, rather than installing everything by default. The source recommends selecting the “Custom Option” during installation to ensure you obtain the necessary packages and libraries for your desired applications.

    Key aspects of a custom Visual Studio installation:

    • Programming Languages You can choose to install additional programming languages such as Visual C++, Visual F#, and Python Tools for Visual Studio. By default, only C# and Visual Basic templates are installed.
    • Windows and Web Development Options include ClickOnce Publishing Tools, SQL Server Data Tools, PowerShell Tools for Visual Studio, and Silverlight Development.
    • Universal Windows App Development To develop universal windows applications, you must ensure that you have the tools, emulators, and SDK. While you can install the Windows 10 SDK later, it is easier to install these during the initial Visual Studio installation.
    • Cross-Platform Mobile Development If you want to develop applications for Windows Phone, iOS, and Android using C#, you can select the cross-platform mobile development tools for the Xamarin platform. This option includes all the emulators as well.
    • Additional Tools You can install Git for Windows and the GitHub extension for Visual Studio to integrate with GitHub source control projects.

    Keep in mind that selecting additional options will increase the installation size of Visual Studio. Before installing, you can review each item to ensure you have all the components, tools, and SDKs necessary for your development platforms of choice.

    C# Hello World Application: A Beginner’s Guide

    The “Hello World” application is a simple program designed to demonstrate the basic workflow of writing code in C#. It involves printing the words “Hello World” to a console window. The purpose of this exercise is to familiarize you with the steps involved in creating a new project, writing code, testing the application, handling errors, and saving the project.

    Key aspects of creating a “Hello World” application in C#:

    • Creating a New Project To begin, navigate to “File,” then “New,” and then “Project” in Visual Studio to open the new project dialog. Select “Templates,” then “C#,” and choose the “Console Application” option. Rename the project to “HelloWorld” (using the naming convention of capitalizing the first letter of each word without spaces) and click “Okay”.
    • Writing the Code Locate the innermost set of curly braces {} within the program.cs file. Inside these braces (approximately lines 13 and 14), type the following code:
    • Console.WriteLine(“Hello World”);
    • Console.ReadLine();
    • Console.WriteLine is code from the .NET Framework class library that displays text in the console window. Console.ReadLine() tells the application to wait for user input before continuing execution. Commenting out the Console.ReadLine() will cause the application to execute the WriteLine command and then exit immediately.
    • Running the Application After writing the code, run the application to ensure it prints “Hello World” to the console window. If there are any errors, Visual Studio will typically indicate them with red squiggly lines, providing clues to identify and fix the issues.
    • Precision in Syntax Writing C# code requires precision. Visual Studio provides assistance by highlighting potential issues and offering suggestions. If you encounter problems, compare your code character by character with a known correct version to identify any discrepancies.
    • Understanding the Code The code needs to be written in the correct place, specifically within the opening and closing curly braces of the innermost set as defined by the boilerplate code. These curly braces define code blocks, which have names and purposes. The first code block is named “Main”, also known as a method. The main method lives inside another set of curly braces with the name “program”, which is a class. A class is a container for all the methods of the application. There is another set of curly braces with the name “HelloWorld”, which is a namespace. A namespace is another way of organizing code.

    By following these steps, you can create a simple “Hello World” application and familiarize yourself with the basic C# development workflow.

    Visual Studio: Creating C# Console Applications

    When creating a new project in Visual Studio, there are several key steps and considerations. The following points provide an overview of the process:

    • Initiating a New Project Start by navigating to File > New > Project in Visual Studio to open the new project dialog.
    • Selecting a Template In the new project dialog, select Templates > C#, and then choose the Console Application option. The number of items displayed may vary based on the Visual Studio version and edition.
    • Naming the Project Rename the project to a desired name, such as “HelloWorld”. A common naming convention is to capitalize the first letter of each word without spaces (e.g., HelloWorld).
    • Understanding the Project Structure Visual Studio creates a starting point for a Console Window Application, including a file named program.cs with boilerplate code. The code is written inside the innermost set of curly braces {} within the program.cs file. These curly braces define code blocks, such as methods, classes and namespaces.
    • Project Files and Location By default, Visual Studio stores projects in your Documents folder, under a folder corresponding to your Visual Studio version (e.g., Visual Studio 2015), and then in a Projects folder. This location can be customized.
    • Projects and SolutionsFiles and settings are organized into projects. A project is compiled into a single .Net assembly.
    • One or more projects are organized into solutions. Solutions can contain multiple related projects.
    • Opening Existing Projects Existing projects can be opened from any location on your computer via File > Open > Project/Solution.
    • Project Files on Disk The projects and solutions are stored as files on your hard drive:
    • The .sln file (solution file) contains information about all projects under the solution.
    • The .csproj file (C# project file) contains references to project files, settings, and metadata.
    • The bin folder stores the binary (compiled) version of the application.
    • References Creating a new project using a project template automatically creates references to files in the .NET Framework Class Library. These references can be viewed under the references node of the project in the Solution Explorer.

    Troubleshooting and Resolving C# Errors in Visual Studio

    When learning C#, it’s common to encounter errors, and understanding how to identify and fix them is crucial. Visual Studio provides several tools and visual cues to help in this process.

    Common types of C# errors and how to address them:

    • Build Errors: These occur when Visual Studio is unable to compile your code. A dialog box may appear, stating, “There were build errors. Would you like to continue and run the last successful build?” Always select “no” to review the errors.
    • Error List: After a build error, a list of errors is displayed in the error list. Double-clicking on an error will typically put the mouse cursor on the line where the problem exists.
    • Red Squiggly Lines: Visual Studio uses red squiggly lines to highlight areas of code that likely contain errors. These lines serve as visual cues, indicating where you should focus your attention to identify and correct issues. Blue squiggly lines are similar, also indicating areas that may need attention.
    • Incorrect Code Block: C# commands must be placed within the correct code blocks, typically defined by curly braces {}. An error may occur if code is not placed between the innermost opening and closing curly braces.
    • Missing Semicolon: Just like a sentence needs a period, each C# statement needs a semicolon ; to mark the end of a complete instruction. The error message “Semicolon expected” indicates that a semicolon is missing at the end of a line of code.
    • Syntax Errors: These occur when the code doesn’t follow the rules of the C# language. The error message might say, “Syntax error, something expected”.
    • Case Sensitivity: C# is case-sensitive, meaning that Console is different from console. Ensure that you match the capitalization exactly.
    • Incorrect Spelling: Ensure that all words are spelled correctly, such as WriteLine instead of Writeline.
    • “The name ‘X’ does not exist in the current context”: This error indicates that a variable or name has not been declared or is not accessible in the current scope. This can happen if a variable is used before it is declared or if it is declared within a scope that is not accessible from the current location.
    • Undeclared Variables: If you comment out the declaration of a variable (e.g., int x;), the compiler will not recognize subsequent uses of that variable. Ensure that all variables are properly declared before use.
    • Missing References: If you are utilizing a class that is not recognized, it may be because you are missing a reference to the assembly in your project, or you are missing a “using statement”. Use “Control period” to have Visual Studio suggest the appropriate “using statement”.
    • Compare With Correct Code: If you are struggling to identify the issue, compare your code, character by character, with a known correct version. The source code from the lessons can be downloaded and opened in a separate copy of Visual Studio to compare.
    • Utilize Visual Studio: Take advantage of the tools in Visual Studio to help identify and resolve errors.
    • Scope: Variables declared inside a code block (defined by curly braces) are only accessible within that scope. If you need to use a variable outside of the code block, it must be declared outside of it.
    • Defensive Coding: Code defensively to anticipate and handle potential issues, especially those related to user input, file access, and network connections. Use try-catch blocks to manage exceptions and prevent application crashes.

    By paying close attention to error messages, utilizing the tools available in Visual Studio, and understanding the syntax rules of C#, you can effectively troubleshoot and resolve errors in your code.

    C# String Manipulation Techniques and Best Practices

    String manipulation involves modifying and formatting strings in C#. There are various techniques available for inserting special characters, formatting numbers and dates, changing aspects of strings, and searching or replacing items within strings.

    Key techniques for string manipulation in C#:

    • Inserting Special Characters The backslash character \ is used to escape or insert special characters into literal strings. For example, to include double quotes within a string, use \” before each double quote. To insert a new line, use \n.
    • To use a backslash character itself, either use another backslash character to escape it \\, or add the @ symbol in front of the literal string. This tells C# to use backslash characters as true backslash characters and not as escape sequences.
    • String Formatting with string.Format This method is used to insert values into a string template using replacement codes. The number inside the replacement code {} corresponds to the argument passed into the string.Format method.
    • Replacement codes can be reused multiple times or used in a different order.
    • Special formatting can be applied within the replacement code. For example, {0:C} formats the value as currency, and {0:N} adds commas and decimal points for large numbers. Using {0:P} will display a value as a percentage.
    • Custom formats can be created using pound symbols # to represent each digit.
    • String Manipulation Methods Strings have built-in helper methods for manipulation.
    • Substring(): Extracts a portion of the string, starting at a specified position. You can specify the starting position and the number of characters to extract.
    • ToUpper(): Converts the entire string to uppercase.
    • Replace(): Replaces all occurrences of a specified character with another character. For example, spaces can be replaced with double dashes.
    • Remove(): Removes a specified number of characters from the string.
    • Trim(): Removes leading and trailing spaces from a string. There are also methods to trim only the beginning or ending spaces.
    • String Length The Length property can be used to determine the number of characters in a string.
    • Efficient String Building with StringBuilder When performing a lot of string concatenation or manipulation, using the StringBuilder class is more efficient than repeatedly concatenating strings directly. Strings are immutable, so each concatenation creates a new string object in memory. StringBuilder avoids this by providing an Append method to modify the string in place.

    By using these techniques, you can effectively manipulate strings in C# for formatting, data processing, and display purposes.

    C# Fundamentals for Beginners

    The Original Text

    >> I am Bob Tabor with Developer University, and I welcome you to this course covering the fundamentals of the C-sharp Programming Language and Programming topics in general. Designed specifically for absolute beginners to programming. Now, if you’re already an experienced Software Developer coming from another Software development platform programming language, then frankly, this series of lessons will move much too slowly for you. You might be better served to find another resource to use as a starting point. One with you the experienced beginner to C-sharp in mind and Microsoft Virtual Academy has many great courses designed for people and all skill levels, so I recommend that you start your search there. However, if you are completely new to programming and you’re new to the C-sharp programming language and you’re new to building applications on the Windows platform, then this perhaps is the best place for you to start. Not only will you and I work together to learn the syntax of C-sharp, but I’m going to take the time to walk through everything that we do together. I’ll explain what we’re doing, but more importantly, I want to explain why we’re doing it, the thought process behind it. I’m going to try to anticipate the questions you might have anticipate the problems that you might run into as you’re typing your very first lines of code into the code window or as you’re working through some of the exercises that we’ll work through together. I’ve literally taught hundreds of thousands people, maybe even millions of people C-sharp over the past 14 years. That’s no exaggeration. This includes children as old as eight years old and as young as eight years old from virtually every corner of the world. They’ve all learned from a version of this course, and I know you can learn too. In fact, this is the sixth generation of this very course, dating all the way back to 2005. And over the years, I’ve incorporated feedback from thousands of students feedback and suggestions on how to improve the course. I’ve incorporated those in an effort to make sure that this is the very best effort that I can put forward to help you get your feet well with C-sharp. Now I’ll only make one real assumption as we begin this course, and that’s that you already have some version in addition to Visual Studio already installed on your local computer and you’re ready to write your very first lines of code. Now, if you don’t already have Visual Studio installed, then please by all means, visit Visual Studio.com, where you’ll learn about the many free and commercial editions of Visual Studio that are available. What the differences are. Now, personally, I used Visual Studio 2015 Community Edition, one of the free versions of Visual Studio that are available on Visual Studio.com, and I want to emphasize that you can use any additions and version of Visual Studio with these lessons. Now, there might be tiny User Interface differences between what you see on my screen and what you see on your screen as you work through the videos. However, I’m not going to be focusing on any specific features of Visual Studio, so hopefully that won’t prevent you from following along, no matter what. There will be other courses on Microsoft Virtual Academy that will demonstrate the power of Visual Studio, all the features that Visual Studio has to offer and explain the differences between editions and versions of Visual Studio. But I won’t be focusing on that in this course. I’m going to focus specifically on the basics of the C-sharp Programming Language itself. And what I will demonstrate will be true no matter which version or edition of Visual Studio that you choose to use, and that’s great news, because as long as C-sharp exists, these lessons should still be valid and useful to you, no matter what. So to get the most out of this course or any course that you find online, you really should become an active learner and that takes several different forms. First of all, you should attempt to follow along closely and do what I call getting your hands dirty in the code. Actually writing the code that I’m writing on screen, you’re writing it along with me. All right, there’s no better way to learn how to code than actually write code yourself. It’s like suggesting that somebody learn how to play the guitar without ever touching a guitar. You’d think, Well, that’s virtually impossible. Typing in the code yourself will give you insights that merely watching videos won’t, so pause the video, rewind the video, re-watch portions of the videos as you need to. I’m going to make the code available for download, and you’re welcome to it, and you can use that to compare the code that you write versus the code that I’ve written in the videos. But you really should be typing in everything on your own, in your own local copy of Visual Studio running on your desktop. Also, don’t rush through this course. If something doesn’t make sense again, pause the video. Rewind the video. Re-watch those portions that don’t make complete sense at first. Sometimes a second or third viewing, focusing more specifically on what’s going on around the screen and on the words that I’m saying can help. Being an active learner also means that you’re taking control of the process of learning so if I say something or do something that doesn’t completely make sense, by all means find a second or a third resource that can help you. Maybe it’s an article out on msdn.Microsoft.com or other videos on Channel nine or Microsoft Virtual Academy, but make sure you search out those resources that resonate well for you. If you’re interested in even more comprehensive version of a C-sharp training course that covers a lot more ground in more depth, complete with dozens of coding challenges and over 30 hours of video instruction, then please visit my own website. Devu.com Developer University You’ll also find many other training courses that I’ve created, designed specifically to help you become a professional C- sharp developer someday. Furthermore, over time, as we go through this course and as I begin to fill questions about it, I might add some study resources and additional free content related to the topics in the course that you’re currently watching right now. That’s another reason to be sure to visit me at devu.com, now like I said earlier, if you’re new to programming, I’m really excited for you. Learning to write applications is really one of my life’s passions. It’s extremely gratifying to breathe life into your imagination and watch your creations come to life and watch other people actually then use your applications. You’re embarking on a really exciting journey that’s immersive. It’s personally and professionally rewarding and best of all, I know you can do this again. I’ve seen so many people start off where you’re at right now, and they might even be working professionally, writing code for a living or building real applications that are being sold in App Stores like the Windows Store. If you’ve ever gotten stuck in the past when trying to learn how to program, I promise you that if you put in the time and you put in the effort and you work along with me as we work together, we’re going to build the knowledge of C-sharp that you need to be well equipped to move on to more advanced tutorials where you can learn how to build your own Web Applications, Windows Applications, Windows Store Applications, Cloud Services, Video Games and even applications that will run on iOS and Android using C-sharp. Now, assuming again that you have some version in addition to a Visual Studio already installed and you’re ready to go, then we’re going to begin writing C-sharp in the very next lesson. I hope you’re excited because I really am. This is so much fun. Let’s go ahead and get started. We’ll see you there. Thank you. >> Let’s take a look at how to install Visual Studio using the custom option for this example, we’ll use the Community Edition of Visual Studio 2015 in order to get it. Simply visit visualstudio.com and click on the ”Download Community 2015″ button. Once we’ve clicked on the download, it’ll download to our computer, and it’s a Web installer, so we click on the “Run” button and it will initiate the installation routine for Visual Studio Community 2015. Once we have the option screen available, it’s time to start looking at customizing the Installation of Visual Studio. For the most part, the default allows you to create web and desktop type applications. But if you want to create different styles of applications or include more languages then the ”Custom Option” is what you should be choosing. I always recommend selecting the ”Custom Option” for the Installation of Visual Studio 2017, to ensure that you’re getting the packages and libraries that you need to create the applications you may wish to use. By selecting ”Custom” and clicking on the ”Next” button, we are now brought to the screen and we can select the different features. The first option is programming languages, and if we click the ”Arrow” to expand it, we can see that we have Visual C++, Visual Fsharp and the Python Tools for Visual Studio that are additional programming languages that will get Installed if you select this option. Remember, by default, Visual Studio Community Edition will only Install C-sharp in Visual Basic Templates. Also notice under Visual C++, we have options for the common tools, the Microsoft Foundation Classes and then windows XP support for C++. For my purposes, I’d like to have all of my programming languages available to me, because I create projects using the different languages all the time. I’m going to select ”Checkbox” next to programming languages to install all of those programming types. Also, under windows and web development, we can choose various options here for things such as the ClickOnce Publishing Tools, SQL Server Data Tools, PowerShell Tools or Visual Studio, Silverlight Development, etc. Here’s a very important component, if you want to develop universal windows applications, we need to ensure that we have the tools, the emulators and the SDK. Now you can choose the “Default” Install a Visual Studio, and then come back and Install the Windows 10 SDK at a later time, and that will include the tools, the SDK and the Emulators for you. But it’s so much easier to install these during the Installation of Visual Studio. Please note that it will increase the Install size of the application, so the toolset will be much larger. Again, depending on what it is that you want to do, you may want to select ”Universal Windows App Development Tool Kit” PowerShell Tool for Visual Studio, rather if you want to be using PowerShell tools within your applications. If you need backward compatibility for Windows 8.1, and Windows Phone 8.0 And 8.1, you can select this option. Also, there are some common tools or Cross Platform Mobile Development Tools. These are important if you want to develop applications using the Xamarin platform. Xamarin is a cross platform tool that allows you to create applications for windows phone, for iOS devices and for android devices by using the C-sharp language in Visual Studio. All of these tools are available for the cross platform mobile development using Xamarin platform. It includes all of the emulators as well. Again remember, it will increase the size of the Install base for Visual Studio. You might also notice that because I selected the cross platform mobile development tools, we now have a little box inside the Windows 8.1 and Windows phone tools. If we expand that, we’ll see that it has included tools and Windows SDK, and the reason it does that, is because there’s a potential that you may want to target Windows phone 8.0 or 8.1 applications. The tools and SDKs will also get Installed. At the same time, the common tools checkbox includes a little square box, indicating that we have also added another component here, and that is the Git for windows. We can install Git, which is your source control, GitHub extension for Visual Studio, so that you can integrate with GitHub source control projects, and then an extensibility tools update three for Visual Studio as well. You’ll notice that by selecting all of these options, set up can require up to 48 gigabytes across all of the drives that you will Install it on. Again, review each of the items that you have selected to ensure you have all the necessary components tools SDK for your development tools of choice or platforms of choice, and then select the ”Next” button. Once you do, you basically see equipment or selected features screen that will tell you, all of the different items that you have selected, and by clicking ”Install” you agree to the license terms of all the software components. If you’re not sure what those are, each one of the items that has license terms allows you to click on it to view those. Once you’re satisfied with it, click the ”Install” button in Visual Studio starts installing all of the components that you have selected. This is a quick overview, of how to perform a custom installation of Visual Studio 2015. >> Hi, I’m Bob Tabor with Developer University. For more of my training videos for beginners, please visit me at devu.com. In this lesson, I want to build a super simple C-sharp Application. I want you to follow along. It’s a Hello World Application, meaning that we’re merely going to print out the words Hello World to a Console Window, and the point of this exercise is just to show you the basic workflow. I’m not going to attempt to even explain why we’re doing what we’re doing. The focus will be on, what I’m going to do next and how I’m doing it? In other words, I want you to focus on the basic workflow that’ll be the same for all the applications we will build in this course, and pretty much every Application you’ll ever build using C-sharp. Things like how to create a new project. Where do you type in your C-sharp code? How do you test your application to make sure that it’s running correctly, and what do you do whenever you have an error in your code? How do you save your project? Things of that nature. For now, just try to follow along. Don’t worry if something doesn’t make a lot of sense at this point, that’s really what the rest of this course is for. In the next few lessons. After this one, we’re going to dissect this tiny little application that we built, and I’m going to explain at that point why we did what we did and then what does the code mean and why it’s doing what it’s doing. Just a quick reminder, like I said in the previous video, the introduction of this course, I’m going to assume that you have some version and some additional Visual Studio already Installed, even if your Visual Studio looks a little bit different than mine does on camera here. Don’t be overly concerned about that. The basics are the same, no matter what, I promise. Let’s go and get started here. To begin, we’re going to create a new project. There are a number of different ways to do this, but I’m going to keep it simple and go to ”File” ”New” ”Project” and selecting that menu option will open up the new project dialog. Now, chances are, the number of items that you see here in the center part will be dramatically different than the items that I see based on which version, in addition, a Visual Studio that you have installed. However, you should be able to select ”Templates” and then select ”C-sharp”, and one of the options should be a Console Application. I want you to select that, and then we’re going to rename this project to HelloWorld. Now notice I use a little naming convention, where I use a capital H in Hello, and a capital W in world, and I don’t use a space in between the two words. Now that’s just the naming convention that I came up with to help me identify projects a little bit easier. Something I recommend that you follow. Shouldn’t have to make any other changes in this dialog. I’m going to go ahead and click the ”Okay” button, and Visual Studio will go off and now create the starting point of a Console Window Application for us, and so now you should see in this main area, in this text area, a file opened called program dot.cs and there’s some code here that is already generated for us boilerplate code. We’re going to ignore most of that, except we’re going to find this innermost set of Curly Braces. One of the first things you’re going to need to do when you’re learning how to develop Software is tell the difference between a parentheses, curly braces, square brackets, angle brackets and I don’t know that I left out any. But here we want the curly braces look like little mustaches turned on their side. These are important, and I want to go inside of those two that opening and closing curly brace and make some room for ourselves. This is where we’re going to type our code. It’s approximately Line 13 and 14, at least in my copy of Visual Studio. Then I’m going to type in the following, type in Console and you may notice now this little window pops up below what I’m typing. You can safely ignore that for now. Eventually, this becomes our best friend. But for now, it might be distracting and give it away to try to ignore it and type in everything by hand to the best of your ability. Console, and then I want to use the period on the keyboard, I’m going to call it the dot. Console dot, and then capital W Write capital L Line. Next, I’m going to use an opening and closing parentheses, so that’s not a curly brace. These are just the characters you’d use for a smiley face, and an emoticon. Then inside of there and use the arrow keys on my keyboard navigate around here. I’m going to go inside of the opening and closing parentheses, and I’m going to use two double quotes, so it should look like that. Make sure you don’t use single quotation marks like that. That’s not what we want. We want double quotation marks like that, and inside of there, we’re going to type in the words Hello and World. Make sure that you have an open parenthesis, a double quote, the words Hello World, then another double quote then another parenthesis, a closing parenthesis, and then at the very end of this line, I’m going to use a semicolon and it looks like that. It’s not a colon and it’s not a comma. It looks like that. Then I’m going to use the Enter key on the keyboard to go to the next line, I’m going to type in Console.ReadLine opening and closing parentheses. Now you may have noticed that as you type in the opening parentheses that Visual Studio will automatically type in a closing one for you. You don’t let that throw, you can continue just to type through that, but make sure that you have exactly what I’ve typed into my code window here for these two lines of code. Make sure that the capitalization is correct. Make sure that you’re using a period not a comma for the little mark that comes after the word Console. Make sure you’re using parentheses and not some other type of bracket, or brace, and then make sure that both lines of code end with a semicolon. The next thing that I want to do is save my project, and there are a number of different ways to do this in Visual Studio. Again, I keep it simple and go to File, Save all. Then the next thing I want to do is now see my application actually running. To do that, I can either find this little green triangle that has the word Start next to it or if I don’t see that by default in my little toolbar here at the top, I can go to Debug and select “Start Debugging.” Either way should work. I’m going to go ahead and click that, and you’ll notice that some windows pop up and Visual Studio changes its appearance a little bit. Now, off to the side of my screen, the console window popped up and we see the words, Hello World with a blinking cursor below it. I’m just going to hit the Enter key on my keyboard and then the console window disappears and I’m back and the Visual Studio resets itself and we’re successful. However, maybe your experience wasn’t successful. Maybe you saw an error message, so what I want to do is take a moment and look at some common errors that people that are new to C-Sharp might run into and how to remedy them and this is a good opportunity to learn some of the syntax rules of C-Sharp as we make mistakes. I’m going to pause the video, make a mistake, and then we’ll talk about it, pause it, and so on. When you attempted to start the application, you may have seen a little dialogue pop up from Visual Studio that says, “There were build errors. Would you like to continue and run the last successful build?” Always select no for that. What you’ll see next is a list of errors. Now, in some cases, the error messages will be obvious to you, and they’ll make a lot of sense. Sometimes they won’t. Like the verbiage might be something we’re just not familiar with yet. Invalid token and class structure interface, what does that mean? Typically what you can just do is double click on these and that’ll put your mouse cursor on the line where the problem is. Notice that Visual Studio also gives you another visual way to tell that there’s a problem with your code. Gives you these little red squiggly lines. Sometimes you see a blue squiggly line. They’re a little bit different but essentially this is an area of the code that probably deserves your attention, something you need to fix. Now, in this particular case, the problem is that we didn’t type our code in between the innermost opening and closing curly braces and so this is an issue with regards to defining a code block in C-Sharp or a block of code. Different C-Sharp commands belong in different kinds of code blocks, and I’m going to spend a lot of time in this course talking about the different types of code blocks and what belongs in each type of code block. But to remedy this issue, what you need to do is use your mouse and just drag and highlight these two lines, or you can use the Shift key on your keyboard in the arrow keys to highlight that area hit Control X, then move up in between the opening and closing curly brace and paste Control V that code in there, and then it should run correctly at that point. That teaches us the first thing about C-Sharp. It matters where we type our code. Or when you try to run the application you may have seen the same build error dialogue, except you see the message, “Semicolon expected.” Hopefully, this is an obvious remedy for you. If you double click on that error in the error list, it should take you to the end of the line of code where you forgot to add a semicolon. That’s the second thing about C-Sharp that we’re going to learn. Is that just like a properly formed English sentence has to end with a period or a question mark or an exclamation mark, a properly formed instruction in C-Sharp has to end with a semicolon, or maybe the error that you saw was something like a syntax error, something expected, the name Hello doesn’t exist in the current context. The name World doesn’t exist in the current context. If you were to double click these, you’ll get to the vicinity of the problem and you’ll also see that there’s red squiggly lines beneath the words Hello and World in between our parentheses. Now, remember, we needed to use double quotation marks around that string of characters Hello World and so alphanumeric characters that we want to literally write to screen, or present in some way, we need to surround them with characters that indicate that we want to use this string of literal characters. To do that, we use double-quotes. Or perhaps you see the error, something like, “The name console does not exist in the current context.” You look at the word and you say, well, looks spelled correctly. Remember that I told you you had to type exactly what I was typing and so C-Sharp is case sensitive, meaning that a lower case C and an upper case C mean that you’re typing two completely different things into C-Sharp and that is tricky because many of us are not used to that degree of precision whenever we’re communicating. But when communicating with a computer, you have to be precise. In this case, all we needed to do was change the capitalization of the word console and we’re back in business. Perhaps you see something like console does not contain a definition for either write line or read line, and again, you’re looking at it and you’re thinking it’s spelled correctly. Well, what could the problem be? Here again, capitalization is important. r read line is different than R read line, and l read line is different than L read line. Again, things have to be spelled correctly and have the correct capitalization in order to be processed correctly by the C-sharp compiler. We’ll talk about compilation in the next lesson. Now, if you’re not good at spelling and you’re not good at typing in capitalization and you’re just not as precise in the way that you would type a letter or an e-mail message or even a text message, fortunately Visual Studio can help you out. There are tools that will help you not only write your code more quickly, but also more accurately. If you utilize those tools, the chances that you will miss some of these really simple syntax things like capitalization, will almost be completely eliminated. We’ll talk about some of those tools in an upcoming lesson. All right, but assuming that you got all of this to work correctly, you’re really well on your way to building applications, you’ve already crossed over one of the big first steps. As you undoubtedly learned in this lesson, writing C-sharp code is an exercise in precision. Again fortunately, the Visual Studio IDE will help you out a lot when it comes to that. It will give you clues and maybe some of the phrases in the words that they use to explain the issue might not be familiar to you. Yet with experience, it will be. But generally, it’ll point you into the right direction and with the red squiggly lines in the message, you can typically figure out what the issue is. Now throughout this course if you run into a wall and you simply can’t figure out what the problem is, do this. Compare character by character, take your time until you develop a vision for the problems where your eye will jump to the problem and code. Compare what you wrote versus what I wrote. I’ll supply the source code to you. Open it up in a second copy of Visual Studio and then just look character by character. What did I do different than what Bob did? That will usually help you figure things out if you can’t do it on your own. In the following the lessons, we’re going to focus on two things. First of all, we’re going to talk about why we did what we did and what was going on behind the scenes that turned our code into a working application, all be it a small application. What happens whenever we create a new project? What happens whenever we choose to save our project? What happens whenever we choose to start or run our applications? Then secondly, we’re going to talk about the syntax of the C-sharp code that we wrote, and we’ll learn more syntax rules and more keywords as we go along. If precision is so very important in C-sharp, then you’re going to need to have some explanation as to what all those little words and symbols actually mean and some rules to guide you as you’re writing your own code. It’s really easy once you get a few of the basics under your belt. Being completely honest, many people learn how to write code in C-sharp. It’s a fairly easy language to learn, you can do this. Just you got to put a little bit of time, a little bit of effort to figure it out. We’ll begin that process in the very next lesson. Will see you there, thanks. Hi, I’m Bob Tabor with Developer University. For more of my training videos for beginners, please visit me at devu.com. Now in this lesson, we want to start the process of dissecting that little application that we wrote in the previous lesson. Now previously, I wanted you to focus on the workflow. What we did and how we did it. But now what I want to do is focus on why we did what we did. It’s really crucial at this point that we cement some really important ideas in your mind because they’re going to provide the basis, the foundation for everything that comes next. What I want to do is start on the inside and work our way out. I’ll start by talking about the nature of writing code. When you learn how to write applications with C-sharp, really any programming language, learning the syntax of C-sharp or in other words learning the nouns and the verbs and the punctuation of the programming language is really just half the battle. The other half of the battle is learning about related, pre-built functionality that’s available to the code that you write. Now in our case, Microsoft has created something called the .NET Framework, which sounds spooky and mysterious, but it’s really not that bad. It’s actually pretty large, but we’re only going to focus on two specific portions of it for our purposes. The first part that I want to focus on is something called the class library, which is simply just the library of code that Microsoft wrote to take care of difficult tasks so that, as software developers, we don’t have to worry about them. There’s library code to help with many common things that many applications will need, things like working with math, or working with strings and text, and working with dates, manipulating dates and times, maybe displaying things to the computer screen or transmitting information across a network. A lot of that foundational stuff that would be difficult for us to write and is utilized by many different applications. That’s really the first part. It’s taking advantage and understanding the class library of the.NET Framework. The second part of the.NET Framework is called the runtime. It’s also known as the common language runtime, you’ll see it called as the CLR as well. Really, it’s just this protective bubble that wraps around your application. Your application lives inside of it. It runs inside of that protective bubble and it essentially takes care of a lot of the low level details so that you, the software developer, you can focus on what your application is supposed to do, not worry so much about how it’s actually accomplishing it under the hood. You don’t have to worry about the computer’s operating system, interacting with it, and interacting with memory, and interacting with the hardware, the computer itself. Many of those things are abstracted away from you. You don’t have to worry about them. Furthermore, the seal are that runtime also provides a layer of protection for the end user so that you, the malicious evil software developer, you can’t do something really bad to somebody’s computer without them at least giving you permission to do it in the first place. So without their knowledge and their approval, you’re not going to be able to wipe out their entire hard drive, for example. For right now, it’s the.NET Framework class library that I really want to focus on because it’s what we used, whether you realize it or not, whenever we were writing our first application. For example in line 13 or 14 where we did our work, you see Console.WriteLine and then we used open parentheses, close parentheses, and so on. We were using code in the framework class library that knows how to display text into a console window. All we got to do is say hey, use this text, stick it in a window. We don’t really care how it does its job, we just care that it did it. The next line of code, this console.ReadLine. It was also really important. We’re telling the application to wait for input from the end user before continuing its execution. Again, here we’re calling code in the.NET Framework class library that knows how to accept user input. You recall that I use the “Enter” key in the keyboard, and then the application continued on. It exited and we were back in the Visual Studio. So in both of those lines of code, we were utilizing methods that were created by somebody in Microsoft to handle that interaction with displaying and retrieving data from the end user. What were to happen if we were to comment out that line of code? Here to comment out of line of code, I use two forward slashes on my computer, it’s over the question mark. Commenting our code simply means that I want those instructions to be ignored. Now, I could have just deleted that line of code completely, but I might want it later. Maybe I don’t want to remove it completely, I just don’t want to ignore it for now. I also might use code comments to write myself some notes to remind myself of something about the application in the future. We’ll talk about code comments a little bit later. But if we were to run the application now, watch what happens. It ran and it’s already done. What happened? Well, you may have seen a flicker on screen for a fraction of a second. The reason was because, hey, it executed this one line of code and it said looks like I’m done here, and it exits out of the application. By adding the read line, we’re now stopping execution, waiting for the end user to do something before exiting out. Hopefully that makes sense. All right, so next let’s talk about the position of the code that we wrote. I made sure to emphasize that you have to write the code in the correct place, and the correct place was in between the opening and closing curly braces of that innermost set of curly braces as defined by the level of indentation that we saw in the boilerplate code. If you don’t add the code there, we saw what the ramification of that was. The application, you’ll try to run it. It’ll give you a runtime error. The correct place for that code was where we have it right now, in between that opening and closing curly brace that you see on screen. Now as you can see, there are several sets of curly braces, and so it’s important that we talk about what these do. I need to oversimplify things here. We will come back and fill in some of the details later. But essentially, you have an opening and closing set of curly braces and those define the code block. Code blocks typically have names and they have purposes. In this particular case, we have a first code block and this code block has the name Main. This particular code block is known as a method, and this particular method by convention is the very first method that’s called whenever your application is executed. I don’t want you to worry about these other words static and void and even the string and the args for right now, we’ll talk about those later on. But this entire code block here, as well as the line above it, they define something called a method. A method is simply a block of code that has a name. Now, later on, you’re going to come to realize that a method is so much more than that. But I want to use that as a working definition as we’re getting started here. The method has a name, and when you have a name, you can call a name and say, I want you to execute. We’ll talk about methods again a little bit more a little while. This main method lives inside of another set of curly braces, and that set of curly braces also have a name. The name is program, it’s a class called program. You can think of a class as simply a container for all of the methods of your application. You can keep the methods that are related to each other in separate classes. Now what do I mean by related to each other? Well, that’s really for you the developer to decide as you get deeper into programming, you’re going to come to understand the thought process behind organizing your code. But that’s a little ways off for now. Just trust me on that. Now I said that a class was merely a way to organize your methods. It is so much more than that. Again, I’m way over simplifying this as we’re getting started here. But the main takeaway for right now is that code is organized in curly brace containers and you have some blocks of code that reside inside of other blocks of code. To emphasize that again, here we have another set of curly braces, and this set of curly braces has a name as well. In fact, it’s a namespace called HelloWorld, which happens to be the name of the application that we gave it. Again, key things extremely simple here a namespace is just another way of organizing code again. At some point it becomes so much more than that, but let’s keep it simple for now. Let’s take a look at these lines of code and illustrate these ideas about classes that contain methods. Here what we’re doing whenever we’re calling Console.WriteLine is we’re actually making a call into the dotNet Framework class library. Remember, it’s that library of code supplied by Microsoft. We’re saying in that entire library there’s a book and there’s a chapter inside of that book that I want to reference. In this case, we’re saying, that book is the console book, the class. I want you to look at the chapter named WriteLine that has the definition for this method. Hopefully, that analogy works for you, but we’re looking inside of a library to find a class, and we’re going to call a particular method inside of that class. By using its name, we can execute all the code that was written inside of that method. Same with the method that we’re calling below it as well. Notice that there is a period that we use between the name of the class and the method name, and we use that. It’s called a member accessor it allows us to access a member of the class or in other words, now that we know what the book is, we can find out what chapter we want to reference. Hopefully, that analogy works for you. Now, notice also that both whenever we call the WriteLine method and the ReadLine method, that they both have parentheses following them. Now, in the case of the WriteLine method, we’re actually sticking something in between the opening and closing parentheses, whereas in the ReadLine method, we’re not. But essentially, those parentheses are saying, not only do we want to reference that particular class method name, but the parentheses mean I want you to actually invoke it, execute it, do it now, so that’s the purpose for those parentheses. Now we can say, do it now and pass in information. Do it now with this stuff, with this argument. We’re passing in an argument to the WriteLine method and saying, we want you to do it right to screen and here’s what we want you to write. It’s an input parameter to the method named WriteLine. Now don’t worry, we’re going to come back to the notion of methods in the future, as well as passing values into a method like we did and as we passed in the literal string HelloWorld into our method here. Just know that whenever you see parentheses after a given word in your code, you should be thinking that code is being called right now as we step through the execution of the code. Next up, let’s talk about the semicolon. We’ve already explained it in the previous video, but just to emphasize it. Notice that almost everything, even these statements at the very top have semicolons, with the exception or whenever we’re defining a namespace, a class, or a method. We said at the time that the semicolons are actually similar to the period or exclamation mark or question mark at the end of an English sentence. It completes a thought in C-Sharp. Now, some programming languages like Visual Basic, for example, they don’t really have this idea. They only allow one complete thought per line of code. However, with C-Sharp, you could do this, what I’m about to do watch. Now I have both of those lines of code on a single line. If we run the application will work just as it did before. The way that you separate or indicate that you have two different complete thoughts, is through the use of a semicolon. Furthermore, we could put lines of code on separate lines like this. Now, it wouldn’t make sense in this case because the line of code is so short, it actually makes it difficult to read. But sometimes when you have a very long line of code, you’ll see me split that line of code into multiple lines, and still the application will execute. Now, in other programming languages, you wouldn’t have that behavior. Because really whitespace in line feeds and things of that nature, they don’t matter to C-Sharp. The only thing that really matters is to indicate a complete thought is a semicolon at the end of the line. Let me go ahead and get rid of all that. The other thing that I want to mention here that you may have noticed is the level of indentation that you get automatically from Visual Studio. Now that’s completely optional, and Visual Studio nudges you in the right direction. But essentially, even if you were to come out here and we’ll use the tab key several times and write the word Console.WriteLine, something like that. Notice that Visual Studio reinvented it for us. Why do you suppose it did that? Well, many people believe that indentation helps the readability of the code so that you can see what code container where code resides inside of the other curly braces inside of your application. Along those same lines for readability sake notice that there are many different colors that are used as text inside of this text editor window. You have these royal blue colors, and these are my default colors. Yours might look a little bit different, but by default, I think you have some royal blue, some black. You have aqua color here. This is a dark red. You have some light gray and light blue. All of those are used to help you identify the parts of speech, I guess you can say inside of the code that you write. We’ll talk more about that as we talk more about the syntax of C-Sharp in an upcoming lesson. Now that we’ve talked about the code that we wrote and its position and formatting and whitespace and tabs and all that stuff, what I want to do is stop right now for this video and in the next one, I want to talk about the files themselves. The file that we typed our code into, how that relates to projects and even solutions. What happened when we saved our project? What happened when we actually ran our project? We’ll do that in the very next lesson. We’ll see you there. Thanks. Hi, I’m Bob Tabor with Developer University. For more my training videos for beginners, please visit me at EW.com. Next, we’re going to talk about how code files are organized into projects and solutions. Then where you can actually find these projects and solutions on your hard drive. Whenever we created a new console project, the program does see a file was opened for us automatically in the main area in Visual Studio. That’s one of the things that project templates do for us whenever we choose File, New Project and we see the new project dialog and we choose a project template. They provide a great starting point for the type of application that we want to build. It includes files with boilerplate code, important settings and other resources that we might need whenever we’re building that type of application. As you can see, we’re working inside of this file in the main area and there’s a series of tabs. Again, this is an intended to be an overview of Visual Studio, but it’s important to note that the names of the code files that you’re working on are contained inside of those tabs. If you take a look over to the right hand side, here is the solution explorer window. It has a tree like structure of all the items that are contained inside of our projects. Now again, as I said at the outset of this course, this isn’t intended to provide a tour of Visual Studio per say. There are other resources on Microsoft Virtual Academy that can really help orient you to using Visual Studio in the various Windows and functionality that it contains, but the solution explorer is probably the most important part of Visual Studio next to this main area, where you’ll usually see the text editor and other designer windows. Simply put, the solution explorer is our main navigational device to the other files and settings that comprise our program. You can see here that there is a program, that cs file. Now, if I were to close the program, that see us tab in the main area, I can always get back to it and open it up again by double clicking it inside the Solution Explorer. You can see it’s open once again. The files and important settings are organized into a concept called projects, so you can see here this word “Hello World” is actually a project. You can see there’s a little C-sharp icon next to it, letting us know that this is a C-sharp project specifically. Projects get compiled into a single.Net assembly, which we’ll talk about later. Furthermore, one or more projects are organized into solutions, and you can see in the Solution Explorer, we have one solution here at the very top solution also named HelloWorld that contains one project. Now, in many cases, as you’re getting started, you’re only going to have one project inside of one solution. But as you come to build more complex applications over time, it’s highly likely that you’re going to need to manage multiple projects that are somehow related. Now again, the reason might not be obvious at this point, but as you continue to learn C-sharp and how to build more complex applications for large companies or for yourself, this becomes a crucial code management strategy. But just for now, accept the fact that there’s this extra layer of a solution and one solution can contain one or more projects and the projects will contain then all of the code files in the settings and the like that will be used to create an actual executable program. Trust me, these concepts will become more important after we get past the basics. Now, the big question at this point should be, where are all these projects and solutions and files actually stored on your hard drive? I mean, can we see them? We can see them in the Solution Explorer. Where are they actually on your hard drive? Well, when we created this “Hello World” project, we merely provided the name of the project, you’ll recall. Then I said, go ahead and accept the other defaults. By default, Visual Studio will put your projects into your documents folder. If you take a look here and we navigate into the documents folder, it will put your projects into whatever version of Visual Studio you’re currently using, so you can say I have side by side Visual Studio 2013 and 2015. We’re using 2015 for this series, but it could be a future version of Visual Studio. You’ll look in that particular folder for your version of Visual Studio. As we drill in, there will be a projects folder and as you drill and you can see that by default, when we created a new project, it put it here in our document slash visual studio, whatever version slash projects folder. As I add more projects, this obviously will be filled up with folder names for those projects. It’s important to note that whenever you create a new project, you don’t have to create it and put it right here. You can put it anywhere. To keep things organized, you’re typically going to keep them in the same place. Now, furthermore, you can actually open up a project that saved anywhere on your computer as well. For example, in this course, I’ll supply the projects. After I record the video, I’ll zip them up and you’ll be able to download them and then open them up on your own hard drive and then walk through them and to better understand them. Just to demonstrate how you do this, I have this project zipped up into a file called example.zip. What I’m going to do is actually right click this and select Extract all, and then in the extract compressed zip folders. I’m just going to put this on my route. C;/Example, and then click “Extract”. Now you can see that on my local hard drive I have an example folder. Inside of that folder there is another folder with a file called Example.sln, I’ll talk about that in just a moment. But I can either double click this.sln file to open up the the solution inside a visual studio, like so. Or I could go to “File”, “Open”, “Project/Solution”, and then navigate to that directory using the open project dialog if it’ll let me. Unfortunately, it’s a little bit too large for the recording area, but then I would just simply select the solution that I wanted to open from this dialogue and then click the “Open” button. Let’s go ahead and close that, and let’s shut down this copy of Visual Studio. I want to get back to where we were just a moment ago in our Documents, Visual Studio, in my case Visual Studio 2015 Project folder. Here are a list of all the solutions in our Project folder. Just want to walk our way through this. This first folder here will contain our solution files. There’s this.sln file, which is a solution file that contains information about all the projects, that are under this umbrella solution. We could actually open this up and look at it inside of notepad, and it’s simply just a configuration file. There’s nothing all that special about it. You certainly don’t want to make any changes to it, but it’s going to have information about all of the locations for the various projects that are associated with this solution, any global settings and some of these things won’t really be useful to us until we get deeper into our understanding of compilation and things of that nature. But inside of the solution folder, is a second folder which is actually going to contain the project files. Here we have a HelloWorld.csproj, which is the C-sharp project file. Let’s open that up as well with notepad. It’ll contain references to things like all the files that are associated with this project, any of the settings and any other metadata. Again, information in here that you certainly don’t want to edit, you don’t want to accidentally make any changes to it whatsoever. But I just wanted to make you aware of it, that there’s really nothing magical going on. There’s just these configuration files that contain information about your project. As you make settings on the project level, those will be saved inside of that cs project. Then finally, there’s this bin folder here. The “Word” bin typically is short for binary, which denotes that this is where a binary version of your application will be stored. The process of compilation it takes your source code, which is human readable, and it’s going to convert it into a format that is machine readable, or understood by a machine, your computer. If we were to take a look inside of this folder, we would see that there is a debug folder. This folders created for us whenever we started debugging our application, it creates a temporary version of our application for debugging purposes, which we’ll talk about later. If we drill into that you’ll see that there is actually an executable file and several other helper files for the purpose of debugging. We’ll talk about these later. If I were to double click the HelloWorld.exe, it actually executes our application. Compiling your code into a working application is the end goal. But I don’t want to talk about compilation just too much yet or about creating a debug version versus a release version of your dotnet assembly of your compile code. I think you’re going to get a better appreciation for those ideas, after we get past some more of the basics. What I want to do is stop our conversation about the directory right now. We’ll come back to that a little bit later. But you’re doing great. Let’s continue on. We’ll start learning more C-sharp now that we have some of these tangential topics all the way. I’ll see in the next lesson. Thanks. Hey. I’m Bob Tabor with Developer University. For more my videos for beginners, please visit me at Devu.com. Now in this lesson, I want to get back in to talking about C-sharp the syntax. We’re going to talk about declaring variables, how to choose the right data type, for your new variable and then also how to initialize variables with values. To begin, let’s take a look on screen. If you’ve ever taken an algebra course, hopefully you’ve seen something like this, where you’re asked to solve for the value of x, and hopefully without a lot of thought, you’re able to see that x equals 7. Using that same thought process, take a look at this little snippet of code on screen. x equals 7, y equals x plus 3. Then we’re going to do a console.WriteLine with the value of y. Hopefully you look at it for a moment, using your existing knowledge of algebra and you think to yourself, then it’s going to output the value of 10 to a console window, right? Exactly. So my point is that C-sharp, first of all, is human readable. It’s got a few things that might be a little formed like the semicolon at the end of the line. However, for the most part, I’m willing to bet that as we go through the series of lessons, you’ll be able to understand what the code is doing for the most part. Even before I explain it to you. It’s really not that hard. Then secondly, it’s probably very similar to things that you’ve done in the past like working with math and algebra and things of that nature. If we’re looking at the C-sharp code, the x and the y in this context, are referred to as variables. A variable is simply under the hood, a bucket. I guess you could call it in the computer’s memory and you put things in buckets and you dump things out of buckets. We can put values into a given bucket in the computer’s memory, and we can retrieve the value out of that bucket. We can even replace what’s in the bucket with something different. That is what you use a variable for. This particular situation that we see on screen, these buckets are just holding numeric values. However, we could create buckets that are just the right size for almost any type of information, whether it be individual alphanumeric characters, or strings of character, strings of alphanumeric characters like even entire sentences and paragraphs, and even books. We can also create buckets that are just the right size for dates and times, buckets that are just the right size for really, really, really massive numbers, or even create buckets that are just the right size for numbers that have a lot of values after a decimal point. Now, in this case, what we would expect to see here is that these two buckets, the bucket that’s labeled x and the bucket that’s labeled y, would hold numeric values. Because we want to add numeric values together. We know that. But how do we express that intent in C-sharp? The instructions that we write in C-sharp were ultimately after a compilation step, they will ultimately be executed by the dotnet runtime that we learned about in a previous lesson. In part its responsibilities are to make sure to allocate memory for our variables in memory to hold the right kind of data. Here we have two data items, are x and y, and we have to tell the runtime that we want to allocate some space in memory that sufficiently large enough, to hold numeric data, like the type of data that we want to work with here and our application. But how do we do that? Well, that’s the topic of this lesson. To get started, what we want to do is create a new project. Here again, I’m going to go to file, new project. We will go to the new project dialogue and make sure we select the Console Application project template. Here we’re going to rename this and call this project variables and then click the “Okay” button. Visual Studio goes to work, uses that template and creates a new solution with a project and as you can see on screen here we are back in our familiar program.cs. Obviously we want to work inside of our static void main in between the opening and the closing curly brace just like we learned about in our previous lesson. Before we get started, there’s one big takeaway from this lesson and that is that a variable is simply a bucket in memory that you can put data into and retrieve data out of but we have to tell the compiler, we have to tell the.Net runtime what size of buckets that we want to create. We have to declare our variables, we have to create those buckets and then give them some label that we can refer to them with from that point on. Now, before we get started here typing some code, all the same rules apply in this video that applied previously. You have to type the code exactly the way that I type it. Take the time, develop the skill of identifying even small differences, different in capitalization, or spacing, or the various special punctuation marks that we use while we’re writing code. Develop that skill to identify the differences between what I write on screen and what you’re writing in your copy of Visual Studio. If you see a little red squiggly line, you already know that there’s going to be a problem there. That gives you the clue necessary to go and focus either on that exact character or in that vicinity and use your detective skills to figure out what it is that went wrong. Now let’s go ahead and we’re going to create two buckets, two variables and define them in such a way that they’re going to hold numeric values. We’ll start with int x and int y as simple as that. Here to borrow the explanation that we used earlier, we are asking the.Net runtime to allocate space in our computer’s memory sufficiently large enough to hold numeric values. Now, we’re asking it to create these two buckets and eventually we’re going to put values into them and read values out of them but at this point we’re just declaring their existence and saying, here’s what we need to work with. Then after we’ve declared that, after we create them in this manner, then we can begin to work with them and assign values, retrieve values from them. But most importantly here I’m telling the computer that I want to assign integer values into those variables. An integer is really just a mathematical term that refers to a whole number that’s within a certain range. No values after the decimal point and as far as C-sharp is concerned, the values have to be between a negative two billion, 147 million and a positive two billion,147 million. That’s the size of the bucket that we have to work with. If you need to work with much larger numbers then the in data type is not the correct data type for you, there are other data types to choose from and we’ll learn about some of those a little bit later. If we need to work with like money values where you have dollars and cents or pounds and pence, then the integer is not the right data type to work with. Let’s continue in our application and this is basically just to continue what we did in Notepad a few moments ago. X equals seven, y equals x plus 3, and then we want to do a console.write line with the value of y. Then remember we want to do a console that read line so we can actually see it on screen without it just flashing and going away immediately. Let’s run the application and make sure we get the value that we’re expecting. Hopefully you got the value 10 in your copy of Visual Studio just like I got in mine. If not, again, make sure you double check your work against mine. After we declared the variables in lines 13 and 14, then in lines 16 and 17 I’m doing assignment using the equals sign. Now, in this case we don’t really call it the equal sign, we call it the assignment operator. We’ll learn about operators in the next couple of lessons. This particular operator, the equal sign means take whatever is on the right hand side and assign that into whatever is on the left hand side. We’re going to say give me the value of seven and assign that to a variable, a bucket named x. The same thing would be true here with y, we’re assigning a value into the bucket named y but we have to do something interesting here. We have to actually retrieve the value of x from memory. Where’s that bucket again? Oh, there’s the bucket, dumped the value in the bucket out, you’re holding the value seven. Add that to three and then we assign that to the value of y. Now, here we’re retrieving the value of y saying, give me the bucket with y in it and you dump it out into the console.write line which we know, then we’ll print that to screen and that’s essentially assignment and retrieval of variables. This is a very simple case. What I want to do now is comment out this code. If I were to begin commenting out the code like we learned about in a previous lesson, I could use the two forward slashes. I’m going to show you a different method in just a moment but notice when I do that, something interesting happens. I commented out the declaration for the variable named x. When I do that, notice these little red squiggly lines underneath x’s and if I hold my mouse cursor there, it says the name x doesn’t exist in the current context. We might say, well, there it is right there. It’s in our code comment, but remember we’re telling the the C-sharp compiler and ultimately the .Net runtime to ignore that instruction. The compiler is looking at our code and saying, I have no idea what you’re talking about X. I’ve never heard of X before, I don’t know what you want me to do with X, and so it raises the red flag and say, I can’t continue on under these conditions, you have to give me more information. Obviously we can fix it by removing the code comments. Now, what I want to do is comment out several lines of code and instead of just doing two forward slashes in front of every line which can be laborious, I’m going to comment out multiple lines at the same time using a forward slash and a star character over the number 8 on your keyboard to begin a lengthy comment. Then right here before that read line, actually let’s go ahead and keep it all together. After that I’m going to do a star forward slash. Now we’re going to type another code example beneath that. This will be a little bit more interesting. Follow along. Pause the video if you need to catch up with me, I’m going to try and type fast just to save time. Before I forget, let’s go “File”, “Save All”. Now let’s begin here at the top. You can see that this is a different style application with some different commands or different uses of commands that we’re familiar with. We’re just going to play a little name game and we’re going to ask, what is your name, and we output type your first name. Now notice in the first case, I’m using a right line, which will print what is your name to screen and then use a line feed character to go to the next line. However, I’m using yet a third method from the console object, the console class, which we’ll talk about classes and methods later. But this method is different than write line. This will just write out the statement type your first name, whatever’s in between our double quotes there, and it won’t go to the next line. It’ll just wait there on that line. Then what we’re going to do is create a new variable using a different data type, a string data type. We’re not interested in individual alphanumeric characters, so a-z, 1-0, and the special characters. We’re interested in a string of them or a collection of those characters. So not just the individual character B, the individual character O, and the individual character B, we’re interested in them as a string or a

    collection as Bob B-O-B. That’s what we’re declaring a bucket in the computer’s memory sufficiently large enough to hold a string of characters, however long that it is. Then what I’m doing is calling our Console.ReadLine method that we’re already familiar with. But there’s a twist on this. Up to this point, we said we’re using the ReadLine method in order to stop the execution of the application to wait for the user to hit the “Enter” key in their keyboard, then to resume. However, now we’re using it for its real intent, which is to retrieve data from the end-user. In this case, we’re asking the question, what’s your name? The user types it in and hits “Enter”, and then whatever they typed in is assigned using the Assignment operator to the variable we created called first name. Hopefully, that makes sense. Now we’re going to create a second variable of type string called my last name. We’re going to do the same thing here, Console.Write, and then we’re going to allow the user to type in their last name, and then whatever they type in when they hit the “Enter” key on their keyboard will be saved or assigned to the variable called myLastName. Now that we’ve done assignment to my first name and my last name, I’m merely going to concatenate the values together. Let me point something out. There are several things we need to talk about here. Notice here we were doing actual math where we were adding values together. This is the arithmetic or arithmetic operator. We’re basically adding things together right here. We’re kind of adding things together, but that connotation is different. We’re not adding Hello and Bob and Tabor with some spaces in there. From a mathematical perspective, we’re concatenating strings of characters together to make one really long string. It’s the same operator, but it’s used in two slightly different contexts. Kind of does the same thing, but we need to understand that there’s a fundamental difference in how operators interact with different data types. You’ll see why this is important as we continue on through this course. But at the very end here we’re expecting to see, Hello, Bob, notice that I have in here a additional double quote with a space in between to give some space in between the first name in the last name, and then obviously, my last name here. We’ll get that one more line of code to write because we need to do another read line so we can see the value on screen. Let’s run the application. Then we have some things we want to talk about here. What is your name? Type first name Bob, Enter, type your last name, Tabor, Enter. Hello, Bob Tabor. Awesome, so very simple application, but hopefully, now we’re pushing the envelope a little bit more, learning a little bit more about additional data types that we can use for our variables and learning about assignment that it works with all kinds of variables, and then also learning about operators that work differently with different data types. Now, before we get too far, in the previous example, we used merely X and Y, which we might expect to see in some mathematical context because we’re used to seeing those characters used in algebra problems. But whenever we start writing business applications or even games, we need to give our variables names that are meaningful inside of the program that we’re writing. I could have just called this x and then done something like this x and then done something like this x, and you’d look at this and you’d say, I have no idea what x is supposed to do. It’s because we used a very vague description of the bucket in the computer’s memory. Instead, you don’t have to worry about keystrokes, make it human-readable. Write your code in such a way that somebody can read through it and understand exactly what the variables are doing and what the logic of the application is doing. Then also notice as I go and change some of these things back here to my first name, I used a little feature of Visual Studio that allowed me to say, now that I have changed the name of x to first name, let me rename it everywhere that I’ve used the word x. Did you notice I did that? I hit the “Control” and the period on the keyboard here. Let’s do that one more time. I’m going to change this back to x. Notice that I get a little light bulb here off to the left-hand side, which is Quick actions, and then I hit “Control” period on my keyboard. Now it gives me the option to rename my first name to x and it even off to the right-hand side shows me all of these changes. This is called a refactoring. I’m changing the code just ever so slightly by renaming things to give them more meaning. In this case, I’m doing the exact opposite, but we’ll come back to that. Do I want to rename every time I use the variable name, my first name to x? Yes, so let’s rename everything bam just like that. Let’s rename it one more time. So myFirstName, Control, period, and now I want to rename everything from x to myFirstName. You might look at that phrase, myFirstName, and then again, I used it down here, myLastName, and you’re thinking yourself, that’s a crazy naming convention. Well, it’s a naming convention that’s called camel casing, where you start with the first letter in a list of words that you’re munching together to describe a variable or something along those lines. Use a lowercase for the first letter of the first word and then an uppercase letter for the second and subsequent words in variable name. Ideally, it makes it human readable. I can read it fairly easily that way. At this point, I think it’s important also to do something like this. I’m going to rename this to myfirstname all lowercase. Remember what we said in the previous video that C# is a case sensitive language. So if you were to use the wrong capitalization, then you’re going to get a red squiggly line and it says my first name does not exist in the current context. Do you remember seeing that just a moment ago when we removed the declaration for x up here when we commented it out? The same thing is true here. Myfirstname, all lowercase is different from the variable defined called my F Name, First name. Capitalization matters. Make sure that you remember that. In this case, let’s just go ahead and change everything back correctly, and we should be good to go again. Great. Now you might be saying to yourself, well, this degree of precision seems pretty difficult. How am I going to remember exactly what I named things in the past? There are a couple of different tricks for them. Keeping your code and methods small, and we’ll talk about that later, that’s one way to do it. But then the other thing is to rely on IntelliSense, which is that little code window that I told you to ignore before. It’s actually pretty important. As I start typing my, notice that it pops up beneath what I’m typing, the correct capitalization, correct spelling for any of the variables that I’ve defined up to this point that start with the letters m, y. Now, at this point, what I can do is simply hit the equals sign on my keyboard and it will type everything else out for me. So I don’t have to worry about spelling, I don’t have to worry about capitalization. You may have noticed while I was typing, I was typing and then using arrow keys on my keyboard, and then you couldn’t really see my fingers moving, but I wasn’t typing every single keystroke. This is what allows software developers to write code very quickly. Once you get used to relying on IntelliSense, one of the tools that Visual Studio gives you in the text editor to make your typing more accurate and allow you to type much faster than maybe you normally could. We’ll come back to IntelliSense later. The other thing that I wanted to tell you about here or talk about is that we cannot define the same variable two times. Let’s try this. I’m going to go and view myFirstName and say I want another bucket in the computer’s memory with the same name, myFirstName, and the compiler says, you can’t do that. We’ve already got a bucket. We’re going to confuse buckets in memory if we give two buckets the same name. it says a local variable name, myFirstName, is already defined in this scope. You can’t do that. Now we could do this, but I highly recommend you don’t do that because, again, myfirstname all lowercase is different than my first name with camel case. But this would cause a high degree of confusion, so never do that. Be descriptive with your variable names, don’t repeat variable names, always stick to a naming convention, and never break that rule. If you follow those little rules, I think you’ll find some of these initial issues they’ll just dissipate, you won’t have to worry about them. What I want to do now is take a look at this second set of code. Then not only are we in line number 29 declaring the variable, but then in line number 31, we’re actually giving it a value. What if we were to rewrite this little passage of code? I’ll go ahead and comment all of this out, and I’m going to make this smaller. In fact, here’s one we’ll do, string myLastName equals Console.ReadLine, and then I will say above that Console.WriteLine, “Type your last name.” You can see that I took these two lines of code 29 and 31 and I combined them together. What I’m doing here is not only declaring the variable, but then I’m initializing its value to whatever we retrieve when we call Read Line. This is called initialization, and initialization is important because you want to give your variables a value as quickly as possible. This puts your variable into what’s called a, valid state, which will be an important idea as we learn to write real applications. But also experienced developers like to write less code, and they’re always looking for a convenient way to reduce the number of keystrokes that they have to type and reduce the amount of code that they have to read. Usually you want to declare your variables as you’re using them and not declare them like some people used to do a long time ago, put them all at the very top of a given method or or section of code. You should get into the practice of two things, declaring your variables as you need them in the body of your code, and then secondly, if you can, give them an initialized value immediately after you declare them, like we’ve done here in line number 34. Tell you what, let’s stop right there. I think we’ve covered a lot of ground for one lesson. Let’s do a quick recap and just talk about over a dozen things that we discussed. We talked about what a variable is. We talked about how to declare a variable, how to choose the correct data type. We talked about the int data type and the string data type. We talked about assigning values into variables and then retrieving values out of variables. We talked about the assignment operator. We looked at the arithmetic operator and also the string concatenation operator, which is both just the plus sign. We looked at Console.Write versus Console.WriteLine. We looked at the other life of the Console.ReadLine method that we can actually retrieve the values that the user types in. We talked about camel casing and naming conventions for our variables. We looked at IntelliSense. We talked about how to rename things, how to refactor our code using the little quick action. Remember the little light bulb that we could make changes to by hitting “Control” and “Period” on our keyboard, and then using our arrow keys to make selections and to rename all uses of our variable name throughout our entire code base. We probably talked about a lot more than that as well, but that’s going to wrap it up here and we’ll start again in the next lesson. We’ll see you there. Thanks. Hi, I’m Bob Tabor with Developer University. For more my training videos for beginners, please visit me at devu.com. In this lesson, things are going to get a little bit more interesting. Based on user input, we’re going to write logic to execute either one block of code or another block of code. When I use the term logic, I mean that we’re going to make a decision and execute some code based on some condition that could be the user’s input from the keyboard, maybe the state of the computer system itself, maybe some of the data that we have access to are available to us, but somehow we’re going to make a decision on whether to branch out and execute this code or execute this other code. Let’s begin the way that we normally do by creating a new project, and I’m going to go to “File”, “New”, “Project”. Make sure to choose a C-sharp Console application, and we’ll call this project decisions and click “Okay.” What I want to do is we’re going to create a little game and we’re going to do it right here in static void main. I’m going to go ahead and start typing. You can pause. Try to catch up with me. Hopefully, most of this will make sense. Let’s go ahead and run the application, and here we’re going to play Bob’s big giveaway and we can choose a door. What’s behind door one, two or three? I’m going to choose what’s behind door number one, and I said, hey, you won a new car. Awesome. Let’s play again, I’d like to win something else. Now we can type in the number two and, well, nothing really happens at all. I’m going to hit “Enter” again on a keyboard and the application just ends. We can try the same thing for three, but I suspect the same thing will happen with number two, and I can just type something randomly and again nothing really happens here. But let’s start at the basics and talk about this if statement that we’ve created here, which is really the purpose of this lesson in the first place. The if statement is called the decision statement because we will decide whether to execute any of the code inside of this inner code block based on this evaluation that we’re going to do after the if keyword. In this case, what we’re doing is evaluating whatever the user typed in and we’re gathering that from the Console.ReadLine like we learned in the previous lesson. The user typed something in then hit “Enter”. We got that now and the user value variable. We want to perform an evaluation to see if what the user typed in is equal to this literal string number one. Here’s where hopefully, I want to call your attention to this, you can see that I’m using two equal signs next to each other. We already learned previously that a single equal sign is actually an assignment operator. We’re assigning the value of whatever the user typed in, and in this case in the Console.ReadLine to the variable user value using this assignment operator. But whenever you use to equal signs next to each other, you’re going to do an evaluation for true or false. Whatever’s inside of this opening and closing parentheses, we’re going to perform an evaluation. Is user value in fact equal to the number one or rather the string character one, or is it not equal to the string character one? It can only be true or false. Based on that, if whatever the evaluation of that expression is, if it turns out to be true, then and only then will we perform the code defined in the code block immediately after that if statement. If that’s not true, if this turns out to be a false statement, then we’ll just ignore whatever is inside of this code block and we’ll continue the execution of our application to Line 23 and then beyond. That’s how it works. But I tell you what, this is a very interesting example because obviously here we have we have no prize for door two or three. Then what happens if somebody just types in four, five, six or SDF or whatever on the keyboard? We need to account for all of those scenarios in our application. Let me continue typing in some code here, and you can again pause the video if you need to to follow along. But we’ll start by using an else if statement right below our code block for the if statement, so here we go. Let’s stop right there for the moment, and you can see that in order to evaluate additional conditions, I can use the else if statements. In fact, I have two of them here. If this first evaluation is not true, then we’ll continue on and do a second and a third and maybe a fourth and fifth, how many other evaluations you want to do. However, if this is true, then will no longer run. Any of these additional checks will just continue on to line number 33, the same is true here. If this is not true, then we’re going to evaluate this next expression. If this is true and we execute the code inside of the code block immediately following it, then we’ll just go ahead and skip over this last else if statement and continue on to line number 33. If we were to run the application, let’s go ahead and just quickly run through scenario number 2. Hey, we want a boat and scenario number 3, which obviously would allow us to win a cat, but then we still haven’t accounted for the situation where we type in four or anything else, like the word or just random letters on the keyboard. Nothing really happens in those situations. What we really need is what I would call a catch all case. To do that, we’ll just create an else statement below that at the very end of our if else, if construct, and so here what we’ll do is just that string message equals, sorry, we didn’t understand, and then Console.Writeline(message). Now, we’re catching every other case possible, no matter what the user types in. Let’s go ahead and run the application. Again, I’ll just type in some junk from the keyboard. Hit “Enter” and says, sorry, we didn’t understand, and we continue on. That’s how and if decision statement work. It also has these optional parts of the else if and the else statements for either additional evaluations or what I call the catch all just in case none of the conditions are true. Now, there’s a couple of things about this, and we’re going to continue on to talk about one other type of decision operator that we can use a conditional operator. But before we do that, here’s an opportunity to clean up our code. Let’s look for areas where we’ve essentially got the same code repeated over and over and over again, and I can see a couple of of instances where this is true. The first would be where we have this Console.Writeline(message). You see, we’ve repeated that in line 20, 25, 30 and 35. Wouldn’t be great to keep our code a little smaller and only use that once at the very end of our evaluation. Like, put it right there outside of the if else, if else, decision statements. Let’s go ahead and just remove those from there completely. But when we do that, notice that I’m getting a red squiggly line under the word message. The name message doesn’t exist in the current context. We’re going to talk about scope and declaring variables inside of certain scopes and a little bit, but just to lead up to that conversation. Essentially, when we defined a variable inside of an inner scope, it’s not available outside of that scope. In other words, if we define a variable inside of a code block, inside of the curly braces, it’s only available inside of those curly braces not available outside of those curly braces. What we’ll have to do is define that message variable outside of our if statements so that it’s accessible to all of the inner code blocks, as well as our Console.Writeline(message) here in line number 35. It’s a very simple fix. We’ll just do this. String message equals and then we’ll just set it to an empty string to begin with. Now, you’ll see a different message, a red squiggly line. But we’ve seen this before. You can’t define the same variable twice, even if it’s in an inner scope. What we’ll do is just say, instead of defining the variable message there, we’ll just set our existing string variable called message to the value like so. Great. Now, our applications should run, we’ve eliminated a lot of code, and admittedly, I created a straw man here. I wrote more code than I needed to, but I wanted to illustrate this point. Again, if we were to run the application. It works correctly. But there’s one other change that we can make. Code blocks as we’re using them inside of, if else, if and else statements. If there’s not more than one line of code to execute, then we don’t even need to use the curly braces. In other words, since there’s just one line of code here underneath my if statement, I can just remove it and make it small like that real compact. Same is true here, and same is true here. Now, in this case, maybe just to illustrate why you would need the opening closing curly braces if I were to do this message equals the message plus, you lose like so, and I’ll even add a little space here to make it look correct. Let’s go ahead and test that else case just real quick, and I’ll type anything in there and hit “Enter” and says, sorry, we didn’t understand you lose. Notice that we were able to concatenate two strings together. I did it on two separate lines you don’t really need to. But if I were to attempt to remove the opening and closing curly braces there, we’re going to get a very different result when we run our applications. For example, if I hit “3”, notice that you want a new cut, you lose weight. Why did that happen? You want a new cut, but you lose. Well, there is no such thing as a free cut, but anyway, it’s because what it’s really seeing is this like that. If we want these two to be evaluated together inside the same code block, we have to include them in the same code block. Otherwise, this being outside of that code block will execute no matter which of these, if or else if conditions are true. Let’s go ahead and put that back in there to illustrate that idea. In fact, if we were to do something like this, I can even make this a little bit smaller. Let’s comment that out, and I’m going to show you a new operator, which is just this. Now, instead of going message equals message plus you lose, essentially, I’m saying, give me whatever’s in the variable message, concatenate on the word you lose, and then assign that into the variable message. That’s what I did here. I just do it all in one step right there, where I say, whatever’s in the variable message on the end of that concatenate, you lose. This is the assignment and concatenation operator combined into one. Just a little shortcut there. Now let’s do this. Let’s talk about another style of decision statements. It’s actually an operator called the conditional operator. This works well if you have an if or else scenario and you don’t have multiple items to evaluate like we did here. I’m going to copy some code from lines 14-15 and line 16 too, I’ll just copy all of those, and we’re going to paste them down below our command area. Then what I’m going to do is this. Will do this a little bit different this time. There we go. Now I’ve written a lot of extra code that I need to, I’m going to show you how to shorten this up in just a moment. Here, the key to this is this little evaluation that I’m doing on line number 42. Remember that we’re going to evaluate anything in between the parentheses. Whenever we see the double equal sign, that means we’re doing an evaluation. Is the user value that they typed in and submitted through the previous line of code, line number 40, is that equal to the literal value 1? If this equates to true, then what we want to do is, everything after the question mark, we’re going to take that value and assign it to our new variable called message. If the user types in one, will find the literal string boat and will assign it to the variable message. However, if this equates to false, so they type in something different, then anything after the colon will be taken and assigned to the variable message, and we’ll use that below. Let’s go ahead and run the application, we’ll run it twice. We can choose the door and if they choose door number 1, they win a boat. However, if we run the application a second time and we choose anything else, then you’ll only win a strand of lint. Again, this is only useful in a if, else condition, not when you have multiple conditions to evaluate. Now, let’s address this last little part here because I can shorten this up considerably. Notice, in order to get it all to print out on one line, I only use Console.Write, then I typed out the literal string, and then I have a second line where I’m actually then printing out the actual message from line 42. Then finally, to add a period at the end, I’m having to do yet another Console.Write statement in order to add a period. I can shorten all that up in one line of code. Watch how I do this. In fact, let’s go ahead. I’ll comment out these lines individually, like so. Then I’m going to use a replacement character inside of the Console.Write line in order to shorten this up a little bit. We’ll use the WriteLine instead, and we’ll fill you one a and then I’m going to use what I call a replacement code of zero. Then after I give it that literal string and you use a comma and then give it the actual message variable that I want. Whatever’s inside of this, I want it replaced in here. Eliminate the curly braces with the zero and put the message variable value inside of there. Let’s run the application again just to see this working. I’m gong to type number 1 and get the same result. Now, what if we wanted to expand on this idea here? Let me comment that out. What if I wanted to replace two values inside of that Console.WriteLine string? Let’s do something like this. You entered and then we’ll go 0. Therefore, you won a. In this case, after the comma, I’m going to enter the user value and then the message goes, make sure you can see that. Hopefully, you can see that on screen at one time. I need to do one little thing here, is change that to a 1. This says, take the first item. In software development, typically you don’t start with the number 1, you start with the number 0. I don’t know. We’re going to see this pop up again and again. The first item in the list will be at element 0. The second item in the list will always be at element 1 and so on. The very first item, this will be matched and replaced by the very first item in that comment a limited list of input parameters, after the literal string that little template that we’ve created for ourselves. Then here we’re going to do a second replacement and replace that with whatever is inside of the message variable, when we run the application. We type in number 1. It said you entered 1; therefore, you won a boat. Awesome. That’s enough for one lesson. Hopefully, you’ve learned a couple of important things in this lesson. First of all, we talked about the if decision statement, as well as the else-if and the else, and how to do a comparison and evaluation between two values to determine true or false. If we’re using an if statement and we’re doing that evaluation, then the code that is in the code block below it will get executed if that evaluation is true. If it’s not, it’ll either drop down to a second subsequent evaluation or even do a catch-all in the else statement. We talked about using curly braces for a code block versus when you don’t need them. We talked about keeping your code nice and tidy and small. We talked about declaring variables inside of scope and inner scope and outer scope as defined by our curly braces for code blocks. We talked about the conditional operators, being able to all in one line do a check for true or false, and if it’s true, assign one value versus a different value to a new variable. We talked about format codes inside of literal strings for our Console.Writeline and how to replace those replacement codes with variable values that we then also pass in our Console.Writeline statement like you see here at the very bottom in line number 49. Again, we covered a lot of ground. Hopefully, this all makes sense, if not, rewatch the video, just watch those portions that didn’t make sense. Make sure you’re typing in the code yourself so that you can come to some of these epiphanies as you’re typing. We’ll pick it up in the next lesson. See you there. Thanks. Hi, I’m Bob Tabor with Developer University. For more of my training videos for beginners, please visit me at devu.com. In this lesson, I want to spend a bit more time talking about some smaller syntax elements of the C# language that you need to master to understand how a properly form line of code is constructed in C#. In one of the previous lessons, almost like the first lesson, I said something to the effect that just like you use a period or question mark or exclamation mark at the end of a sentence in English to complete a thought, you also use a semicolon at the end of a line of code and C# to denote a complete thought. To extend that analogy a little bit, I may have briefly referred to C# syntax as having nouns and verbs. So I want to elaborate on these things and clarify what I mean by that in this lesson. I’m going to talk about the basic building blocks, and I guess you could say, parsing the parts of speech in C#. Let’s start off at the beginning. Statements are what you call complete thoughts in C#. Typically, one line of code. A statement is made up of one or more expressions and expressions are made up of one or more operators and operands, so we’ve seen a number of statements and expressions and operators and operands already, whether you realized it or not. As we’re taking a look at some of the previous work that we’ve got here, I’ve got the variables project from a previous lesson opened up. For example, you can see that essentially each line of code is a statement. Each of them are made up of one or more expressions. Here, for example, is an example expression. This happens to be a variable declaration statement made up of a operator, which in this case is a keyword Int for the data type integer, and then an operand, in this case, a variable name. We also use another operator, the semicolon for the end of the line of code. Another example would be here where we have an assignment where we’re actually calling a method. Here is an operand. It is the name of a class, and we’re using the open-close parentheses. Remember, these are operators. This is the method invocation operator. Then we’re using another operator here, the assignment operator, to assign the value of this expression to another operand, the name of the variable that we created. We were to look through the code, we could continue to parse out and understand what makes up operands, operators, expressions, and then entire code statements. Now, operands are similar to nouns. They are things like objects and classes and variables and even literal values. These are the subject, I guess you could say, of your statement of code. They’re pretty easy to remember because typically you give them names, you define the values yourself, and so on. Now operators are similar to verbs. They are things like the addition operator or the string concatenation operator. These are things that act on the operands in order to perform some action. Typically, you’re going to use the built-in operators, although you could create your own operators. A little bit of an advanced topic, but there are actually quite a few built-in operators and you’re going to need to memorize many of them. That’s how you come to express yourself in C#. Fortunately, as you start out, you probably only need to know a handful to be productive. What I want to do in this lesson is to focus on a few that I think you’re going to use probably 90 percent of the time as you begin learning and you can obviously add to that list as we continue. I’m going to actually present these in a rapid-fire fashion. I created a very nonsensical application. You can open this up, download it from wherever you’re currently watching this video or wherever you originally downloaded it from. I called this project OperatorsExpressionStatements, and the application itself does absolutely nothing meaningful at all. All it really does is show you some examples of the various operators and expressions that you’ll come across whenever you’re working in C#. At the very outset here you can see that I have a variable declaration. We talked about this already. I did something a little bit different this time where I’ve declared several variables all upfront as integer. So x, y, a, and b are all defined as integers. Just wanted to show you something a little bit different there. By separating them with commas, it’s an easy way to declare several variables of the same type, all on one line of code. I typically don’t recommend this, but you might see this around in use in books and on the Internet. Next up, assignment operator. We’ve already seen the equal sign at work in that capacity. Note here in line number 22 and following that there are actually many different mathematical operators. We’re only looking at the most basic ones, but there are also some advanced ones as well. But here we have addition, subtraction, multiplication, and division. As I demonstrate here, you can use parentheses to actually change the order of operations. In this particular situation, the parenthesis is not a method invocation operator. It’s actually how you would typically use it in an algebraic or mathematical sense. You would use it in order to specify the order of operations. So perform this expression first, then this expression, and then take the result of those two and multiply them together in that third expression and then assign them to the value of x. Then there are operators that are used to evaluate. We’ve already talked about the equality operator, where we’re using two equal sign next to each other to make sure that these two items are in fact equal. Here, again, we’re using parentheses in yet a different capacity to define the boundaries of our expression that will either equate to true or false. X equals Y is either true or false. We can use greater than we can use the less than operator. We can use greater than or equal to less than or equal to. All of these, again, should produce a true or false result. There are also two conditional operators that can be used to expand or enhance an evaluation, and they can be combined together multiple times, as I say here in the comments, so I could ensure that both X is greater than Y is true and A is greater than B is true by using the logical and operator. There’s also an or operator to say either X has to be greater than Y or A has to be greater than B in order for this outermost expression to be true. So here is the logical or two pipe characters next to each other. Then I guess we’ve already talked about that in-line conditional operator where we have some item that’s being evaluated. Then if it’s true, then we’ll take the first value and if it’s false, then we’ll take the second value. In this case, we’re assigning either car or boat into this message variables value. Then also wanted to talk about member access and method and vocation. We’re going to talk about object oriented programming quite a bit later on in this series of lessons, but we’ve already said how the console was a class and classes are containers, for lack of a more robust definition, for methods. The way that you access a member method of a class or an object is by using the dot or the period that is the member access or operator. Furthermore, we talked about the method and vocation operator. Here we are, invoking a method called WrightLine by using the opening and closing parentheses. In this particular case, we’re passing in an input parameter. Again, we want to hold off and talk about input parameters and methods a little bit later. But as you can see, here’s a number of different operators, and these are just what I would call a very baseline set. You need to memorize these so that you can express the most basic of C# commands and understand exactly what it is that you’re trying to do. It’s not an exhaustive list by any stretch of the imagination, but you will probably need these about 90, 95 percent of the time. Then you can expand your vocabulary of other operators and keywords over time. In each of these cases that we just looked at, an expression is made up of a combination of operands, which are things like the literal strings and variables and objects like the console class itself, and operators. Things like the addition operator, or shrink incantation operator, or equality assignment operators and so on. You use expressions then to form complete thoughts, statements in C#. Which are how the actions or the instructions of an application are expressed to the compiler and ultimately to the.Net runtime, which executes your application. Why am I telling you-all of this? Why go through this little English lesson, passing out the different parts of speech if you’ve ever had to take an English class? Well, it will help you to understand why this is not a valid statement in C#. You can’t just type x plus y and then give it a end of line character and expect it to do anything. The C# compiler will look at that and say, what are you trying to accomplish here? Have you lost your mind? What do you want me to do with all this? Fortunately, in situations like these, as you can see, Visual Studio can catch these syntactical mistakes even before you attempt to run the application. If we were to hover our mouse cursor over the visual guidance here, the red squiggly line, you can see that the fundamental problem with this line of code is that only assignment, call, increment decrement, and new object expressions can be used as a statement. What’s the problem here? Well, this is not a properly formed statement. We’re not assigning, calling, incrementing, decrementing, or creating new object expressions. What? We’re not formulating a complete thought, a good sentence. I could create an English sentence like this, the red ball. You would say the red ball does what? Who has the red ball? You can understand that just because you use words doesn’t mean you’re creating a complete thought or expression inside of the English language. Same thing is true with C#. That’s all I’m trying to say here. For beginners, understand that there’s a proper syntax, just like there’s a proper grammar in the English language. Understanding this is really a big step towards solving your own problems whenever you’re phrasing C# instructions that the C# compiler will understand and accept and ultimately compile into code that will be run by the.NET framework. Here, let’s recap what we talked about in this lesson. First of all, statements are complete instructions in C#. They consist of expressions and a statement is like a sentence in the English language. Expressions are composed of things like nouns and verbs, in other words, operators and operands. The operands are things like nouns, they’re the subject or what we want to do something with. Then there are the operators, which are more like the verbs. These will act on the nouns to perform some action. We said that operands are like variables and classes, literal strings. These are things that we get to name ourselves. They give the meaning to our application where as operators are, for the most part, built into the language and we have to memorize them. To start off, you might use something like what I’ve given you here in the form of a project for a cheat sheet. But I think you might just be able to walk your way through and rationalize your way through. Now that you understand that there’s a proper way to format a line of code, you might say, okay, what do I need to do here? You might be able to reason your way through the operands and the operators. I’m going to need a variable to contain some values. Once I have created that variable in memory, now I’m going to need to assign it to something now. How am I going to get to that something? I’m going to need to take another variable and this literal value, and I’m going to need to add them together with an operator. Hopefully you get the idea there. I hope that this was a useful exercise. I think it’s useful for beginners to understand that there are syntax rules, and they’re not so unlike what you’re already familiar with. Maybe they look a little bit different than your typical English sentence, but they still have to make sense and they have to perform an action or to do something. When you see errors, sometimes it’s because you typed something incorrectly. Then sometimes is, you may not be using the right forms of speech in a sense in order to express that complete thought at C#. Let’s pick it up in the next lesson, will see you there. Thanks. Hi, I’m Bob Tabor with Developer University. For more of my training videos for beginners, please visit me at devu.com. In this lesson, we’re going to focus on iteration statements; a specific iteration statement called the forlteration statement. Sometimes you’re going to need to loop or iterate through a sequence of things to find something that you’re looking for, to find a successful match. Actually, you’re going to do this data manipulation more than you realize. You’ll have to trust me that this is a very important tool in your toolbox that you’re building. As you can see, I’ve already taken the liberty of creating our project. I called it forlteration, pause the video, go through the steps that you already know how to perform to create a new console window project, and catch up with me. I’m going to begin to add some code here on line 13 in just a moment. Now, the syntax that we’re going to write here in just a moment is possibly the most cryptic of anything that you’ve seen yet. I’m going to be completely honest, sometimes I get things a little bit mixed up myself, but don’t worry. After we struggle through it once or twice, I’m going to share the little secret that I used to get it perfect the first time, every time. Having warned you about the complexity of the syntax, I’m still betting that you could figure it out and read it even before we actually attempt to run the application, even before I take the time to explain what each little bit of the application is doing. Let me write it out here and then we’ll try that. Very simple, at least very compact section of code here. Actually, you need one more line of code, Console.ReadLine. There we go. Now, ready for action. What do you think that this code does? Got a theory in mind? Well, let’s go ahead and run the application and see if your theory is true. You can see that we have a list of numbers from 0-9 and then we can hit ”Enter” to continue on. We’re using C-sharp to execute this little block of code right here until a certain condition is true, at which point we will stop executing that line of code and continue on to line number 17. This for statement says that we should begin by declaring a variable. We’re going to call it i. We could call it anything we want to, and we’re going to initialize its value to zero. Now, as long as i is less than 10, we’re going to continue to execute the code below it in our code block, defined by our curly braces. Each time that we iterate through, we’ll increment the value of i by one. This little bit right here is probably the part that you probably wouldn’t completely understand unless I explained it. You remember how we use the plus equals sign in order to automatically take the value of message and add something to the end of it and then assign it back to the value of message? Remember that a couple of lessons ago? We’re essentially doing that here. This is the the increment operator, so we’re going to increment the value of i by one. Again, we’re going to declare a variable and initialize the value. Then as long as this middle part is true, we’ll execute the code below. Once we finish executing, then we will increment the value of i and then do that evaluation one more time. If it’s still true, then we’ll execute this code again. We’ll increment i. If this is still true, we’ll increment it again and so on.. That’s how it works. Yes, this is cryptic syntax, but if you can just separate the three parts in your mind by remembering that there semicolons that separate them, that can help. You know you’re going to need to start off with some counter of some sort. You’re going to need a condition and then you’re going to need an incremental at the end. Again, I’ll show you a way to remember this so you never forget it. But before we do that, let me comment out this line of code and give you a variation on this idea. This would be fun. Here we go. You can see that I simply added inside of our code block for the for iteration statement, another if statement with its own code block inside of it. Here, we’re checking the current value of i, and once we find something we’re looking for where i is equal to 7, then what? We’ll perform this code. What is this code do? Well, this part’s obvious, but this break statement may not be so obvious. You use the break to bust out of or break out of the forlterations. We’re going to make it to the value where i is seven, and then we’re going to hit the break statement and then we’ll continue on to line number 23. Let’s see it in action. It’s not going to look all that exciting, but I got an idea. It found seven and it pretty much finished. I have an idea. Why don’t we watch this execute line by line? To do that, we’ll use the debugging tools inside of Visual Studio, which we have not even talked about up to this point, and yet is probably one of the most important features of using Visual Studio as opposed to just using a text editor and a command line compiler. To make this work, what I’m going to do is actually set a breakpoint here on this line of code. Now, how did I do that? I just went to this left most column and I clicked in that gray column and it created a little red dot and off to the right hand side. You see that that whole line of code is outlined in red. There are, truth be told, a number of different ways to set a break point. Probably the easiest way to do it is is what I just showed you. But there’s also keyboard shortcuts and there’s menu options as well. For example, with my blinking cursor online number 16, I’ll go to the debug window and I’ll select ”Toggle Breakpoint’. ‘ If we look over to the right hand side, you can also see that the F9 key will accomplish the same thing. Great. Now, let’s go ahead and run the application and see what happens. Immediately the application pops up before anything can be printed out to the console Window, notice that we have paused the execution of our code and we’re paused right here on this breakpoint. Now, at this point, I can do a lot of cool things. First of all, I can see what my local variables values are currently. I can also change the value of those variables. I can monitor those values. I can change which line of code will get executed next and a bunch of other things. Now, this is not a series on debugging. I could easily spend an hour showing you a lot of cool little features. However, what I do want to do is call your attention to this little window at the bottom. Currently, right now we’re in what’s called debug time, and with the application execution pause on this line of code, the next line of code that’s going to execute is that line right there that’s highlighted in yellow. I can look at these little windows like this locals window, for example, and you can see that the locals Window will contain any variables that are currently in scope at the moment. Obviously, args is something that we haven’t talked about yet. Let’s ignore that one. But what I want to focus on is the value of i. Current value is zero. How do I know that? Because I’m looking here in the value column. I can also see what the data type of I is. It’s an integer. I were to hover my mouse cursor over I you can see I’d be able to see it there as well. If I were to go and pin down that value, I’d be able to monitor it as well in this little helper window. In fact, I can drag it around here. Now watch what happens. Let me readjust some things here. I’m going to step through this line of code. Now, there’s a couple of different ways I can step through the code. I’m going to recommend that we only talk about step over for right now. When we learn about methods we can step into and step out of but for right now this middle button right here, the step over or the F10 key on your keyboard is what we want. I’m going to click it once and notice that we jumped from line number 16 to line number 22. Why was that? Well, the reason was because I was not equal to seven, so we didn’t execute the code inside of the code blocks underneath the if statement and we jumped to the end of the ‘for’ code block. Now let’s continue just to step through this. You’re going to see that we’ll increment I by one. Now when we do that, notice what happen. The value of I change from zero to one, and that change is indicated by a change in color. Whenever you see the color red that means something changed in the previous line execution. The value of that variable changed from some of the value now to the value of one. We can also see this in this little mini window right here as well. How it is now turned to the color red. Now that we’ve incremented, we’re going to do the next check to see is I still less than 10. Here we’re going to step one more time into our program. Here we’re going to step and in the Line 14 which opens up our code block and we’ll do another assessment is I currently the value of one equal to seven? No. So we’ll jump out of that if block and continue on, and we can just continue through this exercise until we reach where I is equal to seven. Now, truth be told, I don’t have to keep hitting the step over button. I can just use this continue button and this will just keep bringing me right back to the break point. This basically says, continue running until you hit another break point. Here at this point now I see that my I is equal to seven, and that’s what I’m checking for. Things should get interesting right now. I’m going to go back to start stepping line by line through my code. Here’s where I hit the console that right line and if I look now on screen it actually did write that to the console window. Now I’m going to step to the next line of code and notice that it jumped out from the brake statement outside to line number 23 outside the ‘for’ statement to the console that read line we can hit continue from that point on. Our application is still running until we hit the enter key on the keyboard and then we’ve exited out. Very cool. Now, you may have found it laborious to step through a number of times or even hit the continue button a number of times until we found just the right conditions. What we can do is make this break point into a conditional break point. To do that, I’m going to hover over the little red stop sign I guess you could call it in the left most column and I’m going to click this settings. Here this will open up a little break point settings window right in line in my code, it pushed all the other code down. Notice that it goes from Line 16 here to Line 17 way below it. I’m going to add a condition. Whenever a conditional expression is true, then we’ll break at that point. In our case, when I is in fact equal to seven, then we’ll break on that break point. You can see that when I hit “Enter” on my keyboard, it’s saved, and now I can close this. You can see that the little icon changed from just a red stop sign to having a white plus symbol inside of it. Now when we run the application notice that I is seven and that I is seven in our little window here before we even stopped into our break point. Now we can continue stepping line by line through our code and continue on. We got our result, and we can continue on. Again, I could spend an entire hour just showing you other cool little features that will help you debug your applications but understanding how to set a break point, how to run your application to a break point, how to step through line by line and then how to resume, at least resume temporarily or continue by using the continue button. Those are the key concepts in debugging. In using the Visual Studio debugger. Now let’s go ahead and it’ll turn off this break point. From now on what I want to do is just eliminate it I can do that one of two ways. To completely turn it off, I can just click and it’ll go away. Or I can temporarily disable it by using this little icon that was next to the gear that we clicked earlier. Now, you can see there’s a little outline in the left most column and an outline around the line of code that had the break point, but no longer are we actually going to break on that line. Let’s do this. Underneath the ‘for’ statement from before but above the console that read line, I want to do what I promised to at the very outset which will show you a way a foolproof way that you can get the syntax right for a for iteration statement, and truth be told for just about anything else by using a little secret code snippets. It’s not that much of a secret but you probably didn’t know about it, did you? To do this it’s real easy. If you can remember I need a for iteration statement just type in the word for. You’ll see that it pops up in the IntelliSense. If you look after the IntelliSense pops up a little message to the right there, code snippet for ‘for’ loop. Note: Tab twice to insert the ‘for’ snippet. Let’s do it. Tab, tab, and there we go. Notice that it went ahead and pretty much set it all up although there are some parts that we’re going to have to change like, for example, the length. I don’t have to use the value I for my iteration statement as my placeholder, as my counter, whatever you want to call it. I could call something like my value and notice as I’m typing, and then I hit the tab here on my keyboard, it changed everywhere that was using the I variable label to my value. Very cool. Hitting tab also took us to the next spot in our code that we’re going to need to replace, which was the length. Or in other words, how many times should this ‘for’ loop iterate? I’m going to say we’ll do it until my value is less than 12. Now, here again, we can use a number of different equality or inequality operators so we don’t have to use the less than we could use the equal or we could use the greater than whatever makes sense for our application. But I want to keep simple and leave it just like that. Once I’m done making changes I can see the “Enter” on my keyboard. There were some highlighted areas that were highlighted in gold color that indicate that these are replacement areas that go away. Now my mouse cursor is right between the opening and closing curly braces and at this point then I can continue to create my application, write line, and then my value like so and then we can run our application and we would get the following results. Just to recap. It was a short lesson but we learned a lot. Not only did we talk about for iteration statements and why you might want them and we’ll see them at use later, but we also talked about the debugging tools just briefly, and how to step through a code, how to monitor the value of variables, how to use the break statement to bust out, to break out of a iteration statement. We looked at code snippets and how to replace values in a code snippet in order to make it our own. We’ll use some of these techniques that we learned here throughout the rest of the series, very important video. Let’s continue on the next lesson. We’ll see you there. Thanks. Hi, I’m Bob Tabor with Developer University. For more my training videos for beginners, please visit me at devu.com. In this lesson, we’re going to talk about arrays, and I’m going to start by making a case for why you need arrays in the first place. Often you’re going to need to work with several related variable values. But how do you work with multiple variables and treat them all as if they’re part of the same group? Well, let me show you how not to do it. You can see an example of that on screen. First of all, I’ve taken the liberty of creating a project called understanding arrays, so make sure you catch up with me. Create a new console window application and you can just follow along. You don’t need to type this part in. It’s wrong anyway. You can see what I’ve done here. I need to keep track of five numbers, and I need these numbers to be related to each other, so without any better tools in my toolbox, I might just create something called Number 1, Number 2, Number 3, Number 4, and give them each a value. Now I want to find which variable holds the value of 16. I love to be able to loop through them like we learned about previously, to find which of the values hold Number 16, but I can’t really do that. I’m forced to create an if else structure. As you can see here below, in order to ultimately find which variable has the value of 16 inside of it. This is not the right way to go about working with multiple values that are somehow related and you want to treat them as a group. There’s a better way and that, as you might assume, would be with arrays, so we comment all of this out. Previously I talked about a variable as being a bucket in the computer’s memory that will hold some value. But let’s expand our thinking about this for just a moment and talk about an array. Think of an array as like a bucket, or maybe even better, a tackle box. Ever seen one of those? If you go fishing, there’s a lot of little compartments inside of it, and each one of those little compartments can hold something. Usually a little worm or whatever the case might be. What if we were to use that instead of a bucket? What if we were to put values in each of those little tray areas inside of the tackle box and store that up in memory? Then whenever we needed a value out of that tackle box, we just need to take it and look through and find the particular compartment with what we’re looking for, in order to work with it. That’s the idea of an array, at least if you want to overextend the bucket analogy. Another way to think of an array, it’s a sequence of data, a collection of data, although I’m hesitant to use those specific terms, because they have very specific meanings in.NET. Think of it in a very general sense. You have a collection of data you want to keep together, how do you do it? Well, one of the ways you can do that is with an array. Let’s do this and I’m going to go ahead and create my first array here. I want you to follow along and notice that I’m using square brackets, I’m not using curly braces when I’m working here. First of all, let’s take a look at the declaration of our array called numbers. It is an array of integers. In other words, there are going to be multiple integers all collected under this same umbrella named numbers. You can see that not only am I creating the declaration for this array, I’m also using an equal new in five. Some of this, like the equal in the new part, we’re going to talk about what that really means a little bit later. But for now, just accept it as how you go about creating an array. Then notice next to that, I have int and then inside the square brackets, I have the Number 5. So that’s how many elements that I want inside of my new array. I want a new array of integers that can hold five integers inside of them. Next what I do is I begin to access each element of the array and put a value inside of that element of the array. Here’s the 1st element of the array, the 2nd element of the array. Remember we’re zero based? Here’s the 4th element of the array and the 5th element of the array. Five elements inside of the array, just like we defined here in line Number 31. Now what if we wanted to access the value inside of one of the elements of the array? Well, I would do something like this. It’s a Console.WriteLine, obviously. Now what if I wanted to get to and print out the value that’s in the 2nd element of the array? Well, then I would use the correct index of the array to access that element. Here’s the numbers, and I want the 2nd element, which means I’m going to use the Index 1. So I’m going index into that array to get to the correct element. In this case, the 2nd element is at index Number 1. I can print that off the screen and we do a read line here. Like so and we can quickly run the application. You can see that we are printing to screen the Number 8, which in fact is the 2nd element of our array. Now the other thing that we can do is actually determine how many items are in the array by looking at the length property of the array itself. Console.WriteLine, and I’ll just go numbers.Length. Let’s see what that will output. In fact, let me go ahead and comment that out and run the application. You can see that we’re able to programmatically determine how many items are in the array by using the length property of the array. There’s five elements inside the array. Great. Now what would happen if we were to attempt to insert data into another item, a 6th element of the array? What do you suppose would happen here? Well, we’ll try it. We’ll run the application and you’ll see that we get an exception and IndexOutOfRangeException was unhandled. In other words, we are outside of the boundary of the space that we defined inside of our array. We’re trying to access compartments that were never created in the computer’s memory inside of our little tackle box. In order to remedy this, we can either redefine our array at the time of declaration that we need actually six items or we can go ahead and we can change at runtime, the number of items in our array. That’s a little bit of an advanced topic. I don’t want to talk about how you would go about doing that, but it is possible to do it programmatically at runtime. Let’s move on from there, and let’s talk about maybe a simpler approach to creating new arrays, and that is to not only declare the array, but then also initialize its values at the time of declaration. So let me comment out everything I have here and we’ll do this. Now, instead of giving it a specific size, we’re going to let the compiler figure it out on its own. Because we’re just going to start typing in the values of the elements that should be stored inside of our array. Now in this case, I can create it or just put all the items I want to put in there, and I can trust that the new array that will be created in memory will be able to hold all six items this time. Let me comment that out. We’ve been working specifically with integers, but what if we were to work with strings? How would we go about doing that? Well, same idea here. In this case, we want to give it a number of literal strings. Like so, and so let me move this over a little bit. You can see that we are able to create an array of strings. We don’t have to declare upfront how many elements we want in our new array, we’ll let the compiler figure that out. It will create four items. Now there’s a number of different ways that we can loop through to access each of the items in our array. Let me show you two ways, and one of them is going to be what you’re already familiar with the for loop, right? I’m going to go for tap ”Tab”, and so we’ll start with an integer I equals zero, and now let’s do this instead of names dot Length. Right? Then inside of here we’ll go and do this

    Console.WriteLine and we’ll go names. What do you suppose we’ll put in the middle here? We’ll use the value I. So what we’re going to do is start at zero and continue iterating through until we reach the length of our array and then we’ll stop and jump out of our array. But until then, we’ll do a Console.ReadLine here, and you can see that this will allow us to print out all four items inside of our array to the Console window. Great. Now there’s a lot of management of this, I hear, but there’s an easier way to go about this. Let me comment this out real quick. I’m going to show you a second style of iteration statement. In this case, we’ll just do this. We’ll do foreach and I’ll go ahead and use the code Snippet. I’ll just go tap ”Tab”. For each string name and names I made up the term Name as singular in Names is actually what we called our array right. So now I’m going to hit ”Enter” on my keyboard twice and I’ll just do Console.WriteLine name and let’s go to Console.ReadLine. What this will do is it’ll allow us to essentially loop through every single name in our array of names and for each item, it will copy the current element into this temporary variable code name of type string. Then we can use that to do whatever we want. In this case, we’re just going to print it off the screen so much easier, that is, but we can use either technique in order to iterate through our sequence of data. All right, now, let me show you one last thing you can do, it will be pretty powerful stuff and we can create arrays of different things. What if we wanted to take a string and reverse the string? How would we go about taking, for example, the name Bob Tabor and reversing that to Robert Bob? How would I change that? Well, what we can do is take a string and convert it into an array of individual characters. Once we have an array of individual characters, we can then say, go ahead and reverse the order of those items so that the last becomes first. In the first becomes last, so let’s do this, I’m going to I’m going to create a string called Zig, and it’s going to contain one of my favorite speakers quotes that I have a patterned my life after ”You can get what you want out of life if you help enough other people get what they want.” Now that’s a very long line of code. What I would probably do is I would try to chop this up into multiple lines of code. We said this before that you can do something like this in C-sharp. All I’m doing is going to just break it in half and use this concatenation operator to marry the first string and the second string together, so that’s all really one line of code. Now that I have this, what I want to do is create an array of characters. I’m going to use the Char Keyword, which is the data type Char, meaning I want one character, but I’m going to create an array of characters called charArray, and then I take this zig string and I’m going to call a helper method on it called ToCharArray. Every data type has some helper methods that are built into it by the dot NET Framework. What this will simply do is take a long string and we’ll split it up into individual characters and put those into an array of characters. Now that we have our statement here in an array of individual characters, I can do something like this. I’ll call Array.Reverse and I’m going to pass in the character array. Then finally, what I want to do is we’ll do a foreach tab tab for each char, and I’ll just call this a ziglarchar in my charArray. Console.Write, not WriteLine, but just write, and the zigChar, hopefully all this makes sense. Let’s do a Console.ReadLine. This is just to show you some of the flexibility of working with arrays. Let’s run the application and now we were able to write that whole string backwards. That’s pretty much it. There’s a lot more that you can do with arrays, however, and as we move through C-sharp, you’re going to find that your use several arrays will diminish over time and you’ll start using something a little bit more elegant. Think of it as an array on steroids, or maybe like Super Array. It’s going to be called a collection. There’s a bunch of different types of collections, and we’ll learn about those near the very end of the series of lessons. But at anyway, that’s how you work with arrays. Remember that you have to declare an array by giving it at the time of declaration its size. Then you can access individual elements of array by using indexes into the array to access or to set the values in a given element of an array. We can loop through elements of an array using a four or a foreach iteration statement, and we can even use some cool utility methods like Array.Reverse to swap all of the items in the array, or there’s also ways to sort items and so on. Let’s continue on the next lesson. We’re doing great. See you there. Hi, I’m Bob Tabor with Developer University. For more my training videos for beginners, please visit me at devu.com. In this lesson, I want to show how to create and how to then call simple methods. Now, creating methods are going to help us with a number of different things as we write more interesting applications. Methods are going to help us organize our code better. They’re going to eliminate duplicate code and the need to copy something we did earlier and paste it later in our code base. They’re going to allow us then to take a certain feature or functionality in our application and give it a name and then call it by its name anywhere in our application. Then if we were to ever need to update or fix an issue with our method, with that code that’s encapsulated in a method we have to do one place instead of changing it everywhere, we copied and pasted our code. Remember what we said at the very outset of this course that a method is merely a block of code as defined by curly braces, and it has a name, and since it has a name, we can call it by its name in order to invoke that code defined in its code block. Methods are actually one of the most important building blocks that we’re going to learn in this course, and it will allow us to build more interesting and complex applications. This is definitely something that we need to understand thoroughly. To begin, you’ll notice that I’ve already created a project called Simple Method. Please take a moment, create a new console window project and catch up with me. What I’m going to do is build the most simple example. I can possibly imagine a simple ”Hello world” application again, but this time using a method. We’re going to define our helper method inside of our class program, because remember, we’re going to keep methods inside of the context of a class. Related methods go together in the same class, we’ll expand on that later. But it should be outside of the definition of our previous method, the static void main. I’m going to go right to the end of the closing curly braces for static void main, and I’m going to hit ”Enter” a couple of times on my keyboard that should put my mouse cursor after static void main’s definition, but before the end of our class programs closing curly brace, so somewhere in this area is where we want to work. We have to define things in the right place, just like we learned before, and here, let’s create our first very simple helper method. That’s all it takes. Now I’ll explain the word private when we talk about accessibility modifiers and classes. We’ll talk about the word static much later in this course. However, just to let you know, it has more to do with building console window applications than typically what you might find yourself using in a different style of application. But we’ll talk about it later. The void is something that’s important. We’ll talk about that in just a few moments here. I’m going to create a block of code and then I’m going to give it a name. In this case, the name is simple HelloWorld. Additionally, I’m going to give it an opening and closing parentheses and we’ll look at what those are used for here in just a moment. However, then in the body, I’m simply going to just write any of the code that I need, my HelloWorld function to do. Now, in this case, one line of code very simple but hopefully you get the idea. Now how do I call that method? How do I execute it from my static void main? Well, remember it has a name and we can call it by its name in order to invoke it. But remember, there’s one other piece of information that we need to provide here. Not only do we need to give it the name of the method that we want to invoke but also we need to use the method invocation operators which are the opening and closing parentheses in this context. Now we’ve called our method and we expect output in the console window. Now I’m going to go ahead and add one more line of code just so we can see our result like we always do and now when we run our application, we will get the unexciting results, Hello world. But the most important part of this was to create the simplest example we possibly could. Now that you see how easy it is to create a method and how easy it is to call the method, let’s go ahead and shut down that project. Instead, what I want you to do is open up the project and you should be able to find this where you’re currently watching this video, wherever you originally downloaded from, there should be source code available. You should be able to find that source code in before folder for Lesson 10, copy that HelperMethods project folder into your project’s directory or somewhere on your hard drive, and then you can open it up from there. I’ve already got this opened up here and you can see that I’ve created a simple name game application. Again, this is simple but at least there’s more code that we can use to demonstrate how useful methods can be for us. It’s going to ask us for our name and then where we were born and then we’re going to use the little algorithm I guess you could call from the previous lesson where we learn how to take a string, how to convert it into an array of characters, how to reverse the order of each of the characters in the array and then display it back out to the console window. That’s what we have here in our results, Oak Park Tabor Bob spelled backwards. Now, in order to accomplish this, I have what, from lines 13 to lines 56 so about 43 lines of code. Admittedly, I made this longer than it probably needs to be but notice the amount of duplicate code that I’ve introduced into the application. Here is where I am retrieving the first name and the last name and the city and those are essentially the same even though what I’m collecting is a little bit different but it’s only two lines of code so that doesn’t hurt much. Here we are actually taking the first name or the last name or the city and we’re going to do the reverse operation on it and we do that three times and there’s the third one. Then what we’re going to do is print out the results into a string called result which will then output in a console that right live. But notice here, we’re essentially doing the same thing here and here and then again here so there’s a lot of duplication. Now, duplicate code in and of itself is not a huge problem, there’s really no way you can completely eliminate duplicate code in your application but duplicate code is usually the result of copying and pasting code. You’ve invented the wheel earlier in your codebase and your first thought is, “Well, I’ll just copy and paste it because I need it here and here and here in my code.” Now, invariably what happens is your intent is to copy it but to make a few subtle changes to it and in your haste, frequently, at least if you’re like me, you will forget and you’ll make a mistake and forget to change something and you’ve introduced a bug and it can steal your soul like even if it’s just seconds. But what if it’s minutes or even hours of your time trying to figure out why you have a weird problem with your application? Copy and paste is dangerous, you should always treat it with great suspicion. But in addition to that, if you have the same code repeated multiple times, then whenever there’s a change that’s requested in how our application works, we’re going to have to change it in multiple places. But what if we were to take some of this functionality like this, for example, and this, and we were to extract it out and put it into its own method and then just call it three times? First of all, it would reduce our need for copy and paste. If we needed to fix a problem with our code, we can do it in one place, and then also, if we were to give that method a meaningful name in our system, it would describe what we’re attempting to accomplish. Right now, we’re just filtering through lines of code and it’s a little bit more difficult to ascertain quickly what this application is attempting to do. But if we were to maybe give our methods nice meaningful names, it might read more like a paragraph of English instead of a bunch of disparate lines of C# code. So that’s the goal. Now, the second reason we might want to break this up into methods is to simplify the readability of the code. We already talked about making it more human-readable but also, there’s a lot of lines of code here that we have to pass through to understand what’s going on and if we can reduce the amount of code to read, then we can improve the readability of our code. We want to reduce bloat every time we have the opportunity. We should strive to make our code readable, clean, clear, and perform well and maintainable so that if we need to make a change, we can do it in one place and methods help us accomplish all of those things. Let’s do this. Let’s create a method, we’ve already learned how to do that. I’m going to go somewhere between the end of our static void main but before the end of our program class, I’m going to define a private static void, ReverseString like so, and what I’ll do is copy some of the work that we’ve done here, for example, lines 24 and 25 and I’ll paste those here in our new method and then I’m going to copy the code that we used to actually print all these out to screen and I’ll paste those here as well in our reverse string method. Now to get started here just to make sure that this method is going to work, I’m going to hard code the message. I’m going to create string message equals Hello world and then I will change firstName to just message throughout and firstNameArray to messageArray and we’ll hit control period to rename like we learned about before. Then finally, what I could do is gather up all of the individual items printed out in reverse order using this foreach or I could just go here and go Console.Write each item like so and that’ll accomplish, at least for now, the same thing. Now that I have this working, I want to comment out everything I’ve done up to this point so that I can isolate, and then we’ll start reintroducing things back in as we get them working. I’m going to call the reverse string method by using the name of the method and then also again, method invocation operator and then obviously the end of line character and I’m going to go ahead and hit “Start”, and not a very exciting example but now we know that the logic of our reverse string method is working. What I’d really like to do is make this a reusable method. Currently, right now, it’s not all that useful. How many times do I need a print Hello world in an application? But if I were to remove this line of code here and replace it with an input parameter so that the caller can pass in the string that it wants reversed, now I improve the usability of this method dramatically. To create an input parameter, I need to give it a data type and then a moniker or a name. What I’ll do is say, I’m going to allow the caller to pass in a string and internally I’m going to call that string message. I’m creating essentially a variable that allows an outside passage of code to pass values into the body of my method. I can utilize that value inside of my method and then hopefully as a result of that, achieve some more interesting results. Now, having done that, I’ve changed the signature of the method. I used to have just a method called ReverseString but it accepted no input parameters but now I have to accept one input parameter and that’s not optional so I get this red squiggly line beneath the reverse string and if I were to hover my mouse cursor over, it’s going to say there’s no argument given that it corresponds to the required form parameter message of, and you’re like, “What does that mean?” Essentially, we did not call the method correctly now because we have to give it something like a hardcoded string, or probably the better thing to do here would be to give it the first name that we collect way up here in lines number 16 and 17. Let me uncomment that out and go down here and comment. Now I’m collecting the first and last name of the city but everything else I’ll leave commented out for now. Eventually, we’ll remove them and I’m going to call this reverse string method three times. Each time I’m going to change what I’m passing in like so. Now when I run the application, well, let’s do this as well. Let me copy that so that I can get similar results. Let’s go ahead and remove that and let’s see the application now. Make sure you have what I have on screen, possibly if you need to. Let’s run the application and let’s see it working and it should work similar to what we had before with fewer lines of code. It mostly works but you notice there’s a subtle problem with this. There’s no space in between Oak Park, Tabor and Bob. This is a good example of where I can make a change one place in my code and it will fix the problem throughout the code base, wherever I’m using and calling my new method. To fix this problem, all I need to do is to cancel “Right” and then add in a blank character that should allow sufficient spacing in between each call to reverse string. Now when I run the application and I put in my details, Bob Tabor, Oak Park. It should work correctly and it does great. Now this is definitely one way to go about writing this application. As I look at this method reverse string I see a problem. Typically, whenever I create methods, I attempt to describe in English what that method is responsible for doing inside of my software system. In this case, I would describe the functionality of this method as it reverses a string and it prints it to screen. But herein lies the problem, I really only want each method to do one thing in my system and when I use the word and, and print it to screen, I feel like that’s two responsibilities in the system. Typically, what I would do is split this out into two separate methods and you might say, well, that’s a little excessive, and that’s true in the simple case. But following that rule of thumb will help you as you begin to think about how to compose methods, what goes into a method? How many methods should I write? Should I create one massive method or lots of tiny methods? Typically the answer is more smaller methods with descriptive names are better. In this case, what we’re going to do is change up the functionality of the application a little bit. What I’ll do is take out all of this where I’m actually doing the writing to screen and what I want reverse string now to do is accept an input string and then return or report back, giving the result to the caller. In other words, right now we’re using the void keyword, which means I want you to go off and do something, but please don’t report back to me. I don’t care what you have to say, I don’t need to know anything from you, you just go, you work, you be quiet and everything is great. However, we might want to change this and say instead of being quiet when you finish your job, I want you to report back to me what the results were of what you did. In this case, I might want to say return back to me the reversed string. I’m going to give you a string and then what I want you to return to me is a string that’s been reversed. Notice when I added or changed void to string, I get a red squiggly line because I have not officially returned anything back to the caller. I need to use the return keyword like so. I could do a for each and gather up each individual item into a longer string like we done, pretty much previously right here by building that result. However, there is an easy way to do this with just one line of code, just like there is a helper method called Reverse on the array class. There’s also a string class, and the string class has helper methods too. One of them is the Concat method, and it will allow us to pass in an array of individual characters and it will concatenate them all together and return back a full string. In this case, let’s just give it the message array like so and that should work just fine. Now notice that I’m able to call reverse string and I’m not really accepting back any values. Why is that? I thought if we were going to say, Hey, report back to me that I would need to do something with it. In other words, I would expect to see something like this, where I’m capturing whatever has been returned from the reverse string method. That’s optional. I can listen for it and retrieve it and save it or do something with it, or I can ignore it. In this case, what I would probably want to do is actually save it, so I would call this reversed first name like so and then string reversed last name equals and then string reversed city equals. We’ll shorten this up in a moment. But hopefully you’ll see where I’m going with this. Then what I can do is console dot right. Right line or just here, let’s just do right. Reversed first name plus space. This seems laborious to do it this way. I’ve got a better idea the string has another helper method. We looked at the concat method, but it also has a format and the format will work a lot like canceled outright line. In fact, they’re almost identical. The only difference is canceled outright line will print its results to screen whereas string dot format will merely just create a new string as a result of whatever been formatted. But the reason I’m using this is so that I can use the replacement codes like so. Here I go 0, 1, 2 and I can pass in reversed first name, reversed last name, and reverse city like so. Since that is off to the right-hand side of my screen, I can’t easily see it. Typically, what I’ll do is move each of the input parameters to the method in this case console dotright. I’ll move in the separate lines to increase the readability. Notice that they’re indented a little bit. But this is all essentially one line of code, even though it’s spread on four lines. But it improves readability because I don’t want to have to scroll off to the right-hand side of the screen in order to read my work. Get in the habit of formatting your code for readability and keep things narrow and small. If they do go off to the side of the screen, don’t be afraid to move things down to different lines to increase the readability. Now let’s see what we have. This should work. Let’s run the application. It works great. But what if I want to put this into its own method? I could simply do that like so. I think I can just use a void in this case. What I could do is go display results and I could just take this and paste it in. But now what I need to do is pass in these three values. How do I go about doing that? Well, know how to add input parameter. How do we add multiple input parameters? What we’ll do is define our first one reversed first name like so then to add subsequent input parameters, I’ll just use a comma on the keyboard and add the second one like so and then the third one like so. Again, since it’s off to the right-hand side of the screen, I might put my mouse cursor right before the S in string and move those input parameters below the definition for our display result method again, for readability sake. You may not agree you don’t have to. That’s a stylistic choice. At this point, I should be able then to call display result. Let’s call display result passing in the reversed first name. I just happened to use the same names here, but I could have called either the input parameter something different or the temporary variables here something different. Reverse string, last name and as I’m doing this, I’m beginning to think to myself, why am I even going through all of this? Why do I even need these variables can I just eliminate those altogether and just copy this? Paste it here. I mean, it returns a string. I should be able to do that and I should be able to do this and I should be able to do this. Then I’ll put the Mitch on the line and that should work just fine and here I can eliminate these lines of code completely for my application. See if it works. Still works great, feels like this should probably go into this display result. That should reduce it from being there. Now suppose that I don’t want to pass in each of these individual values. What if I want to display the result and only pass in one value. What could I do in that case? Well, I can provide additional ways of calling a method by creating what are called overloaded versions of our methods. In this case, what I’ll simply do is I’ll start out and copy and paste the exact same method definition twice. Notice on the second definition, I get an error. Let me hover my mouse cursor over so you can see it, type program. That’s the class program already defines a member called display result with the same parameter types, you can create additional versions of the same method with the same name, but they have to have a different methods signature. A method signature is the number in the data type of the input parameters in your method definition. In this case, I already have a method called display result with three strings. I could change these names to just any old gobbledygook text there, and I still get an error. It’s the same problem because the fundamental fact that we’ve not changed the signature of the method means that I’m still having the same problem. However, I could change this by allowing only a single message or a single string to be input as an input parameter. Now I have two completely different versions of the method as far as C-sharp is concerned. Now, in this case, I wouldn’t need any of this. I probably just do this. Like so, and then I could call it by doing this. Basically what I was trying to avoid last time, but we’ll go ahead and do it anyway. This time we’re passing in one long string. Notice the use of the concatenation operator and the use of some empty spaces defined by two double quotes with just an empty space in between. We should have two lines that display essentially the same thing here. Let’s make sure we do this right. Well, in a WriteLine between them just to make sure there’s a break. Bob Tabor and we get two results that look identical. Now you might wonder why are we doing this? Why in the world would you ever want to create two methods with the exact same name that essentially do the same thing, but allow the user to pass in different information? Let me give you a good example of why you might want to do that is with the Console.WriteLine. Here we go with Console.WriteLine Have you ever noticed as you as you type the opening parentheses for the Method Invocation operator, that there’s a little message that pops up down there, there’s one of 19 and then you look to the right of it, and as I use the arrow keys on my keyboard to go up and down. Notice that the number goes one, two, three, four or five. These are all the different data types that the WriteLine method will accept, it’ll accept an input parameter of type Boolean, which is true false. It’ll accept a single character or an array of characters. It’ll accept a decimal value, which is usually used for money or a double, which is used for longer mathematical calculations or a float, which is a massive number in terms of the number of values after the decimal point. It allows you to pass in an integer and other types of integer style values. It allows you to pass in a string and then others as well 19 different versions of Console.WriteLine to make it convenient for the user of the application to utilize that method in their app for the developer, the application to use it in their app. Now when we go to display result, we’ll see the same thing in IntelliSense display result and notice that I have two versions. I’m looking at version one of two, and notice the emphasis on the input parameter that the first version accepts one input parameter of type string called message, and then the second version accepts three input parameters of type String, reverse String, reverse last name and reverse city. There you go. That is why you would create overloaded versions of your methods. Now, in this case, notice that we could eliminate so much of the code from this in order to essentially get the same working results, I’ll just delete that, and, for the sake of simplicity, I’ll go ahead and remove this as well. Now we’ve reduced down the amount of code dramatically for our application and improved the flexibility of our application by adding multiple ways to actually display the results. At Developer University, I issue a decree to students that no method should have more than six lines of code in it, if it has more than six lines of code in it, then it’s probably attempting to do too much in the system. You should be able again to express what it’s doing in English and then if you find yourself saying it does this and that, then it’s probably an opportunity to split those up into multiple methods. Of course, rules are meant to be broken, and as a rule of thumb, six lines of code per method will keep your code tidy and readable. It’ll keep everything scoped, nice and very tightly, and it’ll improve the quality of your code dramatically. That’s all I wanted to say about methods, but we’re going to be using them from this point on. If there’s anything about this that doesn’t make a whole lot of sense to you by all means, please make sure that you watch this lesson again or seek out some other resources. You’re doing great. Let’s continue on. See you in the next video. Thank you. Hi, I’m Bob Tabor with Developer University for more training videos for beginners, please visit me at w.com. In this lesson, we’re going to look at another iteration statement, the while iteration statement. Let’s just recap the iteration statements we’ve learned about up to this point. We’ve learned about the for loop or the for iteration statement and it allowed us to iterate through a block of code a number of preset times based on a counter. Then we also learned about the for each iteration statement that allowed us to iterate through a block of code once per item in an array. Now, in both of these cases, ahead of time how many iterations or how many times to iterate through the given block of code but what if you didn’t know up front how many times that you needed to iterate? Maybe you need to keep iterating until some condition is met. In that case, you’ll want to use the while iteration statement. Also, we’ll take a look at the do-while iteration statement, which allows us to always iterate at least one time before breaking out of the iteration statement. We’ll look at both of them in this lesson, and I’m trying to think of use cases where this would be useful. The most obvious one to me was creating some little menu system for our console window application. You’ve seen him before, especially if you’ve worked with DOS in the past. At any rate, what we want to do is begin with a new project you can see have already created it. It’s called WhileIteration. Again, another console window application. Please pause the video. Catch up with me. When you’re ready, let’s go ahead and get started by creating a method that will print out a list of options to our users in the form of a menu. We’ll do something like this. We have some more work to do here, but what we want to do is display this, so let’s just start by displaying the main menu here like so, and let’s run the application. Here we can choose an option. No matter what we choose at this point, our display will disappear. But suppose that we wanted to actually kick off another feature of our application, so say, for example, let’s go private static void of print numbers and then we’ll go private static void guessing game, like this and it will just console.WriteLine. Now let’s go ahead and call those from here. PrintNumbers and then GuessingGame. Now let’s run the application and we choose the first option and we’re able to play the print numbers game. But when I hit “Enter” we are completely removed from the application. What if I wanted to return back to that main menu? How could I go about that? Well, I could use a while statement to determine whether to show the menu again or to completely exit out of the application. To make this work, what I’m going to do is start off with a new data type called bool, we referred to it briefly a moment ago. It’s basically true or false. We want to create a new Boolean variable called displayMenu and we’ll set its initial value equal to true. Now what we’ll do is create a while statement. I’ll just type in while, tap tab. What I’ll say is while the display menu equals true, and then we will call display menu. Now a couple of things here. What we’ll need to do is actually then retrieve back for main menu, a Boolean, whether the user clicked “Exit” or not. What we’ll set is displayMenu equals MainMenu and then have MainMenu return a bool itself. Of course, we’ve completely broken the application at this point. That’s okay. Here we are going to continue to display the main menu until main menu returns the value false. If somebody chooses option number 3 to exit, then we might choose to completely exit the application, in which case we’ll return false. Now, if they choose some other option, like 4 or 5 or 6 or some other text option, then you might just want to redisplay the menu. We will return true again. Furthermore, we might want to return true as well here after we go through each of these options as well. Now let’s go ahead and run the application and see how it works this time. First of all, if we choose option number 1, it’ll display a message, and after we hit the “Enter” key in the keyboard, it will display the menu again and I can select number 2 and it’ll display the message and then I can hit “Enter” and now we can hit the “Exit” and we actually exit out of the application. What the while statement allowed us to do in this case is check for a condition and when that condition is true, then we can break out of the while loop. Otherwise, we’re going to keep executing the code inside of our code block. Now what we can do here is actually shorten this up a little bit. We don’t need to say, while displayMenu equals true, remember that just like when we’re using the if statement or the else if, we want to evaluate an expression and if an expression is true, then we want to either execute that block of code below it or not. In this case, if displayMenu is already true or if it’s false, we don’t need to actually do this evaluation. It already evaluates to true or false. We don’t have to do an equality there or check for equality. It’s either true or false, and so we can just write it like that very simply. Moving on. Now, what we want to do is maybe fill in the gap on some of these other little games we have here. Let’s play the print the numbers game. In order to do that, let’s go ahead and say Console.Write, type a number, and then int results equals Console.ReadLine. That’s going to return back a string, but what we really want is an integer. I’m going to go integer.Parse and this will allow us to take whatever string has been returned and convert it into an integer. Now we should have the actual integer value. Here what will do is create a counter for ourselves. Int counter equals 1 and then we’ll go while tap tab, the counter is less than our results. Then we will do a Console.Write with the current value counter. We’ll go Console.Write and we’ll do a little delimiter and then we’ll increase the counter. Now there’s a tiny bug with the application. We will come back to that in just a moment here. But let’s go ahead and run the application and let’s go ahead let’s type in a number 5 and it types in, and it will print out the numbers 1, 2, 3, 4. We’re able to change the number of times on the fly that will iterate through a block of code. Now it just so happens that this isn’t exactly what we wanted. Let me exit out of this. What we really wanted was to display from 1-5. I’m going to go ahead and add result plus 1. If I typed in the number 5, this would actually make this value 6. As long as we’re less than six, go ahead and continue to execute these lines of code. But once this statement becomes false, once the counter if it’s equal to 6, it will break out and will hit this line of code here in line number 59, the Console.ReadLine. That should work. Now, the other thing that I noticed when we ran the application is that we keep seeing additional data being written to the window. I might want to clear out everything that’s been displayed so far. Here we’ll start at the top and do Console.Clear, and that should clear off the screen for us. I’ll just copy and paste that here to print numbers as well. When we run the application again, this time I’m going to choose option number 1, and notice that it cleared off the screen and when the print numbers game, I’m going to type the number, let’s go 4, it types out 1, 2, 3, 4. I hit “Enter” it clears that off and it displays the menu again. Awesome. The next thing I want to do is play the guessing game. Again, here I’m going to go ahead and clear off everything that’s currently on the screen. What I want to do is choose a random number and then I’m going to allow the end-user who’s playing the game to try and guess the number between one and 10. How do I create a random number in C-Sharp? We actually use this built-in class in the Dunnett from the class library called the random class. We’ll create a new instance of the random class, we’ll talk about what that means, create an instance of a class, in an upcoming lesson. Let me do this. We’ll go random, my random equals new random. Again, that should make no sense to you whatsoever. That’s just fine. I’ll explain what that actually did in an upcoming class when we talk about classes. I want to get a random number from my random class, so I’m going to call the next method, and here one of the overloaded versions is that I get to give it a minimum value and a maximum value. The minimum value will be 1, but the maximum value, I want it to be 10. I’m going to say, don’t let it be more than 10. In other words, 11 is out of bounds. Now that I have a random number, I’m going to also keep track of how many guesses the player has guessed up to this point. Then I want to also keep track of whether or not the user was correct or not. Incorrect, and we’re going to say it is true that they were incorrect. Now watch this, I’m going to create a do while statement. I want the block of code that I’m going to create execute at least one time. That’s why I’m going to choose the do while as opposed to the while. The while we’ll evaluate the very first time and we may never actually run the code inside of our code block, but this time I want it to run at least one time. We’ll say, do this, but then at the very end, we’ll check for the statement while. If the while condition is true, then we can break out of it. While we continue to be incorrect is true. While we continue to be incorrect, then we’re going to keep guessing. Let’s start this Console.WriteLine and we’ll say, guess the number between one and 10. We want to retrieve that number. The string result equals Console.ReadLine. Now that we have it, we can do an evaluation. If the result is equal to the random number, so if whatever the user typed in is equal to the random number that we generated, then we want to break out of the wild statements so we’re no longer incorrect. In other words, let’s go ahead and say that incorrect equal to false. At this point, we guessed correctly and we’ll break out of the wild statement, and here we would want to say Console.WriteLine. Hey, you did it correct. However if they did not guess correctly, then what we would want to do is write Console.WriteLine and then wrong. We probably want them to guess again, which will happen because while incorrect is still true, then we’ll come and we’ll re-execute this block of code. Looks like a missing end of line character here. I can see that as I hover my mouse cursor over that little red area that I forgot a semicolon there. Otherwise, this should work. Now there’s one of the things that I want to do. I want to keep track of the number of guesses. Each time the user adds a guess, we’ve already initialized that value there, that variable guesses. I’m going to increase guesses or increment guesses by one. I type in the word guesses plus plus. That means I want to add one to the current value of guesses. Then here I want to type out how many times it took. It took you guesses, then like so. Let’s run the application. Let’s choose to guess a number between one and 10. We’ll start off at three. You can see it says it’s wrong, so I could continue to guess a number between one and 10. Let’s go 4, 5, 6, 7, 8. The number was eight. It took me six guesses to get to that. Now when I hit “Enter”, it returns me back to my main menu and here I’ll just hit “Three” to exit. Let’s go ahead and change our menu at this point. Let’s just do Print Numbers and then the Guessing Game. We’ve used the wild statement in a couple of capacities. The wild statement here is used so that we can continue to display the menu until the user decides to exit. We are using it to merely print out values to a screen, but we get to determine it at runtime or let the user to determine it at runtime as opposed to the four or the four each where it’s predetermined ahead of time. Then finally, we’re able to use the do while to continue to ask a series of questions until we get a satisfactory answer, at which point then we can break out of the loop. The do variation allows us to run our code block at least one time as opposed to immediately jumping outside of the block if the condition is true. That’s why we would use the while iteration statement. It’s pretty useful in certain cases. Let’s continue on. We’ll learn about strings in the next lesson. We’ll you see there. Thanks. Hi, I’m Bob Tabor with Developer University. For more of my training videos for beginners, please visit me at devu.com. Now, many of the types of applications that you’ll build as a C-sharp developer will require you to work with text, whether you’re formatting the text for display to the end user or whether you’re manipulating the text in some way. A good example would be whenever you are massaging data. That’s a term that developers use to talk about taking data from a file or a database, and it’s in some raw form and you need to manipulate it. You need to remove certain characters. You need to add certain characters in certain positions in order to get it and prepare it for ingestion to be used by some other software system or to be saved in a different file format, whatever the case might be. Manipulating data is a key skill, whether for display or for the sake of massaging data into the right format. Furthermore, whenever you’re working with the string data type, you’re working with a data type that can hold a lot of information. To extend the bucket analogy, you’re working with a really big bucket. When you’re working with big buckets, you have the responsibility of working with them in an efficient way. Because when you’re working with data that takes up a lot of memory, it requires a lot of processing power, you are putting a strain on system resources. Now admittedly, it would take a lot of string manipulation to slow down a computer, especially a modern computer. However, software developers, we want to do things efficiently, and so it’s important to understand that there are tools in the dotNet Framework Class library that will help us work with and manipulate strings in a very efficient way. That’s really the purpose of this lesson. To show you how to perform some simple string manipulations like inserting special characters in your little strings, formatting strings, especially numbers and dates and things of that nature. Manipulating strings, changing things about string, searching for items and removing them or replacing them with something else and strings. Then also working with strings in a more efficient way. As you can see, I’ve already taken the liberty of setting up a new console window project called Working with Strings. Please take a moment, pause the video and catch up with me. I’ve already added three lines of code that we’ll use to demonstrate some key manipulations for our strings. What I wind up doing is just typing in a string and then showing you some manipulation and then moving on to the next line. But at any rate, let’s go ahead and start by talking about the special nature of the backslash character, which is that character there. I always used to get my characters confused. That’s forward slash, that’s backslash. A backslash character can be used to escape or insert escape sequences into literal strings. This will allow us to do things like put special characters, insert line feeds and things into a literal string. For a good example of this, what if I wanted to type something ironic like my so-called life? I wanted to insert a series of double quotes around the word so-called so that it displays the way that I would, as the author of this, expect it to be displayed on screen. Now unfortunately, you can see that the Visual Studio on behalf of the C-sharp compiler doesn’t like this at all. It thinks that you have two literal strings here. The word my and life and in between something that it can make no sense of whatsoever, the word so or the term so a minus symbol. Then the word called. These are not variables that have been declared. It doesn’t recognize them as keywords. C-sharp does not like this. In order to insert a special character like a double quote to say, I don’t want this to delineate a literal string, I want to use this inside of my literal string, I’ll use the backslash character before each double quote, which escapes out the double quote and makes it available for use inside of the literal string itself. Now when we run the application, we can get double quotes inside of our side of our string. Now similarly, let’s put in my string equals. I tell you what, I’m just going to copy this to my clipboard so I can keep using it. Now, what if I needed to add a new line? What if I need a new line and I want to split this up under two separate lines in my application? What I can do is insert a new line character. Think of a line feed. Slash n will create a line feed. Let’s go to run the application. You can see that it’s smart enough to know that even though we didn’t separate with spaces around the word a and new it was still able to find that escape character for the line feed and represent it correctly in our little string. Now, you might say well, that’s all well and good, but what if I need to actually use the backslash character? For example, in an instruction to go to your C colon slash drive, you’ll notice that we get a red squiggly line underneath the backslash because it’s expecting us to use the backslashes and escape character as an escape sequence. But we’ve given it nothing after that to indicate which escape sequence we want to use. In this case, we have two options. In fact, in all of these cases we have two options. We can use another backslash character to escape out of it to represent this correctly. Now you can see that you should go to your C colon backslash drive. I’ll just do this again. Go to your C drive. What we can do is add a at symbol in front of the literal string, and that tells C-Sharp that we want to use our backslash characters as true backslash characters, not as escape sequences or special characters. Let’s move on from there. We’ve already talked about the use of string dot format and we showed how we could do something like this, where we are going to insert the words 1st and 2nd into this template. The template contains a number of replacement codes. The number inside the replacement code corresponds to which argument is passed in to the string that format as input parameter. Let’s run the application and we would get what you might expect first equals second. What I didn’t tell you at the time was that you can actually reuse the replacement code multiple times. Like so or you can use them in a different order if you like. Let’s go back and change up the order where the second will be the first item displayed and the first will be the second item displayed, like so. Furthermore, the replacement code has some special powers. For example, if we want to do string.Format and say for example, that we wanted to display currency to the end user. I want to display $123.45 to my end user. In my case, since my computer’s culture is set to English U.S, this will be represented as dollars and cents but if your country and culture codes are set to for example, English U.K. or some other language and some other culture you would probably see something different whenever you choose to do this. You’ll see your native country and culture’s symbols for currency. But to create and format values for currency, you use the colon and then C immediately after the numeric replacement code. In this case, I’m using say zero still represents the first item in the list but the colon C says I want you to format it like currency. When we run it at least on my computer you’ll see dollars and cents with the dollar symbol. There’s all these little variations on this. For example, what if I wanted to just display a really long number to an end-user like 1234567890. I want it to look like a number not like how I have it here where you can’t really tell is that what, 12 billion or 123 million or what? To remove the confusion what you can do is use the colon and format character. This will add in decimal points and commas to give you the appropriate formatting for a large number 1,234,000,000 and so on. Furthermore, continuing that same thought what if we were to go string.Format and we wanted to represent a value as a percentage? What if I wanted to display this as a percent? Be sure to get those formatting codes in there. Just to show there’s nothing on my sleeve here, this is called as a percentage like so and then we will insert a percentage here. If this replacement code lets go and run the application and you can see that the percentage is 12.3 percent in this case. Finally, the last one I’m going to show you but I’ll show you where you can find more information is how to create a custom format. For example, in the United States, phone numbers have a very specific way that they’re presented. Let’s go string.Format and let’s go 1234567890. I want that displayed like a phone number so I would use zero and then I’m going to use count symbols to represent each digit that I want formatted. In this case, actually, I’m going to use parentheses around the first three numbers because that’s usually how an area code in a phone number in the United States is presented then a space then three more numbers then a dash then four more numbers. That’s just how phone numbers are presented in the U.S. Let’s go and run the application. You can see that it in fact formats that number the way that I would expect. Let me throw one little monkey wrench in this. What if I were to supply too many extra digits? I added another one two at the very end and yet I don’t have that accounted for in my formatting. Where will it be presented? Well, as you can see it pushes out the area code to five digits instead of just three. The moral of the story there is that the formatting will go from right to left whenever you’re using custom pound symbols to create a custom format for a numeric value. Again, the numbers will push their way out and once you get to the very end, it will put as many numbers as it can on that very first character and push that formatting out to the left. Be aware of that. The next thing that we want to do is start manipulating strings in a more meaningful way. Up to this point, we’ve been formatting strings but what if I want to actually change some things about the strings themselves? Let me start by providing a little something that we can sink our teeth into and work with. I’m going to type in a lyric from a song that I like. Notice that I added or I left in an extra space here at the very beginning of the string and then I left it in two spaces at the very end of that string. Let’s go. My string equals my string. I think the most important thing you want to realize about when you’re working with these data types is that they do have built in functionality that were provided to us by Microsoft. For example, every string has the substring helper method that we can use to just say, hey, I want to start at a specific point and then grab all of the characters within a given range. I can say start at position six and grab me back everything after position six. When I run the application you can see it starts with the word summer which is at the sixth position and grabs everything to the very end of that line. Here is position one, two, three, four, five, and six. It truncates off the first six characters and starts me there and I pulling everything else giving me a subset of the strings from that point on. But I can also say go ahead and give me the next 14 characters after that. Don’t give me everything to the very end of that string just give me the next 14 characters and so I can isolate a couple of characters in this case just three words in that string. I can also do something like my string.Toupper and that will do what you might think it will. It’ll make everything upper case. Great. What if I wanted to replace one character with a different character. My string.Replace and say find every blank space and replace it with a double dash like so. When we run the application, you see that we get double dashes instead of our spaces. It makes it more obvious that we had some spaces at the beginning and the end. We can also use mystring.Remove and we can remove a number of characters from our string. Instead of selecting out the substring of characters we took threes. We can actually remove those entirely from the string. You can see, summer we took it has been removed from the string completely. Also, what if we want to actually remove those trailing and preceding spaces? We could use the trim method. Let’s do my string equals, first of all, string.Format. Here I’m going to grab the length of the string to demonstrate this. The before length and then the after length. Let’s go mystring.Length and then my string dot will call the trim method to strip off all of the extra spaces in the beginning and the end. Or I could choose to trim off only the ending spaces or the beginning spaces but I’m going to call the trim method to get rid of it all and then determine what the length of the string is at that point. You recall that we used the length property whenever we were working with the array to find out how many items were in the array. We can also use the length property on a string to tell us how long the string is. That’s ultimately what we’re doing here. Tell me how long the string is before we make any changes to it and then after we trim off those extra spaces, how long is the string itself? Run the application again. You can see that the before was 46, the after was 43. We trimmed off three spaces. Great. The last thing I want to do is talk about working with strings in a more efficient way. For example, let me just type in a really quick code example here. We’ll just do this. Actually here. The mainstream plus equals. Hopefully you remember what this operator was for, where we’re saying, give me whatever the value of string is and concatenate everything on the right hand side to it. Here we’re concatenating on just double dashes and in the current value of i’s, we loop through 100 times and we’ll merely then just display my string in the console window. Let’s go ahead and actually get rid of that. We’ll start here with a blank slate. Let’s run the application. The output isn’t all that interesting, it’s just a printout of numbers with some dashes in there. But what’s going on behind the scenes is the more interesting part of this. What happens when you’re working with the string data type is that it’s called a immutable data type, meaning that you can’t just add more values to it. What happens behind the scenes is there’s this little dance that the dot NET Framework runtime is is performing to make it look like you’re still working with the original variable My Strings, the original bucket. But what it does is it creates a second bucket and it starts copying things over. In this case, it copies the previous value of My String plus any of the new stuff we want to put in there, and it creates this new string in a new bucket and then it removes the old bucket and it gives the new bucket, the name My String. Then we say, let’s do it again. In fact, let’s do it a hundred times and it has to go through that dance 100 times in order to produce the final result that we’re printing then in our console window. You can see that’s a very inefficient way and we’re requiring a lot of memory management that might put a drain on the system if we were to do a lot of it. Instead, what we can use is a different data type. Whenever we’re going to manipulate strings in this way, where we’re going to do a lot of string contamination or a lot of string manipulation, we can use something called a String Builder. Again, just like I said with a random class from the previous video, this may not make a whole lot of sense at first but hopefully once I talk about what classes are and how to create new instances of classes, this nomenclature that String Builder My String equals new String Builder. What is that all doing? We’ll talk about that very soon. But just let’s create a new String Builder class and then we’re going to do something very similar to what we did before where we will iterate through a 100 times. But this time, instead of just doing a simple concatenation, we’re going to use an append method, which is a more efficient way to append additional information to the String Builder object, rather than going through the previous step of forcing the runtime to create all these temporary versions of string. My String apend i and the result will look identical. But what’s going on under the hood is that we’re working with strings in a more efficient way. Use the String Builder along with the append method of the String Builder to work with strings in a very efficient manner. We talked about quite a bit in a very short amount of time how to work with the backslash character for escaping and inserting escape special characters into our literal strings, how to use string.format. In fact, let me show you this little page here for standard numeric string formats. If you just search for this on bin.com, you’ll be able to find this article and it gives you examples in many other usages for the format that we looked at several examples of here. We looked at several of the built-in helper methods to replace or define subsections or completely remove or actually create two upper or two lower to change the case of strings. Then finally, how to work with strings in a more efficient manner. Now we’re going to give the same treatment to dates and times because you’ll again find yourself working with dates and times frequently whenever you’re building applications and there’s a lot of similar functionality there as well. We’ll see in the next lesson. Thank you. Hi, I’m Bob Tabor with Developer University. For more of my training videos for beginners, please visit me at DevU.com. In the previous lesson, we looked at how to format strings and how to manipulate strings, whether it be for display or for the purpose of massaging data. In this lesson, we’ll do the same thing except for dates. We’ll start off by talking about formatting dates and times. We’ll look at how to add and subtract time to a given date. We’ll look at how to create a daytime object that represents this moment in time or the past or the future. Then finally, we’ll look at how to determine the length or the duration of time between two daytime objects. To begin, I’ve created a new project called Dates and Times. Pause the video, please and catch up with me. What we’ll do here is actually just create a new DateTime time object by going DateTime and we call this my value and we’re going to initialize its value to a valid DateTime. The easiest way to do that is to represent this very moment as the application is executing. We’ll go DateTime.Now and that represents this instant. The easiest thing that we can do is just do a Console.WriteLine, taking my value and calling the ToString method. Now you’ll see we have a lot of to something strings and we’ll look at a several of these in an effort to format our DateTime the way that we want. But this default ToString method will take our our country and our locale and will present dates and times as they are typically presented in our country and in our culture. Here in the United States, we usually represent the month first and then the date. I know most other countries it is date, month, year and then we have the time of afternoon that I’m actually recording the video. Notice that it also has AM, PM as opposed to military time or 24 hours. In order to change the way that this is presented, we’re given a bunch of other additional helper methods and so we can do something like this, myValue.ToShortDateString and this will just display the month, date, year. Isolate These short time string. Here we just want to display what time of day it is , 3:35 in the afternoon. Great. We can also choose a more long form version of the date. You can see it’s Tuesday, March 15, 2016, as I record this and we can do the same longer version for time as well, so myValue.ToLongTimeString. You can see not only do we have hours and minutes, but also seconds in the long time string. Great. Oftentimes what we’ll want to do is do some daytime math, which means we either want to add hours, minutes, I guess, to seconds, minutes, hours, days, months, years, whatever the case might be. But we can do it through a series of helper methods, the add methods. Here I’m just going to console.WriteLine and we’ll take myValue and we’ll start off with something simple, like AddDays. You can see that we can add milliseconds, seconds, hours, days and everything up from there. Let’s just do something simple, like AddDays. We’ll add three days and then we’ll just do it ToLongDateString on it like that. Now you may have noticed me do this in the past where I’ve

    used the period, remember, that’s the Remember Access operator and chained together a series of commands. In this case, we have a value that represents a date. If I were to call the AddDays method notices that hover my mouse cursor over it, that the return value of AddDays is another date time. Now, since I have another date time in my hand that represents today plus three days, then I can call that date times ToLongDateTimeString, which now returns as you can see a string data type. That’s the notion of chaining method calls together. As long as you continue to chain together methods that return some value of some data type, you can continue to call methods for that given data type. Let’s go ahead and see now, three days from now it will be, in fact, Friday, March 18th. Let’s do something with regards to hours and let’s go myValue.AddHours. We add three hours ToLongTimeString and that would be 6:38 PM. Then what if I wanted to subtract time? Are there any subtract hours or subtract days? No. However, what you can do is simply use a negative number to subtract, so instead of adding days, I’ll subtract days. We’ll just go ahead and run that. You can see three days ago it was Saturday, March 12th. Great. In addition, we can just grab off parts of a date or time. Here again, let’s go myValue, and let’s just pull off this current month. This will return an integer. Now, Console.writeLine we know can accept an integer, so we’ll just go ahead and print out the current month. The third month, obviously, that’s going to be March. Now, we’ve looked at how to create the current DateTime, but what if I wanted to create a DateTime in the past or in the future? I could do something like this, so DateTime and I’m going to call this myBirthday. Here again is that new keyword. I’ve hinted at a number of times, we will get to it, don’t worry, but I’m going to use it one more time, new DateTime, and I’m going to parse in the year 1969, the month December, and then the day the 7th, that was the day I was born. Now what I can do is something like we’ve been doing up to this point, Console.writeLine and just myBirthday.ToShortDateString just to prove that it’s of date just like the other dates that we’ve been working with, so 12/7/1969. Now there’s one final way to create a new DateTime, so let’s create another version of birthday equals DateTime.Parse, remember we’ve used in parse. We were able to take a string and turn it into an integer. Here we’re going to take a string and turn it into a date, hopefully. We’ll just type in myBirthday again one more time, and that should give us a DateTime object that represents December 7, 1969. Now what I’m going to do is try to determine how many hours that I’ve been alive or how many days I’ve been alive. Days is probably more interesting number. In order to represent a span of time, we’re going to use a new data type called TimeSpan. Here I’m going to use a new TimeSpan, and we’re going to call this myAge equals DateTime.Now.Subtract, and the subtract method will take the current date and subtract whatever date we want to use. In this case, we’ll use myBirthday. Now that I have an object that represents a span of time, I can say represent that span of time in terms of days or years or whatever the case might be. To do that, I’ll go Console.writeLine and then I’ll use this myAge.. Here I can say, give me the total number of days that I’ve been alive and print those to screen. You can see I’ve been alive, what? Well, 16,900 days. I’m getting old. I say that every time I record this video and I feel older every time. Anyway. Here we were able to format dates for display. We’re able to manipulate dates by adding and subtracting date and time, and they were able to determine the difference between two dates using a TimeSpan object. We also talked about different ways to create a date, whether it be now or some time in the past or future, by either just using one of the versions of the DateTime objects constructor, we’ll talk about that later, or by using DateTime.Parse and parsing in a string. Let’s stop right there and we’ll pick it up in the next lesson. Doing great. See you there. Thanks. Hi, I’m Bob Tabor with Developer University. For more of my training videos for beginners, please visit me at devu.com. You might recall at the outset of this course, I said that a class is a container for related methods, and I used the console class as an example of this. We had the Console.writeLine, Console.readLine, Console.Write, we’ve even used Console.Clear. All of these methods that had something to do with working with the console window. I said it makes sense to put them all in the same class, the console class. Now, truth be told, I intentionally oversimplified my explanation about classes and their relationship to methods, because first of all, I wanted you to gain a little bit of confidence in yourself that you can do this, that this isn’t hard. You can get your hands around it and you’re going to do just fine. I wanted to do that before we got into the topic of classes, because while there’s nothing hard per say about classes, they do lend themselves to a conversation about object-oriented programming, a style of programming that some beginners find a little bit difficult to grasp at first. Now, the code that you’ve been writing in your methods have all been defined inside of classes, and you’ve been calling methods that were defined inside of classes. Classes have been all around you, you’ve been working with them from the first line of code that you wrote. You’re really already an old pro at this whether you realize it or not. I’m merely going to fill in some of the details that you don’t yet know about in this lesson in a couple of subsequent lessons so that it rounds out your knowledge so that you can fully harness the power of the.NET Framework Class Library in your applications. Maybe someday, whenever you sit down to architect some big application for some large company that you go to work for, you’ll begin to think like an experienced, object-oriented software developer. But at this early point in your C-Sharp experience, I really just want you to be able to do one thing and one thing well, that is to find what you’re looking for in the.NET Framework Class Library and be able to have the confidence to utilize the methods and the properties in those classes that have been defined there. The truth of the matter is that object-oriented programming is such a massive topic that I certainly couldn’t do it justice in this course. In fact, I have a whole course devoted to it on devu.com. Again, I really just want to accomplish one thing here, I want you to know enough about classes and objects and properties and methods and things like that so that you can harness the power of the.NET Framework Class Library inside of your own applications. Now, the way that we’re going to learn about classes and methods and properties and all that good stuff is by creating simple custom classes of our very own. Let’s start by talking about creating a simple application for a car lot. Suppose that I own a car lot and I want to sell cars, and I want to build an application that helps me keep track of all the cars on my car lot. I might need to create a number of variables to hold information about a given car, because I’m going to use that information to then determine its value based on its make and its model and its year and so on. I might start off by creating a couple of variables called car1Make, car1Model, car1Year, and so on, in order to keep track of that information. Now, what if I need a second car in my application? Well, then I guess I could create another set of variables called car2Make, car2Model, car2Year. What if I need a third one? Well, I think you see where I’m going with this, things are going to get out of hand pretty quickly here. Then what if I decide one day that the value of the car is not only based on the make, model, and the year, but we also need to keep track of the color of the car as well. In that case, now I got to do car1Color, string, car2Color and so on. You can see that this simply is not the right approach to keep track of information that should be collected together about a given entity. I need a way to keep all of this data about a car together in its own little container. I want to keep track of the make, the model, the year, the color, and maybe a bunch of other things too about a single car, but I don’t want to have to treat it like a bunch of loose information, I need it all related together. What I’m going to do is start off by defining a class that contains four properties that describe any given car on my car lot. To begin, what I’m going to do, you can see I have a project that I’ve already started with here, SimpleClasses, go ahead and pause the video and catch up with me if you like. What I want to do is work actually outside of the first class that’s already been defined in our program.cs file. I want to work inside of the namespace SimpleClasses, but I don’t want to define a new class inside of my existing class, I want to work outside of that class here, and so I’m going to define a new car class like so. I’m going to give it four properties, and I can type it all out like this and I’ll explain what I’m doing here in just a moment or I can use a shortcut prop, tab, tab and then I can use the replacement areas by using the tab on my keyboard, so I want to make a string, tab, tab model, enter, enter, prop, tab, tab, int, year, enter, enter, prop, tab, tab, string tab, tab, color, enter, enter. I’ve just defined a class name car with four properties. This car class allows me to define a data type that describes every car in the world. Every car has a make, a model, a year, and a color, and a bunch of other information that I might or might not be interested in for my specific application, but my aim here is to use this definition of what comprises a car in order to create additional instances of the car class that represent all of the cars on my car lot. In other words, I want to create a bucket in the computer’s memory that’s just the right size to hold information about any given car on my car lot. It should contain not only the fact that it’s a car, but then also the value of its make and its model and its year and its color, all in one big bucket up in the computer’s memory so that I can access it. There’s two parts to this. There’s defining the class itself and then once I’ve defined it, I can create instances of that class. Here the class is the definition, but when I create a new instance of this class, then I’ll be working with an object and sometimes those terms get confused. But the class is the blueprint, the object is an instantiation or something that’s been created as a result of having the blueprint or the pattern. The way that we create a new instance of the car class is to do this. I’ll just call this my car to avoid confusion. This point, I’ve defined it just like any variable I would by declaring the data type itself, whether it be string or integer. This is just a little bit more interesting, a little more complex. It’s the car class. Then I give it a name that I want to call it by my car. Now, that’s part of what I need to do. The next thing that I want to do is actually then create a new instance of that class and say, put this up in the memory, in the bucket, so to speak. Here we go, new car. Again, there’s two parts of this equation, we’ll talk about this more as we go throughout this course. First of all, I want to declare a new car in memory and then I want to create an instance of car and then put it up in the memory, so there’s two distinct steps there. In the real world, you can use the same blueprint to create many different houses. In the neighborhoods that I’ve lived in before, you might describe them as cookie cutter houses, they all look the same. You could use the same pattern to create clothing over and over, or you could use the same recipe to create the same cake or casserole and get the same results each time. Each time you want to build a new house, it will be at a different address. Each time you follow the pattern, you’ll create a new instance of the clothing that can be sold to a different customer. Each time you follow that recipe, you create a new instance of the recipe and you can offer it during either the same meal or a different meal. The same is true with classes, each time that you create a new instance of the class, you have a new object that is distinct and separate from the other instances of that same class in the computer’s memory. They each live by themselves. A class is like a cookie cutter. Now keep in mind, you can’t eat the cookie cutter itself. You eat the cookies that you make from the cookie cutter. The cookie cutter gives each of the cookies some shape, and so when you instantiate a new instance of a class, you’re basically using your class as a cookie cutter to stamp out new instances and you have 1, 2, 3, 4 new instances of cookies that you can then put in the oven and bake. Focus on the new keyword, it is what you would consider to be the factory. It actually builds the new car and puts it into memory. It uses the blueprint, it uses the pattern, it uses the recipe, it uses the cookie cutter in order to create a new instance of that blueprint or that pattern or that recipe or that cookie cutter and it brings the class to life in the computer’s memory, and it makes it usable by your application. You can create many instances of a given class or you can create many objects, all based on the same class, but each object will be distinct from the others. If by no other distinction then by is merely the address in memory where they live. What I want to do is not only set the properties of this car because I have these four properties that I want to use to distinguish this car on my color to represent this single car. But then also, I may want to then access or get those properties back out, and it’s working just like you’re working with variables. In this case, instead of just accessing make variable, I would go mycar.make and I would set that equal to Oldsmobile. Now, admittedly, in this particular case, I am merely hard coding these values. If this was a real application, I would ask an end user to input this information or I grab it from a database, something along those lines. There we have it. We have one instance of the car class and I’ve set all of its properties, and now I want to get those properties and print them out in a console window. We’ll just do this in the most easy way possible. We access, or we get the values just like we set the values before by using the name of the object, dot the name of the property. Let’s go make, myCar.Model, myCar.Year, and myCar.Color. Now you might be wondering, well, Bob, why did you do it that way and not Car.Make, or Car.Model? Remember car in that instance, car describes the class, the blueprint. But what we want to work with is one instance of the blueprint so that’s why we’re calling that instance myCar. It’s the variable name in the computer memory that we want to work with. Let’s go ahead and separate these out on the separate lines and then finally will go Console.Readline, so and this should not be an exciting application at all because we’re merely just printing things to screen. But at least I can show creating new instance of a class, setting the properties, and then getting the properties and printing them out. That’s what this get in the set are for. There are actually longer versions to declare a property in fact, let’s just do this propfull, tab, tab. This is a longer, more complete version of creating a property, but I don’t want to talk about it right now there are reasons why you would want to use this. But for the most part, for our simple needs, we’ll just use this abbreviated version of defining a property in our classes. Now did you notice that we got full IntelliSense support, so whenever I typed out myCar. and I used the member accessor operator that I’m able to see all the members of the class, the Make, the Model, the Year and the Color. All represented as a little wrench icons in IntelliSense so that I can access them, whether to set their value or get their value. Furthermore, I’m able to set values the way that I would just with normal variables by using the the assignment operator, I’m able to work with the variables and write them just like I would any other variable in my system. There’s nothing all that special about it outside of the fact that they’re all related, to a specific instance of a class. We created a new data type, the Car data type, and since the data type, we can use it just like we would any data type in our system, so if I wanted to create a little method here, private static, and I’ll use the decimal data type because I’m going to work with dollars or money currency, and I’m going to create a method called determine market value and I’m going to allow this to accept a car as an input parameter. What I’ll do is just in this case, I’m going to have to carValue to $100 and we’ll leave it at that. In fact, I’ll go ahead and the end here. However, if this was a real application someday, I might look up the car online using some web service to get a more accurate value. But for today, we’re just going to hard code the value to be 100 and we’ll return carValue. Here I can go determine market value, I can pass in myCar, and I should return back the value, so let’s go decimal value equals determined market value and then let’s go Console.Writeline and will use what we learned previously, to print out the value of the car like so, and let’s run the application. You can see that it’s worth $100. Now notice what I did here. I used the C in car in a c in car. The C corresponds to the name of the class because I named it with a capital C, and the C-sharp compiler is smart enough to know that again, C car and c car are two different things, and this is a common naming convention to use the same name for an object if there’s no reason not to. If there wasn’t something special about the car like it being in some special state, but I can reuse the word car, I chose not to do that here just to make it obvious what I was actually doing. But there’s nothing wrong with doing this as well. Defining this input parameters data type and then giving that input parameter the same name. But just with it lowercase character they’re two very different things. Moving on, I want to talk about creating methods on the class. We’ve already said that classes are containers for methods. We’ve created this helper method here inside of my static void main. But it might make more sense for us to create that method here inside of the car class itself since the car class already has access to information like the make model of the year and the color and that’s the information that we would use in making a determination on its value. Here, let’s go ahead and define this as a public decimal DetermineMarketValue. Now, we’re not going to allow anything to be passed in, because we already have all the information we need right here. Let’s create a little algorithm here. If the year is greater than 1990, then we will set the value of the car, the car’s value, which we need to define as a, so let’s go. Decimal carValue, set the carValue equal to $10,000 so if it’s a relatively new car, we’ll set it to 10,000. Otherwise, we’ll say the car’s values only words of 2,000. This is a very, very overly simplistic example. But we just want to demonstrate the fact that inside of an instance of the class, you’re going to be able to access its properties. We’re able to access the current car’s year in order to determine its value, and so in this case, what I’ll do is let’s comment this out and comment that out, and here will go Console.Writeline, myCar.DetermineMarketValue. Like so. Because this is going to come back as a decimal, I’m still going to want to format it. Now let’s go ahead and run the application. Since it’s in 1986, is before 1990, it’s only worth $2,000. In this lesson, we used a very concrete example. We’ve all seen cars, driven cars, own cars. A car is easy to conceptualize and represent in a class because there’s a tangible real world equivalent. Now my assumption again, is that your main exposure to classes will be whenever you’re using classes define by Microsoft in the.Netframe class library, and most of the time, those classes don’t represent real tangible things. They’re very conceptual in nature. You might have a class that represents a connection to the internet. You might have a class that represents a buffer of information that streaming from hard drive. They don’t really have real world tangible equivalence, so you need to be aware of that. In most cases, the.Net Framework class library classes don’t have real world equivalents, but the ideas are exactly the same. As you choose a software developer, you might want to invest a little bit more time in learning how to create your own library of classes, and those classes can interact with each other, they can represent real things in your company or in the real world or conceptual things. The process that you go through to break down a problem in the world and represented in objects, is object-oriented analysis and design. Again, that’s not a topic that we’re going to cover in this series of lessons, but you can learn more about that at DevEW.com, where I spend a lot of time talking about those things. To recap, a class is just a data type in.Net and it’s similar to any other data type like a string or an integer. It just allows you to define additional properties and methods so you can define a custom class with properties and methods, and then you create instances of those classes or rather you create an instance of in class, therefore working with an object using the new operator. You can then access that object’s properties and methods using the.Operator, the member accessor operator. There’s quite a bit more to say about classes. Don’t worry if you don’t understand everything just yet, why you even need them, how to really fully utilize them. Just make sure you understand the process that we went through in this lesson of defining a new class, creating an instance of a class, setting its properties, getting its properties, passing an instance of a class into a method, or even defining the method inside the class itself, and allowing it to access its own members like its other properties. If you really don’t understand much more than that, then you’re doing just fine. You’re exactly where you need to be don’t worry, we’ll cover lots of other topics related this in the upcoming lessons. We’ll see you there. Thank you. Hi, I’m Bob Tabor with Developer University for more of my training videos for beginners, please visit me at DEVU.COM. In this lesson we’ll continue to talk about classes and methods. We’ll begin by talking about the lifetime of objects so objects come to life. They live for a period of time, and then they die. They’re removed from memory, and we’ll talk about the.NET Framework runtime and its role in the creation, the maintenance and then ultimately, the removal of objects from memory. Next, we’ll talk about constructors, which are simply methods that allow us to write code as developers at the moment when a new instance of a class is created. Finally, we’ll talk about static methods and properties that study keywords been lingering around now for some time, and we’ve been using static properties and static methods throughout this course, even from our very first examples. So we’ll finally tackle that issue in this lesson. Let’s begin by creating a new project. You can see I’ve already done that and pause the video and catch up to where I’m at right now. I’ve created a new project called Object Lifetime. Furthermore, you’ll see that I copied the car definition from our previous lesson. If you like, you can type that in help build some muscle memory, help remind you to use the Prop Tab Tab shortcut, the code snippet in Visual Studio to create these short and auto implemented versions of properties. We’ve talked about that a little while, and then ultimately you can see in line number 13, we create a new instance of our car class. That new instance we’ll call myCar, and we’ve talked about this in the previous lesson, but I felt like this deserved a little bit more explanation because there is actually a lot that’s going on under the hood, and it would be helpful to understand this as we begin to work with classes and objects. Whenever we issue a command to create a new instance of a class like we have in line number 13, the.NET Framework runtime has to go out and create a spot in the computer’s memory that’s large enough to hold a new instance of the car class. Now that much we know. The computer’s memory has addresses that are similar to street addresses like the address you live at, the address that I live at. Now, admittedly, a computer’s memory address is looked dramatically different than our addresses, like 123 East Main Street, because the computer’s addresses are typically represented in hexadecimal values, but they’re known addresses nonetheless. It’s easy then, for the computer to find something in its memory by using its address. The.Net Frameworks first job is to find an empty available address where nothing is currently living, where there’s no data that’s currently being stored, and that address has to be large enough to store an instance of our class. The.NET Framework runtime will then create the object instance, and it will copy any of its values that are currently stored in that object instance up into that memory address. Then it takes note of where it put that object. It notes the address of the memory where it put that instance of our object, and then it serves that address back to us, and we store that address in the actual name or the instance name of our class. In this case, myCar, that variable is actually holding on to a reference or, in other words, an address in the computer’s memory where we can access that object once again. Now, whenever we need to access the new instance of the car class, we merely can use its reference name. It’s in this case myCar, so myCar is simply holding an address. It’s simply a reference to an instance of, in this case, a car class in the computer’s memory. Whenever you need to work with that instance of the car class, you just use the myCar Identifier and the.NET Framework runtime, takes care of everything else for you. It gives you the illusion that you’re actually working with the object itself, but in reality, you’re just holding on to a reference to an address in the computer’s memory. Now there’s an analogy that helps me to sort all this out in my mind, and we’re going to continue to extend that bucket analogy, if that object is stored in the computer’s memory, if it’s what we have equated to a bucket, an address, an area that holds on to our values, then what’s returned back to us as programmers is a handle, that’s what myCar is, it’s our handle to the bucket. We’ve used that bucket analogy in a number of different times and it’s served us well. But we essentially are storing values in that bucket just like we were before, and we’re holding on to that bucket using our reference to that memory area in our computers memory. What happens if we were to let go of the handle? Well, at that point we’ll no longer be able to get back to the bucket. We’ve lost the bucket somewhere in the computer’s memory. The bucket will no longer be accessible to us. Now, can we ever get back to that bucket? Well, no. What happens is that the.NET Framework runtime will be constantly monitoring the memory that it manages, and it’s looking for objects that no longer have any handles associated with them. Once we let go of a handle, the reference count, the handle count, I guess you could call it will go to zero and at that point, the .NET Framework runtime will say, I see that nobody’s interested in you anymore. They’ve let all of their handles to you expire or to go out of scope. That must mean that you’re no longer needed and it removes it and throws it in the garbage. That process of monitoring memory, looking for objects that no longer have any references to them is called garbage collection. It’s one of the core features of the .NET Framework runtime, and it’s one of the reasons why it’s easier to work with C-sharp at first as a developer than maybe going directly to C++. In an unmanaged language like C++, you, the developer, may have to manage memory on your own, and sometimes you might forget that you actually are leaving things in memory and you’re not cleaning them up, you’re not removing them yourself so your application might have a memory leak. Or you might have a corrupted memory region where you’re using an area of memory and you forget that you’re using it, so you copy something else to that area of memory. Now you go back to retrieve the value that you originally put in there, and it’s corrupted. That leads to corrupted memory in applications. You don’t really get that issue so much in C-sharp because again, the .NET Framework runtime takes care of all the memory management for you. Let’s do a little of experiment here, if we said that we can have one handle to a bucket, what happens if we attempt to create a second handle to the same bucket? Let me do this real quick. Let me go to myCar and start setting some of the properties like the Make equal Oldsmobile. Then we’ll set the Model equal to that Cutlass Supreme and then we’ll set the Year equal to 1986. Finally, we’ll set the Color to Silver. Now, keep that in mind, we’ve created a new object that we’re referencing using the myCar identifier. Instance of the car class lives in memory, and we’re holding on to it with a handle called myCar. But what if we were to create another car like this? So my other car, what have we really done right now? We simply have created a handle, but we’ve not attached it to any buckets of cars in our computers memory. At this point, what I could do is go myOtherCar equals myCar. Now, what have we really done there? Well, we’ve merely taken one handle to a bucket in memory, and we’ve created a second handle and said, “Hey, let me copy your address,” so that we’re both referencing the same bucket in the computer’s memory. Now, to prove that what I’ll do is do a Console.Writeline and we will do what we did before. Just give me a second here and we’ll reference myOtherCar’s Make, myOtherCar’s Model, myOtherCar’s Year and then myOtherCar’s Color. Let me separate these two different lines for readability sake. Then a Console.Redline for good measure. Now let’s run the application. You can see that even though we created or set the properties of myCar since we copied the reference to the car object in the computer’s memory into a new variable called myOtherCar, I can still get to the values that are in memory because they’re both pointed to the same object. Now I can even do something like this where I actually change something, myOtherCar.Model equal to the 98. That was the large style model for that car. Let’s then go back to and do something similar to this just to prove that they’re one and the same here, and I’ll say, “Hey.” Let’s do that. We’re going to use our reference called myotherCar and set the model, change the model from the value Cutlass Supreme to the 98. Then we’re going to say, Hey, show me what’s in the myCar object. So now we’re going to run the application, and you can see now we’re printing out what’s currently in my car. It’s the same thing that we changed in my other car because they’re both pointed to the same place. I just want to emphatically make that point here. As you can see, we have now two references to the same object in memory. We essentially attach the second handle to the same bucket so that we can use either one to retrieve the data in the bucket, so to speak. If you don’t like that analogy, maybe it helps to think of this in terms of balloons. I have a balloon and I have two strings tied to the balloon. What happens when I cut the first string? I’m still holding on to the balloon, but what happens when I cut the second string? The balloon now will fly away, and we’ll never see it ever again. As references go out of scope, in other words, whenever the current thread of execution leaves the current code block that we’re currently in, or those object references are set to null intentionally by the software developer, then the number of references to the object, the number of handles to the bucket, the number of strings attached to the balloon, they go to zero. So here again, when the. NET Framework runtime looks through memory and finds objects that have a reference count of zero it will remove those objects from memory. We talked about the two instances in which the connections to the object get removed. One is that the reference goes out of scope, so whenever we create a new variable called myCar, it will continue to be in scope as long as we’re inside of this main method. But once we exit out of the main method, that variable goes out of scope. it’s no longer available for us to access any longer. The same would be true if we created a different method, and defined a variable. As soon as we go out of scope of that method and we have finished executing all the lines of code in that method, then any of the variables that were declared inside of that method go out of scope. In this case, we would lose then any references to the objects that we created in the context of that method. That’s one instance in which we’ll lose references to objects that we created. But the second is if we, as the developers, actively take a role in cutting the strings or removing the handles from the buckets in memory. The way that we do that is by setting our objects equal to null. The value null is not zero, and it’s not an empty string, it just means indeterminate. In this case, what we’ll do is go here, and we’ll set myOtherCar equal to null like so, and when we do this now we’ll remove one of the handles to the bucket, so we’re back to just one handle in the bucket. To prove this, let me go ahead and copy this little section of code, and go here and put it below this, and when I do that, notice what happens will get an exception. The exception is that there’s a null reference exception that was unhandled, and the reason why it was a null reference exception is because we have now removed the handle. The handle does not point to any objects in memory, and yet we’re still attempting to access values from the object in memory, so we get an exception in our application. Now what will happen if we were to remove the second reference like so myCar equals null. Well, at that point now we have removed all the references to the bucket, even if we were to attempt to get to it with either myOtherCar or myCar, either way, the references are gone completely, and so now the object will be removed at some indeterminate time in the future by the.NET Framework runtime. In some situations, this indeterminate period of time can cause a problem, especially when the object in memory is holding on to some special resource, maybe something like a reference to a network connection or a file on the file system or holding on to a handle to access a given database. Again, we don’t know exactly when the.NET Framework runtime will actually execute the garbage collection step, and that might pose a problem in certain situations. In these cases, you would want to use a more deterministic approach to requesting that.Net removes the object from memory and, if necessary will finalize and clean up anything that needs to happen inside of that object to completely get rid of it in the computer’s memory. In these cases, you want to learn about deterministic finalization. That’s a little bit of an advanced topic, so we’re not going to talk about it in the series of lessons. Just keep in mind that whenever we set reference to null or whenever we go out of scope, we will be removing all the references to our objects. But the .NET Framework runtime itself figures out when it’s ready and willing to remove those objects from memory completely. In most cases, that’s not a problem. Occasionally, you’re going to run into a situation where it is a problem, know that there is a remedy for it called deterministic finalization. That should suffice our explanation of really what’s going on whenever we create new instances of objects, how objects are maintained in memory, and then at what point they’re removed from memory. Let’s move on and talk about constructors. I said at the very outset that a constructor is merely a method that allows us as developers to execute code at the moment that a new instance of a class is created. There’s something really subtle about what’s going on here in this line of code line number 13. Did you notice that whenever we use the new keyword, and we give it the name of the class that we want to create a new instance of that we’re also calling it using the method invocation operator. Why do you suppose that is? Whether you realize it or not, you’re calling a method whenever you create a new instance of a class, and that method is referred to as a constructor. It allows you, the developer, the option, you don’t have to do this. It’s an option to write some code at that very moment whenever a new instance of a class is created. Constructors can be used really for any purpose, but typically they’re used in order to put that new object into a valid state, meaning that you can use it to initialize the values of the properties of that given object, and so it’s immediately usable. Now, let me give you a really quick example here. Let’s say that you want to create a constructor that would allow you to set a property of the car at the point whenever you create a new car class. That property is available immediately in the very next line of code whenever we begin to work with it here in line number 15. Whenever you actually want to create a constructor, you would go and create something like this, public car. In this case, what I’m going to do is simply set the make property to Nissan. By default, whenever we create a new car class, we’re going to set one of its properties, the make property to Nissan. Now let me say this as well, you might see the keyword this used that this keyword is optional, it refers to this instance of this object, and it’s just to help clarify where this variable name or this name is coming from. When I see that this keyword, I automatically think, Oh, that’s part of the declaration of the class itself. It’s saying that you want to access a member of this class that’s been created. But as you can see, it’s faded out in my text editor. It might not be in yours, which lets me know that I could actually remove this it’s not necessary. You might see that though in other people’s code, just understand what that is. Now if we were to go ahead, and create a new instance of the car class, here’s what I’ll do. I’ll actually comment out all of this code. Like so, and then I’ll comment out the code that we know will break the application. We can leave the rest of it, I suppose. Notice that the very first item that is displayed is the make of the car, and it’s set to Nissan. I didn’t set any other properties. That’s why we didn’t get any other values there in the printout, but hopefully you can at least see how we go about creating constructors. Now, admittedly, it may not make a lot of sense right now why you’d want to do this, but I’m showing you the technique you’d use, not the rationale, necessarily, but the rationale is simple. What we would typically do here is to put any new instance of an object into a valid state. You could load values into the various properties of your class from a configuration file or from database or some other place in order, again, to get that object into a valid state so that it’s immediately usable at the point of whenever it’s instantiated. Let’s go ahead and talk about overloaded constructor. You’ll see this frequently whenever working with objects in the.NET Framework Class Library. Just like you can create an overloaded method in your classes by changing the methods signature, in other words, the number and the data type of the input parameters for the method, you can do the same thing with a constructor. You can create an overloaded constructor. What I’m going to do is create an overloaded constructor here like so. Now at this point, the method signatures are the same, so I’m going to get a little error here. But to modify that, I will merely add at least one input parameter of type string, but I’ll go ahead and do them all as well. Then here in the body of the constructor, I would Make equals make. This Make is in reference to the property itself. This ‘m’ in make is the name of the input parameter, and it’s a good convention to use the same name for readability sake and for your own sanity. You don’t have to do it this way, but just keep in mind that M and m are two different items as far as C-sharp is concerned. It’s not confused. You might be confused, but you will be able to handle this just fine. Now you might ask, what’s the point of that? Well, in many cases, whenever you create a new instance of a class, typically you don’t want to take five steps to do this. You would want to immediately whenever you create a new instance of a class, so my third car equals new car. At this point, you can do one of two things. Notice here that underneath the open parentheses, I have one or two ways that I can call the constructor. I can either give it no input parameters or I can give it four strings as input parameters to initialize that new instance of car and put it into a valid state immediately. Here I might go Ford, escape, 2005, white like so. Now I have not only created a new instance of the car class but I immediately initialized its values by calling its overloaded constructor to populate all of its values at the moment of instantiation. What would happen if we were to actually remove these two completely? What if we were to comment these out? What happens? You can see that we’re still using the method invocation operator for our new instance of car that would suggest that we’re calling a constructor, but we don’t have a constructor defined. Why is this working? Why isn’t it giving us an error? Well, the reason is because a default constructor is automatically created for you whenever you compile your classes. It will be a constructor without any input parameters and will have no body, but it’s essentially the equivalent of doing this right here, except with nothing inside of it. That’s created automatically for you. No matter what, you’re going to have a constructor, it just won’t do anything for you. The implicit default constructor has no input parameters, no method body, but it allows you to make calls and create new instances of classes in a consistent way. It’s actually just generated for you. Again, it compile time, of course, by defining it yourself, you’re taking control of the process of instantiation. Let’s talk about the static keyword now. You’ve seen static around since the very beginning. I said, let’s ignore that for now. We created our own methods, and I said, we have to use the keyword static. I’ll explain later. Well, now is the time. I want to ask a question, did you ever notice that whenever we were working with the Console window, we never had to create an instance of the console class in order to call its methods? That combined with the fact that whenever we wanted to work with DateTime, we could get to this moment in time by using the DateTime.Now property, but we never had to create an instance of DateTime. Furthermore, whenever we were actually working with arrays and we wanted to call the reverse method, do you remember we did Arrray.Reverse and then we passed in the array itself? How is it that we were able to use the reverse method without creating an instance of the array class? Well, in each of these cases the creators of those classes, or specifically those methods adorned their methods with the keyword static, which means that you do not have to create an instance of a class in order to utilize that method. In some cases, they may have defined an entire class as static, meaning that all of its properties and methods were static. You can create your own static methods in classes as well. Again, the objective here at the very outset is to just help you utilize the.NET Framework Class Library. So just know that some of the classes and methods in the.NET Framework Class Library are static and some are instance or require you to create an instance of the class before you call its methods and properties. Static methods will be available to you without first requiring you to create an instance of a class. Just so you can see how this works, we can create a static method on our car class like so. In this case, we’ll go public static void MyMethod, and here we’ll do Console.WriteLine called static MyMethod. Now we can go here near the very top and just say Car.MyMethod, and notice I didn’t have to create an instance of car. I’m using the actual car class definition itself when we run the application. Before we go too far here, let’s comment out pretty much everything. Let’s remove that. Let me go down here. Just make this so that we don’t run into any potential issues here. Let’s run the application and you can see that we were able to successfully call the static MyMethod. Now, what would happen if we attempted to reference one of the properties in our class? Let’s just print out the make property. Notice that I immediately get a red squiggly line beneath the word make. It says that an object reference is required for the non-static field, method, or property called Car.Make. It’s important to keep in mind that there’s a fundamental difference between working with classes that have static members versus instance members. Instance members are the things that we’ve been working up to this point where we have a series of properties that describe a single instance of a given entity like a car. They might be methods that operate on a single instance of a car like the constructors that we saw, whereas a static member, like a static method in this case, they don’t really operate on any single instance. They’re more like utilities. You can call them at any time. They don’t depend on the state of a given instance of the class or even the application itself, they can be used at any time because they’re not really tied to one specific car. They’re true of all cars and can be used at any time. Static members versus instance members, just keep those two clean in your mind. You might want to ask the question, why would you ever create a static member like a static method? Well, that’s a bit more complicated. That might require a longer discussion of things like design patterns which are common solutions to common problems for software developers or coding heuristics which are more the best ways to go about solving problems. I just want you to know that there’s a fundamental difference between static members in a class and instance members of a class and it’s easy to recognize them. If it’s a static member, it’ll have the static keyword and in which case you cannot reference any instance members like instance properties or even other instance methods that act on instance properties. They require an instance of the class to operate. Just know that there are these two types of members in a given class and that you’re going to encounter both whenever you’re working with the.NET Framework Class Library. Why you would use one or the other, well, that’s really again another story. I would say this that typically, I would recommend that you don’t mix and match them in the same class. Clearly, not everybody agrees with me because you’ll find that many times, but it’s not really important at this point to understand why you would use one over the other, just know that that possibility exists, that’s why you don’t always have to create an instance of a class before you use the members of its class; in this case, a given method. Let’s recap what we talked about in this lesson. We began talking about the lifetime of an object, how we create a new instance of an object, what that’s doing in terms of creating an area in the computer’s memory, returning back to us an address, a reference to that object in memory, what happens during the lifetime of that object, and ultimately, what happens whenever we remove all of the references to that object. Talked about the role of the.NET Framework runtime and how it’s keeping track of the number of references to objects so that it can perform garbage collection on objects that have no more references to them in memory as means of keeping things clean and making the memory available to other applications or even our application again. We talked about constructors and how developers can use them to put a new instance of an object into a valid state at the point when that object is created. Then we talked about the static keyword. We looked at some usages of static members inside of the.NET Framework Class Library. We looked at creating our own static member, this MyMethod. We talked about the difference between static members and instance members and how it’s really oil and water. You can’t mix the two and why that is. We didn’t really talk about why you would choose to use one over the other. However, that’s again a topic for another day. Hopefully, all of these concepts make sense. If not, don’t continue on and hoping that you’ll just catch up to them at some point in the future. Make sure you thoroughly understand this before you continue on. If you are continuing, great, we’ll see you in the next lesson. We’ll see you there. Thanks. Hi, I’m Bob Tabor with Developer University. For more of my training videos for beginners, please visit me at devu.com. Now we haven’t spent a lot of time talking about variable scope. It’s actually extremely important. We recently learned that it also impacts the lifetime of objects. We want to spend a little bit more time really making sure we understand the scope of the variables, whether they be variables holding simple types or references to complex types in our applications. Not only do I want to fully explain that, but then I want to use that as a launching pad to explain key words like public and private that we’ve seen several times in our course up to this point but I haven’t really talked about. Before we talk about that, let’s talk about variable scope. Let me start by saying that whenever you declare variable inside of a block of code, that variable is only alive for the life of that code block and any of the interior code blocks or code blocks inside of that code block. Meaning that when the code block is finished executing, the variable that was defined inside of that code block is no longer accessible and its values are disposed off by the.NET Framework runtime. We’ll start by looking at how that is impacted by common code blocks that we’ve been working with up to this point and then we’ll use that and expand beyond there. You can see that I’ve created a project called UnderstandingScope and you can pause the video and catch up with me. I want to create this project and focus on testing how variable scope works. I’ll start with a pretty simple code example. Again, the concepts that we talk about also apply to object references not just variables that hold simple strings and integers. Let’s start by creating a simple for iteration statement and we’ll just loop through 10 times and we’ll do a Console.WriteLine containing the value of i, and then here, we’ll do the Console.ReadLine. We can see our results and we’ll run the application. As we would expect, we can see values from zero through nine. Now, what if I wanted to access the value of i here right after the closing curly brace for the for statement? We’ll notice that I’ll get a red squiggly line under i, and if I hover my mouse cursor over, it says that i does not exist in the current context. Why? Because i is now outside of the scope of its definition, we defined i inside of the for loop, it’s available inside the for statement itself plus in the code block below it but not outside of either of those. Let’s comment that up. Second, we’ll continue by going and creating a string of j equal to empty string. What we’ll do inside of our loop here is just go j equals i.ToString. Now let’s go outside of our loop where we’d be able to access the value of j. Let’s go outside of the four, and well, we’d we be able to actually print to screen the value of j. We were not getting any errors, so let’s run the application. You can see that the last value that was inserted into j was the value nine. Since we defined j outside of the scope of this of the for statement and its code block, we can access it inside of that code block and outside of that code block as well. Next up, let’s look at something like this, where we’ll actually create what’s called a field or a private field. We’ll go private static string k equals. A private field is like a property, except it’s private in nature, but it is available to all of the members of the class. We should be able to see k inside of our for loop. Let’s do i.ToString. We should be able to see it here as well outside of the for loop like so. Let’s go ahead and run the application. You can see that second Console.WriteLine will also display the number 9, but the real question is, what if we were to create a helper method? Static void, and we’ll just call this HelperMethod. Here we go. Console.WriteLine, and we’ll say this is the value of k from the HelperMethod, and we’ll do that. Now here, we’ll call the HelperMethod like so. Will this work? Will we be able to access the value of k as it was set inside of our for loop outside of our static void Main? Let’s run the application, and you can see that we can, in fact, get the value of k from the HelperMethod. Why? Because k was defined at, I guess, you could say, the class level. It is a sibling to static void Main and static void HelperMethod; therefore, it’s accessible to each of these as well as any of their inner code blocks. Hopefully, this is starting to make sense. Let’s go inside of the for loop now, and here what we’ll do is a simple if statement. So if i is equal to 9, so on the very last run of this, then let’s declare a string called l, and we’ll set that to i.ToString. Then outside of that, we’ll go Console.WriteLine the value of l. As you might anticipate, we will see that l does not exist in the current context. Why? Because we declared the value of the string variable l inside of the if statements curly braces. Outside of those curly braces, it’s no longer accessible, so we have to comment that out. Hopefully, this solidify in your mind many of the combinations that we can use in determining whether something’s in scope or out of scope. If you had any confusion about this, hopefully, that cleared it up a little bit. Now let’s move on to the larger topic of accessibility modifiers. We’ve been creating classes, specifically the car class up to this point, and whenever we were creating methods, I would typically use the public keyword. Occasionally, I would use the keyword private like I did here in line number 11. Private and public are both accessibility modifiers. They’re used to implement a tentative object-oriented programming called encapsulation, which is actually pretty important. In a nutshell, you should think of classes as black boxes. Whenever you think of a black box, maybe you can think of one of those old-style television sets. Maybe your parents or grandparents had one. I remember as a kid, us having one, there were no remote controls. You had to get up, walk across the room and actually turn the dials of the TV in order to tune to either VHF or UHF channels. You had another dial where you would adjust the volume. You had an antenna in the back, so you would connect this wire out to your antenna, and you had another one where you would plug it into the wall. Everything else about the television was self-contained. Now, as a kid, I was fascinated whenever my dad would pop off the back of the television set, and he’d go and try to fix it by changing up the tubes. It always seemed like magic to me because I knew absolutely nothing about the innards of televisions. All I knew were the public interfaces, the button for on/off, the dials to turn the channel, the dial to turn the volume up and down the antenna, whatever that did, and the little plug that would obviously give it electricity, but frankly, in order to use the television set, that’s all you really needed to know. You did not have to know anything about how a television worked. All you really needed to know is how to plug it in and change channels, turn it on and off, and then adjust its volume, and that is exactly how your classes should be treated. All the important behind-the-scenes functionality should be encapsulated behind interfaces like public methods and public properties. Now classes might, in fact, have private fields like we looked at here in line number 11, or they might have private methods that are used behind the scenes to enable all the magic that goes on inside of that class, but the consumer of the class shouldn’t know anything about the inner workings of the class in order to work with the class, to operate the class. All they need to know is what’s publicly exposed through the public properties and public methods. In a nutshell, private means that a method can be called by any other method inside of the same class. I used the term private HelperMethod a number of times accidentally. Essentially, when I use the term private helper method, I’m talking about a private method that’s add some additional functionality to those public methods that are exposed to anybody who needs to work with the class through that method. A public method is what’s actually going to be then called by somebody outside of the class, some other code outside of the given class, and private methods are only going to be called by members inside of the class. Let me do this. I’m going to paste in some code, recreate our Car class, and here I have a public and a private method. The public method is called DoSomething, and the private method is called just helperMethod. These are not very interesting examples. I want to keep this as simple as possible. Now, from the outside of this Car class, it’s just roll this whole thing up here and save it. Now, whenever I want to go here inside of my static void main, I might want to work with the Car class, so I’ll go, Car, myCar equals new Car, and then I’ll do myCar. and notice that I can only see the public method DoSomething. Now I might happen to know there are other methods also inside this class, but I can’t see them from outside. Their visibility is hidden to me because they’re marked as private. All I really need to know is how to use the DoSomething method. If I understand that I can call that, all the implementation details will be hidden from me, but it’ll work as I expect it to work. Here you can see that it’s merely prints out the words Hello world. Now, whose responsibility inside the class it is to actually display that? That’s none of my concern. All I need to know is how to call the public method DoSomething. In a sense, the consumer of the Car class has absolutely no idea that the helper method even exists. All it really knows is that there’s one public method and it could call that public method, but it doesn’t know any of the Harry implementation details. Now, I use the term in a sense that in a sense, the consumer of the car. The consumer is going to be a software developer and a software developer is going to be able to drill in and say, “Oh, I see how it’s doing its work. It’s actually making a call out to this other private helper method.” There is a sense in which it is public to developers, but it’s private from the perspective of the consumer, which is this main method. It can only see the DoSomething method, not the private helperMethod. That’s all we really mean here. Now admittedly, this is extremely mundane. It’s a simple example that’s only real value is to illustrate the notion of encapsulation, that we typically want to hide the implementation of our classes behind well-known public interfaces. In this case, a friendly method called DoSomething. The purpose of this lesson is to better understand the notion of scope because we said that once variables, especially variables that contain object references, fall out of scope, their objects will be garbage collected. Furthermore, it’s important to understand that there are parts of classes that you have access to and parts of classes that you don’t have access to. Now, if you ever decide that you want to create your own custom classes someday, even a library of classes that represent the business domain of your company or of your specific application, it could be a game, you should strive to expose public methods and give a simple, straightforward, obvious way to call the public methods from your class, but keep all the other helperMethod, all the other internals privately tucked away and not available to prying eyes. You don’t want a developer to simply go fiddling around inside of all of your methods and use your class in a way in which it was unintended. You want to give them a way to use your class properly through the methods that you’ve designed and that you’ve made available through public interfaces. This also will help to remove any ambiguity in the usage of your classes, and it should be much cleaner as well. All of these things were under consideration whenever the developer’s build the.NET Framework Class Library. In the.NET Framework Class Library, methods and properties are exposed using the public keyword. Now, they might also be using private fields and private methods behind the scenes, but you would never know. They may use other types of accessibility modifiers as well. There’s actually a couple available called protected and internal. However, these are primarily for whenever you’re working, either in a rich inheritance relationship between classes and you’re building a rich inheritance hierarchy between classes, or whenever you’re working with a very large library that’s compiled into separate assemblies. That’s when some of these other accessibility modifiers might come into play. They’re topics that are beyond the scope of this absolute beginner series, but topics that I do cover on Developer University. If you want to know more about object

    oriented programming and encapsulation by all means, go ahead. We are well past halfway through this course. You’re doing great. We’ve already covered the most difficult material already, now we’re just adding on details, so you should be encouraged by that, that you’re still plugging away at this and you’re doing great. We’ll see in the next lesson. Thank you. Hi, I’m Bob Tabor with Developer University. For more my training videos for beginners, please visit me at devu.com. Previously in this course, I said that the .NET Framework Class Library is merely a collection of classes, each containing methods filled with functionality that we can utilize in our applications, but we didn’t have to write. Microsoft has spent tens of thousands of man hours building and maintaining this library of code, and we can benefit from it by merely calling into his classes and methods inside of our applications. Now, the Framework Class Library is massive. Thousands of classes, each with their own set of methods, and so the developers of the Framework Class Library wisely decided to split this library of code up into multiple files. Just imagine if you had to load the entire library into memory every time you wanted to run your application. First of all, it would be excruciatingly slow. Then secondly, it would probably take up the maturity of your computer’s memory. They split up the code into multiple files. These code files are called.NET assemblies. In fact, even the applications that we build, they’re ultimately compiling into.NET assemblies. As you can see, I have a new project called AssembliesAndNamespaces already open. I’ve added two lines of code. If you want to pause the video and catch up, that would be great. In lines 13 and 14, I’m merely printing Hello world to the screen and then pausing the execution of the application. However, even in this application, a executable.NET assembly is being generated the very first time that we run the application while we’re debugging. Now, if you want to take a look at what happens, go to your project’s directory and inside of the project folder, you’ll see that there’s a bin directory. We avoided this very early in this course, but now I want to talk about it briefly. The bin directory will contain both at a bug in a release version, ultimately a release version. The debug version will contain additional files required by Visual Studio to connect to the execution of the compiled executable. This allows us to step through the execution and pause the execution line by line in the Visual Studio debugger. Now, we can additionally, then after we created our application and thoroughly debugged it, we can say I want to create a release version of the application and go to Build Solution in the Build menu, and it will create a version of our application without any of those debugging symbols without that connection to the debugger. If you look at the file system, you might be a little confused to see that it also has a lot of those extra files in there, but they’re basically ignored. But that is what’s going on behind the scenes. Notice that in each of these cases, we’re building an executable file that will run and we could even just double click it and run the application from here like we did before. Now that is different from the type of.NET assembly that allows you to create a library of code that can be shared across multiple projects. In that case, you’d be compiling a project into a.DLL file extension. We can create a code library. I’ll show you how to do that in another video. But at any rate, the.NET Framework has to already be installed on any computer where you want your application to work or to run. Basically, every copy of Windows already has the.NET Framework runtime and the class libraries installed in a location that’s globally accessible, called the global assembly cache. Every.NET application can reference the same set of assemblies in that one spot on your hard drive. Now, you might say that whenever you build your application and set up your application, you may not realize that by choosing to create a file new project and then selecting the Console Window project template, you were actually creating references to those files in the .NET Framework Class Library. That’s one of the functions of the setup routine for a project template. If you take a look at the references node underneath your project in the Solution Explorer over here on the right hand side, you’ll see that, there are some references already to these things like system, System.Core, System.Data, System.Net and so on. We’ll talk about what these are in just a moment, but that’s indicative of the fact that we have references into files of the .NET Framework Class Library that the creator of the Console Window application thought we might be or might find useful at some point. We’ll come back to that in just a moment. Now sometimes you’ll need an assembly from the .NET Framework Class Library that has not been referenced and I’ll demonstrate how to do that in an upcoming lesson. Or perhaps you need to add a reference to an assembly created by a third party, maybe even yourself. Again, I’ll demonstrate not only how to create your own class library, but then also how to create references to third party assemblies as well. Again, there are 10’s of thousands of classes defined in the full.Network framework class library. In a few cases, the same class name was used, or at least there was the potential for it to be used. When that happened, the creators needed a way to be able to tell one class from a different class and so they introduced the notion of name spaces and name spaces are like last names for your classes. Think about your name or my name. For example, somebody might say, “Bob loves coffee” You might say, “Well, which Bob?” There’s like a billion Bobs in the world. But if somebody were to say, “Robert Theron Tabor likes coffee.” Well, that narrows it down. I’m pretty sure that I’m the only person in the world that has that combination of first middle and last name. I could either use the full name, Robert Theron Tabor to reference one person or once we understand the context of who we’re talking about, maybe we’re talking about only people in this room. Then you might say, well, Bob likes coffee, he’s the only Bob in this room, so they must be talking about Bob. The same idea works with your code. We could use the full name of the classes that we need inside of our application. For example, the full name of the console class is actually System.Console.WriteLine. Or the System.Console class. That’s the full name of the class and then we’re calling the method in that class. However, you’ll notice that I didn’t have to use the Word system here. Why not? Well, because we used a using statement at the very outset of this code file, which says, ‘I want you to look inside of these name spaces whenever you find a class reference that you don’t recognize and so the C-sharp compiler, it finds the Word Console and it says, “Hmm, I wonder where that came from?” It begins to look through the name spaces listed in the code file and it says, “Oh yeah, I found a class name called Console inside of a name space called System.” So it thinks, “All right, well that must be the Console class that he’s talking about.” Occasionally, you might have two classes with the same name, and you’ve added using statements for each of these inside of your code file. When that happens, you merely need to disambiguate by adding the full name of the class instead of relying simply on the using statement. You’ll notice here that by default, the program that CS file has a number of different using statements. In my text editor they’re faded out a little bit, which indicates to me that they’re not being utilized at this moment. We could remove unused using statements from our code and our code will compile just fine. This is a convenience for us, that was set up for us by whoever created the project template for a console window application. To further illustrate this idea, let’s talk about how we can go about using the.NET Framework Class Library to do meaningful things and how we would go about finding the source code or the classes we need to do something cool in our application. For example, maybe I want to write data to a text file. How could I go about doing that? Well I might open up bing.com, and I’m going to type in site:Microsoft.com, so I’m going to limit the search results to just those that are returned by Microsoft.com. This is going to help me find the documentation specifically created by Microsoft as opposed to third party articles or whatever the case might be. So site called Microsoft.com and then I might just say, write to a text file and then using C-sharp. One of the top results are from msdn.Microsoft.com and msdn stands for the Microsoft Developer Network. This is your primary source of information as a software developer on the Microsoft platform. In this case, here’s a how to article that will describe the code that we would need to write in order to write data to a file. Here’s a long code example. In fact, it gives us three examples in one and we could use one of these examples in our application in order to write data to a file. We might decide to go ahead and use the second example. It comes close to what we want to work with here and I copy and paste it into my application and I might remove some of the extra information here just because I don’t need it and I may need to modify this path. I believe I created a folder called Lesson 17 for this purpose. Notice that it’s going to use a class name file and a method called write all text. In this particular case, notice that we already are given the full name name space of this file class, System.IO.File. What we could do is actually remove that from here and go up and add a using statement for System.IO like so. Notice that, the compiler will find it and will be able to run our application and got a little message there because I was in release mode, lets go back to the bug and start that over again. We don’t get any feedback there but if we were to open up our Lesson 17 folder, we would be able to find the text in a text file. Great, so now we can use that little snippet of code to do what we want to do, but notice it all started by searching on msdn finding a code snippet that we could use and then we can modify it and add our own text here that we want to then we want to write this to our file, so that we start stitching things together. That’s one way that we can find the features inside of the.NET Framework Class library that we need is to search on msdn. Let’s try one more quick example and let’s go back here, back to bing.com and here again I’m going to cycle in on Microsoft.com. Then I want to do c-sharp download html as a string and I might find another reference. This is a different style web page. There is one web page on msdn for every class and every method in the.NET Framework class library. In this case, we’re looking at a specific page for this download string method and if you were to look at the remarks and some of the additional, the syntax and some of the exceptions that it would throw, what we ultimately get to is a little snippet of code that we can copy and that we can paste inside of our application. That’s what happens this time, it does not recognize the term WebClient. Why not? Well, we may not have the assembly referenced in our project, or we may have the assembly referenced, but we do not have a using statement that would include the WebClient class. To remedy this, I’m going to hit “Control period” on my keyboard, and it says that it found this class in system.Net so we can automatically add a using statement for the System.Net class by merely hitting the “Enter key” on my keyboard. Or I can just go ahead and say, let’s go ahead and use the full name of the class here, I’ll choose the first option using the Arrow keys and the Enter key on my keyboard. Notice what happens, it adds a using statement for System.Net and then notice that the WebClient class is now found. It is obviously in a different color, there’s no red squiggly line, so it looks like it found the correct class that we’re looking for. Now we merely need to give it a URL so let’s try, msdn.Microsoft.com like so and then we will just write this out to string reply. Then we might even rework our application in attempt to save that into our text file as well. Let’s see what we get here. Hopefully, this will work, we’ll run the application. It took a moment, but it loaded up a bunch of HTML into our console window. We can see the closing body in the closing each HTML tag. Now, if we were to go back to our folder and find our Lesson17 folder, and open up our text file, we see here is the full web page that we scraped off of msdn.Microsoft.com. That pretty much wraps up what I wanted to say in this lesson. We are able to utilize the classes and methods in the.NET Framework Class Library and we can find what we need by doing simple searches in bing.com using Psyco and Microsoft.com to find the classes in the methods that we want to work with. Once we find those classes that we want to work with and we find maybe even little code snippets, we can copy those into our program, and we may need to at that point, fix the references to those classes. Now, in this first case, remember that it gave us the full name of our file class System.IO.File. But in the second case, we had to provide the using statement, System.Net in order for the compiler to find the class that we were wanting to reference and work with. Ultimately we did that with hitting “Control Period” in the keyboard to add a using statement to the very top of our code. We talked about the purpose of namespaces to provide disambiguate between class names. We talked about the using statement as a way of creating a shortcut or a context and say, we’re not talking about every class in the.NET Framework Class Library. We’re only talking about the classes that happen to be in these namespaces. If you find Mr. C# compiler, if you find a class that you don’t recognize, look in those namespaces first before you complain. We’re going to continue on these ideas in the next lesson. We’ll see you there, thank you. Hi I’m Bob Tabor with Developer University, for more of my training videos for beginners, please visit me at DevU.com. Now, previously I said that the creator of the console window application project template, added references to those assemblies in the.NET Framework Class Library, that we as developers might find useful for the majority of use cases. However, if we need an assembly containing some portion of the.NET Framework class library, that has not already been added to our project, then we can simply add a reference to it. This is one of three ways that will demonstrate how to add a reference to an assembly. The first being an assembly from the.NET Framework Class Library. Now there’s a number of different ways to go about this. The easiest way, I think, is to go to the Solution Explorer, and then right click on “References” and select “Add Reference”. Here you can see there are a series of, I guess, tabs along the left hand side that would allow us to choose from the various types of assemblies that are available to us. We want to choose the Framework and these are all of the assemblies that are part of the.NET Framework Class Library. Now, and you can see that there’s already check marks next to a number of the system.this, system.that, System.Net.Http. These contain a number of different classes each with many methods, and these are just automatically accessible. If we needed something that is not contained here then we could choose, for example, to just select a checkmark next to the one that we want to add to our project System.Net and click “Okay”. You can see that is added a reference to System.Net into our project in the Solution Explorer. Now we can reference any of the classes and utilize any of the methods in that particular assembly. That’s one way if we need to access some part of the.NET Framework Class Library. Now, in addition to that, there are libraries that are created both by Microsoft and there are libraries that are created by open source contributors, other companies that are provided for free for very specific purposes in our applications. These are often common features that many applications need that’s why they’ve been open sourced. However, they’re available through a special tool called NuGet, which is a repository that’s maintained by a foundation supported by Microsoft, but ultimately its own entity. There are a number of different ways to work with NuGet in Visual Studio, I’m going to choose the visual way to do it. I find that to be the easiest for those who are just getting started and for me, because I’m a more visual person. There’s also a textual, almost command line style interface that would allow you to do similar things and even script these things. Let’s go to the tools menu and select “NuGet Package Manager” and then “Manage NuGet Packages for Solution”. This will open up a tab, undoubtedly no matter what you see on my screen, it will look different on your screen because this is going under active development for the last few years, and it has changed frequently. Now, if there were a package that we wanted to add to our solution, we could simply search for it. Typically, we can learn about these things through blog posts and what have you. Say for example, I wanted to access a database from my console window application, and I wanted to use the Entity Framework API from Microsoft. It’s available as a NuGet package through this Manage NuGet Packages for Solution dialog. I can select it as one of the options you can see it’s one of the most frequently downloaded. Furthermore, I would then choose which project in my solution that I wanted to add it to, and I can choose the “Install” button. There’s some other options as well, I’ll leave you to to investigate those on your own. I’m going to go ahead and click “Okay” I agree to the terms for using the Entity Framework. In this particular case, it installed just a number of references to assemblies and copied them down locally to my computer. Now, depending on the type of package, it could not only contain.Net assemblies, but also sample source code files. It could actually run macros inside of Visual Studio. It could include things like style sheets and HTML, and even graphical assets that it will include your project. This is the second way that we can go about adding assemblies and more to our projects. But the third way that I want to talk about is whenever we want to add a reference to a class library that we created. Now we haven’t created a class library up to this point, so this is a perfect opportunity to do that and then add a reference to it in our project. What I’ll do is start off by creating, New, Project. Let me go ahead and let you see my entire screen here. In the New Project dialogue, I want to make sure to choose C#. Then I want to choose Class Library, notice that I chose the one that doesn’t have a little Nu.Get logo next to it, it’s just looks like several books in the old C# logo. Now, this will undoubtedly look different to you, but just make sure that it’s a regular old class library. Here we’re going to call this MyCodeLibrary and click “Okay”, and I’m going to go ahead and say, I don’t really care to save my other solution there. Inside of this, you can see that I don’t have a program.cs, all I have is a Class1.cs. There’s no static void main, and so what I’ll call this is the scrape class, and we’ll have one public method, so public string ScrapeWebpage and we’ll create a version of this where you provide it just the URL. Then we’ll create a second version of this. Where you provide the URL and file path. In this first case, I’m just going to copy down some of the code that we’ve worked with previously to create this functionality, where we were actually using this webClient to go out, download a page and then save it to a text file. I’m just going to generalize this. Remember what I did previously when I hit “Control Period” on the keyboard in order to add a reference to System.Net or add a using statement for System.Net? The next thing I’m going to do here is actually replace this hardcoded string with whatever gets passed in by the end user. Finally, I’m also going to have to add or resolve this reference to the file class. It’s in the System.IO namespace, so I’m going to add a using statement for that. However, in this specific case, I’m not going to write this to a file and this overloaded version of it. In fact, what I’ll just do is return whatever’s been actually downloaded from client.DownloadString. Now, the second version, we’ll do something almost identical. Here, let me replace this with the URL, and we’ll get rid of Console.WriteLine and we’ll go ahead, and write this to the file path that was passed in and then we’ll return the reply. Now, truth be told, this might be a good situation where I could actually take these lines of code and create a private helper method out of them. Maybe that’s a good idea, let’s do that right now. Private string GetWebpage and we’ll pass in the URL here. Now both of these can just call, GetWebpage like so. Here we’ll go string return or reply, equals GetWebpage. See what I did there. I was able to use a private helper method to encapsulate the functionality of actually getting the web page itself, and then in this case, I was able to extend the ScrapeWebpage method to include writing that to an actual file path. Now that I’ve created this, and let me go ahead and rename this file as well by right clicking on it and selecting Rename, and I’m going to choose to name this file scrape as well. I could name it anything I want, it won’t matter, because the name of the class itself is scrape. But at this point now I’m going to go ahead and build the solution. It looks like it built. In fact, let me go ahead and build a release version of this. Great. Now let’s open up a second version of Visual Studio. I’m going to call this MyClient. This will be a console application called MyClient, and we’ll click “Okay.” What I want to do, is to first of all, add a reference to that deal that we created just a moment ago. I’m going to go in right click on references and select add a reference. Here I have some choices. Ideally, I would be able to look and find it in the same solution, will come back to that and do it in just a little bit here. But I may have to go and actually browse through the file system to find this, and unfortunately, this is popping off the screen. However, hopefully we can work our way through this. I’m going to navigate to the bin directory into the release directory and find my code library, and then I’m going to select the “Add” button and then click “Okay”. Now that I’ve done that, what I should be able to do is get to the scrape class, but it doesn’t see this scrape class. I’m going to hit ” Control” “Period” on my keyboard, and notice that it will find the correct using statement. The Using MyCodeLibrary namespace. Scrape myScrape equals new Scrape. Now I should be able to go myScrape. and there we go, ScrapeWebpage and I should be able to give it a url. Let’s go. That should return a string. String return or actually just value equals. Let’s move this over a little bit. Then I should be able to print that to screen. Console or write. Now we should be able to run the application. It takes a moment, but it pops up. What we’re able to do there? Well, we created a reusable library now. Whenever we want to scrape a web page, we can utilize this and any of our other projects. Now did you find how inconvenient it was to actually go and search around whatever we wanted to add a reference to it? I had to go, and browse through all my projects and everything. But I do want you to notice one thing about what happened after we did that. Let’s go to my projects. Let’s find that client and let’s navigate into the bin directory. Notice that it copied MyCodeLibrary.dll into the bin directory for the client application. That’s one of the things that it will do with any of the third party assemblies that it we’ll utilize. But wouldn’t it be easier if we were to start this over from scratch, and we were to create a single solution that had both the client and the code library in the same solution. Let’s do that now. I’m going to actually open up a third copy of Visual Studio. Here, let’s create a new solution. What I’m going to do is actually scroll all the way to the bottom and choose other project types, and choose Visual Studio Solutions, and find a solution. This might be in a different place, so you may have to hunt around for it, but you ultimately want to choose blank solutions that should be available to you. We’re going to call this a Lesson 18. The solution’s name will be Lesson 18, but we’re going to do is add projects to the solution. The first project that I’m going to add, and there’s a number of ways to do this like add, but it goes off to the right hand side of the screen, I could add new project, file add New Project and then we’re going to choose the class library. We’ll call this the ScrapeLibrary. Then I’m going to choose to create another project and add it to our solution called app type Console Application. This will be the ScrapeClient. In our ScrapeLibrary, what I do just for simplicity’s sake, is actually go to the work that we’ve done here a moment ago, and I’m going to copy all of this like so. Let’s come back here, and I want to paste all this in, like so. Yes, I’m going to have to resolve these class names by adding using statements here and here as well. That should work. Looks like I actually lost my class name, so let’s go public class Scrape. Then let’s make sure to put everything inside of it. There we go. Now we get it working, and I’ll rename this as well to just scrape. I could have left it, call the class one to but that’ll work just fine. I’m going to go ahead and build that right clicked on the project name a select to build. Now what I want to do in the client to utilize that class library, is I need to add a reference to it. So here again, I’m going to right click and select add reference. This time we go to projects, and notice if solution is selected, the Scrape Library will be an option. I’ll choose that and click “Okay.” Now we can utilize ScapeLibrary in our application. Let’s go ahead and just type in the “Word” scrape., and it’s not going to find it. The Here Control period, and I need to add a using statement, since I renamed it. Now it’s called ScrapeLibrary. I’m going to add the ScrapeLibrary namespace too, using statement to the code file. In fact, I don’t have to do all that right. I can just copy and paste it from the previous client, like so. We can rerun the application. It says a project with an output type of class library cannot be started directly. Why do you suppose that happened? Well, because there are actually two projects now in my solution, and you can’t execute a library, correct? So what we need to do is right click on the client project and select Set as Startup Project. It’s going to close that, when we attempt to run the application. It’ll work. Furthermore, if we were to make any changes to how the library actually works, let’s say what could we do here? That’s interesting. Let’s do this. We’ll make a change in one spot and then I’ll go content plus equals THAT’S ALL FOLKS for the very end of that string this return. I’ll return content this time. Let’s make sure we have everything there. We’ve made pretty big change to the application. Now when I run the application, it will recompile the DLL. It will add it to our project and at the very end, it adds, “THAT’S ALL FOLKS”. The only thing I could think of off the top of my head. Hopefully now you can see that there are several different ways to add assemblies. If it’s part of the .NET Framework Class Library, then obviously there’s a way to do that. If it’s a free or open source, package that’s available from NuGet, we can use the NuGet package manager or we can create our own third party class library and then add a reference to it by browsing. Or if we were to create the client and the library inside of the same solution, then we can reference it in the add reference dialog. But just under the project solution option, and we get the added benefit of being able to make updates, not having to go through two copies of Visual Studio to updated. It’ll update the next time we hit, run it or recompile it and everything. That’s pretty much it for this lesson. We’ll continue on the next lesson. Will see you there. Thanks. Hi, I’m Bob Tabor with Developer University for more my training videos for beginners, please visit me at devu.com. Previously, we looked at arrays which allowed us to keep a sequence or group of related data together inside of the same variable, so we would create an array by providing a data type, and so each item in the array had to be of that data type. We would also provide the number of elements we expected in the array by defining that number between a set of square brackets. Now that we have that predefined sized array, we could add items into each element of the array or retrieve values out of each of the elements of the array by indexing into the array using a zero based index to index in and address one specific element of the array. Now, once we have the data collected into an array, we could do some interesting things. We could iterate through the array and investigate each element in the array, or we could even pass the array around as if it were one variable. Pass it in, for example, as an input parameter to a method. But you recall that time, I also said that at some point we would talk about collections. I even gave collections a nickname, calling them arrays on steroids. I think you’re going to agree after this lesson that collections are great whenever you’re working with all data types, especially those custom data types that we’ve been working with up to this point in this series of lessons. For example, the car class that we created ourselves. Now, as far as the .NET Framework class library is concerned, it will often use both arrays and collections, depending on the need. But I think you will probably wind up preferring to use collections in your applications because of the rich filtering, sorting, and aggregation features that are available to collections through a technology, a language called LINQ L-I-N-Q, which stands for the language integrated query. It was a very innovative feature whenever it was first introduced back a number of years ago in C-sharp and other .NET languages. Other languages have since implemented something similar to it. But we’re going to dive into that topic of LINQ and what you can do with it in the very next lesson. But first of all, let’s talk about collections. We’re going to talk about two collections, specifically lists and dictionaries. Now, truth be told, there’s probably a dozen additional varieties of collections that you could use for very specific purposes. They each have a superpower. They each have a very specific use case where they’re intended to be used. I find myself using lists and dictionaries 95 percent of the time. So we’re going to focus on those for this lesson. But after this lesson, by all means, feel free to go off and learn all of the additional collections that are available to you and what they can do that’s a little bit different than the list in the dictionary. Suppose that I have a number of cars on my car lot and I want to write an application that allows me to manage them. So I need some way to collect all of the individual instances of the car class together into a single array or collection. Now again, I might use an array of cars, but I think I’m probably going to choose to use a collection because of the added features that I’m going to gain using collections. We’re going to talk about a bunch of different types of collections, but I want to start off with a conversation about an older style of collection that’s no longer used anymore to show why there’s a newer style collection that’s available, and it’ll help you maybe understand that idea a little bit better. As you can see, I’ve got a project called Working With Collections already set up here. Please take a moment and create a new console window project. I’m also going to paste in two classes that I’ve defined simplified version of the car class that we’ve used before. Then also, I’m going to create a book class, as you can see there at the bottom. Very simple classes. The next thing that I’m going to do is actually paste in some code to actually create new instances of each of these classes and then populate their values. You may want to pause the video yet a third time and copy in the code that I have copied to screen there as well. The very first thing that I’m going to want to do is to work with a collection and I’m going to work with something called an array list. Let me just say this about array lists that they are dynamically sized, which is one of the great benefits. You don’t have to do anything to say, I need to add one more item and another item and another item. Remember with arrays, I said it was possible to resize an array, but it’s a little bit of an advanced operation. Not so with an array list. That’s one of the big benefits. You can just keep adding items to it and it’ll be just fine. It will also support cool features like sorting. You can easily remove items from the collection and so on. Let’s go ahead and create a new instance of this array list. When I do notice that we don’t already have a reference or a using statement to a namespace, so what I’ll have to do is hit Control period on my keyboard, and you can see that it is in a namespace called using system. collections. I’ll go ahead and add that namespace to my project and so will create a new one called myArrayList equals new ArrayList, like so. Now that I have my array list, I can begin to add items to the array lists like, for example, the first car, and then I can add a second car like so. Now, one of the problems with the old style collections like the array list is that there was no easy way to actually limit the type of data that would be stored inside of the array. For example, I want to work with automobiles, but I might accidentally add a book into the array and it will work just fine. There’s no complaints. The old style collections are not strongly tight in so much that you can put anything inside of a collection. At first glance, that might seem great. But what if I wanted to actually then print out a list of all of the cars makes and models? Let me start by at the very bottom here type Console.ReadLine so we can get through that formality and then I’m going to just do a for each. What am I going to work with here? Let’s just say I’m going to work for each car car in my array list. Then I might do a Console.Writeline, and let’s just go car.Make like so, and print that to screen. You must run the application, and we will get an exception whenever we hit the third item in our array list. Notice that it is printed first to the screen, but when we get to the book, it says that there’s an invalid cast exception. In other words, we could not convert a book which was the third item in the array list into a car, so when we get to this spot as we’re iterating through each of the items in our array list, we’re going to hit a problem here. The fundamental problem is that we allowed our collection to store something other than cars, so we cannot work with these collections in a strongly type fashion. Now, what I can do, one of the neat features here, is that I can actually remove that item prior to going into that for each list, and we should just be able to execute the application without problem. That is at least one of the good benefits there. But unfortunately, the downsides outweigh the benefits. Let’s go ahead and take a look at the newer style collections. The first, I said, was that we were going to look at a list, and more correctly, we’re going to look at something called a generic list. Often, you’ll see it referred to as List of T, like so. That of T in the term generic might require a little bit of explanation. When done, that was first released, the first set of collections allow you to put anything you wanted into them, like we saw here just a moment ago. Now, it might make sense in some contexts, but typically, it doesn’t, and it leads to potential errors like you saw. Now, at some point, then, C# introduced the notion of generics, and specifically for our purposes, they released a series of generic collections. A collection is essentially generic but it requires that you make it specific by giving it the data type that should be allowed inside of that collection. We have a generic list but we’re going to make it a specific list to car so that we can’t even add a book to that collection. Let’s attempt to do this one more time. This time we’re going to go List, and notice that I’m using angle brackets, and in-between the angle brackets, I’m going to say what data type I want to use. In this case, I want to use the car data type. List of car called myList equals new List of Car, like so. At this point, we can go ahead and add the car1, just fine. We can add car list to myList beginning at car2, just fine. But what happens when we attempt to add the book into our list? Well, at the point when we attempt to add the book to the list, we get an exception. We hover over and it says it cannot convert a book to a car. That makes a little bit more sense. It is specific to a car data type, so we cannot add a book to that list. But from this point on, we can work with it now with some confidence, so each car car in myList, and we can use the car.Model, like so, and we would get what we would expect here, create a list of our car models. That’s one of the big benefits of working with a generic type, is that it allows us to work with the specific data type and only allow those types into our collection. This is probably the most popular of all of the collections available. But I’m going to show you one additional collection called the dictionary. A dictionary is similar to, think of Webster’s dictionary, where you have a word and you look it up in alphabetical order and find the word that you want definition of. Then once you find the word, you can look to its right and it will have the definition. There is a key, which is the word itself that we want to look up, and then there is the definition next to it. There are two components to each entry in a dictionary; there’s the key and then the value itself. Typically, when you see a generic dictionary mentioned, it’s going to be listed like this Dictionary of TKey, TValue. In this case, what we’ll do is specify the data type of the key. This allows us to find one specific item by the key. Now the key should be something that is unique to every entry in the dictionary. In the case of people, there might be some identifier. It could be a customer ID in your system, it could be a Social Security number if you’re in the United States, but something that uniquely identifies one entity inside of that dictionary. Then the value can be of any data type. In the case of, again, a customer, you might have the customer ID being the key, but the customer object itself is the value that we actually want to get access to. Now, in our case, this seems a little bit weak because our car class only has make and model, and we know that we can have multiple cars that have the exact same make and model. They may have different colors, they might have been created in different years, but you can have multiple cars in the car lot that have the exact same make and model. Neither of these are good candidates for keys, but there is something called a vehicle identification number. Let’s do a prop string and let’s call this VIN. That will differentiate every car in the world that’s been created. What I’ll do is come back up here to the definition in the car1.VIN and I’m just going to use a very short VIN number. I think they are typically like 18 or 24 characters long, something like that; I’m not exactly sure. But this should uniquely identify every car in the world, especially every car in our car lot. Now what I can do is create a dictionary of my cars by starting off and saying something like dictionary, and they were going to give you the two data types. The VIN will be of type string, and then the actual value will be of type car. We’re going to call this myDictionary equals new Dictionary of String Car; notice the InteliSense help me out by essentially giving me a lot of that, and I can just hit the semicolon at the end of the line for it to type out that entire phrase. Now that I have this, what I can do is go myDictionary.Add, and we’ll do car1.VIN and passing car as the actual value. The car1.VIN, again, is our key into the actual car1 itself. Likewise, we’ll go add car2.VIN in car2. At this point, here, if I were to attempt to find a given item, so Console.Writeline, and I need to find a specific car in my car lot, I can allow a user to type in the VIN number and I can look it up in the dictionary quite easily. Then there’s a number of different ways to go about this, I think probably one of the easiest ways actually. Let’s go back and not use the dot. Here, I’m actually going to use the key itself, so we’ll call this B2. Then now we can reference a specific item in the Dictionary of Type car so we can get the make, for example, and print that out to screen, like so. We were able to find the Geo that way. Hopefully that makes sense. Let’s continue on, if you recall when we originally were looking at, let me comment all this out. We were looking at a raise, I said there’s some interesting things you can do to initialize an array with values like we see here. We’re creating an array of strings called names and to initialize it, I give it a collection of names that are common to limited. Now I have an array that has four elements in it and it’s already been initialized with the values. You can do the same thing with the objects to initialize objects at the point of instantiation, to do that will use an object initialization syntax. In fact, let’s go ahead and just approve this all works is coming out everything we have up here as well and get rid of the cars in the book, we’ll come down here and go car1 equals your car and then notice what I do, I use that same syntax the curly braces and inside of here, what I can do is actually define all the values to make equals. Let’s just dream large here and go make in the model would be a 750 and we’ll make it an ally and then we’ll also give it a vehicle information of C3 like so. Now I’ve done the actually three things in one line of code, I create a new variable called car I create a new instance of car and computer’s memory now I’m getting access to that address in memory by using the car1 label, the variable name and then I go ahead and populate the properties of the car object at the moment that I create that new instance by using this object initializer syntax. Some people don’t like this. It looks like it might be doing too much in one line of code, but I think you’ll find that if you ever do need a hard code, examples like I do frequently that the shortened syntax actually saves you several lines of code and it’s just fine it’s valid code Let’s go ahead and while we’re working here, let’s go ahead and create a Toyota. We’ll set the model equal to a 4Runner and we’ll get to that a VIN of D4. Like so and now we can work with the cars just like we did before but in and of itself, this might not be so interesting but this is the object initializer syntax. We can take this one step further when it comes to working with collections, we can use collection initializer syntax. I want to point out one other thing that we didn’t have to use a constructor to make this work like we looked at before that we’re able to regardless of the constructor, go ahead and set these attributes just like we use the syntax there. Well, let’s now talk about a collection of initializer which can look a little hairy, but it’s essentially the same thing we’re just taking it to the next level here. In this particular case, let’s go ahead and create a list of car called my list equals a new list of car. Now, at this point, what I can do and notice that I put this on separate lines here, I typically might keep this on the same line just for my own sanity here and now inside of this new empty list of cars, I can create a series of car objects like so. In fact, what I can do at this point then is use an object initializer inside of that, so here we’re going to make vehicles lose it all then we’ll set down the model equal to Cutlass Supreme and then the number of a set that equal to E5, so comma and then we’ll create another new car to add to this list of cars and we’ll set its object initializer setting it’s make equal to Nissan and its model equal to an Altima then finally, it’s VIN will equal F6, something like that. Now what I’ve done, all in one line of code essentially is I’ve created a collection and I’ve added two objects and in each of those objects, I went ahead and already initialized all of the property values. There’s a lot going on there and just that one line of code. Great. At any rate, just wanted to recap the things that we talked about in this lesson. First of all, we talked about the difference between arrays and collections and I promised that there will be a more obvious set of features that are available to collections, which we’ll learn about in the next video. We talked about the old style collections versus the new generic collections. We said generic collections are superior because they allow us to make sure that we’re only adding specific types to our collections so we make a generic collection specific by passing in the data type that should be allowed to be referenced inside of that collection. Then we looked at object initializer just a shorthand syntax for initializing the properties of a new instance of an object and then finally taking that one step further within a collection initializer where not only are we creating a new collection, but then initializing it with new instances of the car collection. In both of those cases then we are using object initializers. We can do it all on one line of code. Now, honestly, unless you’re building a lot of example code like I do, you may not see this as often unless you are creating some hardcoded objects for use within your application. But I wanted you to be aware of that syntax nonetheless, because we’re going to use it again in the next lesson and we’ll see you there. Thank you. Hi, I’m Bob Tabor with Developer University for more my training videos for beginners, please visit me at DEVU.com. In this lesson, we’re going to look at link the language integrated query syntax that was introduced some years ago to provide a way to filter thoughts and perform other aggregate operations on collections of our data types so will demonstrate two different styles of Links Syntax there’s a query syntax that will resemble the structured Prairie Language sequel for querying databases. If you’re already familiar with sequel, this will at least feel familiar. Then there’s also a method syntax which might feel more familiar to C-sharp developers. However, there is one little strange nomenclature thingy that we got to figure out but I think it’s pretty easy. I think I have a good way of explaining it to you and hopefully you’ll understand what it’s trying to do there but what I’d recommend is you find the code for this lesson there should be a before and after folder and you want to copy the code in the before folder in your project’s directory and then open it up and you’ll be where I’m at right now. In the understanding on project, you can see that I merely created a car class and then I also have here a collection initialized class filled with cars filled with attributes that will be able to search and sold on and that’ll give us something to work with here. What I want to do to begin with is to show you a comparison between links query syntax then links method syntax to do the exact same thing. You’ll see the obvious difference and we’ll talk about the ways in which they’re different but let’s begin with a query where we want to find all BMW in this list of cars called my cars. It’s as easy as this, and we’ll talk about the VAR keyword here in just a moment but BMW equals from car any cars looks from car in my cars, where car.Make is equal to a BMW, that’s car. Now, let’s come down here and print all those guys out. Let’s go console that right line and let’s provide the vehicle information number let’s do zero on on, actually, let’s do this. It’s good for each tab VAR car in my in the BWS Console.WriteLine and then we’ll go car.Model and car.VIN. Let’s go ahead and add some of our replacement characters in there. Now, let’s go ahead and run the application and we see that we get three cars that have been returned, so of all the cars, I think there’s five or six three of them with those VINS A1C3 and E5 are BMWs. If you take a look at the data, that would be correct. Very quick, concise way of finding only those cars that match that criteria. What if we wanted to add additional criteria? Say, for example, we wanted to also see where the cars year equals 2010. We could do that and rerun the application and now we see that it just finds one of the BMW cars was created in 2010. It is this last one, the 555i. That is the language integrated query syntax, the query syntax of Link. Let’s go ahead and comment that out and compare that to the method syntax and so here will go far. BMW equals myCars.where. This will give us all the BMWs, so let’s go and run that. It gives us the same three that we got before. Now, what if we wanted to also find only those where the year is equal to 2010? We would do that. You can see we found just that E5; that last one. This might take a little explanation here. For the moment, let’s just ignore this last part, we’ll talk about that in a moment. But what you see here, in fact, the whole thing in between the opening and closing parentheses is called a Lambda expression, and you can think of it as a mini method. Essentially, what will happen is, you say given p, so given an instance of the collection, only return back to me those instances of car where the make is equal to BMW. See how easy that is? Again, just a mini method. You could think of this as like the input parameter, and then this is just some condition. When it’s true, then return that instance and add it into this little collection over here, so now that we have a subset of all of the available cars in our car lot. Furthermore, I just added the logical and operator and said, and make sure also that it was in 2010. Well, that filters out two of them. Again, a Lambda expressions are just many methods, so for any given item in the collection it has to match that criteria. If it does then we can add it to this little subset collection over here that I’m calling bmws. The var keyword it has a very different connotation in C# than it does in other programming languages. Here I would ask that you forget what you know about var from maybe JavaScript or Visual Basic or some other programming language, it does not mean the same thing. In this case, the var keyword says that we’re going to let the compiler figure out what the correct data type is. I’m not even sure what gets returned from this little query that we do here. If you were to hover your mouse cursor over the where, you can see that it’s going to return back in i numerable car. What’s that? Not entirely sure, doesn’t really matter. I don’t care what it is, I know that it is a collection of cars. To prove this point we’ll talk about this in just a moment a little bit later where the var keyword can really come in handy because we truly don’t know what it is that’s being created by our link queries. Again, the var keyword it’s still strongly typed. We’re just going to let the compiler figure out what the type is at the point when the code is compiled. Let’s move on, and let’s take a look at a few other examples. I may want to find an ordered list of cars, so I might go orderedCars equals from the car in m Cars, order by car.Year descending, select car. That’s how I would take all of my cars and order them in descending order by their year. Let’s just change this from bmw, let’s put this to orderedCars like so, and this might help if we actually saw the year itself so I’ll add in the car.Year as well. Let’s go ahead and run the application. You can see it starts at 2010 and in descending order, works its way back to 2008. Awesome. That same query if we were to do it in using the methods syntax instead of the query syntax, it would look something like this. var orderedCars equals myCars.OrderByDescending. Given each item in the collection only return those or actually order them by the year like so. We should see the same grouping and we do. Starts at 2010 and works its way back to 2008. Again, in my opinion, this is more concise. The only conceptual hurdle you’ve got to jump over is just make sure you understand what a Lambda expression is. In this particular case, it’s not a filter, we’re just saying, given each item in our collection, we want to order by this particular property; the year and then add that ordered item to our new collection of cars over here. Now, there’s a lot of interesting things that we can do, and I’m only going to work with the methods syntax from this point on. The first we might do something like this, for example, if we want to find just the first item, so let’s go ahead and grab this and maybe we want to find the first item where the make is equal to a BMW like so. This will give us the first car; the first BMW car in the list that it finds. Let’s go ahead and console. In fact, let’s change the name of this to firstBMW, so Console.WriteLine. All that right. firstBMW. just a VIN number should be sufficient. Let’s run that. We can find that the first BMW in the list was A1, or we can do the first BMW, and we can actually start by ordering by descending given the year. You can see I’m chaining these together, we’ve talked about method chaining before. This will return a collection of cars and then this will return a single car in that collection. Then we’ll print that single items then out to window, in this case E5. The list is first sorted and then we grab the first one that matches our criteria of BMW. That’s how we can use first. We’re going to comment that out. We can also do something like this, Console.WriteLine., and inside of here, let’s go, myCars.TrueForAll and say the year is greater than 2012. We need one more right there. Is it true that all the cars in my car lot that every one of them is greater than 2012? That would be false. Well, then how about are they all greater than at least 2009? That’s still false because we have at least one that was created in 2008. If we were to change this to 2007. Are they all at least greater than 2007? True, so that’s true for all. Very helpful in order to aggregate and look across all of them and see is this true for all the items in my list. We can also even do something interesting like this instead of doing this for each statement where it’s essentially what, at least two if not four lines of code we can create a for each like so. myCars.ForEach and then inside of here for every item, let’s just do a Console.WriteLine and in here, I can do p.VIN and p.StickerPrice. Let’s go ahead and do that. In fact, we’ll just do that as well, one and zero. Hopefully, that all makes sense. Now let’s run that and see what happens. Here we are, we’re able to list them all out and format their values, so you see how much more compact this looks than what we were writing here. We do it all in one line of code. Again, we’re passing in for every single item in our collection just call Console.WriteLine and then use that particular item’s VIN sticker price inside of our formatted string. Here’s another interesting example of this. Maybe in each case we want to go, so myCars.ForEach. In fact, here let’s do this before that line of code. Let’s keep that one and then go myCars.ForEach. In this case, I want to perform an operation on each of the data inside of there, so I might take the sticker price and reduce it by $3,000, actually let’s go minus equal to. This will take the sticker price and subtract $3,000 from the sticker price of every car in my collection. You can see now what was if we could get a comparison going here. See, unfortunately not going to be very easy to do, but you can see that what was $55,000 is now 52,000 what was 35 is now 32,000, and so on. Again, a lot of functionality in a very small space. Let’s continue on with this thought and go and do something like, myCars.Exist. Do we have a car in our car lot where the model is equal to the 745LI, true or false. Here let’s do a Console.WriteLine and let’s see if they turn true or false? Yes, we have at least one item in our inventory where the model is equal to 740LI. Now here’s another good aggregate function. Here, let’s just do Console.WriteLine, and let’s go, myCars.Sum, and here we’ll say, sum up all the sticker prices. Let’s see what the total value of our car lot is right now. You can see that it’s about 247,000 so actually, there should probably be a better way to format that using a format code but hopefully you get the idea. We’re able to sum up a single field across all objects in our collection of cars. There’s so many other things that I can show you, but I don’t want to overwhelm you, but I want us just to go in one ear and out the other for now. This VAR keyword we’ve looked at, and I said that we use it because we want the compiler to figure out what the data type is. Sometimes it’s easy for us to figure out what the data type of something is. Sometimes it’s not so easy. To illustrate this, let’s do a Console.WriteLine line and what I want to do is call on myCars, I’m going to call the get type. In fact, all data types in.Net have this GetType method declared because it’s declared on the grandparent of all objects called System.Object. It defines this method called GetType, which will tell us what the type of a given object is and we can print it to screen. In this first case, what is myCars? Well, myCars is a generic list of the car data types so this understanding link is the name-space and specifically, though, it’s the car type. We’re basically saying this is a list of T, a list of car. That’s what’s being printed out whenever we’re looking at what the cars are, and that’s pretty easy to see because we define it here. But once we perform an operation like one of these here, let’s just see ordered cars and copy that again and stick it down here, and then I’m going to do Console.WriteLine, orderedCars.GetType and it’ll show us what the data type is for ordered cars. Let’s go ahead and compare the two. Now, in this case, you can see that we’re no longer dealing with a list of car, even though under the hood we know we’re working with a list of cars the way that it’s represented in.Net is that it’s actually ordered enumerable so an ordered list of the LINQ.Car, Understanding LINQ.Car. Again, that makes sense. That’s an ordered version of cars. How about just a regular old where statement. Let’s do that. Let’s copy that and see what the data type of that is and then do the same thing here. Let us see what that is. Let us go and run the application again. Here is this third one. The second one was an ordered enumerable, then the one where we just called the where was an enumerable plus the WhereListIterator. So things are starting to get a little funky here. It might be difficult for us to be able to express this ourselves if it were not for this var keyword. The var keyword is essential to help us to be able to create these very complex queries, and not have to worry about what the data type of it is that’s returned. We know that it is a type of list. It is an innumerable list, whether it is ordered or not, and we can follow each our way through it or whatever the case might be. Now the last thing that I want to demonstrate, is I am going to take this first query here, and I am going to pop it all the way the bottom. If this stuff doesn’t make sense, don’t worry about it too much. I wanted to go in one ear and out the other, just to explain again the value of the var keyword. In this case, let’s change something about this. Let’s call this my new cars. Here, I am not going to return cars. I am actually going to do what’s called a projection. I am going to only take certain values, certain properties of a car, and I am going to project them into a new data type. What’s the name of the new data type? Where am I defining that data type? I’m not going to define the data type. It is an anonymous type. What’s the name? I have no idea, it is anonymous. We can define types at runtime and only choose those properties that we need in the type for the moment. Why may not be obvious just yet, but I want you to understand that there is this idea, what we can do here. In this case, let’s pull out just a few things like the car.Make, car.Model. That is all we want. We are going to leave all the other attributes of car alone. We are going to only take these two values, put them into a new anonymous type. Where is the type defined? Nowhere, we just made it up off the top of our heads, and we are going to save each of those anonymous types into a new collection of anonymous types. Let’s go. Console.WriteLine, and then take a look at newCars.GetType, and let’s run the application yet another time. This time you can see that we also here have an innumerable plus where select list iterator, whatever that means, but then notice that the data type involves something called an anonymous type that has two attributes, two string attributes, which would be the make and the model. I say all that to say this, that whenever you’re working with LINQ, there is a lot going on under the hood to make it all very easy and accessible, but it all depends on defining your types as var, which says, let the compiler figure out what the type is, we are not so worried about it, because the data type might be so crazy that we can’t even comprehend what it is. Hopefully that makes sense. Just to recap the things that we talked about, we talked about the difference between the query syntax and the method syntax. We looked at a number of different examples of the various LINQ extension methods that were available. We saw how we could break apart an individual Lambda expression, to better understand that essentially we are saying each item in the collection, run this little mini method against it, and return back a given item that matches that criteria. Then we looked at how to tell what the types were and what the value of the var keyword is, and then we looked at anonymous types. We covered a lot of ground, I didn’t explain everything in great detail. But the key here is just to look at that little

    formula and try to understand what it means. Look for examples online, make yourself a little cheat sheet, and you should be able to utilize these methods inside your own application. That wraps up LINQ. This will be the hardest thing that you have to think about today, I guarantee it. That is it, we’ll see YOU in the next lesson. Thanks. I am Bob Tabor with Developer University. For more of my training videos for beginners, please visit me at DevYou.com. In this lesson, we will introduce a new decision statement, the if, else if else statement, and the conditional operator are both great. They work best when there is only a handful of things to evaluate. But if you start needing to evaluate many different potential cases, you might find that the Switch statement is a little bit more concise and keeps things a little tidier. That would probably be one of the only reasons why you would use it, and I will show you a second reason why in this video as well. We will come back to the switch in just a little bit. But first, I want to talk about a special data type called an enum or an enumeration. Typically, we want to limit the possible values of a given variable. Now, admittedly, we’re already limiting the possible values that can go into a variable by virtue of the fact that we’ve given it a specific data type. However, even within that, I may want to limit the number of possible values to just a handful. Typically in software development, you want to limit and constrain your data to ensure its validity inside of your system. An enumeration is a data type that limits and constrains all possible values to only those that are valid and have meaning within our system. For example, we might want to keep track of series of to-do items. Maybe that is the type of application we’re building, and each to-do item is represented by an instance of a to- do class. We may want to keep track of the current status of a given to-do item on our list. We may want to constrain the possible statuses to maybe like five, that the task has not been started yet, or it is in progress, or it is on hold, it is been completed, or perhaps it is been deleted. There might be some other statuses, but you can see how I may want to just limit the number of options that are available for a status field or status property of my to-do class. We could do this in a number of different ways. We could just concoct a numbering scheme, where one always represents not started, and two represents in progress. I refer to those as magic numbers. They may have some meaning in the system but it’s not readily obvious if you’re reading the source code. As the developer, you may have to look up at some external reference, maybe some code comments, and who knows, maybe they are not even current anymore. Maybe things have changed since whoever wrote those code comments originally wrote them. I may need to reference or look through a number of different code to ensure that what number one means in the system, what number two means in the system and so on. The same thing can be true with strings. I could just use a literal string to indicate the current status, so I could use a literal string, not started or in progress. But the problem with literal strings is that somebody can misstype them, or there could be a space, and not started one time, and then somebody uses not started without a space the other time. If you are looking for all those items that have not been started yet you may have a hard time finding those that have not yet been started or in progress because they are not spelled correctly or whatever the case might be. The great thing about an enumeration is that it gives us a textual equivalent to a numeric value so that it will remove any ambiguity inside of the system. As developers, we know exactly what we are working with, and yet behind the scenes, it is still working with the number. Enumerations are used frequently in the.Net Framework Class library for the very same reasons. For example, you can see here that I have a project, EnumsAndSwitch, and here again, if you look in the code folder for this lesson, there should be a before and after. You want to copy the project from the before folder and copy it into your project’s directory so that you can catch up to me where I am at at this moment. You can always pause the video and type all this in if you like, it can quite a bit of typing though. You can see that in this project, I have already created a to-do class, with a description of each to-do item, the estimated number of hours it should take to complete the to-do item. Then notice that I have a status of type status. Where does this come from? You can see directly below, I have created an enumeration called status, and I have not started in progress, on hold, completed, and deleted. Did you notice as I hover my mouse cursor over it, that each of these values are given a numeric values? Not started equals zero, in progress equals one, on hold equals two and so on. If we were to store these values somehow in a database or a text file, those are the values that might actually get stored. However, they will be translated into this more textual format so that when we are actually working with the data, as you can see here in the static void main as we are creating a new list of to-do’s using the collection, initializer or syntax, here, I am setting the status equal to either completed or in progress or deleted or not started and so on. Visually, it’s much easier for a developer to work with those options in a more textual way. Now, the.NET Framework Class Library will use enumerations extensively. In fact, even in the Console window, if we were to set the foreground color, notice that IntelliSense automatically pops up to the console color enumeration. See, it says enum over there. Let’s see. I don’t think you can see that. Let’s go up a little bit here. All right there. Now, you can see the word enum right here. It’s a console color in enumeration. When I hit the member access operator, the period, it will show me all the colors that we can choose for the foreground color of our console window, so I might choose dark red. Again, enumerations are great because they are descriptive and they limit the number of possible values for our applications, for the properties of our classes. The next thing I want to talk about is the switch statement, and these two are going to marry together here in just a moment. But a simple switch statement is going to look something like this. In fact, I’m just going to go switch Tab Tab, and that will create essentially the outline for it. In this case, we can use an individual to do item and choose it’s, or let’s say estimated hours. If the estimated hours are, for example, case four, then we might perform some operation until we hit the break statement. Or we could go case five, so we could perform something and then we would hit the break statement and break out. There’s also a default case, that would be the catch all just like the else statement and the if else, if else, construct. But the most important aspect of this, is the construct of the switch statement. You have the keyword switch, then you have a variable that’s under evaluation and then a series of cases where we would try to match it up with one of these cases, and then we use the colon after that case. We write our code below it and then we use a break statement to break out and continue on our execution of the code. Now we might choose to, for example, do something like this. This makes a little bit more sense to work with the statuses. In this case, we might go status.completed. We might do something versus case studies.deleted and we might perform some operation there and so on. Now the beauty of the switch statement and the enumerations are that they can conspire together here. Watch what I do. I’m going to type Switch Tab, Tab and then I’m going to do, which is each the items in the to do collection dot status, and then I hit the “Enter” on my keyboard twice. The second time I hit “Enter”, see the macro that will actually blow out, each of the individual statuses so that I can write code associated with each status. Isn’t that crazy? Now, I can do here anything that my business logic would require. I have an idea though. Let’s use the foreground color and change it up for each of the individual to do items. It can be as simple as this. Let’s just copy this, and we’ll put it here for each of these statuses. Then here at the very end, we will actually then do a console.write line of the actual item itself, the todo.description and here will change up the color. If it’s not started we’ll leave it as dark red, if it’s in progress, we’ll use green. If it’s on hold, maybe we’ll use the dark red. Let’s use the red here in the dark red there. Completed, let’s mark those as blue and if it’s been deleted, we’ll mark that with yellow. Now let’s go ahead and save and run our application. You can see we have a very colorful list of tasks that are color coded by their current status. See how cool that is. In this lesson, we talked about enumerations and why we would use an enumeration to constrain the possible values for a given property of our classes. We saw how it was used in the.NET Framework class library, one little instance of it here, where they’ve created their own enumerations. Just be aware of as you’re trying to work with a given class and its properties, always look at, for example, in this case, what data type it is. This is a data type console color and typically IntelliSense will point you in the right direction. As you hit the equal sign it will pop down to that data type, that enumeration so that you just hit the period then you can make your selections there. That’s a really good hint. Then we looked at the structure of the switch statement, where we’re evaluating something in between the opening and closing parentheses. We looked at the body, the opening, and closing curly braces, the entire body of the switch statement. Then inside the creation of the number of cases, each case equating to one possible value of the item that’s being evaluated and then a colon and after that, then any of the code that we want to write, and finally, a break line which will pop us out of that switch statements body. Then finally, we saw that there is a catch all the default colon, which we can use to write any code for cases that we haven’t accounted for in any of the other previous cases. That wraps up this lesson. Doing great work, getting close to the end now. You feel pretty confident C-Sharp. You’ve got the majority of it under your belt. Just a few more topics we want to cover, and then we’ll wrap this up. We’ll see in the next lesson. Thank you. Hi. I’m Bob Tabor with Developer University. For more of my training videos for beginners, please visit me at devu.com. In this lesson, we’re going to talk about handling exceptions that occur within our applications. We’ll discuss what can go wrong, why things go wrong, and how to build resilient applications that are impervious to crashing through the use of C-Sharp’s Try Catch block statement. When the compiler catches a data type mismatch or an unresolved reference to a class or some malformed C-Sharp instructions, it’ll refuse to compile your C-Sharp code into a.NET Assembly until you fix the problem. These type of errors are called compilation errors, and that’s not what we’re talking about in this lesson. However, there are other types of errors that happen during runtime or in other words, they happen when the compile.NET Assembly is actually in the act of executing. Honestly, there are countless number of reasons why you could encounter an exception while the application is running, depending on the kinds of things you’re trying to do in your application. Many times these things are outside of the direct control of the software developer. For example, if your application can’t read or write to disk because a folder or a file is missing on disk where it expected to see it, it could trigger a runtime exception. Or maybe the files corrupt, or maybe the network access to that resource is unavailable, or it attempted perhaps to access a database, and it couldn’t find something in the database that it needed. A table, a column, whatever the case might be, because the structure has changed of the database out from under the application. All of these things and many more could cause the absolute failure of your application, and the user will see a nasty error message at runtime and the frustration, say the developer. In some cases, the developer may have not even foreseen that that could have potentially been an issue. If they didn’t see that it could be an issue, they couldn’t have accounted for it. Maybe the developer for example, allows the users to type in a country, but the user misspells the country name. Now, maybe they did that intentionally or unintentionally. Perhaps they maliciously use numerical characters instead of alpha characters. But as a software developer, your job is to make sure that you account for all of these possibilities. A friend of mine was fond of saying that 80 percent of all code exists to solve 20 percent of all the potential problems that could happen in your application. Generally, software developers should be pessimistic regarding the reliability of everything outside of their control. Whether that be input from an end user, any connection to a network, to the file system, anything that the developer cannot directly control be should be held a great suspicion. Again, if you rely on a file or a network resource, you should treat it with great suspicion. If you rely on the user to type data into your application, definitely treat that with great suspicion. It’s absolutely evil. This is the software developers equivalent to driving defensively. Always code defensively, which means you are always looking for problems all around you-all the time. Now, the way that the C-Sharp developer codes defensively, or one of the ways in which they do it is through the use of a try catch block, and I’ll demonstrate that in this lesson. Up to this point, we’ve been reading or actually writing files to disk. This time I want to read a file to disk. We use the same file class like we’ve used previously. I noticed that I already have a using stand for system that I also finds it. This time I want to use the read all text instead of the write all text. Here, let’s just go ahead and set this example. Notice that I’ve already got a project created called handling exceptions. Please, pause the video and catch up with me if you like. But here we go. String content equals file.read all text. Then let’s just for the sake of argument, hard code a location. I’ll put this at less than 22 slash example.txt and then we’ll do console.writeline.content. Then finally, console.readline like so. Great. So far, so good. Now, here I just want to demonstrate that this actually will work. You can see that I created of my route a Lesson 22 folder with example.txt in it. Let’s go and run the application and show that there is actually text in that file. It’s just a quote from Mark Twain. Now that we’ve got it working correctly, let’s break the application by giving it a fake name just by removing the E on the end of example.txt, and now you can see that we get an exception. This is a file not found exception was unhandled. I’ll tell you what, let’s do this. Let’s stop the application. That’s what the developer will see while they’re debugging their application if they were to run across this issue while they’re building the application. But what if we were to build a release version of the application by changing the solution configuration and then selecting “Build Solution”? Now we’re going to go out to our projects directory and I’m going to act like an end-user and actually attempt to use this application outside a visual studio, so outside of the debugging environment, just to see what the end-user would see if they ran into this exception at runtime. The name of this is handling exceptions, there you go. Let’s go into the bin directory, into the release folder, and then I’m going to double click the “HandlingExceptions”. Whoops. Notice that I get this ugly little message here and it’s trying to help me figure out what happened and I get all of this text here with all this ugly information just spewing out all this information that an end-user probably would have absolutely no idea what the issue was. Although we can read here near the very top that the problem is that it couldn’t find the file Lesson 22 slash example with no E dot txt. Now, a very observant user might be able to look at this and figure it out if he stared at it for a while. But most users are going to be scared off by this, and I don’t blame them. We ideally would like to make sure that the end-user never sees anything like that whenever they run our application. Again, Windows will then close the application, notify you if there is a solution available. There’s just a mess going on there, and we want to protect our end-users from this mess, from ever seeing this. What we can do is actually wrap a try and a catch around this. We’ll do this. There’s a couple of different ways to go about it. I’m just going to take the easiest approach to begin with. What I might do is just go ahead and let’s switch back to the debug configuration and run the application. Now, you may have noticed that the application ran briefly and then went away, and the reason it did was because we ran this, we hid an exception here, the catch statement kicked in, there’s nothing defined in the catch statement, and we continued on. What if we were to move this to right there? We would at least see the application now run for a little bit and we would see no output. So still not an ideal situation, but at least we’re not seeing any exceptions. Let’s go one more step with this and let’s actually catch the exception that occurred. Here we’re going to catch an exception that we’re going to call ex. Now, exception is the most general type of exception that can be thrown. What we’re going to look at in a few moments are very specific versions of exceptions. But this is the most general version so that at least we can see what the problem is and we might do something like, there was a problem, something like that, and even we could provide a description of the problem, so the message from the exception. Let’s go and run the application. At least this time we’re giving the user some feedback here. There was a problem, could not find the file Lesson22/example.txt. That’s better. Again, it would require an observant and slightly more technical end-user to be able to resolve this issue on their own to say, “Wait a second. I wonder if that file might be named something different here on my own hard drive.” As they traverse through and look for the file, they’re, “I see what the problem is. There’s no e on the end of example.” That’s asking a lot of your end-user, but that at least is a step in the right direction, at least we’re giving them some clue as to what the issue is. Now, really what I would like to do is account for all the possibilities and be a little bit more specific. If I were to hover my mouse cursor over this read all text where the issue seems to be mostly, you’ll see that we’ve only been looking at the return value and the input parameters for a call to a method. But notice below that there’s a list of possible exceptions that could occur. Also, if we were to go to System.IO.File.ReadAllText. Let me just copy this and let’s go to Bing. We’re basically going to be searching through Bing here for System.IO.File.ReadAllText. That should help us find an article in MSDN that has a full description of this method. You’ll see that there’s two overloaded versions. We’re using this 1st overloaded version of it. Then if we were to scroll down and pass some of the initial information, there’s a list of exceptions, and it would provide us some scenarios why that particular exception might happen. Like a security exception, the caller doesn’t have the required permission. The path is an invalid format. Interesting. File not found, the file in the path was not found. There’s also a directory not found. Interesting. Maybe the path was too long or maybe we provided a no value. There’s a lot of things that could potentially go wrong whenever calling this method. As developers, we really need to, to the extent that we can, account for all those potential situations, at least the ones that make sense. For example, I could rewrite this code example to begin catching some of those specific examples. For example, let’s take a look here. Let’s, first of all, make sure that the directory exists, and then if it does exist, then we’ll check to make sure the file exists. Then if the file in the directory exists but we’re still getting exception, then maybe we let it drop off to this most generalized exception here. I’m going to start from the most specific case and then work my way to the most general case. In this case, I think the file not found exception is probably the most specific of the ones that we’re going to work with. Then we’ll catch the directory not found exception. Then if that doesn’t work, we’ll just print out whatever the exception was. Here I might do something like Console.WriteLine and say there was a problem. Then give it a specific. Make sure the name of the file is named correctly, should be example.txt Then we can do something similar here and say there was a problem. Make sure the directory:\Lesson 22 exists. It’s something like that. Remember, we’re getting the red squiggly, why? Well, because we either need to add another backslash here or add the @ there, remember that from earlier? Let’s go ahead and test our application. I’m going to set a breakpoint here whenever we hit this line of code so that we can watch this execute. Let’s go ahead and step over. Looks like it found the file not found exception, and so we will see, there was a problem. Make sure the name of the file is named correctly. Then let’s go out and let’s rename this to Lesson22a. I think we’re still going to get the same actually exceptions. I know we did get the directory not found exception, good. In this case, we’ll see that error message, make sure the directory Lesson22 exists. Then for any other exception, maybe there’s a permissions issue on the computer, maybe the file is corrupt somehow and we can’t read from it, we would get this last catchall, where we catch just the general exception and print it to the user. When you read the key to this is that we check the most specific exceptions first and the most general or generic exceptions last. There’s also one other item I want to add here, and that’s a finally statement. This is where we would write any codes to finalize, which might mean setting objects to null, closing database connections, but this code is going to run no matter what. We’re just going to go console.WriteLine, closing application now that like so that we can see that this code will run regardless. It’s just that one last chance as a developer to clean up our mess before we stop the execution of the application. You can see that now represented here by closing the application now. Great. Now, you might look at this and you might think to yourself, great, I’m going to use this try catch around everything in my application. Every single line of code in my application, I’m going to wrap it with a try catch. I’ll just take every method and I’m going to blindly just copy and paste everything in there. That’s definitely a strategy that some people take. It’s a little bit lazy, quite honestly. Some developers have done that, but they’re often ostracized by their end users for providing very cryptic error messages. If we were to leave all of these off and just wrap everything and just only show the exception ex, we would just be saying, hey, there was a problem here, figure it out for yourself. That’s not really advocating on part of the user. We’re not protecting the user. Furthermore, we might be tempted to provide some type of debugging information for ourselves as developers. Sometimes you’ll see some error codes pop up that no human couldn’t be expected to understand, except the guy who originally wrote the application. The reason developers do this because sometimes they take that exact approach where they just say, hey, we’re going to forget about the user. I’m just going to wrap everything in a try catch and it will pop the error message to me, it’ll flip back to me. I’ll fix the problem and everything will be okay. But, again, this catch all is convenient to the developer, but it’s really frustrating to the end user so you shouldn’t do that. You should strive to put the same amount of attention into protecting your user from having these issues and protect them from having to guess at what to do next by simply helping them fix the problem. Tell them specifically if you possibly can. If you the developer can fix the problem, or at least you can point the user in the right direction, then that’s awesome. You should do that. But if you can’t, well, then at least try to identify the exact nature of the problem and then ask the user for the type of input that you would need as the developer to fix the issue. You don’t want to leave your users feeling stupid that they did something wrong. You want them to feel empowered and you want them to feel like your application is well built and it considered them whenever you were building it. That’s what makes your application polished. It’s what users expect, a reliable experience with no surprises. To recap this lesson, we talked about a number of different things related to exceptions that can happen essentially any time that you the developer are not completely in control and you’re accessing things outside of your boundary of control, outside of your domain. You need to wrap those in a try catch and be thoughtful about the types of exceptions that you’ll be handling, listening for specific exceptions that you know a particular method could raise, and it’s easy to find out. All you got to do is hover your mouse cursor over it, or you go to mstn and you find that method and you look for it like we did, all the potential exceptions that could happen. Then be reasonable about it, but then write the code necessary to handle those exceptions and protect your end user. We looked at the try, the catch, we looked at catching the exception and then using certain properties of the exceptions, like the message property to print out to the user what the issue was. We could also use this to log the error, even send it to a centralized logging service like application insights that’s available from Microsoft Azure to report back to the developers what the issues were. Then you can use the finally code block to clean up any connections you have to file systems, databases. You can set objects equal to null and go ahead and remove all of your references and be very explicit about that before you shut down the application. Hopefully that was helpful. This is a great lesson in building resilient applications, giving the users the experience that they would expect whenever things go wrong in your apps. We’ll have one or two more lessons and then we’re done. We’ll see you in the next lesson. Thank you. Hi, I’m Bob Tabor with Developer University. For more of my training videos for beginners, please visit me at devu.com. In this final tutorial video, in this course, we’re going to discuss event-driven programming. Event-driven programming is really at the heart of Microsoft’s presentation APIs, whether it be for web or Windows. Really, for that matter, it’s at the heart of just about every other API in the .NET Framework Class Library. It is so essential that we have to spend a little bit of time here near the end talking about it because it’s that next step that will help you graduate on to building real applications with real user interfaces beyond this course. Events allow you, the developer, to respond by handling those key moments in the lifecycle of the application’s execution, allowing you to write code to respond to an event being raised. Up to this point, in our simple console window applications that we’ve been building, there’s really only been one event that ever gets fired off, and that is the application startup. On application startup, the static void Main is executed, so it’s handling that event, I guess you could say, and this is where we write the majority of our code, and that’s why it actually executes whenever we run the application. Now in a modern user interface, whether it be for Windows or for web, users can interact with the various elements that they see on their screen. They can hover their mouse cursor over given things, like buttons or graphics or text boxes, and they can see maybe a change in the visual presentation, maybe they see a pop up that explains the usage of that given item, perhaps they can click on an item to enact some business functionality inside the application, they can press keys on the keyboard to make things happen, they can type inside the text fields, or they can drag and drop items around the user interface, and each of those will raise a number of events. As a software developer, you can decide to write code that responds to those interactions between the end user and those various user interface elements on screen, and you can also choose to ignore those that really don’t make sense that you really don’t care about, you don’t implement for your application. A given component, let’s say a button, for example, in its development by Microsoft, they included or defined an event, let’s say it’s the click event for that button. Now the developer, you and I, we say, “Hey, I’m going to write a code that performs this business logic that I’m writing here in C# whenever that event, the buttons click event is raised, that I want this code that I write to be executed.” So the developer creates a method and attaches that method to the event, and I’ll show you how we do that in just a little bit here. As the application is running, the user is interacting with the application. Eventually, they click that button. The .NET Framework runtime says, “Okay, if you were listening for the button click event, here it is.” It just happened, and it will notify every one of the methods that you and I, as developers, have attached to that specific event notification, that we’ve registered to that event. Now I’m going to show how events are used in a simple Windows application near the end of this video in a more realistic scenario, but first, I want to start with the absolute basics and keep things as clean as possible, so we’re going to work purely in a console window application. We’re going to work with a timer class, a timer object, and it has one event which is Elapsed. We can say after a certain amount of time, we want you, timer object, to execute or to raise an Elapsed event, and then we’re going to attach our event handler code to that event so that it gets executed every time that event is raised. Maybe it’ll be easier to see this in action than explain it. There are a number of different timer classes inside at the.NET Framework Class Library. We want to make sure we get the right one. I want to work with System.Timers.Timer, and I don’t want to use that long name every single time, so I’m just going to add that to my using statements up here at the top like so, and I’m going to say “Timer myTimer equals new Timer”. One of the overloaded versions of the constructor for this timer class allows us to pass in the interval in milliseconds. So every, let’s say, 2000 milliseconds we want the Elapsed event to fire, to be raised. So 2000 milliseconds would be simply two seconds, which is an eternity as far as a computer is concerned. Next up, what we’re going to want to do is say, my Timer we know that it will raise an event called Elapsed, and so we want to create an event handler, a method that will be executed whenever the Elapsed event is raised by the.NET Framework runtime. Here, you can see that we get this little message on screen that says, “Press TAB to insert,” and I press “TAB”, and it automatically creates the method stub called MyTimer_Elapsed, and it creates in a very specific way with a very specific method signature, and it also gives us this little stubbed out, “Hey, don’t forget you did not implement me,” so throw new NotImplementedException. Let’s go ahead and remove that for the moment, but notice what happened here as well. We are attaching or registering an event called MyTimer_Elapsed to the Elapsed event, so this references this code block right here. Inside here, we can write the code that we want to execute each and every time the Elapsed event is triggered inside of our application. This is where I might write something like Console.WriteLine, and the Elapsed event will send along some event arguments. One of the interesting event arguments is actually the signal time, and that will give me the exact, down to the millisecond, when that particular event was raised. Here we go. Actually, let’s do it this way so that we can format it nicely. We’ll call this Elapsed, and then hour, minute, second.fff. That should give us down to milliseconds. Now what we’ll do is actually tell the timer to start ticking by calling the start method, and then we’re going to go Console.ReadLine, and we’re going to say, “Continue running until somebody hits the Enter key on the keyboard.” Hopefully that makes sense, and let’s run the application. Now we see every two seconds, we get this message. You can see at 32, 34 seconds, 36 seconds, 38 seconds plus some thousandth milliseconds there. We get that MyTimer_Elapsed method executing. Now let’s do this. Let’s say that we want more than one event handler to execute whenever the event is raised. I can do this all day long. I can say, “Hey, well, let’s go ahead and add another method.” This time it will be called MyTimer_Elapsed1. Notice the 1. I’m going to get rid of this little box again. Inside of this new method, I can do essentially the same thing, and I’ll just use that Elapsed1 versus Elapsed. In fact, just to make this obvious, I’m going to use that little trick we learned just a lesson or two ago, where we set the ForegroundColor equal to the ConsoleColor.Red. That would be for the second one, and then we’ll do Console.ForegroundColor equals ConsoleColor.White. We can see clearly the two different event handlers that are both executing whenever the Elapsed event is raised by our timer. Let’s run the application, and now we see the pair running every two seconds. We could continue adding additional event handlers to the event. That’s what this little operator is doing. It’s saying, “How many current items are subscribing or have been attached to this event, I want you to attach this other one too.” Now we can do the opposite as well. In fact, let’s go Console.WriteLine line, and we’ll say “Press enter to remove the red event.” There’s probably a better way to say that, but hopefully you get the idea. Then after this ReadLine, we’ll add another ReadLine for the very end of the application, and in between what we’ll do is actually unregister, detach this second event handler for this event, so we’ll just do the reverse. myTimer.Elapsed minus equals MyTimer_Elapsed1. So now we have removed it, and it should no longer execute whenever the Elapsed event is raised. Let’s run the application. You can see, here we go, and now I’m going to hit the Enter key on the keyboard, and we should only see the white, the first version of our event handler firing every two seconds. Hopefully, that all makes sense. This is the most simple scenario that I could think up without having to actually create a real application, and by real application, I mean, one with a graphical user interface. But now that we’ve broached the topic, let’s go ahead and build an example WPF application. WPF stands for Windows Presentation Foundation. It’s one of the APIs inside of the.NET Framework class library that you use to build Windows applications. In other words, applications that are executed on the Windows desktop, not web pages that are executed on a server, and their markup is delivered into a browser but a true application that’s running on the end-users desktop. I’m going to File New Project, and here I want to make sure to choose WPF application. It should be one of the templates that are installed in the new project dialog. What I’m going to call this is, “WPFEvents” like so, and then click “Okay”. This is not going to be a tutorial on how to create Windows presentation, application, interfaces, or how to work with it, but I just want to show you the basics are generally the same. Here we have a basic application, we can actually run the application, it will do nothing at all. We just get a white form on screen. But I want to go to my toolbox over here on the left-hand side, and I’ll even pin it down briefly. Then inside of here, where I’ll go is to this rolled-up area called common WPF controls. Now. What you see on screen might be a little bit different than what I see on my screen. Just make sure you’re working inside of this MainWindow.xaml, and that you see some visual representation of your form here in the main area. You can ignore everything below. That’s the actual markup that will generate what you see visually here. We’re only going to work with the visual editor but know that there’s some markup that’s going on to produce this. But again, that’s a topic for another day. I’m going to drag and drop a button onto the design surface like so. I’m going to go over here to the Properties window on the right-hand side. This will allow me to set various attributes of that object, that visual object. For example, I can change the content to, “Click me” like so. I’m also going to add a label, control. I’m going to drag and drop it anywhere on this design surface. I’m going to remove the content completely, but I am going to change the name to, “myLabel” like so. Now, what I want to do is print out the phrase Hello world, whenever somebody clicks the “Click me” button. I’m going to choose the “Click me” button again by selecting it here in the visual editor, and then I’m going to look for this little lightning bolt over here in the Properties window and click the lightning bolt. This will show me a list of all of the events that this single control, this button can raise. Now, a lot of these are going to be for very specific situations, and we can ignore the vast majority of these. But the most important one here at the top is the click event. Now, I can write C# code that will execute as a result of this click event being raised by the .NET Framework because somebody, the user clicked on that “Click me” button. I’m just going to double click here in this white area, and when I double click in the white area, it created this button click method stub. This is going to be my event handler code. Let me use the auto-hide PIN to get rid of that, so I can see this. Here what I’m going to do is type in myLabel.content equals “Hello world” like so. I’m going to save my work, and then I’m going to start the application by running it. I’m going to click the “Click me” button and it displays the word “Hello world” inside of the little label. Now, what you didn’t realize is that maybe that whenever we double-clicked inside of Visual Studio in this little white area right here, it created a event handler for us, and it wired up or attached or registered that event to this button. You might wonder, well, where is the code that looks something like button.click plus equals, where’s that code at? Well, that’s a little bit difficult to describe if you take a look at this markup code here at the bottom and we scroll all the way to the right, that is essentially what happens right here. This code will get converted into C# at the point of compilation, and it will create that little snippet that we were used to looking at in the previous code example. However, I can create a second event handler in C#. By doing this, let’s go to the toolbox and I’m going to actually grab another label and just plop it down anywhere, and I’m going to select that label and they go to the Properties qindow and I’ll change this to be named my other label, and then I want to change the actual content of that label to be blank as well. Now what I want to do then is go to the MainWindow.xaml.cs, and here I’m going to go button underscore dot click plus equals and I could click “TAB to insert” but I’m not going to do that. I’m going to name this manually myself. But in my other click like so and then I hit Enter on the keyboard or actually I’m going to hit that. Now I’m going to, you can see that I get a red squiggly line. I’m going to put my mouse cursor on that line and hit Control period and then choose generate the method button underscore MyOtherClick and it does it for me, and you’ll see something that looks very familiar here, a method stub with the not implemented exception. Here I’m going to say myotherlabel.content equals “Hello again”, like so. Now if I did this correctly, whenever my user clicks the button, it will not only fire off this event handler, but then also this event handler. This event handler, we wired up manually using the technique that we learned in the previous code example. Let’s just run it, and make sure this actually works, and it does. The same principles are at play here. The difference is the vast number of events that are accessible to every single visual control in your toolbox whenever you’re working with the Windows Presentation Foundation API. The main takeaway of this lesson is that events are all around us, and especially whenever we’re working with Windows and web applications, we’re going to write our code in methods that respond to specific events that are raised by the .NET Framework runtime in response to events that are published by the various objects inside of our Windows apps, our web apps, and so on. We can either rely on Visual Studio to wire things up for us in a very quick and elegant way like we saw here in our XAML code, where we let it essentially do the wiring for us. Or we can take control of that process of wiring, of attaching, of registering an event handler to a specific event, and then write the code ourselves to actually respond to that event being raised. Again, extremely important. Hopefully, that’s the next logical step for you is to move on to other APIs, whether it be something like ASP.net or WPF like we’ve worked with a little bit right here or the Universal Windows Platform to build Windows Store applications. You’ll need to know these concepts for all of those. That pretty much wraps up this lesson and this entire course. We’ll have a couple of closing comments in the next video, and then that’s it. We’ll see you there. Thanks. Congratulations. You did it. You made it all the way to the end. That’s a huge accomplishment, don’t sell yourself short. When I look at the given views for our course, I typically see the first two or three videos in the course have an astronomical number of views, and then it begins to tail off over time until you get to the very end, you see a rather small percentage of those who started actually finishing the course. Then it used to concern me thinking, maybe I could be a little bit more engaging and keep people’s interest longer but good folks at Microsoft Virtual Academy assured me that that happens across the board with every course. I think what’s really going on is that everybody has the best of intentions to follow through to watch an entire course. But then life happens, distractions pop up, maybe changes in priority present themselves they interrupt or completely halt progress. But the good news is that is not you, you were able to make it all the way through to the end and now you’re well on your way to mastering C-sharp, or at least learning more about C-sharp. Then from here, learning more about.Net, picking a user interface technology, whether for web windows or mobile, maybe learning more about databases, maybe using C-sharp to access APIs around the Internet. We’ll talk about some of those things that you could learn as you move on from here a little bit later in this video. But soon you’re going to be building your own applications, whether for yourself, for your employer, maybe your future employer. But whatever the case might be congratulations, I really encourage you to continue your momentum. Don’t stop here, keep pushing forward, keep taking baby steps on a daily basis. As you know, daily progress, no matter how seemingly insignificant, is how you make real improvements in your life, it’s how you add skills to your skill-set and you’ve taken this great first step in the right direction and I’m proud of you can’t say that enough, great job, and I’ll continue to encourage you throughout this lesson. But I want to wrap up this series in this lesson and provide a few suggestions about where to look for answers whenever they pop up from here on out, as inevitably you can continue by building applications and learning more about the various APIs that are available to C-sharp developers. We’re also going to talk about the right way and the wrong way to ask for help out on the Internet. Then I’ll make a few suggestions on topics that you might want to investigate from here on out as you continue your self-directed training. But before I get started in earnest, let me say that some of the ideas that we talked about here, especially some of the more advanced concepts that I hinted at or that I said, you can let this go in one ear and out the other, I just wanted to show it to you up briefly. Some of these things could require weeks or months or even years of thought work before your mind is really able to accept them and digest them. I know I’ve personally spent hours just staring at a wall, thinking about some programming concept, trying to wrap my head around it. The mind needs quiet time to reflect. You need to put yourself into a position to succeed by giving your mind the time to discover, the time to ask the crucial questions, the time to allow those neurons to make those vital connections. Honestly, there are things that I learned about 10 years ago that I’m still trying to really wrap my head around, figure out what this means overall, in what contexts it applies, things like that. Many times I might need to read different books and articles, watch videos, and to hear what different authors have to say about a given topic before it finally resonates with me and I really understand what the topic is, how it pertains to me, what do I need to do with it? Things like that. Each author who talks or writes about a given topic can say things in just a little bit differently, and sometimes that can finally unlock something for me. Don’t forget to keep pushing forward and keep learning because there’s always answers out there. But ultimately, I hope you realize that you really don’t need to know everything right away to get started and to be productive right now. You don’t have to be an expert first before you can begin to write software. In fact, some concepts really only make sense after you have more experience. Once you’ve made some mistakes, or you can see where a given idea and Oh I see where that applies, I could use that here in this scenario, that finally makes sense to me why I would want to do that. Adjectory in a program is a good example and there’s some others too. I titled this lesson, where do you go from here? My intent was to answer that in two different ways. First of all, where do you go from here whenever you have a problem and you’re having a hard time resolving the problem and getting back on your feet again? There’s a good chance at some point as you’re learning, as you’re building applications, you’re going to run into error messages or something that just doesn’t make any sense. It happens to everybody. But I would encourage you do not fret, I think in fact, what makes programming such a vital skill is learning how to solve problems that combine your existing knowledge with your ability to reason through what could be the problem and then your ability to research and perform research on a given problem until you come up with the solution to it. The good news is that there is this large community of other developers inside and outside of Microsoft that can help nudge you and get you past these problems. These people write blog posts, they answer questions in the various forums, they write books, they record screencast video tutorials like this one. You can tap into that community of knowledge at any time. But let me give you a few tips on how to utilize that community in the most effective way. Let’s suppose that you do hit a wall. You’re experiencing some issue with your application, it’s not behaving the way that you expected, maybe you’re getting some strange error message popping up every time you try to debug your application. Where do you start to debug this to pick apart the problem and get to the root issue? First of all, I research using key phrases directly from the error message itself, and I can’t emphasize how vitally important that is. If there’s an error number or a specific phrase that I can latch on to and I can “surround those” as I type in my query to Bing.com, that always helps me get closer to a resolution. I might spend 10-15 minutes scanning through various blogs and forum posts or on MSDN as search results pop up for these sources in order to find a potential solution. If I’m mindful about my search terms, I almost always find a solution. I think the reason why a lot of beginners fail with finding solutions to the problems is because they become impatient or they don’t use the exact error messages in their searches, and they don’t know how to search correctly, and they’re not willing to put in the time to actually read through pages and pages of content to find a solution to the problem. I can’t emphasize enough using the exact phrase inside the error message that you see on screen “surrounded”, will get you closer to finding a resolution to the issue that you’re having. There are always usually people with other similar issues that are posted and then explain what they did to actually solve that particular issue, so research is vital. I think actually one vital skill as a modern software developer is you become great at search. Searching on the Internet to help solve issues that you run into is such a vital skill. Now, it might seem easier to go directly to the forums immediately and to post a question to the forums in hopes that somebody else can help solve your problem for you. But I assure you that it will actually take longer to ask the question and get an answer than it would if you spent the time searching, refining your searches, and so on until you find a solution to your problem. Frankly, I almost never have to ask a question in the forums because a simple search will almost always yield a clue to what I did wrong or what the core issue is. In fact, I get embarrassed when I have to ask questions. Maybe that’s a bad attitude to have, but I don’t want to burden other people with when they could be answering other legitimate questions, so I go overboard and try to figure out the issue on my own. Now, virtually any issue that you run into, I’m almost positive that somebody else has at some point run into that issue before you have, and they’ve already posted the solution to that problem online. You just need to get out there and find it. If you get good at doing research, doing searches on the Internet to help find solutions to your problems, then it’ll get you back on your feet faster than again, posting into a forum and asking other people for help. Now, let’s suppose that you’re at your wit’s end and you’ve done searches and there’s nothing out there that really seems to apply to your situation. Nothing you’ve tried actually works to resolve your problem, maybe at that point, you need to ask for help. That’s fine. Here’s what you really need to do whenever you ask for help. You need to ask your question in such a way that you’re going to get a resolution and how you ask your question is important. You need to be an empathetic requester. In other words, you need to get people who are willing to help all the information they need to get you back on your feet again to pinpoint the issue and then isolate the issue and prescribe a solution. This means that you need to, first of all, clearly state your request. There’s a checklist that I have in my mind of the things that you need to do. Some of these will be obvious and some of them you may have not considered before so let me just go through them real quick here. First of all, you should start by posting your question in the right place. Find the right category in the given forum or use the correct tags for your post so that the right people are looking at your questions. Posting a C-sharp question in a visual basic form is not going to be all that productive, in fact you’ll probably get chided for it. Secondly, you also need to choose a simple clear title for your post so that it attracts the attention of the people who can help so that it saves everybody a lot of time. If I see a forum post that just says, please help, I usually just skip it. If it says link to objects queries yielding unexpected results, well, okay, that’s oddly specific. That might be something I can help with. I look like the person put some effort into concisely stating what the issue is. I’ll read the question and I’ll see if I can help. Third, a short synopsis of the issues that you’re having, including the exact error message, including the exact behavior you are expecting, and what you’re actually experiencing. Describe what you expected to happen, but what if it happened instead and keep it concise. Fourth, if you can at all possible include screenshots, and ideally you would go one step further and use some screen editing or image editing software and draw circles to draw the eye’s attention to those parts of the screenshot that are pertinent to your question. Fifth, if possible, include a code example. Make sure to change any super-secret information, passwords things of that nature before you post it, but without a code snippet, many problems are unsolvable. I can’t tell you how many times I get people writing e-mails and they’ll say, I’m having a problem with this what do you think the solution is? I’m like, show me some code, I need to see what you did to get to that point, and then maybe I can help you figure out what your issue is. Always include, if you can, a code snippet of the code that you think is causing the problem. Then be choosy about which code you choose to post. There’s nothing more frustrating than looking at somebody who posts like 200 lines of code and expecting me to go through it all when a lot of it doesn’t even pertain to the question at hand. I mean, you had to spend a little bit of time narrowing it down to a few things. You need to help me be empathetic to me, the person who’s willing to help you to identify those lines of code that might be involved in the issue. Number 6, if a given forum has special HTML tags or shortcodes that you can use to format the code or some other aspect of your question to help it stand out in the post, then you definitely should use it. Number 7, tell me, what have you done so far to try to resolve the issue? Did it change anything at all? Did it change anything? Did it help? Did this lead you to rule out certain possibilities? Again, empathize with me, the person who’s reading your question, trying to help you. This will result in a faster resolution. Otherwise, people will start with the obvious issues and then move forward. There’s that old joke, Hey, I’m having a problem with my computer and the technician asks, well, do you have it plugged in? Everybody says, Oh, the technician was, but there’s a reason why they do that. It’s because the most obvious answer is the one that most of the time works for people. Don’t be that guy make sure you already list out what it is that you try to do and you’ve eliminated it as a possibility. Number 8, tell me which operating system you’re using, which version Visual Studio and the DUnit framework, which programming language you’re using, which updates, service packs have been applied anything that you feel is pertinent to help me help you diagnose the issue that matters more than you might realize. Number 9, suppose that there’s a resolution to the issue, you figured it out. Awesome. Very cool. Maybe somebody made some suggestions that led you down to investigate some things and you finally figured it out that’s great. Take a moment, go back wherever you asked the question, and describe exactly what you did to resolve the issue step by step. Use that as a means of better understanding it yourself and articulating that will help you better understand the issue and what the solutions are. It makes you part of the community of the wealth of information that’s out there so that others in the future who have the same issue can look at your post and that you are feeding it back into the community just like you’re taking out of the community. Chances are that honestly, that person that you help in the future is you, I can’t tell you how many times that I found a resolution to something, and then months later, I hit up against the same thing, thinking to myself, I know I’ve solved this once and I’ll go searching for a solution and I’ll find the exact solution and I’ll read it. Oh, that was me, that was me who answered the question. It would be nice just to search for your solution online if you knew where it was, or at least be courteous to everyone else and your future self to post the answers to the questions that you have. Finally, absolutely 100 percent be polite, people don’t owe you an answer they don’t owe you anything there. If they’re going to help you, they’re going to do it out of the kindness of their hearts. They’re going to be doing it in their spare time as a means of maybe, furthering their own understanding, helping themselves grow but then also to help you grow as a software developer. Say please and thank you and be nice and then help other developers as you have the opportunity. I do sell training content, but I give a lot of it away for free. I do ask questions in the forums, but I answer a bunch too, make sure that you become part of that community and that you are feeding back into the community, you help, and you support, just like you’ve been supported by others. You might be wondering, where do you go to find this level of support, where you can ask questions. That depends. Typically, I’d recommend that you go to msdn.Microsoft.com here, let’s go out real quick. So, msdn.Microsoft.com/forums and it might redirect you based on where you are in the world. But typically you can choose from a number of different forums, so you definitely want to find the specific technology or language or whatever the case might be, or do a quick search for those keywords again right here inside of the MSD and forums. It is monitored by Microsoft employees, as well as people called Microsoft Most Valuable Professionals, or MVPs. MVPs are usually knowledgeable people who’ve demonstrated their willingness to help, and they’ve been identified by Microsoft as people who are willing to help and so they qualify for that based on some criteria, not the least of which is participation in these forums. Then there’s also another more comprehensive place you can take a look at Stack Exchange, programmers.stockexchange.com, and there might be one other place where you could go but also by the same company that has similar forums, depending on the type of information you’re looking for. Now, in my experience, Stack Exchange is a little bit iffier. It’s a little less beginner-friendly. Maybe that’s changed by the time that you visit, and I only say that it’s a little less friendly because not only will you be critiqued for how you ask your question, but very often if people do a search to help you and then they find that there’s already an existing question that’s similar enough to you, they’ll shot your question down. Just follow the rules, do an extensive search before you ask a duplicate question, don’t take offense to criticism about your question. Again, I’d recommend that you search long and hard before actually posting the question because I’m convinced that virtually everything that you could run into has been asked by somebody already. You just need to spend the time to find the answer that you’re looking for. I said that I would answer the question of where to go from here in two different ways, and I’ve answered the question of where to go whenever you have problems. But now I want to answer the question where do I go to learn more about application development, where do I go to learn more about software development? At this point, you’ve got a pretty good foundation of C-sharp basic knowledge of the C-sharp programming language.Net and a little bit about Visual Studio but there are still a lot of opportunities to practice what you know and to grow beyond that. No matter what type of application that you want to build, there are a few fundamental ideas that you need to be fundamentally acquainted with before you move on. First of all, I would recommend that you learn about relational databases like SQL Server, you learn how to access data that’s stored in a database using the Entity Framework, part of the.Net API for accessing data in your applications. Both SQL Server and the Entity Framework have visual tools that you can use inside a visual studio to drag and drop and configure your settings and selections and so spending some time not only learning about the tools and the APIs themselves, but then also these visual tools and start a visual studio can pay big dividends. You’ll want to quickly grow past that and learn how to write code and rely less on the visual designers and visual studio. But still, it’s a great tool to help you get to that point where you can be productive quickly. Next, you’re going to need to choose a presentation technology that you want to master, and this is really more about platform, honestly than just simple UI. So you have no lack of options, whether you want to build web or Windows applications or mobile applications or games or backend processes, whatever the case might be. So let’s say, for example, you want to build web applications. There’s a couple of different platforms. The older API is called asp.net web forms, and there’s a lot of code that was written on the Web Forms Platform API. But then there’s also a newer API, that’s called asp.net core MVC, and there are some huge differences between the two, but we don’t have enough time to talk about those. I had content on both of those topics on my own website debut. There’s Windows Forms, which is the older desktop API. Then there’s Windows Presentation Foundation, which is a newer API that companies use for building applications internally and then there’s the Universal Windows platform, which you use to build more consumer oriented applications, typically for sale on the Windows Store. There’s also the Xamarin platform, which Microsoft recently purchased at the time, I’m recording this for building true cross-platform apps for iOS and Android and even Windows Phone. Then there’s a third party called Unity 3D or 2D, depending on the type of game that you want to build. And so you might want to check out unity for building games. Now, if you’re not really sure about where you should go next and what you should learn next, I really would recommend that if you don’t already know each HTML5, CSS3 and JavaScript, that’s a great place to start. And I’ve created several fundamental series on Channel 9 that are aimed at each of these topics. They’re also available here on Microsoft Virtual Academy again at the time when I recorded this. Then beyond that, I recommend learning about the basic tenets of application architecture, particularly how to structure your code into layers of responsibility and what that even means. So splitting your code into layers of responsibility will help you build applications that can withstand the impact of change. And like I said earlier in the series, change comes from a number of different places. It could be changing business rules. It could be changing requirements, changes in the technology that’s available. It also comes from defects in your software, bug reports that come in and you need to make changes to fix those. But in each case, you can mitigate the negative impact of making changes in your code by encapsulating the responsibilities behind well-established APIs between each of the layers of responsibility. And I spend a lot of time talking about this, about application architecture on debut. So if that’s something that interests you, you definitely want to check that out. But from there, you want to learn more about basic software design patterns and tactics and techniques. And there are a few keywords that you’re going to want to learn about, and each of these can spawn an entire book, an entire video series. And I’ve already alluded to the topic of object oriented programming. That’s a huge topic that you definitely want to learn about first. If you can just get your mind wrapped around object oriented programming and how that changes the way that you create solutions to programming problems, then that’s a huge step in the right direction. But beyond that, you’re going to want to learn about the principles of software development, principles that guide you to write your code in a very object oriented way. There are some more generalized principles, like the drive principle. I don’t know that I’ve ever given it a name, but it’s essentially don’t repeat yourself. I said be leery of copying and pasting. When you do find yourself wanting to copy and paste code in multiple places in your application, you should be stopping yourself and thinking, how can I create this in such a way that I can reuse it? So don’t repeat yourself, put code, extract it out. That will be reused into its own method or class, and then reuse it from there. There’s also another principle called Yagni or Y-A-G-N-I. Which is you ain’t going to need it. Which means, yeah, you could probably set yourself up and architect your application in such a way that in the future you could expand, but you’re probably not going to need to do that. You ain’t going to need it. All right. Then there’s another principle or idea called dependency injection, which is super important. It’s a design pattern that guides you towards building loosely coupled objects that then can be swapped in and out of the solution, and you’ll want to learn about dependency injection. It’s really crucial to building some of the new style applications using like the ASP.Net Core MVC, which relies heavily on dependency injection. There’s also a set of principles called Solid, S-O-L-I-D. Each of those stand for a different sub principle. They help you realize the promise of object oriented programming inside of your applications. So again, a lot of ideas that are more conceptual in nature and less code syntax or tool oriented. All right. You’re also going to want to learn about the process of software development, so the workflow surrounding software development and managing software projects. So specifically, you’re going to want to learn about the tools and the techniques that you use whenever you work inside of a team sharing source code between team members using a source code repository like Git or like Visual Studio Online’s implementation of Git and their own internal source code repository tool. You’re definitely going to want to learn about building unit tests, which are tiny little code based tests that continually are testing your code every time you write. Some people have even gone as far to say that you should be writing those little unit tests first and then you write the actual production code that satisfies those unit tests. Now, whenever there’s a change made in the system, you can see what the impact of that change is because you’ll begin to see these little tests start filling, that is a process called test driven development, and some people swear by it. Other people swear at it. So you’re also going to want to learn about agile project management, agile software development techniques, defining requirements in user stories, playing a game called planning poker to determine what features can we include in a given iteration of our software building process, using agile boards to manage assigned tasks between the various software developers on the team. You’re going to want to learn about the nature of iterative development. How to use that term iteration. So you want to learn about what are iterations and one of the goals of iterations and why they’re useful. You’ll want to learn about developing a spike of functionality all the way through all the layers of responsibility in your system. So I’ve given you probably what, several dozen different key terms that you could use as a launching point to search on. Honestly, if you were to look at all those terms that I just use, it’ll take several years to learn about all those things, even in a general way. But fortunately again, you don’t have to know at all to get started to be productive today. So, yeah, there’s so much to learn in so little time. But it’s what makes software development fun and makes it exciting because there’s always something new to learn and some new technique to try. I’ve had friends at Microsoft, actually confide in me that it’s a challenge for them to keep up with it all. Nobody just knows all this stuff automatically. It’s a challenge for everyone, everybody to keep up with. Nobody just knows it all. It just keeps evolving. You just have to really commit yourself to learning. I realized some time ago that my full time job is not creating video content or training content for developers, my full time job is really learning. And then if I create training content, that’s really a byproduct of all the learning that I’m doing, the value that I have to somebody else is my knowledge. And so without that is the core piece of what I do. Whether it’s building applications for somebody or creating training content, they’re only interested in me because of my knowledge. Then how I apply that knowledge is a byproduct of actually gaining the knowledge. So you have to really commit to learning. And I know since you’re here on Microsoft Virtual Academy that you’ve already done that to some degree. There’s a whole bunch of great resources out that are available on the Internet, not the least of which are Channel 9 and Microsoft Virtual Academy. Obviously, there’s MSDN, as we looked at earlier in the series. However, before I close this out, let me make one final plug for you to visit my website. If you haven’t already developeruniversity@devu.com, is there on screen. I’ve designed the courses there specifically for someone who’s a beginner to help them get up and running as quickly as possible, pointing out what I feel like they really need to know in order to master key ideas that will lead them to get jobs in the software development industry, providing homework exercises and quizzes. But more importantly, coding challenges that force people to write and to develop the muscles of your mind that allow you to pick apart a problem and create a solution for it. All right. So please check out devu.com whenever you get a chance. All right. So as I close here, I hope you found this course to be valuable and this lesson to be valuable. If there’s anything that I can ever do to help you, please let me know. You can find me out on Twitter. I sometimes go out there. Hit me up on Facebook or, you can write me an e-mail. But finally, as we close out, I sincerely wish you the best of luck in your career. C-sharp in software development is such an exciting field to be a part of, and I’m really excited for you. So good luck. Thank you for watching this series.

    By Amjad Izhar
    Contact: amjad.izhar@gmail.com
    https://amjadizhar.blog

  • JavaScript Concepts: Variables, Data Types, Syntax, and Functions by Bob Tabor

    JavaScript Concepts: Variables, Data Types, Syntax, and Functions by Bob Tabor

    The source provides instruction for learning JavaScript. It covers creating files and directories for code and explains the structure of JavaScript statements, including operators, operands, and expressions. Various JavaScript concepts are explained, such as variables, data types, coercion, scope, functions, objects, arrays, loops, the ‘this’ keyword, classes, inheritance, template literals, regular expressions, and built-in native objects. The material also touches on design patterns like the module pattern and new JavaScript features like arrow functions. The explanation includes examples in both Node.js and web browser contexts.

    JavaScript Fundamentals: A Comprehensive Study Guide

    Quiz

    1. What is JavaScript and who is it designed for? JavaScript is a programming language designed primarily for beginners, especially those familiar with HTML and CSS, and even individuals with no prior programming experience.
    2. What problem is Babel.js designed to solve? Babel.js addresses the issue of browser compatibility by transpiling newer JavaScript code into older, more widely supported versions, ensuring functionality across various browsers, including outdated ones.
    3. Explain the difference between declaring and initializing a variable. Declaring a variable involves creating a named storage location in memory using the let keyword, while initializing assigns an initial value to that variable at the time of its declaration.
    4. What are the rules for naming variables in JavaScript? Variable names must begin with a letter, dollar sign ($), or underscore (_), can contain letters, numbers, dollar signs, or underscores, and cannot be keywords or contain spaces. Additionally, variable names are case-sensitive.
    5. What is coercion in JavaScript, and why can it be problematic? Coercion is the automatic conversion of one data type to another. This can lead to unexpected behavior, especially when performing operations on values of different types (e.g., adding a number and a string).
    6. Explain the difference between the equality operator (==) and the strict equality operator (===). The equality operator (==) checks for value equality after performing type coercion if necessary, while the strict equality operator (===) checks for both value and type equality without coercion.
    7. Explain the purpose of the break statement within a switch statement. The break statement is used to exit a switch statement after a case match has been found and its corresponding code has been executed, preventing the execution of subsequent cases.
    8. What is variable scope? Variable scope defines the accessibility and lifetime of a variable within a program, determining where it can be accessed and when it is removed from memory.
    9. Explain the module pattern in JavaScript and what problem it aims to solve. The module pattern is a design pattern used to encapsulate code within a module, creating private and public scopes. It primarily solves the issue of polluting the global namespace.
    10. What are template literals in JavaScript? Template literals are string literals that allow embedded expressions. They use backticks (`) instead of single or double quotes and can contain placeholders (${expression}) that are replaced with the values of the expressions.

    Answer Key

    1. JavaScript is a programming language designed primarily for beginners, especially those familiar with HTML and CSS, and even individuals with no prior programming experience.
    2. Babel.js addresses the issue of browser compatibility by transpiling newer JavaScript code into older, more widely supported versions, ensuring functionality across various browsers, including outdated ones.
    3. Declaring a variable involves creating a named storage location in memory using the let keyword, while initializing assigns an initial value to that variable at the time of its declaration.
    4. Variable names must begin with a letter, dollar sign ($), or underscore (_), can contain letters, numbers, dollar signs, or underscores, and cannot be keywords or contain spaces. Additionally, variable names are case-sensitive.
    5. Coercion is the automatic conversion of one data type to another. This can lead to unexpected behavior, especially when performing operations on values of different types (e.g., adding a number and a string).
    6. The equality operator (==) checks for value equality after performing type coercion if necessary, while the strict equality operator (===) checks for both value and type equality without coercion.
    7. The break statement is used to exit a switch statement after a case match has been found and its corresponding code has been executed, preventing the execution of subsequent cases.
    8. Variable scope defines the accessibility and lifetime of a variable within a program, determining where it can be accessed and when it is removed from memory.
    9. The module pattern is a design pattern used to encapsulate code within a module, creating private and public scopes. It primarily solves the issue of polluting the global namespace.
    10. Template literals are string literals that allow embedded expressions. They use backticks (`) instead of single or double quotes and can contain placeholders (${expression}) that are replaced with the values of the expressions.

    Essay Questions

    1. Discuss the importance of browser compatibility in web development. Explain how tools like Babel.js contribute to addressing this challenge and enabling developers to use modern JavaScript features while maintaining support for older browsers.
    2. Explain the concept of variable scope in JavaScript, detailing the differences between global, function, and block scope. Provide examples to illustrate how variable scope affects the accessibility and lifetime of variables within a program.
    3. Discuss the advantages and disadvantages of using the module pattern in JavaScript for code organization and encapsulation. Compare and contrast the module pattern with the revealing module pattern, highlighting their differences and potential use cases.
    4. Explain the concept of closures in JavaScript. How do closures enable the association of data with functions? Provide an example to demonstrate how closures can be used to create functions with persistent state.
    5. Explain the behavior of the “this” keyword in JavaScript and its implications for object-oriented programming.

    Glossary of Key Terms

    • Transpilation: Converting source code from one programming language (or version) to another.
    • Variable Declaration: Creating a named storage location in memory to hold a value.
    • Variable Initialization: Assigning an initial value to a variable at the time of its declaration.
    • Identifier: The name given to a variable, function, or other programming element.
    • Keyword: A reserved word in a programming language with a specific meaning and purpose.
    • Coercion: Automatic conversion of one data type to another.
    • Data Type: The classification of a value, determining the kind of data that can be stored and the operations that can be performed on it (e.g., number, string, boolean).
    • Assignment Operator: A symbol (=) used to assign a value to a variable.
    • Operator Precedence: The order in which operations are performed in an expression.
    • Operand: A value or variable on which an operator acts.
    • Expression: A combination of values, variables, and operators that evaluates to a single value.
    • Statement: A complete instruction in a programming language.
    • Function Declaration: Defining a function with a specified name, parameters, and body.
    • Function Expression: Creating a function as part of an expression.
    • Function Invocation: Calling or executing a function.
    • Argument (Parameter): A value passed into a function when it is called.
    • Return Value: The value returned by a function after it has completed execution.
    • Code Block: A group of statements enclosed in curly braces ({}).
    • Decision Statement: A statement that allows the execution of different code blocks based on a condition (e.g., if, switch).
    • Iteration Statement: A statement that allows a block of code to be executed repeatedly (e.g., for, while).
    • Variable Scope: The region of a program where a variable is accessible.
    • Lexical Scope: A variable’s scope is determined by its location within the source code.
    • Global Scope: Variables declared outside of any function or block have global scope.
    • Function Scope: Variables declared inside a function have function scope.
    • Block Scope: Variables declared inside a block (e.g., if statement, loop) with let or const have block scope.
    • Module Pattern: A design pattern used to encapsulate code within a module, creating private and public scopes.
    • Immediately Invoked Function Expression (IIFE): A function expression that is executed immediately after it is created.
    • Closure: A function that retains access to variables from its surrounding scope even after the outer function has finished executing.
    • Truthy/Falsy: Values that are implicitly converted to true or false when evaluated in a boolean context.
    • Template Literals: String literals that allow embedded expressions, enclosed in backticks (`).
    • Regular Expression: A pattern used to match and manipulate strings.
    • Arrow Function: A concise syntax for writing function expressions.
    • DOM (Document Object Model): A programming interface for HTML and XML documents. It represents the page so that programs can change the document structure, style, and content.
    • Event Listener: A function that is called when a specific event occurs (e.g., click, mouseover).

    JavaScript Fundamentals: A Beginner’s Guide

    Here’s a detailed briefing document summarizing the main themes and ideas from the provided source, with direct quotes to illustrate key points.

    Briefing Document: JavaScript Fundamentals

    Overview:

    This document summarizes a JavaScript course intended for absolute beginners to programming. The course covers basic JavaScript syntax, data types, operators, control flow (decision statements, iteration), functions, object-oriented programming principles, DOM manipulation, and more advanced concepts like closures and the module pattern. It emphasizes the core language rather than web development aspects, initially focusing on console-based applications before discussing browser implementation.

    Main Themes and Key Ideas:

    1. Target Audience and Scope:
    • The course is designed for individuals with HTML and CSS knowledge who want to learn JavaScript, targeting absolute beginners to programming in general. “This course is aimed at those who are absolute beginners so beginners to javascript and frankly given that we’re going to discuss some very basic things like if statements and for loops it’s really designed for those who are beginners to programming in general.”
    • It focuses on the JavaScript language itself before delving into web browser implementations. “My focus is the javascript language the pure language not web development necessarily although we will discuss javascript in the context of the web browser at the very end of this course.”
    • The course covers the Javascript language itself, not necessarily web development.
    1. JavaScript Versions and Compatibility:
    • The importance of browser compatibility is discussed, highlighting the issue of older browsers not supporting newer JavaScript features. “hat are viewing web pages with browsers that were created 10 years ago so clearly in these cases the newer features of javascript many of which we’ll discuss in this course will not be available in those browsers and your javascript won’t even work in those web browsers.”
    • Two approaches to address compatibility: writing code friendly to older browsers or using transpilers like Babel to convert modern JavaScript to older versions. “You can either attempt to write your code in such a way that it is is as friendly as possible to those older web browsers or you can use a tool which will transpile your javascript code.”
    • The website “can i use” is suggested to check browser support for specific JavaScript features.
    1. Importance of Precision and Syntax:
    • Emphasis on the need for precise syntax in programming languages. “You can’t just write a text message full of lowercase letters and things of that nature that would make it a well-formed english sentence and you’re you’re relying on your the person receiving that text message to understand what you’re trying to say the computer doesn’t work that way it means it needs to know exactly what you’re saying and so you have to be precise precision is the key as a software developer.”
    • Use of code comments ( // ) to exclude lines from compilation.
    1. Variables and Data Types:
    • A variable is defined as “basically just a a an area in the computer’s memory where we’re storing a value.”
    • Explanation of variable declaration using the let keyword. “A keyword is something like let… essentially think of it like a verb in the english language. It’s an instruction to the javascript compiler that we want to do something…”
    • Rules and conventions for naming variables (identifiers). Identifiers must begin with a letter, dollar sign, or underscore and can contain letters, numbers, dollar signs, or underscores, but no other special characters. Identifiers cannot contain spaces and cannot be keywords.
    • Discussion of data types: number, boolean, string, and undefined. “The variable itself does not have a data type only the values that we store inside the variables have the data type.”
    • The typeof operator is introduced to determine a variable’s data type.
    • Coercion is introduced with example let a = 7; let b = “6”; let c = a+b;, which yields 76, and parsing b to an integer solves it.
    • NaN is discussed as representing “not a number” if an illegal parsing is attempted.
    1. Operators and Expressions:
    • Definitions of operators (keywords, symbols) and operands (identifiers, variables, functions).
    • “By combining operators and operands we create expressions that are then used to compose statements”.
    • Examples of different types of operators: assignment (=), arithmetic (+, -, *, /), increment/decrement (++, –), comparison (==, ===, !=, !==), logical (&&, ||).
    • Discussion of the order of operations and using parentheses to control evaluation.
    • Introduction of the member accessor operator (.) for accessing object properties.
    1. Control Flow: Decision Statements and Iteration:
    • Explanation of decision statements: if, else if, else, switch, and the ternary operator.
    • The structure of the if statement is outlined. if (some expression that expression should equal true or false)
    • “The ternary operator has kind of got several parts here there’s an expression there’s a question mark that that has true or false ramifications.”
    • The structure of the switch statement is outlined, and the need for break statements to prevent fallthrough.
    • Explanation of the ternary operator for inline conditional evaluation.
    • Iteration statements: for and while loops.
    • “Iterations allow us to loop through a body of code a block of code a number of times until a certain condition is met.”
    • Example showing how to iterate through an array using a for loop.
    • The “break” keyword allows premature escape from iterations.
    1. Variable Scope:
    • “When I use the term scope I mean variables are a little bit like people in so much that variables have a lifespan they’re born they do work and then they die and they’re removed from computers memory when they go out of scope”.
    • Scope is defined as the region of a program where a variable can be accessed.
    • Variables declared outside a function have global scope and can be accessed within the function. Variables declared inside a function have local scope and cannot be accessed outside the function.
    1. Functions:
    • A “method as a function that belongs to or rather is defined inside of an object”.
    • The declaration and invocation of functions. “To actually invoke a function we have to use the function invocation operator in this case it’s the opening close parentheses.”
    • Passing arguments to functions. “We’re able to reuse that code but change it up by passing in the name that I wanted to say hello to.”
    • Returning values from functions using the return keyword.
    • Discussion of avoiding creating variables in the global scope.
    • Returning a function from a function.
    • Example of a function that returns a string like one using the keyword return.
    1. Objects and the this Keyword:
    • Definition of objects as collections of properties (key-value pairs).
    • “Simple objects have a single property, other objects can have more properties including other objects.
    • Creating object literals.
    • Accessing object properties using dot notation (.) and bracket notation ([]).
    • Introduction of the this keyword, emphasizing that its value depends on how a function is called.
    • this depends on how a given function is called, not necessarily how/where it was created.
    • Examples showing how this refers to the global object in a regular function call (in non-strict mode).
    • Using the call() and apply() methods to explicitly set the value of this.
    • The this keyword in the context of a web page is different.
    • Use the id property in a button to specify a unique identifier for this DOM element.
    1. Template Literals:
    • Template literals are delimited with backticks (“`) and allow string interpolation.
    • They’re “a nice addition to the javascript language here again they can make your code more compact and readable allowing you to do some interesting things in line that would require a lot of appending of strings previously.”
    • Example demonstrating how to embed expressions within template literals using ${expression}.
    • Ability to create multi-line strings without concatenation.
    1. Regular Expressions (Regex):
    • Regular expressions are patterns used to match character combinations in strings.
    • Use the test() method to check if a string matches a pattern.
    • Use the replace() method to replace matched patterns with a new string.
    • There’s a lot to Regex, but a simpler approach is to use methods for checking if a string matches a pattern.
    1. Arrow Functions:
    • Arrow functions provide a more concise syntax for writing function expressions.
    • “Arrow functions… just get rid of the keyword function but this remains and it allows us to define an input parameter name inside of or after the fat arrow and inside of the body I can go console.log…”
    • Basic syntax: (parameters) => expression or (parameters) => { statements }.
    1. Truthy and Falsy Values:
    • Understanding truthy and falsy values in JavaScript is crucial for conditional evaluations.
    • Falsy values: false, 0, “” (empty string), null, undefined, and NaN.
    • Truthy values: All values that are not falsy.
    1. Date and Time:
    • Creating Date objects using the new Date() constructor.
    • Using methods like getDate(), getDay(), getMonth(), getFullYear(), and getTime() to extract date and time components.
    • Calculating elapsed time between two dates.
    1. String Methods:
    • split(): Splits a string into an array of substrings based on a separator.
    • slice() and substring(): Extracts a portion of a string.
    • endsWith() and startsWith(): Checks if a string ends or starts with a specified string.
    • includes(): Checks if a string contains a specified substring.
    • repeat(): Repeats a string a specified number of times.
    • trim(): Removes whitespace from both ends of a string.
    1. Array Methods:
    • push() and pop(): Adds/removes elements from the end of an array.
    • shift() and unshift(): Adds/removes elements from the beginning of an array.
    • splice(): Adds or removes elements from any position in an array.
    • concat(): Concatenates two or more arrays.
    • slice(): Creates a new array containing a portion of an existing array.
    • join(): Joins all elements of an array into a string.
    • sort(): Sorts the elements of an array.
    1. Error Handling (Try/Catch):
    • Using try, catch, and finally blocks to handle exceptions.
    • The try block executes normally, but if an exception occurs, the catch block gets invoked, and at the very end, regardless, is the finally.
    • Throwing custom exceptions using throw new Error().
    1. DOM Manipulation:
    • Selecting DOM elements using document.getElementById().
    • Adding event listeners to DOM elements using addEventListener().
    • Creating new DOM elements using document.createElement().
    • Manipulating element attributes and styles.
    1. Module Pattern and Closures:
    • The module pattern uses an immediately invoked function expression (IIFE) to create a private scope and return an object with public methods.
    • “These are topics that could have easily been covered much earlier in the course but because I was trying to get somewhere I left those details off till now so hopefully you don’t mind that we’re going to circle back and fill in some of the or backfill some of the topics that we just didn’t cover in a lot of depth”.
    • “Closures create lexical environment” for each closure instance to define an environment.
    • Closures allow a function to access variables from its surrounding scope even after the outer function has finished executing.

    Conclusion:

    This course provides a comprehensive introduction to JavaScript for absolute beginners. It systematically covers fundamental concepts, equipping learners with the knowledge to write basic JavaScript programs. The emphasis on core language features and progressive exploration of concepts helps build a strong foundation for further exploration of web development and other JavaScript applications.

    JavaScript Fundamentals: A Concise Guide

    Javascript FAQ

    • What is the primary goal of this JavaScript course?
    • The course aims to teach JavaScript to absolute beginners, even those new to programming in general. It focuses on the core JavaScript language itself, rather than web development aspects, although it does touch on JavaScript’s use in web browsers at the end. The course emphasizes precision and understanding how to write code that a computer can interpret accurately.
    • What are some important considerations when choosing which JavaScript features to use, given different browser compatibility levels?
    • You have two main choices: write code that is compatible with older browsers, or use a tool like Babel to transpile your modern JavaScript code into an older version that is compatible with most browsers. The website “Can I Use” helps determine browser support for specific JavaScript features.
    • What are variables in JavaScript, and what are the rules for naming them?
    • A variable is a named storage location in the computer’s memory that can hold a value. Variable names (identifiers) must start with a letter, dollar sign, or underscore. They can then contain letters, numbers, dollar signs, or underscores, but no other special characters (including spaces). Variable names are case-sensitive, and you cannot use reserved JavaScript keywords as variable names.
    • What are data types in JavaScript, and how does JavaScript handle them?
    • Data types define the kind of data that a variable holds. JavaScript is dynamically typed, meaning the variable itself doesn’t have a fixed data type; only the value stored in the variable has a data type. Common data types include number, string, boolean, and undefined. JavaScript can perform type coercion, automatically converting data types in certain situations (like concatenating a number and a string), although this can sometimes lead to unexpected results.
    • What are operators and operands, and how do they relate to expressions and statements?
    • Operators are symbols or keywords that perform actions (like +, =, let), while operands are the values that operators act upon (variables, literals, function calls). Operators and operands form expressions, which evaluate to a single value. Expressions are used to compose statements, which are instructions that the JavaScript interpreter can execute.
    • What are functions in JavaScript, and how can we define and use them?
    • Functions are reusable blocks of code that perform specific tasks. You can define functions using function declarations, which involve giving a name to a code block. You can also create function expressions, assigning a function to a variable. To execute a function, you call it by its name followed by parentheses (the function invocation operator). Functions can accept input parameters (arguments) and return values.
    • What are the module pattern and revealing module pattern, and what problems do they solve?
    • The module pattern and revealing module pattern are design patterns used to encapsulate JavaScript code, reducing the impact on the global namespace and promoting code organization. They use immediately invoked function expressions (IIFEs) to create a private scope and return an object that exposes only specific variables and functions (the module’s “public” interface). The revealing module pattern makes it clearer what the “public” methods will be by declaring them at the end.
    • How does the this keyword work in JavaScript, and how can we control its value?
    • The this keyword refers to the context in which a function is called. Its value depends on how the function is invoked. When a function is called as a method of an object, this refers to that object. You can explicitly control the value of this using the call() and apply() methods. In arrow functions, this is lexically bound, meaning it inherits the this value from the surrounding scope.

    JavaScript Syntax Elements

    The sources discuss JavaScript syntax and some of its elements.

    Key aspects of JavaScript syntax:

    • Statements JavaScript files contain one or more statements that execute sequentially from top to bottom. A statement is a complete instruction, similar to a sentence in English.
    • Expressions Statements are made up of one or more expressions. Expressions consist of operators and operands. By combining operators and operands, expressions are created that are then used to compose statements.
    • Operators Operators are keywords or symbols that perform actions, such as the addition operator (+), string concatenation operator (+), and assignment operator (=).
    • Operands Operands are identifiers, such as variable names and function names. Programmers give operands their names.
    • Keywords Keywords are like verbs that instruct the JavaScript compiler to perform actions. Examples include let, var, and const.
    • End of line character A semicolon (;) typically indicates the end of a statement.
    • Code comments Double forward slashes (//) can be used to comment out a single line of code, instructing the compiler to ignore it. Multi-line comments can be created using /* to begin the comment and */ to end the comment.
    • Precision Being precise is key when writing code. The computer needs to know exactly what to do.
    • Data Types Values, not variables, have a data type, which describes what you intend to do with the data. Examples include number, boolean, and string.

    There are naming rules and conventions that need to be followed as developers. For example, code conventions include using camel casing, using descriptive and clear names, and being consistent in the style and naming conventions used.

    JavaScript Variable Declaration Guide

    Variable declaration in JavaScript involves reserving a space in the computer’s memory to store and retrieve data during an application’s lifespan. There are several parts to a variable declaration.

    Key aspects of variable declaration:

    • Keywords Keywords are a way to declare a variable.
    • let The let keyword is an instruction to the JavaScript compiler to create a variable. It declares a block-scoped local variable, optionally initializing it to a value. The recommendation is to abandon var unless it is required, and to use let instead.
    • const The const keyword is used when it is intended for the variable to never change its value. If a new value is assigned to a const variable, the JavaScript compiler will throw an error.
    • var The var keyword was the original way to declare a variable in JavaScript. However, its usage is nuanced and can be problematic for new developers.
    • Identifier An identifier is the name assigned to a variable so it can be referenced later.
    • Assignment operator The assignment operator (=) assigns a value to a variable.
    • Initialization Initialization refers to assigning a value to a variable at the same time it is declared. When a variable is declared but not initialized, its value is undefined. It is preferable to initialize variables at the moment of declaration.
    • Scope Scope refers to the accessibility of variables in different parts of the code. Variables declared outside of a function have global scope and can be accessed from anywhere in the code. Variables declared inside a function have local scope and can only be accessed within that function.

    There are several rules for naming variables:

    • All variable names must begin with a letter, a dollar sign ($), or an underscore (_).
    • Variable names can contain letters, numbers, dollar signs, or underscores, but no other special characters or spaces.
    • Keywords cannot be used as variable names.
    • Variable names are case-sensitive.

    There are also code conventions that are good practices to follow:

    • Variable names should be descriptive.
    • Camel casing should be used for multiple words, where the first word is lowercase and subsequent words have a capital letter.
    • Be consistent by following the same naming convention throughout the application.
    • Do not rely on case; avoid using the same name with different casing for different variables.

    JavaScript Function Execution: Definition, Syntax, and Scope

    Here’s a discussion of function execution based on the provided sources:

    • Definition A function is a block of code with a name that can be called to execute the code within the block. Functions are a primary construct in JavaScript for getting things done.
    • Parts of a Function A function includes a name/identifier, parentheses for arguments/input parameters, and curly braces to define the body of the function.
    • Function Declaration A function declaration begins with the keyword function, followed by an identifier (the function name), then parentheses (), and finally curly braces {} enclosing the code to be executed.
    • Calling a Function To execute a function, it needs to be called or invoked by its name, followed by parentheses (). This is the function invocation operator.
    • Arguments Arguments are values passed into the function when it is invoked, which the function can then use.
    • Function Expressions A function expression is similar to a function declaration, but it does not require a name. Function expressions are useful when a function is needed temporarily and will not be called again.
    • Return Values Functions can return values using the return keyword, passing data back to the caller.
    • Variable Assignment Functions can be assigned to variables, allowing the function to be invoked using the variable name and the function invocation operator.
    • Scope The location where a variable is defined determines its accessibility. Variables defined outside of a function are accessible inside the function, but variables defined inside a function are not accessible outside the function.
    • this Keyword The this keyword refers to the object that a function is associated with. The value of this depends on how the function is called.
    • Call and Apply The call and apply methods can be used to explicitly set the value of this inside a function.
    • Hoisting Function declarations are “hoisted” to the top of the execution environment, so they can be called before they are defined in the code.
    • Immediately Invoked Function Expressions (IIFE) An IIFE is a function expression that is defined and then immediately executed. This pattern is often used to create a private scope for variables and functions.
    • Arrow Functions Arrow functions provide a shorthand syntax for defining functions.

    JavaScript Object Creation Methods

    Object creation in JavaScript can be achieved through several methods, each with its own nuances.

    Object Literal Notation

    • Objects can be created using object literal notation, defining the object and its properties directly using curly braces {}.
    • Properties within the object are defined as name-value pairs, separated by colons.
    • The property names are identifiers, similar to variable names, and the values can be of any data type.
    • Each property definition is separated by a comma, except for the last one.
    • After the object is defined, it can be assigned to a variable.
    • For example: let car = { make: “BMW”, model: “745li”, year: 2010 };.

    Constructor Functions

    • Objects can also be created using constructor functions.
    • A constructor function is a regular JavaScript function that is called with the new keyword.
    • By convention, constructor functions are named with a capital letter.
    • The new keyword performs the following actions:
    • It creates a new empty object.
    • It sets the this value of the function to the new object.
    • It executes the function, adding properties and methods to the new object.
    • It returns the new object.
    • Inside the constructor function, the this keyword is used to refer to the object being created.
    • For example:
    • function Car(make, model, year) {
    • this.make = make;
    • this.model = model;
    • this.year = year;
    • }
    • let myCar = new Car(“BMW”, “745li”, 2010);

    Classes (Syntactic Sugar)

    • JavaScript also has a class syntax, introduced in later versions, which provides a more structured way to create objects and deal with inheritance, but it is essentially syntactic sugar over the existing prototype-based system.
    • Classes are declared using the class keyword, followed by the class name.
    • The constructor method is a special method within the class that is automatically called when a new object is created using the new keyword.
    • Methods can be defined within the class, outside the constructor.
    • Classes support inheritance using the extends keyword.
    • For example:
    • class Car {
    • constructor(make, model, year) {
    • this.make = make;
    • this.model = model;
    • this.year = year;
    • }
    • print() {
    • console.log(`${this.make} ${this.model} (${this.year})`;
    • }
    • }
    • class SportsCar extends Car {
    • revEngine() {
    • console.log(“Vroom goes the ” + this.model);
    • }
    • }
    • let mySportsCar = new SportsCar(“Dodge”, “Viper”, 2011);
    • mySportsCar.print(); // Output: Dodge Viper (2011)
    • mySportsCar.revEngine(); // Output: Vroom goes the Viper

    Object.create()

    • The Object.create() method can create a new object, using an existing object as the prototype.
    • This allows for prototypal inheritance, where the new object inherits properties and methods from the prototype object.
    • Changes to the prototype object can be reflected in the new object, and vice versa.
    • “`javascript
    • let originalCar = {
    • make: “BMW”,
    • model: “745li”,
    • year: 2010
    • };
    • let newCar = Object.create(originalCar);
    • console.log(newCar.make); // Output: BMW
    • “`
    JavaScript Fundamentals for Absolute Beginners

    The Original Text

    hi my name is bob tabor and in this course you’ll learn about javascript the language this course is aimed at those who are absolute beginners so beginners to javascript and frankly given that we’re going to discuss some very basic things like if statements and for loops it’s really designed for those who are beginners to programming in general so if you know some html and some css and you want to learn javascript awesome you’re in the right place also there’s nothing specific to windows in this course the tools that i use will be free and available in mac and linux as well so you should be able to follow along no matter which operating system you’re comfortable with using now my background is really not all that important but in case you’re curious i am a software developer by day and by night i run a website called developeruniversity or devview you can visit me at http://www.devview.com occasionally microsoft invites me to create courses and what you see here is a collaboration between myself and the good folks at microsoft virtual academy i’ve been creating courses like this since 2004 and i created a very successful version of a javascript course way back in 2011 it’s been viewed millions of times and i’ve got a lot of very positive feedback about it this is a rewrite a complete rewrite of that course because uh frankly javascript has changed dramatically in the what six or seven years since i originally recorded that course uh and so if you’re already a software developer coming from a different programming language just kind of pick back up what i said earlier this might move a little bit slow for you it just wasn’t designed with you in mind there might be some other courses that can move you through the the introductory material a little bit more quickly than what i plan on than than the pace that i plan to take with this course and my focus is the javascript language the pure language not web development necessarily although we will discuss javascript in the context of the web browser at the very end of this course but i felt like teaching javascript and how it’s implemented in the web browser clouded the discussion of javascript the language itself so we’re going to be writing what amounts to console or rather command line style applications to isolate javascript the language as purely and simply as possible without clouding it with a bunch of html and css and things like that we’re going to discuss the language we’ll discuss popular patterns that have emerged from the javascript development community to help overcome some of the challenges associated with working with such a highly dynamic language such a unique language and sometimes kind of a quirky language the last time that i recorded the course uh about javascript way back in 2011 the the course actually had a fairly long shelf life and so much has changed with javascript since then that uh i necessitated that i actually play catch-up and kind of learn some of the new features that were added because i wasn’t keeping my skill set uh up that’s how quickly things change out from under you if you’re not careful if you know anything about javascript you know that the community around javascript is moving extremely quickly it’s the most popular programming language not just in the web browser where there are hundreds of javascript frameworks and libraries that you can leverage in your own applications but it’s also becoming one of the most popular languages for server-side web development meaning the code that actually runs on a web server that can perform business logic that can interact with data storage uh databases and and other uh styles of data storage and we’re not going to talk about any of those topics in depth per se but it is important to know that it all starts with a basic understanding of the things that we will discuss in this course the absolute basics of javascript so since this course may have a long shelf life it’s important to know that some of the features of the latest version of javascript which i will be covering in this course may not yet be implemented in all web browsers depending on when you view this course and then uh you have to take into account that some of the people viewing your website for example might be using very old web browsers and so you have to keep that in account as well so i’m going to make two general suggestions and i’m going to try to remind you about these at the very end there are still people on the internet that are viewing web pages with browsers that were created 10 years ago so clearly in these cases the newer features of javascript many of which we’ll discuss in this course will not be available in those browsers and your javascript won’t even work in those web browsers so you have a choice at that point you can you can go one of two routes you can either attempt to write your code in such a way that it is is as friendly as possible to those older web browsers or you can use a tool which will transpile your javascript code that you write using the latest features of javascript it’ll transpile it back into a version of javascript that is compatible with all web browsers even those that were built 10 years ago and it uses a combination of techniques to accomplish this we’re not going to get into any of those but if you want to take the first tact if you want to be careful with the javascript that you write and only use those those original features i guess you can say of javascript or the early features of javascript there’s a website for you you want to take a look at this website called can i use and so we can take a look at maybe one of the newer features of javascript the let keyword i’ll type it in here in the search box can i use and it will show us the let keyword gives a quick description of what it is and then it will show for the current versions of each of the web browsers whether it’s supported or not you can see that the let keyword does have wide adoption across all modern web browsers with a couple of exceptions now if you want to go ahead and use the absolute latest version of javascript and then take that second text where you transpile your code so that it’s come backwards compatible with as many versions of the various web browsers as possible then you want to check out a website like anatool actually called babel js so you can find it at babeljs.io and it will again use a combination of techniques to uh to take your code you can see some of this little animation that’s on the page right now you can actually use this to type in some code here and see how it converts it into the older style javascript and i’m not going to cover how to use babel in this course but you should know up front that writing javascript for web browsers requires that you give some careful thought to how your javascript will ultimately be consumed and who your targets are and that definitely means that you’re going to have to take into consideration uh the fact that some people will be using older web browsers writing javascript that will run on a web server using a framework like node.js is a bit easier because well you’re going to have some some upfront knowledge about where that code will ultimately be executed but this is not a course specifically about node.js either even though we’re going to use node.js uh as a as a lightweight means of executing these little tiny javascript examples that we’re going to create throughout this course so you’re going to learn enough about node.js to be able to write a simple tiny application but it won’t do anything cool like serve up a web page however i’m sure there are other courses here on microsoft virtual academy and elsewhere that will help you kind of take that next step so the game plan for this course is to start in the very next video by installing the tools that you’ll need to get started and then we’re going to start with the absolute abcs of javascript and programming in general and i encourage you to follow along by typing in the code that i type in the video and that’s you know typing it yourself is the absolute best way to learn it starts to develop muscle memory you’ll have many of those aha moments where you realize oh i see how these two things are related you can hear it and that’s one thing but to type it in and to see it on your own computer working is something entirely different i highly recommend that you you become an active learner by typing in the code yourself but i encourage you also to pause and rewind the video as many times as you need this isn’t a race you don’t consume these kinds of videos the same way you would watch a tv show a movie or a youtube video if something’s not clear to you don’t just let it go in one ear and out the other and worry and say i’ll figure it out later no stop down and figure it out now because you never know it might be something foundational you’ll need to know uh in the next lesson and the next lesson but by the end of this course you’re going to be well positioned to move on to a more advanced javascript course to learn how to use modern client frameworks like react and view and angular or you’ll be well positioned to learn more about server-side framework libraries frameworks and libraries like node.js and express.js and others but no matter what you’re going to have a great foundation to build on if something i say doesn’t make sense again i can’t stress this enough seek out other sources online and you’re going to ultimately want to know something from me i’ve recorded enough of these courses i know the questions that are already coming you’re going to ask me if there’s a book that goes along with this course that i could recommend and i’m sorry i don’t really have a specific recommendation honestly my recommendation is that you exhaust the dozens if not hundreds of javascript online resources uh where you can simply use them for free and find them in an instant uh if you want to get more explanation about any given idea that are that’s covered in this course okay so let’s go and get started i want to encourage you to take your time don’t feel overwhelmed stick with javascript stick with this course and you’re going to be well rewarded i promise it’ll be more difficult than playing a video game then watching a movie or reading a book but i promise you you’re gonna wind up enjoying it even more than any of those things even if i wasn’t paid to write code i would do it because it’s fun it’s mentally challenging and you get this rush whenever you you write code and you see it working and you’re like wow this is awesome so i’m glad you’re going to get an opportunity to do that it’s the most fun you’re going to have on a computer i promise and you’ll you’ll wind up enjoying it so stick stick with it and i’ll try to encourage you along the way all right so we’ll get started in the next video see you there thanks all right so let’s get started uh we’re going to install the tools that we’re going to need for the remainder of this course fortunately we don’t need a lot and everything is free and everything i show you will work regardle regardless of which operating system you currently have installed so uh regardless of whether you’re using windows mac or linux everything i show you will be available for those platforms the first thing we’re going to need is a web browser i’m pretty sure you already have one of those installed any will do i would probably recommend that you either use microsoft edge or you use uh google chrome the second tool that we’re going to need to install is node it is the the javascript runtime it’s what will actually execute the code that we write and we’ll talk about that more in just a moment and then we’re going to need an authoring tool something where we can actually type the code in now in the past i’ve used notepad to actually demonstrate because i didn’t want to like you know recommend one tool over the other but then microsoft came out with visual studio code it’s available on uh all three platforms so it’s also available for free so no matter what you’re using you should be able to download and follow along now you may already have a favorite tool for creating web pages and so forth feel free to use that i’m not going to do anything that’s so visual studio code specific that it will exclude you please follow along no matter what tool you prefer but let me put in a good plug for visual studio code i’ve been using it pretty much as one of my exclusive tools in my full-time job for the last three months and uh it’s it’s really good so i highly recommend it let’s get started we’re going to need node and you may already have node installed so let’s just see if you do or not let’s go and in windows i’m going to open up a command prompt and i’m going to type in node dash v if i had node installed it would display the version of node that i currently have installed i don’t have node installed on this computer so i get an error message that’s good so to begin we’re going to go to node js i can type there we go nodejs.org and again regardless of which operating system you’re using you should be presented with an opportunity to download either the supported version or the current version which has like the latest features you don’t need that just just use the lts version which is recommended for most users as long as you’re using the version that i’m using or greater we should always be in sync again we’re not going to use any really advanced features of node so this shouldn’t really matter much i’m going to go ahead and run it run the installer here what you see next depending on which operating system you’re using uh will you may see something a little bit different than what i see on screen but hopefully you’ve installed things frequently enough that you can work your way through it so here we have the node js setup wizard and i’ll just walk my way through agree to the license i’m going to pick a place on my hard drive to install this there are some options i’m not going to really do much of anything but i do want to make sure that in windows that this is added to my path this will make sure that node is available in any directory of my hard drive so when i type in node v from anywhere in my command prompt it’ll it’ll pop up okay so just make sure that everything is selected you’ll be fine it’s not that large next i’m going to have to agree to windows uac you might see something different here on the mac or linux i’m going to go ahead and agree to that little security prompt and it only takes a minute or two to install node and then we’ll move on but basically node in a nutshell is uh the v8 javascript engine that they ripped out of chrome they added some tooling around it to support things for like http working with with requests and responses and with the file system and they created one of the most robust web server tools that is available today and many large applications are using node currently to host their applications we’re not going to use it for that we’re going to use it for something much more mundane which is to really just write out little text messages to a console window as we get started then we’ll graduate on and use it in web pages much later in this course all right so i should have it installed right so i come over here and it still says it’s not installed i’m going to have to reboot my computer so let’s pause i’m going to pause the recording of the video right here i’m going to reboot and then when i come back in we should be able to move on from there all right so i’ve rebooted let’s open up a command prompt type in node v and i can see the version number so we’re successful the next step is to install visual studio code visual studio code is different than the full version of visual studio so visual studio community professional or enterprise visual studio code is a lighter weight code editor mainly used for web development but i know people that use it to develop c-sharp applications and other type of of applications where you can uh use the the command line tools to compile your code and things of that nature that’s not something i would ever want to do it’s great for web development and that’s what we’re going to use it for for authoring our javascript files and then executing node commands in a built-in little command window command prompt like we see there again available for all uh operating systems you just go to code.visualstudio.com it should be able to detect which operating system you’re currently using and it gives you a download option for that all right and we’re going to go ahead and run it in place again windows uac prompts me to make sure that i am authorized to install it we get to the to the code setup wizard i’m going to go ahead and accept the agreement and we’re going to work our way through the defaults sure and you can see that we can also add visual studio code to the path which will become available after restart i don’t need that necessarily for this course but hey you know it doesn’t hurt in fact let’s go ahead and use it for everything here that’s up to you you can read those options and choose what you want but for my purposes this will work just great and we’ll see throughout this course some of the things that visual studio code will do for us as we’re typing our our code simple things like uh like code coloring and code completion managing our files giving us an environment to execute command line tools like the node command line tool and there are many things like that intellisense others that will give us the tools to to hopefully allow us to author our javascript code accurately so let’s go ahead and launch it and let’s just do what i call a quick smoke test and we don’t need get for this course i’m just going to hit close on that so what we’ll do is go to the explorer it’s the little icon in the upper left hand corner here let me kind of pull this out and make this a little bit sized a little bit more nicely here i’m going to close down the welcome screen i am going to click open folder and i’m going to go on for me i’m going to go to my c drive and i’m going to create a source folder now depending on your operating system or what your preferences are you may want to create a folder somewhere else but create a folder because we’re going to put some some javascript files and later some html and css files in that folder and we’re going to want a folder structure so right here in the open folder dialog i’m going to right click and select new folder i’m going to call this source lowercase s and source and then select that folder now that becomes the working folder that i’m going to use to add additional files and and all the work that we do for this course inside of there here it doesn’t really wants me to put get install get and i don’t want to do that what i really want to do is go to terminal all right and depending on which operating system isn’t you’re installed on you might see something different here in windows you see powershell doesn’t really matter as long as you get a command prompt and here i’m going to type node v and i can see that that’s awesome and then what i want to do is add a file inside of this folder this working folder so i’m going to click on this little file with the plus symbol in the upper left hand corner i’m going to type in app.js and it opens up a new file here in the main area with a little js icon right next to it and here i’m going to type all lowercase console.log hi i’m gonna go to the end and hit a semicolon so let’s kind of walk through this the word console a period on your keyboard the word log log and then an opening and closing parentheses inside of there i want to put an opening single quote mark and a closing single quote mark and then some word i put hi you could put your first name it it really doesn’t matter but what does matter to me at least is that you end it with a semicolon and as you’re going to come to learn writing code is an exercise in precision if you don’t write exactly what i write there’s a chance that you will not get the results that i get and so you want to double check and make sure there’s not extra spaces you want to double check to make sure that you’re using the right characters like this is not a comma it is the period on the keyboard all right this is not a curly brace it is a parenthesis this is not a double quote although that would be acceptable in this particular situation i would prefer if you use the single quote which is on the same key you just have to hold down the shift key all right to get to it all right so now i’m going to use control s on my keyboard to save or it might be command s if you’re on the mac or something else on linux i don’t know whatever you you use or you can just go file save all right now watch what happens when i just use the space bar on the keyboard did you notice see that little symbol there it went from x to a circle that means that file has not been saved yet that change that i made is not saved so here again i’m going to use the keyboard shortcut to save it then i’ll come back down here into the terminal now how can i do this easily well on windows the keyboard shortcut is control and then the back tick that’s usually next to the number one kind of to the left of it on most keyboards so the back tick will close and open up that little terminal window at the bottom and now i can type in node space and then i want to use the name of this file so app dot js and hit enter on my keyboard and it should print out that word hi that i have inside of those two single quote marks in console.log all right now we can also shorten this up node space app we don’t have to use the file extension and it will work as well all right so assuming that you were able to follow along and you got to this step then you’re ready to move forward and we’re ready to get started actually writing some javascript let’s start that process in the next video we’ll see you there thanks so our job as software developers is to author code which is using a language that’s human readable and author in such a way that can be understood and parsed and interpreted and ultimately then executed by a computer and the code that we write we save into files and we ask we ask some execution environment whether it be a web browser or in this case node to to take a look at this this code that we wrote in this file and to interpret it and to execute it all right and so it’s important first of all as we get started understand that how our code is going to be used we’re working and learning the javascript language but ultimately the code that we write will be executed in let’s be honest one of two maybe even a third environment we’re either going to write javascript code that will ultimately be executed in node and typically when we’re writing code for node-based applications we’re writing applications that we can access the file system access the network respond to http requests and provide an http response things that are more server-side in nature all right and then we’ll also then write javascript code that will execute in the context of a web browser and we would expect for that code to be able to dynamically interact with um with elements html elements on a given web page all right but we might also use javascript to uh to write video games in an environment like unity for example and be able to author and control the various objects on screen and their animation and and their interaction and so on so there’s what i’m trying to get at here is that there’s a difference between the language itself and then the environment that it runs inside of and we need to be aware of that that those are two separate things even though sometimes they feel like one thing in this case console for example the console.log function is provided to us by node it allows us to tell node that we want to print something to the command line like we did just a moment ago now there’s also a console.log function in most web browsers and it allows us to print little debugging messages or console messages that can only be viewed inside of a web browser whenever we have the developer tools open and we’ll see how to do that much later in this course once we start building uh web pages uh and and javascript that can interact with them but at any rate let’s get back to the matter at hand here if i write my javascript incorrectly then the run time what whether it’s node or a web browser will won’t be able to compile it and it’ll give us an error and so javascript is similar to english in so much that javascript has a syntax and it has a proper syntax versus a syntax that’s incorrect so if you’ve ever taken an english english class you’ll know that there are parts of speech that that you’re supposed to use punctuation at the end of a sentence to indicate the end of a complete thought there are nouns and verbs and adjectives and adverbs and and propositions and all these sorts of things right and so you know in general terms the same thing is true with javascript there are parts of speech we’ll talk about those and so you will be learning a new language starting with your abcs and and with with uh i guess uh vocabulary words so to speak and then to move on to authoring sentences that are complete thoughts and then stringing those sentences together into paragraphs in order to accomplish some higher level task and even kind of arranging those paragraphs together to create entire applications all right so hopefully that analogy will serve you well as we get started here our goal as we get started is to author javascript statements and a statement is basically just one complete instruction it’s like a sentence in english and each javascript file that we create like this app.js it’ll it’ll contain one or more javascript statements that will execute in sequential order from top to bottom at least usually and i’ll talk about the exception of that as we get further into this course but there are some other similarities between javascript and english for example there’s an end of line character i was very very specific about adding that semicolon at the end of of our statement and that just is an indication to the compiler that this is a complete thought and it should be carried out as is all right um now we also see that we have our statement all on one line of code and generally speaking as we’re getting started we’re going to write our javascript statements one per line now we’ll bend those rules as some of our statements become very long we can actually for readability’s sake from a human perspective we can split things up onto multiple lines if we need to javascript specifically node doesn’t really care about that that’s really more for human readability it can deal with multiple lines or a single line for a given statement but be that as it may we’re going to try to strive at the beginning to write one statement per line in our files and a statement usually consists of one or more expressions so uh we’ll talk about expressions a little bit later but this particular expression is essentially just executing a function that’s built into node it’s the log function it belongs to an object called console we’ll talk about objects and functions a little bit later here and we execute it by using operators those in this particular case this is the function invocation operator or the method invocation operator it’s those open and closing parentheses and we can even then pass in what are called arguments to those functions so you can see that each little piece of this has a name and it has a role to play in creating our functions and we’ll learn more about that as we move on here one thing to note is that javascript is case sensitive and this trips up a lot of people to begin with that’s why i was very specific to say hey don’t accidentally or mindlessly use capital letters make sure everything is lowercase let’s see what happens if i were to save this work that i did here with the capital c in console and the capital l and log let’s go node space app and hit enter and we get a reference error console is not defined it’s not defined inside of node console doesn’t exist with a capital c inside of node it exists with a lowercase c inside of node the same thing is true with the function name log let’s go ahead and i’ll just use the up arrow on my keyboard that’ll give me the last command that was used in the in the terminal so again node app and i’m going to try to execute this little program again and i get another error this time console.capital l log is not a function that’s true it’s because it’s lowercase l and log and i’ll save that change and then we’ll re-execute this and it will work now there are some things that especially when your application is small don’t matter so you might have accidentally left off that semicolon at the end and the application still runs but that’s a bad practice to rely on that you should always try to create properly formed sentences even though you could write an english sentence or a text message that somebody could understand that has no punctuation has no capital letters and things of that nature that would make it a well-formed english sentence and you’re you’re relying on your the person receiving that text message to understand what you’re trying to say the computer doesn’t work that way it means it needs to know exactly what you’re saying and so you have to be precise precision is the key as a software developer all right so what i want to do here as we kind of start wrapping things up for this first first foray into javascript i’m going to comment out this line and add some new code below it and use that as kind of the next step beyond where we’re at right now so to uh to tell the compiler to ignore line of code i’m going to add a code comment and here i use two forward slashes i added also a space but that was really just for readability’s sake so that myself as a human i can kind of make an easy distinction because sometimes all these characters run together i like adding a space between this but these two characters say forget everything on this line of code don’t compile it don’t try to use it all right and we’ll see in a moment that there’s another way to create code comments as well but here let’s create something a little bit more interesting i’m going to say let x equal 7 i’m going to say let y equal 3 let z equal x plus y and then we’ll do console.log and then i’m going to use open and close parentheses i’m going to use a single quote i’m going to type in the word answer colon space i’m going to go outside of that quote so it’s i’m going to go between the closing single quote and the closing parenthesis and i’m going to make some space for myself in there i’m going to use the plus key or the plus operator and the letter z i’m going to go to the end of the line and use the end of line character the semicolon i’m gonna save it all now before we actually execute this what do you think this will do what do you think will be printed to our console window do you have any guesses i’m betting that your background in math or algebra probably will lead you to the correct answer and i think that your intuition in many cases is something that’s important as you’re learning javascript it is human readable it should be somewhat understandable it might require a little extra explanation because there’s some things that are not extremely obvious but for the most part this shouldn’t blow you away and nothing we cover should ever blow you away it just might require a little extra effort than you’re normally used to putting into things but by no means impossible right so just take some comfort that this is well traveled ground and that if i can understand it i promise you can too let’s run the application see that we get the the the correct result which is answer colon space and the number 10. so how do we get that well we have something here let x and even though again you’re not a javascript developer you know or an advanced javascript developer just yet i’m willing to bet that you understood that we were creating a variable essentially uh a a bucket that could contain a value and immediately we set that variable equal to the value seven and then we did the same thing with the value of 3 we put that into a different variable a different bucket called y and then here we have an expression an expression that will add two values together what are the values inside of those variables x and y well we just assigned them in lines three and four and we know that that probably means we’re going to add those together to get the result of 10 and we assign that into a new bucket a new variable named z and then we merely print out that literal string but then we also say also append the letter or the value that’s in z now hopefully that made sense to you even before we ran the application but you can see here that for example the plus symbol has has double duty it’s it’s serving to be the addition operator but it’s also serving to concatenate two values together in this case to string values together so that we can print it out to screen so we’re going to use this kind of as a starting point and talk about this at more length in the next and subsequent videos but hopefully up to this point you get some comfort level you’re writing some code you’re getting your hands dirty in the code and you know i know you can do this so just keep pushing forward and let’s pick it up in the next video we’ll see you there thanks in this video i want to continue talking about line number three so that we completely come to a full understanding of what variables are in javascript so i’m going to add a new file and i’m going to do that by hovering over the source tab of the explorer and i want to type in variables.js like so and then i’m just going to copy in the code that we had here we’ll use this as a starting point all right so let’s focus in on line number one let’s just first of all let’s make sure this still runs and let’s go node and this time we’re going to give the new file name variables and we get the same result as before great so what is a variable i think i said at the very end of that previous lesson is that a variable is basically just a a an area in the computer’s memory where we’re storing a value we’re requesting or declaring our need for a new variable a space in the computer’s memory where we can put information and retrieve information and then we can from that point on continue to use that variable to to store different values and retrieve those values back out throughout the the life span of the application so there are actually several different parts to the variable declaration statement in line number one the first is the let keyword uh and let’s start start talking about the parts of speech in javascript a keyword is something like let and we’ll see some other examples a little bit later but essentially think of it like a verb in the english language it’s a it’s an instruction to the javascript compiler that we want to do something that we want to take action so we want to create a variable with the name of x and we’re expressing that intent to javascript using the let keyword all right so that’s the first part of it and then the second part is the name of the variable that we want so we’re requesting that a area of storage uh a unit of storage is assigned to our application that where we can put things but how do we reference that again it needs a name so that we can get the values and put new values in memory all right and so that’s usually called an identifier we want to declare a new variable with the identifier of x and we’re going to talk about naming our identifiers naming our variables there’s some rules and some conventions that we need to follow as developers all right we’ll come back to that at the very end of this lesson now before we get too far there’s actually a couple of different ways to to declare a variable in javascript the original keyword that you’ll see used and used in 99 of all tutorials and articles and books and videos is the var keyword and until recently this was the only way that you could declare a variable in the latest version of javascript however the recommendation is to abandon var unless you really need it use the let keyword instead or the const keyword which we’ll talk about in just a moment if we were to save our application using the var keyword in line number one and then rerun it nothing would change so what’s the problem with var there are some well i guess there’s there’s two ways to to kind of explain it at this point the first is that its usage is very nuanced it does stuff that somebody new to javascript may not anticipate the ramifications of until it’s too late and there are problems in code we’ll talk about the var keyword and how it relates to scope and so on uh in an upcoming video but we need to introduce some more concepts before we can get to the point where that discussion is even interesting okay so it’s usage is nuanced and the ramifications can be uh pretty challenging uh if you’re just getting started so that’s why the people who decided what goes into javascript said why don’t we introduce a new keyword called let it will work like most other programming languages as you try to learn javascript hopefully it won’t be problematic so that’s why we have the let keyword the other uh the other keyword for declaring a variable is const and we use that whenever we want to express our intent to the javascript compiler that we do not intend for that variable to ever change its value so what we initialize the value to in this case to seven we wouldn’t expect that to change throughout the lifetime of the application and if we try to change it like in the very next line of code we can attempt to set it equal to six i’ll save that let’s go over and try to run that code we’re going to get an error and it actually is pretty helpful it gives a little a little carrot right underneath the equal sign and it says assignment to constant variable that’s the problem and and the issue here is that we’ve said to javascript we never want to change that value and then the very next line of code we say yeah i’m going to assign it a new value and set it equal to six and it says can’t do that okay so for the most part we’re going to use the let keyword most of the time because that’s the recommendation now in as we learn javascript all right so uh just want to point out that we can uncomment out line number two as we assign the value of x to different values and we can keep doing this as many times we want to so at this point in line number one we’ve declared the variable set it to the seven then we’ve assigned the value of six then five then four we can keep changing the value in the computer’s memory uh and what is the value in line number six what’s x’s value well the last time we assigned a value to it was four so uh the application now whenever we run it will give us seven because three plus four equals seven right so that’s what we get in line number seven great all right so uh i guess this should be obvious at this point the equal sign here is actually what’s called an assignment operator this is how we assign a value into a variable and we can keep assigning values as many times we want but we can only declare value our variable one time so if i were to try and come down here and say let x equals you know seven again or let it equal eight i’m going to get an error whenever i try to run the application the identifier x has already been declared again you can only declare a variable once but you can assign its value as many times as you want to after that all right so in line number one not only are we declaring the variable then we’re also assigning its value right off the bat in the same line of code and when we do that it’s a technique called initialization this is actually two lines of code rolled up into one lines number one and two now are roughly equivalent to what we had before well roughly equivalent there is one difference here at the end of the execution of line number one what is the value of x well let’s let’s find out console.log and we’ll just say what’s the value of x at this point and then let’s run the application and you can see that first value that’s output above what we get now in line number 11 is the term undefined we’ll explain what undefined means in more detail a little bit later but essentially it is what it sounds like we’ve declared a variable but we’ve not defined it we’ve not put a value into it so it’s undefined all right and that’s generally not something we want it might be in some cases something we need uh but for the most part we won’t do that it’s preferable that at the moment of declaration you also in uh initialize your variables if you can alright so that would be valid right there um all right so now let’s finish this up and talk about the rules for naming our variables the variable name itself i think i’ve already referred to this as an identifier and so there are rules for identifier names and then there are some code conventions and these are not enforced by the javascript compiler but are rather things that are best practices as determined by the community of software developers who’ve come before you so let’s talk about those things which are hard and fast rules that will actually break your application rule number one is that all identifiers all variable names have to begin with either a letter a dollar sign or an underscore so that’s rule number one rule number two is that the variable names can contain letters or numbers dollar signs or underscores but no other special characters and you can’t use a space uh in between you know two words that you intend to be considered together as an identifier identifier can’t have any spaces all right and then rule number three is that you can’t use any keywords so i can’t do something like this let let equal to eight maybe if we try that we’re going to get a weird error let is disallowed as a lexically bound name all right and so it even if we were to scroll just a tiny bit it puts that those carrots right underneath the let the second one because we’re trying to use that identifier but it’s already a keyword right so you can’t do that all right so those are your own oh yeah there’s one other rule and that is that variables variable names identifiers are case sensitive so we could do this and it would be a perfectly acceptable application these are two different variables uppercase x and lowercase x so if you intend to do something like this let’s see what we get here all right it doesn’t it doesn’t blow up so we were able to use x and assign it to 8 but we didn’t declare the variable well something fishy is going on and we’ll get to the bottom of it before the end of this course but the key to this is that we did not we’re not working with the same x as we’re working with here all right so let’s just get rid of that but those are the rules has to begin with the letter a dollar sign or underscore the rest of the name can have pretty much anything including numbers but no spaces or other special characters can’t use any keywords for names of variables and uh be aware that uh variable names are case sensitive now there are code conventions and these again are just good practices the first one is that variable names should be descriptive and unfortunately uh x y and z are not very descriptive names ideally we would use something like maybe um let’s go down here so let uh first number equals seven and then let second number equals three and then we could use that in line number 12 instead here’s some better ones actually like if we wanted to capture information or represent information like the first name or let zip code and so on all right so use names that represent the thing you’re trying to store and it from an application perspective what meaning does this variable have inside of our application meaningful variable names the second is camel casing so if you are going to use multiple words you should use this format called camel casing and that means that the first word of your variable name should be lowercase so the f in first is always lowercase but then any subsequent names that we appen or words that we append together should have a capital letter so you can see that i followed this convention every single time in lines 15 through 18. lowercase z and zip code capital c in zip code all right so camel casing third one is to be consistent and that is to always follow the same kind of naming convention and this would be true kind of across not just the names of variable names but for every other type of identifier that we wind up creating in our application stay consistent pick one style and stay with it throughout the remainder of the application and then the other is to not rely on case we’ve already seen the danger of that but what if i intentionally wanted to let zip code equals 60459 what we’ve just done while it’s grammatically correct from javascript’s perspective and those are two separate variables in line 18 and 20. we’ve introduced some subtle um dissonance in the application now it’s more difficult for me to see that these are actually two different variables and maybe i intended to do that but that’s poor programming practice we might choose uh maybe a better name like first zip code and second zip code that might be a better way to go about that same sort of thing okay so those are the code conventions and the naming rules for variables and that’s just about everything you need to know about variables just about there’s actually a little bit more that we need to talk about and we’ll finish up this discussion in the next in the next video when we talk about the values that we’re actually signing into variables and their data types and we’ll talk about that next see you there thanks in this video we’re going to talk about the values that we store in variables and we’re going to talk about the types or rather the data types of those values and why they’re important so to begin with let’s go ahead and create a new file called datatypes.js and this is where we’re going to do all of our work and one of the things that makes javascript so unique when compared to other programming languages is that whenever you declare a variable like we do here let x equal 7 [Music] the variable itself does not have a data type only the values that we store inside the variables have the data type so we kind of see this whenever we’re working with variables we can use something called the type of operator and this will tell us the data type that we’re working with so well let’s go ahead and go back to here let x equals seven so let’s start off by just doing console.log and then we’ll say type of all one word lowercase and then x and let’s save that save it and uh here i’m going to type node and then data types and you’ll see that it outputs a number so that’s one of the first data types the x data type is a number and a data type is really just the kind of data that we want to store so if you want to perform math or some algebraic operation then you want to use a number and if you want to do a yes or no true or false uh evaluation then you’ll want to use a boolean and if you want to display something on screen then you’ll want to use a string which is basically a shorthand for string of characters and you usually represent those with single quotes with whatever string of characters you want to uh to use inside of it so let me give you a few examples here we’ve already looked at number let y equal true and so then we’ll do console.log type of y and then i’ll just go ahead and do z as well let z equals hello world and then console.log z whoops not to z i want type of z all right and so now let’s go ahead and run this and we can see that we get the three data types that we’re currently working with a number a boolean and a string so in the case of a number it can be any positive or negative number it can even have decimal values in the case of a boolean it can either be true or it can be false those are the only two values and then if we want to create a string it’s going to be anything inside of the single quotes it’s a literal string of characters but i literally want h-e-l-l-o space w-o-r-l-d all right and so those are your three of your seven basic um basic types data types there’s also another case let’s let a and then console.log the value of a and then console.log type of a all right and just to remove the confusion here i’m going to use a multi-line comment this allows me to avoid having to do this on every line right i can just do this little slash star at the top then go down to the bottom of where i want to comment out and then star slash you can see everything that’s highlighted in green or or turned to the green color is now commented out just as if i had commented out each individual line separately so here i’m just creating a variable a but i’m not initializing it to a value remember we saw do you remember what it output when we did this before it output the value undefined but we want to see what the type is because we said that it’s the the value that’s assigned to the variable that has a type so what is the type of a variable that has nothing assigned to it well that’s what we’re going to get to the bottom of right now so we see that the value is undefined and the type is undefined so now we have four types we have number boolean string and undefined and there’s two or three others that we’re going to look at here before the uh before the very end we’ll get to them they’re a little bit more complex but those are the four that we have to work with at least to start off with and so that’s all i really wanted to say the next thing we’re going to talk about very quickly is how i would convert one type into another type how do i force javascript to treat a string like this console.log and then a literal string of the value nine how do i make it treat it like the number nine well we’ll talk about that in the next video we’ll see there thanks in the previous video we learned that values not variables have a data type and that the data type is essentially a description of what you want to do with the data there’s more to it than that but for our purposes right now it’s essentially what we intend to do with the data and we learned of four data types and we’ll learn about a couple more a little bit later there’s the number data type the string the bool and the undefined so let me ask you this what happens when we need to use them together and they don’t quite work the way that we think they should what options do we have then so let’s go ahead and create a new file i’m going to call this coercion c-o-e-r-c-i-o-n dot js i think that’s how you spell it and uh let’s start off with a quick little example here so let a equal seven let b equals the string the literal string so i want to use single quote 6 single quote all right and then let c equals a plus b and then console.log answer and then c all right before we execute this application what do you think is going to be output uh when we run it what will the answer be all right get that in your mind and now let’s go node and coercion and uh looks like we don’t get anything at all oh i need to save it okay there we go let’s try that again there we go we get the answer 7 6. wait 7 plus 6 should be 13 right why are we getting 76 something i can see what’s happening it’s not treating these as to numeric values it’s treating them both as string values so it’s not adding two numbers together somehow it’s coercing that a from a string in from an integer into a string and then concatenating together a and b so this operator the plus operator we saw how we can use it for addition but we also it plays double duty and it’s the string concatenation operator but moreover javascript realizes that it can’t add a a number and a string those are it’s like adding you know an apple and a car together it’s not like making an apple and an orange even these it’s not like fruit salad it’s like two disparately different things what do i do well i will i will take the numeric value and coerce it convince it force it against its will to become a string and then i will concatenate the two together so that’s the notion of coercion and most people consider that to be an evil thing or a very dangerous thing and others just say well it’s just what happens you know it’s just part of the language now what if i really wanted to perform addition on two integers well then i would need to take steps to force the string six to become a number so that i could then add them together and so to do that there’s actually a special function that will force that conversion so let me uh change this just a little bit and um we already have the value b so i’ll just reuse the value b and i’ll set b equal to parse int now i want you to notice something i haven’t really talked about visual studio code much but one of the nice things about visual studio code is that it popped up this little box called intellisense and intellisense is just a visual cue as i’m typing to show me things that i might need to reference or things that will help me to to find the right command or the right idea in this case i knew it was something parse so i start typing in and i can then use the arrow keys to start looking i’m like oh yeah there’s po parse float that would give me a number with decimal values but this in this case the the string that i want to use i know that it will only be a value without without any decimal point so i want to use the parse int now what i can do is just use the space bar or like the opening parenthesis whatever the next logical character is to do what’s called code completion so i don’t have to type everything else now in this case i know that i’m going to need to use the parentheses for reasons i’ll talk about later so i’m just going to do an open parenthesis well it didn’t do it for me well there we let’s just go ahead and [Music] use the tab key instead all right so the tab key will give me what i want now i’m inside the the parentheses that i need to pass in first of all the string that i want to change so in this case take the value of b and then i need to give it optionally what’s called a radix or radix and that is essentially the base system so if i wanted to um to use like a hexadecimal i might give 6 but in this case i’m going to give it 10 because i want to be a base 10 or a decimal conversion all right so that’s a little technical but typically if we use 10 in there we’re going to be just fine so essentially what i want to do is take this 6 and based on the normal decimal system i want to convert that into a numeric value and then i want to continue on in lines four and five like we had before let’s see what we get this time the answer is 13 just as we had hoped all right so the parseint is a built-in function to javascript and i can count on it being available in node or in a web browser or any other implementation of javascript all right so i guess this begs the question what if i try to do something kind of evil with this so let d equal uh parse int and then i’ll use the tab key to do the code completion and this time i’m going to pass in a character that will not convert to a or or even a string that will not convert into a numeric value especially one that’s decimal so i’m going to save this well let’s go ahead and console.log it and d so let’s go that and then we’ll do this all right and i get n a n which represents not a number it’s not really an error it’s just telling us that the value we passed in is not a number um we could actually do something along these lines as well um let e equals is n a n and then i can give it some numeric value in this case i’ll give a d and i’ll do console.log e so let’s save that run it again and so this time now i’m evaluating whether d is not a number and that is true it is not a number because i can see it here that’s printed out all right so we saw two built-in functions but there’s a bunch of built-in functions for various things all kind of centered around in this case just working with coercion and checking the results of that attempt to to coerce or or convert one data type into another all right unfortunately there’s no parse boolean so you can’t take a string of true or false and convert it into a boolean you’ll have to take a few extra steps there’s a bunch of of examples online for that and so depending on the type of conversion that you’re attempting to to perform it may not be easy to convert from one to the other there’s always a way and usually you can find some code online especially on a site like stack overflow that will help you figure that out but that’s all i wanted to say let’s continue on the next video we’ll see you there thanks in this video i want to refocus on the javascript syntax specifically and the various parts of speech inside of a properly formed statement in javascript so i started by explaining javascript by saying that you write statements each of which are executed sequentially and statements are complete thoughts complete instructions to the javascript compiler of what we want it to do for us and i said the statements are made up of one or more expressions and that an expression is made up of operators and operands and i just made that statement in passing and kind of blew past it really quickly but i wanted to take a few moments and explain why that is an important statement whenever we’re setting out to write code and so we’ve already looked at a couple of different operators if we’re thinking about the most atomic level of our javascript statements we’re thinking about in terms of operators and operands so operators are things like keywords we’ve already looked at the addition operator using the plus symbol we looked at the string concatenation operator using the plus symbol so that one is doing double duty and it will be understood based on the context of how it’s being used and then there’s the assignment operator the equal sign that we’ve already looked at and soon we’re going to look at a few other common ones just to start building out a list of operators that we can use to do more interesting things inside of our application but there’s also an operand so operators are things like keywords and those various symbols that we’ve already looked at and we’ll add more operands are something like identifiers a variable name we’ll we’ll learn about functions soon and functions are another type of operand and so unlike keywords and operators in javascript which are fixed and part of the language we you and i programmers give operands their name and so by combining operators and operands we create expressions that are then used to compose statements and so sometimes it’s easy to spot an expression and then sometimes it’s not so easy but identifying several major categories of expressions we can better understand why javascript works sometimes and why it doesn’t work sometimes so for example in the english language we cannot write a sentence a proper sentence like this the dog period if we’ve said hey uh the dog some our friend would say what are you talking about the dog did what which dog you know give me some more information right why is that not a proper sentence in english because it didn’t have enough inside of it to be considered uh proper we have a noun we have the dog but we don’t have any verbs or adjectives or adverbs describing or or um you know kind of giving us more detail about the dog the same thing is true with javascript so we can’t for example let me just create a quick file here we’ll call this expressions.js so we cannot do something like this in our program right uh because the javascript compiler will say okay what do you want me to do with that uh that makes no sense to me whatsoever i don’t know what you want me to do with a i don’t see it it’s not one of my variables you’re not asking me to create a new variable there’s nothing inside of a a means nothing to me all right so at a minimum we’re going to need to either and these are the types of expressions in a very high level we’re going to either declare a variable so we would do something like this once again let a all right and even in this little tiny um two word line of code there’s already an operator and an operand here’s the operator the let keyword and here’s the operand a name we want to give to a new variable that will be created in memory all right so that’s one type of expression we’re going to call this types of expression here we’ll just use some comments types of expressions [Music] number one variable declaration i think i spelled that right all right so let’s go ahead and just move that up to the very top and say this is bad uh and then we’ll do something like this i kind of like doing some ascii art there whenever i create lists inside of my code all right so there we go the other one is to assign a value so the other type of expression we can assign a value so a equals three or four uh and then another type of expression is to perform an evaluation that returns a single value and so that might be something like and if we’re talking purely about the expression itself it might be something like that b plus c so in a more interesting example uh we might do something along these lines um and i’ll just comment this out because i want to reuse a there we go good all right so here we go line number 16 i’m going to go let b equals 3 let c equal 2 and then let a equal b plus c i just want to focus on line number 19 and i want to say that there are three expressions in here can you find them all right well let’s identify them so number one we’re gonna see that uh let a so that’s a variable declaration the next thing that’s going to happen is we’re going to perform an evaluation of b plus c right and that will basically add those two values together because we’re using the addition operator and then finally we’ll do um the result of b plus c is assigned to a so three expressions all combined into a single statement and there’s a lot more going on than meets the eye but that is the kind of thinking that will help you understand why your javascript code works sometimes and sometimes it doesn’t you have to think in terms of writing expressions that do things to form properly formed javascript statements all right so hopefully that little lesson in syntax is helpful let’s talk about operators and the different types of operators and again we’ve used this collection of five or six operators so far let’s let’s add to that collection i’m gonna go create a new file called operators dot js [Music] and so um there are several categories [Music] of operators and i’ll just kind of go through them really quickly here so there’s assignment like the equal sign it’s really the only one in this category but it’s a pretty important one we’ve seen it use quite a bit there’s maybe some other keywords and things that can fall into this category sort of but the assignment operator is usually the only one in this category and there’s arithmetic with which as you might uh suppose would allow you to do mathematical style operations so that’s the plus where we’re adding two numbers together subtraction multiplication that’s the asterisk key over the eight on most keyboards um there’s also the division all right and then there are some special ones like um let’s call these and i’ll they’re kind of arithmetic but i’m gonna call them increment decrement so this is the plus plus and the minus minus and used out of context these don’t seem so interesting but what we could do is for example um let’s go var a equals one a plus plus and then console.log a all right let’s save that and then go over to our terminal and i’m going to do node operators all right and so you can see that we increment the value of a so let’s do this let’s now increment it one more time and see and let’s save our work here and then let’s run it again and wait a second the value is still two how is that possible let’s do this console log a like that so now we’re going to print the value out twice we’re going to print it out i thought maybe we would get three but we didn’t but if we print it out a second time let’s see what value we get and so when we print it out the second time we get three and the reason is this because this operator this increment operator works after the line or after the value is already utilized inside of this line of code so basically hey console.log here’s a and after you print that to screen then let’s add something to it that’s why we’re able to see the new value if i print it a second time all right what we may have preferred instead of this is to go console.log and put the plus plus before the a that means i want you to first evaluate the increment of a and then print it to the console.log all right so let’s save that let’s rerun this and now we see three in both cases the same would be true with the decrement where we could subtract either before or after the evaluation of that variable all right just something to keep in mind all right so that’s increment and decrement um there’s also going back to arithmetic there’s the modulus and this will give me uh the the remainder amount so let’s go var m for modulus equals 10 divided by whoops whoops whoops that’s not what i wanted 10 modulus 3 and then i want to console.log m and just to kind of keep everything clean i’m going to comment out all this as well keep it around for posterity but otherwise that’s all i want to see what will i get back from this this statement and i get one what is one it’s the remainder so 10 divided by three equals three with one left over that one is the modulus all right and actually this becomes a lot more interesting and important when we’re looping through lots of values and every like 10th or 20th or 100th item i want to print a little message to screen to say hey we finished processing the the 10th the 20th the 30th the 40th the 50th item all right and i use that actually frequently so i’m a pretty big fan of modulus let’s comment that out so uh moving on to the different categories of operators uh let’s talk about the various string operators and we’ve already seen these so this is going to be like the literal string operator we’re using single quotes and then also we saw the string concatenation operator that will take two strings and and allow them to be appended together to create one new string other operators precedence so we might uh you know order of operations we actually use this quite a bit um even in non-mathematical situations so for example um let’s just do var b equals 1 plus 2 times 3. now if you’re coming from an algebra background there’s an order of operations where things should be done in a certain order and i’m pretty sure if memory serves me correctly it’s been a long time since i’ve had an algebra course but you perform algebra before you perform addition so if i were to do a console.log here i would expect b to output two times three plus one so that would be seven let’s see if my my memory serves me correctly here and yes it does but what if that’s not what i want well i can use just like in algebra i can use parentheses to kind of control the order in which things are evaluated so in this case i would do 1 plus 2 first and then multiply that by 3 which will give me a completely different result of nine because three times three equals nine okay so we’ll use this uh the um the opening and closing parentheses for different purposes uh for example um whenever we want to do console.log these parentheses are also used as the um the function invocation operators all right and that just says here’s a function name called log and we’ll learn about functions soon but i want to actually invoke the function now and i can even use the function invocation operators the opening close parentheses to pass in arguments we’ll talk about that a little bit later but again that is the open and closed parentheses um there are other operators and i’ll just put them here they may not make a lot of sense at the moment but they will soon when we look at decision statements so there’s the logical if i’m sorry the logical and in the logical or okay so when i want to add two things together and evaluate two things together either one of them needs to be true or both of them needs to be true and we’ll look at that in in a little while there’s also the member accessor operator so when we did console dot log if you look at intellisense as i hit the dot on the keyboard there’s that period why are we using a period there that allows me to access the various members of this object and we’ll talk about object and we’ll talk about properties and functions or methods of objects soon but that’s what allows me to access the log function of the console object inside of javascript so here again comment that out but we’ll use the period for that purpose we’re going to also look at the code block operator soon and so you know i’m going through all these i’m saying hey we’ll look at these soon really the point of this exercise is to say that there’s lots of operators and we’re going to have to begin to identify what all these special characters are and the only way to do that is to first of all learn that they exist what their function is and then use them as we’re writing programs and so i think that’s really the only thing i wanted to say i mean let me just put one more in here the array element access operator goes by different names but i’m just going to use that and so we’ll use square brackets for that purpose so almost every single character the special characters that are above our numeric values and we can access using the shift key and the various ones that are usually on the right hand side of the keyboard the various braces and brackets and colons and semicolons and and all these are are are used to um for various purposes in javascript uh and in most programming languages all right so i think that’s all i really want to say uh let’s pick back up in the next video you’re doing great hang in there with me we’re getting through uh some of the easy stuff and we’re gonna start moving on to some challenging stuff here really quick but you’re doing great see you in the next video thanks up till now each variable that we create can store one value at a time per variable but what if we need to work with lists of data in other words i need to keep track of several people or several numbers and i need to store them in such a way that it doesn’t matter if i have 2 or 10 or 100 i can kind of keep them together and move them all around and use them in my application as a list as a grouping of related values in that case i want to create an array and so let’s start by creating a file called arrays dot js and first of all it’s basically an array is basically a variable that can hold many different values and so we can declare variable and initialize its value like so so here we’ll do let a equals and here we’re going to use an opening and closing square brace or bracket and then i’m going to give it a series of values each value will be separated by a comma for 8 let’s say 15 16 23 and 42 all right and so now i have an array of those values now these are just numeric values what if i wanted to create an array of string values i can do something similar in fact i can use any data type inside of here that’s allowable in javascript and we’ll see some examples of that a little bit later but i might want david eddie alex and michael all right and then what if i want to get one of the the values i can just do console.log all right inside of here i’m going to use the variable name so in this case i’ll use a and then i want to provide a index to retrieve one of the elements so each of these is an element of the array and i want to use an index a numeric value that that allows me to get at one of those elements inside of the array the indexes are zero base that trips up beginners sometimes uh you for example to get at the number four the first element in the array i would use the index zero if i want the second item in the array the second element of the array i would need to use the index one and so on so to get at it i’m going to use a and then right next to the a square brackets and then i’m going to give it an index so here we’ll grab the first value and then i’ll grab the second value and then i want to do show you how console.log will just print out all of the values for you nicely if you just want to give it the name of the of the array itself the the variable itself so let’s save our work and um we’ll go node arrays all right so you can see the first element of the array at index 0 gives us the value 4. the second element of the array at index one gives us the value eight all right hope you can see the correlation there or if i just want to print out all the values in the array i can just provide the variable name that contains the array and it will print them all off for me just like i have kind of here when i actually initialized our array variable all right let’s comment this out now that is how we access individual elements what if i wanted to change or set the value of one of the elements the same would work so in this case i would say for example a0 and i would set it equal to 7 like so and so then we can just do console.log like so and then we run our application now you see the first element of the array has been changed from 4 to 7 because that’s how we can access a single element and assign it a new value all right all right so um what about these mysterious uh these mysterious arrays what is their data type so let’s do console.log type of a and [Music] we can see that it’s of type object and we’ll talk about the object data type later because there’s a lot more to it than just being able to create arrays but it’s a little bit more advanced at this point we’ll get into it soon just keep in mind that an array isn’t a data type of itself it is a type of something called object and we’ll talk about objects later all right um so the other thing that’s important to remember is that a array can can include elements of different data types so let me just do let c equals um [Music] we’ll start it with four and then we’ll do alex and then we’ll do true all right so we’ve used three different data types right there and we can just do uh node arrays oh i need to actually do a console.log c there we go there we go all right so you can see that a single array can hold different data types there’s no restriction there let’s comment that out what happens if i try to access an element that within with a index that does not exist so let’s do console.log and i happen to know that the b has four different elements in it four names and let me try to access the fifth element by using the index four and this will be undefined so just like a variable without any value assigned to it is undefined so is a element of an array undefined if we don’t give it a value now i can also just programmatically determine the number of elements in an array by using a special property called length so i can do console.log a dot and remember the dot is the member access operator so arrays are objects and this particular object has a special property called length which will give me the number of elements in that array so i would expect to see let’s see one two three four five six so the question is is it going to give us six the actual number uh or is it going to give it us to it in a zero based fashion and the answer to that is that it will give us the actual number not zero based and this will come into uh into play a little bit later when we use the length of an array and we uh iterate through each element of the array to print them to screen when we learn about looping all right so just keep that in the back your mind now there’s a lot of strange things that you can do with with arrays and some of them are not always intuitive like for example if i wanted to just randomly create a new element so in this case i’m going to create what the um use the index 10 which means this would add an 11th element to the array what happens with all of the elements between where we left off 0 1 2 3 4 5. so 6 through 11 what will we get so let’s just assign this to 77 and then i want to do a console.log of a and then i want to do a console.log and a dot length like we just learned about and kind of see what happens here and then let’s run that all right so we can see that it prints out four five six seven or i’m sorry 4 8 15 16 23 42 and then it says there’s four empty items and then there’s 77 and it says that there’s 11 uh there’s 11 items 11 elements in this array because we filled up the 10th index or index 10 with a value so it will create essentially what’s called a sparse array and that means that there are empty elements inside now this isn’t usually the way that you want to work with arrays if you need to add new values because it’s not as safe we’re inadvertently creating elements with nothing in them there’s a safer way to go about this using some additional built-in functions of the array and so if i wanted to add that value and add it to the end of the array no matter how many elements are currently in the array i could use the push method and so i say hey i want to push the number 77 to the end of the existing array so let’s um let’s copy this and paste it here and then if i wanted to remove it i can use a method called pop so this function pop will remove the last element of the array in fact i can call it several times to keep removing elements of the array and here we’ll just print out what the end result is just like we did previously so now this should put some fireworks into our terminal window so you can see that using push in line number 29 i was able to add the number 77 to the end of the existing array and that gives me seven total elements now i call pop three times it removes 77 42 and 23 leaving us with just four elements in our array okay so we’re going to continue to use arrays they’re a great way to to keep lists of things together and accessible and will become even more important again as we learn how to loop through arrays and to evaluate each element we can even use arrays to hold on to other things like like objects and functions and we’ll learn about some advanced use cases uh with arrays a little bit later all right so that’s all i have to say about arrays let’s move on and start looking into some things that are beyond the absolute basics we’ll start moving and talking about functions all right see you there thanks throughout this course even from the very first line of code that we wrote we use the console.log function to print things to our terminal window and i kept referring to log as a function as part of the console object in its simplest form a function is merely a block of code that we as programmers can name and once it has a name then we can call it by its name but it’s just one or more lines of code that we put into a block and then we say we want to execute that block over and over and over again throughout our application so again that’s a very basic explanation of what a function is but in javascript function functions can do so much more in fact most of this course will be devoted to working with functions because frankly they’re one of the primary constructs in javascript for getting things done so first of all uh let’s go ahead and create a new file i’m going to call this function declarations.js all right and first of all if i have some code that i want to reuse throughout my application i want to add it to a function so we can create a function and i’ll walk through and explain the parts of a function here in just a moment let’s create the most basic function that i can possibly think of and i’m actually going to copy and paste some code in so we don’t have to type at all but nothing here should be all that revolutionary so i’ve created a new function called say hello notice my name i use camel casing right in order to name my identifier my function name all right and then i have three lines of code notice that they’re inside of these curly braces notice that they’re indented so we see kind of a relationship between this code on the inside and this line of code and this line of code on the outside so it kind of represents a container relationship this code sits inside of or is part of or is rather the body of the function that we’ve just declared all right so um here we just declared a simple function this is called a function declaration this style we’re going to look at other ways to define functions later and i’ll draw your attention and why you’d want to choose one or the other later there’s at least two other ways that i’m thinking of off the top of my head but first of all notice that we use a keyword call function then we give the function some identifier that we come up with something meaningful we’ll use similar rules to what we use for variable names all right then we use an open and close parentheses you’ll see how these will be used a little bit to define arguments or input parameters to our function but right now it’s empty we don’t require that the caller give us any additional information uh and then we use the open curly brace here and the closed curly brace here to define the container to define the code that we want to be the body of this function and everything inside of that is just any javascript that we want to write for the most part all right so uh how do we actually then use this well we gave this block of code as defined by the open close curly brace we gave it a name and so we should be able to call it by its name so i should be able to do something like this right say hello and that will get me most of the way there but to actually invoke a function we have to use the function invocation operator in this case it’s the opening close parentheses and obviously we want to use our end of line statement here so let’s go uh node and then function declaration [Music] and let’s see oh declaration sorry there we go all right and we get hello so hopefully you weren’t expecting something uh super interesting we’re just printing out three lines with what i would call a flower box kind of a rounded some dashes to to style it up a little bit we can do some interesting things with regards to assigning the function to a variable so let’s do let a equals say hello now do i want to invoke the function here no and i’ll explain why in a little bit i merely want to get a reference to the function and then i’ll do um a and invoke the variable so this variable is now pointing to this function and now i say okay i have a function inside of this variable go invoke it using the function invocation operators in fact here let’s do it a bunch of times just to make sure that we’re seeing what we think we should see here and so we can see hello hello hello all three times in a row great so let’s comment that out now up to now this function’s not all that interesting let me just copy it and i’m going to comment it out and i’ll create a new version of this function down here beginning in line 17 and i want to actually pass allow me to pass in a name so i can say hello bob hello steve right so we’ll just create a new argument into our function say hello by giving it a variable name so essentially now we’re able to use this variable name in the body and we expect the caller to give us the name it wants us to say hello to so um here i’m just going to use some string operators here with name and make sure things are spaced nicely and so here i can do whoops say hello to bob [Music] say hello to beth say hello to mr tibbles my cat all right and let’s go ahead and run it and you can see now how i’m able to reuse that code but change it up by passing in the name that i wanted to say hello to all right so let’s comment all this out and let’s talk about one more thing that we can do with functions and that has returned values from functions so this first uh function that we created it’s merely just outputting we’re not expecting it to to perform some operation and then give us some value back but what if i wanted to create a more interesting function that implements some business rule in my system and my e-commerce system like to calculate the sales tax on a given amount say a subtotal of all the items that are in my shopping cart i might create a simple function called um calculate tax like so and we’ll get to the body in just a moment but i want to allow the caller to pass in the amount that we’re going to charge tax to all right then i’m going to say let result just the name of a variable result be the amount that value passed in times [Music] 0.0825 which is the sales tax where i live and then i want to use the keyword return and then the value i want to return so you can return one value from a function in this case i want to return the amount of tax so i’m going to return result now what i’ll do is i’m going to call calculate tax passing in an amount so let’s say a hundred dollars and i want to capture that into a variable i know it’s going to return a value to me so let’s just do let and i can reuse the variable word result but i might use something more descriptive like let tax equal calculate tax and then console.log the amount of tax like so let’s save that and then let’s run it and you can see that for a hundred dollar purchase it would charge eight dollars and 25 cents in tax okay but that’s what the purpose of the return keyword is to actually give me back something so this is an expression a function invocation expression it’s going to give me a value back that i can then assign to the new variable tax and then i can work with that that value in this case a uh a number representing the amount of tax all right and i think that’s all that i’m going to say about this for now but there’s lots to say about functions it’s going to again consume the majority of this course and you’re going to have to become very familiar with the ins and outs of working with functions and we’ll start that process in the next video we’ll see there thanks in the previous video we learned how to create a function declaration and a function declaration and a variable declaration are similar in so much that they both have an identifier or a name because we plan to call them later on in our javascript but what if we don’t need a name what if we’re in a situation where there’s just a need for a function but that function will never get called for the rest of the application we know that then we can take a different tact we don’t need to add a new identifier we can just create what’s called a function expression and we don’t have to supply a name we just give it the body of the function and say here go do this when you need to run some code all right and a good explanati a good use of that is whenever we need to create some code that should run in the future so here let me start off by creating function expressions.js a new file and here i want to use the settimeout method that’s available inside of javascript and if we use intellisense we can see that there’s actually two input parameters to this function set timeout we’re going to first of all need to give it something called a handler which i happen to know is just a function now i could give it a function declaration but usually people just create function expressions here for the handler and then the second thing we’ll need to do and i’ll use the down arrow to move from the first argument to the second argument is to give it a timeout and so that’s the number of milliseconds that i want it to wait before executing this code and i’ll show you how that might be interesting in just a few moments here but the first thing we need to do is create a function expression to pass in so just here right in line i’m going to create a function open close parentheses open close curly braces which denote the body of this expression i’m creating inside of here i’m gonna do something simple like console.log i waited two seconds and then here at the very end of the function declaration i’m going to give it that second argument the number of milliseconds that i want to wait before executing that function that function expression so i’m going to say wait two seconds and then i want you to call this inline function i’m creating and the body of it will merely just log out i waited two seconds all right so here we go let’s go and uh do node and then function expressions one one thousand two one thousand and you can see it prints to screen i waited two seconds all right now it’s kind of hard to read it like this all in line one of the things in javascript that’s a little bit challenging especially if you’re getting started is the number of curly braces that you’ll encounter and differentiating for example this outer set of parentheses and this inner set of parentheses and and visual studio code tries to help you like when i put my carrot right next to that opening curly brace it tries to find the matching closing curly brace and you’ll see as we add more curly braces for different purposes and indentation levels inside of our application visual studio code does a pretty good job most of the time of finding its match it’s just a matter of looking for that carrot that surrounds the closing one here over you can see whatever in column number 61 here i’m looking at the the bottom okay anything inside is just the body of the function and the same rules apply whoops i didn’t use a semicolon at the end of that line but i should have all right it shouldn’t change the function in this simple case but nothing changes about how we work with this now to be honest most people do not put this much code on a single line i may want to split this up into multiple lines so i would do this in a way that feels natural to me and you can see that as i put my mouse cursor next to where i feel like the split should have been like at the beginning of console.log and here at the end of our body of our function expression visual studio code naturally will create some indentation now if i don’t like that level of indentation i’m free to come in here and change it up like i would prefer to use a tab here so i’m using the tab key on my keyboard to move things out and the shift tab to move things back that only works if my mouse cursor is here right at the beginning of that line if i were to move one character in and use the tab key well that’s you know that’s not what i want at all that’s going to split that word up but if i use the keyboard the arrows on the keyboard to maneuver and then the shift tab to move it out i can move things in and out but that is pretty much how i would like to see that function represented right and then i use a comma to pass in a second argument in this case the number of milliseconds to my set timeout function all right so but the f the the focus of this is that function expression i never want to use that function again but i need it in this case as an argument to pass into my settimeout function all right so functions can take functions as input parameters okay so uh just keep that in mind because things are going to get a lot crazier than that and let’s move on and talk about using both the function declaration and a function expression to do something just a little bit more interesting here same basic idea here but what i want to do is start off with a counter and this will count the number of times that we actually execute our uh our function expression i’m going to start with a function on the outside function timeout let’s call this function timeout like so and then inside i’m going to set timeout using that built-in function to javascript and pass in a new function expression all right and then i’m going to here give set timeout say in two seconds i want you to basically run this function expression that i’ve defined right there so i pass in the second argument of 2000 again you using visual studio code to help me find the matching set of parentheses at the beginning and the end to pass in uh the uh input parameter to the set timeout function recognizing that the function expression is the first argument to that and 2000 is the second input parameter to that set timeout function here’s what i’m going to do now i’m going to append so i’m going to put a little space there between high and the closing single quote mark counter but i want to after every time i reference calendar i want to increment it by one so this will allow me to count the number of times that set timeout has run now one of the things that i want to do is after i have printed that line i’m going to schedule the next time that this code should run so i’m going to schedule and call timeout in a recursive manner so i’m using the name of this outermost function and saying hey uh now that you’ve run me run me again in two seconds because i’m gonna basically call set timeout again all right now i need to kick this off the first time so we’ll call set timeout once here on line number 15. and that will kick things off and then [Music] i’m going to hit ctrl and c on my keyboard to stop the execution because it’ll just keep looping and looping and looping all right hopefully in your mind you understand the sequence of events here i’m going to call this function declaration once the body of that function will create a set timeout in two seconds i want to execute this function expression which will not only show me the number of times that this function has been called because i’m keeping count of it in that counter variable but then also it’s going to call the timeout function again which will schedule two seconds from now the next call to the set timeout function okay so let’s see it run this all makes sense so i waited two seconds saw it run once all right twice three times and see it’ll just keep going every two seconds until i hit ctrl c on my keyboard to stop its execution all right all right the last thing that i want to show you now comment all this out is that you can create a function declaration i’m sorry a function expression that says something like console.log and i’ll make something a little bit more interesting later and then i can immediately invoke that function by first of all surrounding this function expression in parentheses just kind of say hey i want to group all this together and then using another set of parentheses as the function invocation operator like that do you see that format so there’s this intersect that we use just to define input parameters we don’t need any but we still need it in order to create a function expression then we’re going to group this whole thing together and say i want to execute it so there’s actually what four sets of parentheses we just have to keep them straight in our mind on what each of them are doing but this last set will do what’s called and this kind of structure is called an immediately invoked function expression in other words i will have a function expression and i want it to be invoked i invoked immediately when this application is run and this actually is a pretty common pattern in javascript development it comes in super handy and we’ll talk about why it comes in handy a little bit later but we want to just remember immediately invoked function expression it’s also just known as an iife sometimes i think it’s pronounced iffy all right so keep in mind if these and we’ll come back to them a little bit later all right so let’s move on and uh move away from functions just for a little bit we’ll come back to them later uh but hopefully you can now tell the difference between a function declaration of function expression most importantly for our purposes you want to keep in mind what immediately invoked function expressions are okay all right so we’ll come back to this and uh let’s move on see the next video thanks in this video we’re going to talk about decision statements there’s actually three that we’re going to consider the if the switch and a ternary operator and so whenever we need to add logic to our application in other words perform different blocks of code based on some condition that we evaluate we’ll want to use one of these decision statements and so let’s go ahead and start by creating a new file called decisions.js and here what we’ll do is start with the if statement so the basic structure looks like this if and then we’ll evaluate something here some expression so let me just kind of start off with this some expression that expression should equal true or false and there’s lots of ways to evaluate this we’ll come back to it in just a moment but we’ll consider those in between the opening and closing parentheses if that is true whatever that expression is then we’ll execute all the code inside so let’s begin simple bar count equals three we’ll just hard code a value and then say um [Music] so if count and then we’ll use the equality operator so this is going to evaluate for equality if count indeed is equal to 4 then we will that will that expression will return true if it’s true then we’ll perform whatever code we write here so console.log and count is four so the first time we run this we’re not going to get really anything all right so the first time we run this we’re going to not give anything it’ll just exit what we can do is change this to count equals three like so and now when we run it we’ll see the message count is three all right very uninspiring let’s set this back to four and here we can consider the alternative that the count is not equal to four and we could kind of give the counter message count is not for this much we know to be true all right all right so count is not four we basically skipped over this block of code because this returned false therefore we executed the else statement this second block of code and skipped over the first one okay so there’s actually several different variations of this we can use because there are some different conditions here maybe i don’t want to jump right to that else statement maybe i want to keep evaluating i can use an else if and so here i might say else if the count is greater than four then i could maybe do a message like console dot log uh count is greater than four and i can do kind of the opposite as well else if count is less than four so console.log count is uh less than four i guess i changed modalities there and then at that point this will never happen ever because one of these three conditions would occur we’d never get to this final else statement right it would just would never happen so it’s going to save our work here and see this run count is less than four because it’s three okay so that’s the general structure of the if statement it allows us to evaluate one or more expressions if it returns if that expression returns a true then we execute the code in the code block associated with that expression we can create optional else or else if statements to continue to evaluate other expressions usually you’ll want to make related ones but you don’t necessarily have to although that may not make a whole lot of sense depending on your business rules and then we can finally use a catch-all in case none of the previous else if statements uh are are correct and kind of capture that so let’s go ahead and comment that out that’s our first structure we’ll use the if statement a lot the next type of statement is a switch it’s a little bit more tricky to use let’s start off with just typing out the switch keyword and what we want to evaluate and so what we’ll do is actually evaluate whatever’s in this expression against a number of cases so i might for example let hero equal superman and then depending on the hero i might want to print out the um the super powers that that particular hero has so based on the hero if that hero so if the case is superman i would say well that hero has console.log super strength may also have x-ray vision [Music] alright let’s add another case here and say case batman and notice that kind of the the format of this to use the case keyword inside of this block that belongs to the switch the case keyword the value we want to compare our our case against and then a semicolon and everything underneath that will become part of the body of that of that case that gets executed so in this case we’ll say what are batman superpowers he has intelligence and he has fighting skills all right and then we can also then say well the default for that hero is that they’re a member of the jla now watch how this works it works a little bit different than the if and else if so let’s go ahead and say what we have and then rerun this all right so in this case it was superman and notice that we matched the case superman because it prints out super strength and x-ray vision but then everything else inside of all additional cases including the default case will be true as well so he also is intelligent he has fighting skills and he’s a member of the jla now if we were to change this to let’s say batman and we were to run the application you’ll notice that it skips over all of the console log statements that describe superman superpowers and they they come in however here at batman so console log intelligence fighting skills and he’s also a member of jla now we could try somebody like a green arrow not particularly one of my favorite heroes and um he’s just a member of the jla all right now if we don’t want that that flow through style what we can do is actually use a break statement in here so let’s go back through this now and see what happens whenever we break out of a given case so back to superman and now when we run it we only see that he has super strength and x-ray vision batman has intelligent fighting skills and then um green arrow is just a member of the jla okay all right one other quick tip here is that whenever you’re evaluating strings there’s a possibility like for example batman what if we had capital b in batman all right and then we run the application and you see he’s a member of the jla why didn’t it catch the case batman because capital b batman is not the same as lowercase b batman in that string now what we can do to circumvent that whenever we’re working with strings and we want to do some comparison with them we can use the two lowercase method of our strings so strings have a built-in method called two lowercase and that will take whatever that input is and we’ll make sure that all the letters are lowercase so that we’re really comparing apples to apples instead of apples to oranges so now when we rerun the application we get what we would expect with batman okay all right so let me comment this out we’ve looked at the if statement we’ve looked at the switch and then the third one we’re going to look at is the ternary operator and this is useful whenever i want to i want to just do a quick inline evaluation of some expression and then return back a value a string number boolean whatever probably just a string or a number back depending on whether that expression evaluates a true or false very small short concise inline statement so i’m going to create two variables i’m going to do something a little bit different though the first variable i’ll create like you would normally expect but instead of ending that line and moving to the next one i’m going to do another variable creation variable declaration and assignment right here in the same line so i’m going to create another variable called b and initialize its value to the string one all right so just a slightly different technique you might see that online moving on so we’re going to create another variable called result and we’ll set that equal to some evaluation of an expression does a equal b so two uh equal signs that are next to each other is the equality operator this is a check for equality to say does a equal b and if that is true then what we’ll do is return the word equal as a string but if it’s not true notice the colon that separates the true from the false will return the word n equal so the ternary operator has kind of got several parts here there’s an expression there’s a question mark that that has true or false ramifications and we’ll just do a console.log result like so so now let’s go ahead and run that and these are equal great um we could also do this in line so let me just take this part right and do that instead you can see how we can basically perform that same check without having to create a new variable to hold the result all right so it’s a nice inline way of running a quick check and then returning back a string one string or another string now let me just go back for a second here or actually let’s do this and then we’ll do console.log result okay let me comment this one out i want to keep it around for you in case you want to reference that in the future um we used two equal signs but there’s another another type of equality that we can check for and that’s strict equality and this will check to make sure that these two values are equal but then in addition to that it will not coerce for example the number one and the string one it’ll say are these absolutely equal even with the same data types all right and so in this particular case we should expect a different result these are n equal they are not the same all right so these are the same because i’m looking for equality but if i’m looking at strict equality and i’m not allowing javascript to coerce the integer into a string and then check for equality uh then i have to say no these are not the same because one is a number one is a string all right all right so let me comment that out and let’s take do one more check here um in this case i’m going to use a different operator the not equal to operator so i’ll use the word not in equal and not not equal and not n equal all right which would be the same as saying equal alright so now let’s see and run that and this produces a false so this would be returned back and then displayed on screen but then we can also do strict inequality by adding another equal sign to that operator and these are not equal again because it is true that a is not strictly equal to b because they’re different data types all right hopefully that makes sense all right so let’s go ahead and stop there um and hopefully all this ternary operator business and and equality and strict equality makes sense and let’s move on you’re doing great we’ll see in the next video thanks in this video we’ll talk about iteration statements iterations allow us to loop through a body of code a block of code a number of times until a certain condition is met and there’s a couple of different types of iteration statements we’ll look at two in this lesson and we’ll even look at them in relationship to arrays something i promised several lessons ago so let’s start off by creating a new file and call it iterations.js and inside of here we’ll create our first for loop so four and then there are three parts inside of the opening and closing parentheses first of all [Music] we’ll let i equals zero or we can actually just shorthand this and not even use the keyword let here i less than 10 i plus plus and so this is going to take some explanation but let’s just get this working first and then i’ll come back and i’ll talk about it and we’ll just print out the value of i all right what do you think is going to happen here if i didn’t tell you anything about how the for loop actually works what do you think will be printed to screen when we execute our script let’s find out so let’s go here and type in node iterations all right so we get ano uh several it looks like 10 different values printed to screen each on a separate line zero through nine and then our application exits all right so let’s talk about this it’s a shorthand syntax and there’s three parts as separated by these two semicolons inside of this this evaluation header for the four first of all we declare variable in this case i’ve declared i that’s why we use the let but then i said well we don’t really don’t need it let’s keep it short so we’re declaring it and then we’re going to um initialize its value to zero the second step we’re going to say continue running this for loop as long as this condition is true so as long as i is less than 10 continue running the the body of this for loop as defined with this a set of curly braces here and then finally after you’ve run an iteration increment the value of i by one all right and here we’re going to then print out the value and that’s why we start at the value of 0 and then we work our way all the way through this 10 times on the 10th time i gets incremented to 10 this this check is performed it’s false and then we exit out of the program all right now let’s do something a little bit more interesting like i suggested before let me comment this out here let’s go let a equal two and this should look familiar 4 8 15 16 23 and 42 whoops i guess i forgot equal sign there and now what we’ll do is four i equals zero i is less than a dot length i plus plus inside the body of this we’ll do console.log a and what element will we use i because i will start off with the value of 0 and it will continue until we get to the length property which is not 0 based and once we get to for example the 0 1 2 3 4 5 so length will be 6 elements so once i is 6 it’s no longer true that i is less than the length of this array and will exit out so let’s go ahead and save this and then run and we can see we get all of our values printed out to screen so that’s the proper way to iterate through or one way i should say to iterate through an array now one thing about visual studio code that i really love is that they have this notion of code snippets so if you ever forget this this syntax and it can be a little daunting at first there’s a way to remember it perfectly every time and that is to let the code snippets build it for you so i type in the four keyword intellisense pops up with a little window under it and i’ll use the arrow keys to go to the for loop javascript all right there’s a couple of fours but the one that we want has this little box with dots underneath of it that tells me that this is a code snippet i hit enter on my keyboard and now i get the basic structure of my um of my for loop already created for the purpose of an array now notice that every word index is highlighted and i can change that every instance of that by just using a letter like i’m going to change this to the letter b instead of index and notice that it changed it everywhere and then i’m going to hit the enter key on my keyboard which is the wrong move then i’m going to hit the tab key on my keyboard and i can change the name of the array now everywhere the word array is used i can swap that out with the letter a for example i’ll use the tab key one more time here it puts me to the another replaceable area for the element and here i’ll use c i’ll use tab one more time and then it kind of exits me out of that snippet replacement structure and now i can continue on and type like console.log we’ll just print out c okay so let’s grab a from our previous example and then we get the same results we got before but this time we didn’t have to memorize exactly how to use for the code snippet walked us through and allowed us to replace the names of the various replaceable areas like the name of the counter the name of the array and the name of the given element c that we extract out of uh out of our of our array okay let’s comment that out that’s four and now let’s take a look at the while loop um so we’ll talk about the difference between these it may not be obvious at first but essentially we’ll do this all right so take a look at this knowing what you know about loops what do you think is going to happen here well we start off with 1 and we’re going to continue to execute this loop until this condition is false so the very first time we run it one is indeed less than 10 so we’ll continue to run the body the block that’s associated with our while statement and we’ll print out the value of x and then increment its value by one we’ll continue to do this until we increment the value of x and it becomes 10 at which point this is no longer true it becomes false and then we’ll break out and continue on so let’s go ahead and see what value what what the values that we get so we get one through nine that’s expected and once we hit 10 we break out great all right so what’s the difference between the while statement and this first for loop that we did here at the very top well the difference is that the for loop first of all has a lot of infrastructure that we have to build these three pieces and um it uses a series of indexes that represent the number of iterations that will move through this block of code now the while statement is a little bit different anything can be used to derive the iterations as long as this statement continues to be true we’ll continue to execute this block of code and so we control the number of iterations in the body in this case here i do the x plus plus now we don’t have to use counters we could use anything any kind of business logic like we may want to read to the end of a file and once we hit the end of the file it no longer it makes sense to continue to read each line of the file then we would want to break out so the while is a little bit more flexible and so much that we can build the business logic for how many times we’re going to iterate in the body of the uh the while statement whereas with the four we’re pretty much limited to the number of times we want to run this being the number of times that we’ve kind of pre-set it up here in this top section outside the body itself okay now there’s also one last thing we can talk about and that’s a way in both the for and the while we can kind of circumvent this check right here and we may want to do a check like this so if x is equal to 7 then we’ll call the break statement all right so learning what we’ve learned about the if statement it probably should look more like that right so let’s first of all let’s make sure it works all right in this case we’ve got one two three four five six once we reach the seven we circumvent this check and just say hey i want to break out of this all right so we can use that always to break out just like we broke out of the switch uh when we wanted to not let it flow through additional cases now the one thing i will say if you notice how i typed this to begin with let’s retype that so hold on let me comment this out so that you can see it in the code if you want to download my code but we could also do it a little bit more shorter and in line since i only have one statement that i want to make right after the if statement i can do it on the same line and i don’t need to surround it with a code block a code block indicates that there’s usually more than one line of code in this case there’s just one line of code i could put it on the separate line and use some indentation like that or i can just keep it all on the same line since it’s so short but that might improve readability or i might decide that this is a more readable form that’s kind of up to me and if i’m working on it with a team of software developers i might want to get and kind of do it the way that they do it but stylistic for me this is so short i can read it all in one shot if x is seven then break out of it it just it looks good it’s very readable i’ll be able to understand what i’m doing later on it doesn’t take up and move the code down so i like that that format if i just need to create one statement right after my if right after my if so sometimes it makes sense to split things on separate lines sometimes it makes sense to keep two different statements on the same line again i think it kind of is a stylistic choice that you’ll have to make for yourself at some point all right so that is iteration statements we looked at two different kinds and we looked at how code snippets can be used to help us remember the format now i believe the while has in fact i believe most of the things that we’ve looked at has um uh some uh some code snippets available to them like if i find it here in intellisense you hit enter on the keyboard but there’s not as much to it there i mean while with the condition i can change this to x is less than 10 right it’s not so much for me to type that out but the four makes a little bit more sense because there’s so many parts to it and replaceable parts of that okay so let’s continue on the next video we’ll see there thanks it seems like quite a while ago we talked about variables but now that we’re working with blocks of code inside of blocks of code like we had here in lines number 23 and then 29 through 31 we need to talk about variable scope and when i use the term scope i mean variables are a little bit like people in so much that variables have a lifespan they’re born they do work and then they die and they’re removed from computers memory when they go out of scope and we’ll see an example of of that in just a moment but they’re also like people in so much that they have a citizenship i guess you can say in other words depending on where they were born they can work inside of some code blocks but not other code blocks and so the remainder of this video we’re going to look at lifetime and availability or citizenship i guess you can say inside of the rest of your application so let me create a new file and we’re going to call this scope basics and there will be more to say about scope as we move forward and learn more about functions and so on in just a little while here but let’s start and create first example here so let a equals first i’m going to create a function called scope test and inside here i’ll just do a console.log and the first thing i want to see is if i declare variable out here outside of my function can i reference it inside of my function and so to find out let’s just call scope test and see what we get so here we’re going to type node scope basics and we can in fact view the value of a variable that was declared outside of the scope of a function we can view it inside of the scope of that function all right so the next thing that i want to do is to say hey let’s create a variable here now if i create a variable inside of a function scope can i view it out here outside of the function scope so console.log b and let’s see and so no not only can i not see it but my application actually blows up and you can see the little carrot here is right underneath the b and it says b is not defined so in other words you could kind of think of it again in terms of the life span we created a function and we created a variable inside of that function that variable lives as long as that function is running but after the function after that code block is has completed executing then b is removed from the computer’s memory and essentially thrown away therefore we cannot reference that variable outside of the function because it no longer lives it’s dead all right so we’re gonna have to comment that out and we can go ahead and comment this out as well now let’s do one more thing here let’s say if a and we’ll just do something silly here if it’s not equal to an empty string so just two single quote marks next to each other so uh then can we still see the value of a even inside this innermost block of code that we defined with an if statement if we can we should see then it printed here a second time the value first so let’s save what we have let’s run this again and so we see first first the first time it’s printed out and the second time that is printed out all right so yes if something is declared in an outside scope it is visible or it can it has citizenship in every inner scope from that point on but here once again if we were to create a variable third and then try to reference it outside of the code block in which it was defined like so will this work what do you think we’re going to get that same kind of error before we get the little arrow pointing to the c and it says that c is not defined the variable c was defined inside of this code block and once we executed that code block and got to the end of it then it c was removed from the computer’s memory it’s no longer available to us in a sense dies and it’s no longer available okay now let’s just do one last thing here just to to kind of understand that we are in fact able to work with uh the variable that was defined in the outermost scope can we still work with it do it use it and change its value so i’m going to change this to changed and then i’m going to reference it here console.log a and so now let’s run our application one more time all right so the first time that it’s run this first console.log it will be the value first but then we change the value and we log it again and that’s where the second change comes from after we’ve executed that function then we execute line 20 and that’s where this third changed appears all right so i guess the moral of the story once again to kind of reiterate what we said when you declare a variable you have to understand in which scope it was defined because based on the scope or rather the code block in which that variable is defined it’s going to have a life span and it’s going to have citizenship if it was defined in the outermost scope it will have its life and its citizenship in all inner scopes but if it’s defined in an innermost scope it will not be available to outer scopes now one last thing and i’ll kind of end it right here if we were to take and this is probably just a question for you just a thought question if i define b here right above that if statement and then i attempt to use it right here and call this inside if do you think that will be able to reference that value well based on what we know about the rules i would expect to see the value second printed out so let’s try it and in fact we do see it so hopefully that supports your new understanding of the scope of variables defining them outside of a code block versus defining them inside of a code block and trying to reference them outside okay so hopefully that all makes sense want to make sure you’re clear on that we’re going to revisit the topic of scope because there’s a lot more to this but this is your first introduction so that you kind of understand what the rules of scope are at least in the most basic sense all right so we’ll continue on the next video see you there thanks scope is a topic that will keep coming back to over and over throughout this course it’s important because at least when your javascript is run inside of a web browser you must be aware of the topmost level of scope which is referred to as global scope in node like we’re using here it’s not as much of an issue they’ve got some safeguards against it but in web development working against the global scope is a crucial concern a lot of consternation and consequently a lot of effort has been exerted to preach that declaring variables at the global scope is a bad idea so you would never want to do something let me create a new file here returning functions.js js there we go you never want to do something like this note the use of the var keyword and you never want to do something like this although you’re more likely to do it than the previous line in line number one now the reasons why you would never want to do that this will require a little bit more explanation a little bit down the road and i’ll make this point emphatically when we start writing javascript for the web browser later on in this course but for now just understand that much of what i’ll say and why i say it over the course of the next five or six lessons or so will be working towards a solution to avoid writing your code in the global scope if at all possible now the eventual solution that i want to demonstrate relies on how javascript functions work but we need to take a few baby steps to get there so the first aspect of this technique that i want to demonstrate has to do with returning a function from a function now up until now our functions performed one or more actions and then exited quietly we may have returned a simple value like true or high or something along those lines however we can create functions that can not only perform some action but then at the very end can return a value to the caller and not just any value can return a function so let me comment all this stuff out and i’ll say don’t do this to make sure you never do that and this either and then i’ll just uh do a multi-line comment here and so let’s start off really simple this is something that we’ve already talked about when we talked about declaring functions or function declarations so here’s function one and inside of function one we can just return the string one right it’s not very exciting but it demonstrates the point that you can use the return keyword to return a value to which ever calls that so for example let value equals one for example and what would we expect to be in our variable value well we would expect to print out the string o n e or one so console dot log and value like so and just to see this working let’s go ahead say node and then returning functions and we see it returns here at the bottom of our screen the string one as we’d hoped now we could also kind of paraphrase this make this a little simpler by just doing it all in one line right so we could put the call to the function and not use a variable we could just make the call to the function which returns a string and that returned value will automatically be passed into the console.log method let’s save that hopefully that makes sense and that’s a common technique that we’ll want to use but things start to get a little bit more mind-bending when you start to think of a function as just another data type in javascript so for example um let’s go back to this i’m gonna copy this again and then let’s go um console.log and then type of [Music] value all right and [Music] well let’s do this let’s get rid of the method invocation operator so now we’re just setting a reference called value to our function one let’s see what we get and you can see the type is function so let’s think about all the data types we know about now we know about string we know about number we know about boolean we know about undefined and we know about function right and we’re going to learn a couple more before this is all said and done but at any rate notice here again i’m just in fact we could even do this a little bit differently i may have muddied the waters by introducing a variable let’s just do that instead and we should get the same the same result all right so uh i guess the heart of the matter here is that we can get a reference to a function and we can store that reference to the function out in uh in a variable which means we could also do something like this so now we have a reference to the function we can call the function using the method invocation or the function invocation operator so let’s go ahead and run it whoops i guess we need to actually then go console.log there we go now we’re getting somewhere there we go okay so hopefully that makes sense i just have a variable pointing to the function and then now that i have a variable point of the function i can execute the function by just using that variable with our method and location operator right all right hopefully you’re still with me so far hopefully this isn’t too mind bending let’s continue on here so since a function is just a data type like any other data type that we’ve learned about so far our functions could return a function because we’re just returning a value right and that value can be any type so in other words let’s let’s do this function two and here we’re going to return a function now this is a function expression inside of a function declaration right and here console.log and 2 like so and then do something like let my function equal 2 now what gets returned to my function it will be this inner function expression so i should be able to do something like my function with the method invocation operators and let’s see what we get and we get the value 2 like we’d hoped all right so hopefully you can see here we’re using the return keyword to return a function expression we get a reference to that function expression by calling the outer function declaration now we have a function in hand or reference to that function this inner function right here and we merely invoke it hopefully all that makes sense and we might be able to do this a little bit differently let’s try just a slightly different tact so here i’m going to go function three and here i’m going to return um function and then return three all right oops let me spell return correctly all right so in this case i’m returning a function that returns a string so i should be able to do something like console.log and then i’m going to call 3 what do i get back from that i should get back a function so i should be able to invoke that function to get back the string to give to the console.log now you would never do this and you would never see this but this is just to illustrate a point that um of what you’re really working with and that’s references whoops let’s actually execute it there we go three what you’re you’re working with here are references to functions that can return references to other things and maybe even other functions right so again that last one’s pretty far-fetched you probably never do that but the fact is that what gets returned from our three function declaration is a function and then it can be invoked with the function invocation operator here the second set of inner parentheses right there all right so on the surface this might not seem like a very significant development in our javascript journey but nothing actually could be further from the truth because this is actually a huge step towards moving our code out of the global namespace like i talked about the beginning of this video but to complete the story again we have several more baby steps to go we’re going to need to step away from functions for a little bit and come back to them once we’ve learned a little bit more about arrays and objects and objects specifically all right so just keep this thought in mind and we’ll continue on you’re doing great hang in there we’ll see in the next video thanks if you remember uh when we were looking at arrays i did the type of on an array and it returned back the word object so that’s actually another data type in javascript that we haven’t looked at until now obviously given the title of this lesson we’re going to look at objects so an object is similar to an array in some ways but its intent is dramatically different an array will hold a list of information in other words there may be many data items whether they’re strings or numbers or booleans or even objects each stored in a different element of the array contrast that to how an object works an object contains the related properties of a single data element so array many data elements an object one data element but has attributes so the settings of the properties define the characteristics of the object so let’s say for example that you want to have a car and so an array will only really let you save maybe the year of the car or the make of the car or the model of the car as a string or maybe some identifying number but an object would allow us to define all of those properties kind of in the same container so you know if you try to keep track of all the properties and maybe even all the methods that that belong to a car but you keep them as separate variables and separate functions you’d run the risk of clashing with other variables and functions that have the same name for a different car okay but objects let us keep that information kind of safely locked away in their own little container where the relationship between all those properties and functions uh are obvious that they all kind of belong together to describe one car and then you might have another object that describes a different car and you can keep both of those objects those two cars in an array of cars so hopefully you can see the relationship between those all right so um let me first of all start out by creating and you file object.js and so um you know i may have an object that has a series of properties that describe a specific car and i might want to for example keep track of the make the model in the year and so on and i may have some functions that i need as well things like uh getting the price of the car based on some criteria maybe you know the year of the car and things of that nature and i may want to print out a special description of the car that includes many things like the make the model of the year in a special format but i might define a car object like so so let’s do um let car equals and then we define an object using a um a code block so curly braces now i’m going to use kind of a name value pair here so let me just go ahead and start typing all right take a second and catch up with me there if you like now let’s go ahead and use the print description function like so and let’s use the year property like so i’m going to save my work and then i’m going to type in node object or object and the first printout is bmw 745li because we’re printing out the make and the model of this car all right and then here i’m just getting the year of the car and printing that out in a console window all right so in this case this object that i’ve built on screen we’re dealing with a tangible real world and very relatable concept that of a car we’ve all driven in cars or have driven cars in your javascript code you’ll occasionally be working with objects that define tangible real world things like cars but you’re also going to work with things that represent more abstract concepts that are specific to web client or web server development so in this sample i created an object using what’s called object literal syntax so i literally want to create this object and then i’m going to assign that object to a variable named car and the body of the object is like i pointed out defined with cur a series of curly braces here this set of curly braces at the outermost level here this defines kind of the boundaries for the object and everything that lives inside of it is either a property of that object or a function called a method inside of that inside of that object so let’s start off in lines three four and five here we have a list of name value pairs so here’s the name of the property and here’s the value of the property in this case notice that each of the names of the properties are just identifiers they’re just like variables in fact you’ll probably want to use the same naming conventions that you would use inside of with a variable and then the values can be any data type in this case i have a literal string bmw a literal string 745li and a literal number 2010 that represents the year all right and notice that the property and the value are separated by the colon character all right and then each property definition as well as each function up until the last one are separated by commas now i put each of these properties and functions on their own line or series of lines as it might be for the functions in order so that we could see some readability but that’s not entirely necessary from javascript’s perspective it would be fine if we put all this on one line of code all right so again with regards to the names of both properties and these functions which i call methods you’ll want to use the same naming conventions that we used previously when we talked about variables now there’s some other ways to create objects and i’ll discuss another technique in one of the upcoming lessons um so uh we’ll come back to that notion because it’ll lead into another discussion that kind of takes us off at a whole other tangent that i don’t want to go on right now so um here we define the function kind of the same notion i gave it an identifier the name of the function that i want to access and then i’m using a function expression and define the function expression within uh several lines here but essentially we’re just returning a value or in the case of the second one just just calling console.log we could write any uh number of lines of code inside of here these are just happen to be very simple for the purpose of illustration all right so i’ve defined my object now i want to actually use it and reference it how do i do that well you can see that whenever i wanted to access a specific property of my object or when i wanted to access a function i use the variable name that i set the object reference to and then i use the period on the keyboard that which i call the um the property access operator just the dot on the keyboard same is true when access of accessing a function as you can see here in line number 15 i used that period that member access operator and then you know all else is fair this is a function so i’m going to use the method invocation operator just like i would to invoke a normal function now uh i i keep referring to these functions that are inside of a an object as a method and and i think you should probably start referring to functions defined inside of objects as methods it’s a more descriptive term and i’m already used to it for my work with other programming languages but simply put a method as a function that belongs to or rather is defined inside of an object now there’s another syntax that i could use in addition to what you see here and it opens up some interesting possibilities that frankly i’m not very fond of but you could definitely do something like this so it almost looks like i’m using the array uh array element accessor to access a specific property here let me go ahead and save that so we’ll see the year appear twice here if all goes well and we do at the bottom so that’s one approach to accessing an individual property and the other is similar uh but it uses a um an index so it’s actually kind of interesting how this works um what is the the fur or index one of my car let’s find out the hard way here and it’s set to undefined in this case so actually it doesn’t reference any of these it basically creates its own new property and sets its value to undefined let’s never do that let’s not do that i prefer the dot syntax again it’s going to be most familiar to those of us coming from other programming languages but you could in some advanced scenarios use these techniques to do something a little more advanced and that’s way beyond the scope of this of this lesson all right so i recommend you just use that dot notation for now and all will be happy so um you can do like i kind of mentioned a second ago some pretty advanced things with objects and there’s a lot of room for variation so i’d recommend taking a look and taking notice of how other people work with objects in their javascript code as you’re perusing the internet because there’s always seems to be a new twist i think i understand how objects work and then i’ll see somebody do something really extreme and interesting and i’m like wow that that opens up my understanding a little bit more to how objects work i’ll just give you a quick example of what i’m talking about here here we can create a another car and i can create an empty object like so and then i don’t have any properties inside of my another car how do i reference another properties of inside of that well what i can do is just um kind of just say hey i want to create a property here called whatever and i’ll set it equal to bob all right and it’ll just automatically create a property called whatever and set its value equal to bob just like that no let or var keyword or anything if i do console.log um you’ll see that card.whatever in fact will come out to be bob or i thought it would oh i think what i’m going to need to do is save my work here and then do try this again whoops oh i’m sorry another car i had the wrong reference it didn’t exist on car but we need to look at another car dot whatever and there we go there’s bob okay so just an interesting feature of objects you can you can add properties kind of ad hoc and some people do that and that is kind of a feature not really a bug of javascript it’s dynamically typed you can just say hey i need a property here i need a function here and you attach it to an existing object and there it is it’s you’ve got an object now with this additional property called whatever all right um you can also do some other kind of interesting things might as well take a few moments and look at these so um i’m feeling unoriginal now so i’m going to create a new object called a and inside of this i’m going to create uh my property and i’m going to actually set that to another object i’ll define a property inside of that and i’ll just say hi because again i’m feeling rather unoriginal um and so let’s figure out how can we actually print out the a uh so console.log a dot my property dot b will i get what i think i’ll get i will so you can see how i can chain things together whether they be functions or properties by just continuing to use you know this is an object that has a property that has an object that has a property and so i can kind of chain through and and create essentially what becomes a namespace and we’ll reference that a little bit later when we talk about solving the global name space issue or or putting our variables at the at the global level of our of our applications which we’re trying to avoid all right let’s take a look at another quick cool example of things you can do with objects that might not be so obvious at first glance so here i’ll create var c and inside of that i’m going to create another my property and this time i want to create an array so this property the value of my property now will be an array of i could do strings i could do numbers but i could do an array of objects so all right and that’s perfectly valid so here think with me again i have an object that has a property that contains an array of objects that each have different properties all right and that’s perfectly valid so objects can contain properties of the type array that can contain other objects that can contain well really just whatever makes sense for your application however you need to store it and kind of represent the data that you’re working with also if you’re going to work with an array of objects it might make sense for all of them to have the same set of properties like in this case each object has a different property i’m not so sure that would be so useful but it might be something that you need to model in your application there’s nothing forcing you to keep the same set of properties for any given object uh inside of an array of that of that object you know as long as your javascript code or whatever will consume this object understands how to interpret it that’s all that matters so once you get past the simple hierarchy of values you typically refer to something like this that gets a little more complicated as an object graph a graph of objects all right just keep that in mind let me paste in some more interesting examples here just kind of get expand your thought process on how to work with objects let’s say i have a car lot and i want to store an array of objects each object has year make and model all right then i could iterate through the car lot and print the screen each of those individual car objects right so that’s one example how about um you know if this was more of a of a yes you could say a system that kept track of all of our customers and employees we might do something like this this gets a little more complicated and unfortunately runs off the side of the screen a little bit but you can see here i’m creating a contacts object here’s the start in the end and inside of that i have a property called customers and a property called employees now both of these have as you can see an array of objects and these objects look very similar and so much that they have a first name last name and then phone numbers and then phone numbers actually is an array of strings in this case this particular what is he a customer this customer bob tabor has two phone numbers richard bowden has two phone numbers and then but our employees like steve and conrad and grant well steve has two phone numbers but connor and grant only have one full number all right so you can see that things can get pretty crazy really quick but that’s a perfectly valid object initializer it just happens to be a little bit more complex than the ones that we started off with so now as you’re looking at this you might think to yourself wow this this actually looks similar where have i seen this before it looks a lot like jason have you heard of jason json or js json i guess some people put the emphasis on the on it’s short for javascript object notation json is both descriptive and compact and it’s probably the most popular way to send information between two disparate systems so we might in fact use it uh to store um settings or properties inside of um you know a more advanced javascript application or they use it in visual studio and c sharp projects to store application settings for example now in in the new version of c sharp and net um we might use it in our application sooner than later to send data between a single page application that lives on the client and the backing web api that on a web server that hosts a web api if none of that made sense don’t worry about it eventually you’ll get to that point if you continue on learning javascript all right so what was my point here well if you’re familiar with what json is you might notice that there are a lot of similarities between the object literals that we’ve looked at in this video and jason however there are some subtle but important differences between the two and i’m not going to take the time to go through that you can easily do a quick search online to see what the differences are between object literals and javascript and the javascript object notation or json just be aware that these are not one in the same there are subtle differences you cannot use them interchangeably but their syntax is very very similar and json or i’m sorry javascript has a built-in function that i’ll let you work with jason as you might expect okay wow i’ve really gone along on this one but objects are pretty important and we’re going to use them a lot and there’s a lot to them in fact we’re probably going to be talking about them a couple more times before the end of this course maybe even in the very next video so you’re doing great hang in there we’ll see in the next video thanks previously i said that much effort and education is centered around the dangers of defining variables and functions in in the global scope also referred to as the global name space especially when writing javascript that will ultimately be targeted at running in a web browser but i never really answered the question why is it dangerous i never kind of ventured into that and i’m going to illustrate more clearly later on why this is dangerous and how you can really hurt yourself when you are creating variables and functions in the global scope but in a nutshell the global scope is global so number one each variable that you define to the global scope is not removed from the computer’s memory until the web browser or the tab of the web browser navigates to a new web page so the more that you add into that global scope the more memory you’re taking up and that memory just is is consumed the entire time that that tab is open uh for that particular web page but more importantly number two um again emphasizing that this is the case with javascript in the web browser not so much true whenever you’re building these node style applications as you load javascript that you wrote and you rely on javascript code that others write whether that be code that javascript libraries that you’ve downloaded from the internet or that you include your project somehow maybe they’re ones that other people in your company have written and you need to include them in your project or perhaps even sold commercially online some product that you purchased came with a javascript file and you included maybe it hasn’t been updated in a number of years the variables and the functions that are defined in those files when you consider the the the variables and the functions that you’ve written in your files there’s a the more that you write at the global scope the more that they wrote at the global scope if they didn’t take precaution the more likely you’re gonna have a collision of names at some point somewhere down the road somebody’s gonna have a variable named what you named and they’re both trying to contend for uh the global for being the variable the winner in the global scope so we call these naming collisions uh and when these naming collisions happen either your data will get overwritten by their code or their data will be overwritten by your code but either way undoubtedly it’ll cause unanticipated uh bugs that are difficult to track down and quite frustrating and the reason why this is even a thing is because it’s happened okay so now that it’s happened everybody is extremely concerned about it and so a series of suggestions came out and and a lot of effort went again around trying to figure out how to solve this issue given the the tools in javascript that they had available and the first one that has come out and that i’ve recommended from the very first lines of code that we’ve written is to use the let keyword start the instead of the var keyword because the var keyword will attach variables to the global scope which in a web browser is the window object in the document object model we’ll talk about that a little bit later and i it’s also recommended that you use the technique the design pattern that we’re going to discuss in this video whenever you’re writing javascript code or there’s a third option too which is new in javascript in the latest version of javascript called modules unfortunately and i may even talk about this at more length later on the implementation of modules is a little bit uneven between node and the web browsing environment so i’m not sure how helpful that would be at least as we’re getting started and learning about javascript just keep in mind there’s several different attacks but this is probably the one that you’ll see used most often in at least uh javascript that’s been written over the course of the last five to ten years but there are some newer ways to to tackle this all right so any rate the technique that i’m going to discuss in this video or the design pattern actually uses a couple of techniques that we’ve learned about so far we’re going to use an iffy remember what that is an immediately invoked function expression to create a function and then that function will return an object and that object will have defined functions and variables that will then be kind of scoped to one variable so instead of having five or ten variables that we’ll have only one variable in the global scope uh or at least in some scope and then we’ll be able to reference the individual uh variables and property variables and functions of that particular object that gets returned all right so we’ll see how variables and functions can be made essentially private so that we can hide some implementations from the ability for just any code to call them this is often called encapsulation in software development terms and so these will be unavailable outside of the public variables and the public functions that we return and that’s generally a good thing so there will be a couple of benefits that come out of this all right so um let’s get started by creating a new uh a new file called module pattern dot js all right so let’s start by creating an iffy and to do that hopefully you remember how to do that we’re going to start with a function expression we’ll just create an empty one to start off with we wrap it in a set of parentheses and then we use another set of parentheses to actually invoke it all right so what i’m going to do before we get any further is actually set this immediately invoked function expression to a variable i’m going to call this counter so i’ll set counter equal to whatever is returned so eventually what we’re going to do here is return an object full of properties properties that have values properties that point to functions that can be called but we can also do some private stuff here and this will not be accessible outside of the calling the counter dot something to access it and so we can like have a private variable here like let count equals zero and we would not be able to do counter.count it just wouldn’t be accessible we’ll fix that here in a moment when we return an object will give an accessor to it we’ll take a couple of passes at that actually okay so um let’s go and create now a private function as well and this will just print out a message and style it up a little bit differently so we won’t get crazy here so console.log and um we’ll just uh say whatever the message is and then we’ll just do like three dashes like that just a little bit of style just to show that you know we have something here that could be private but now ultimately what we want to do is return an object that will get set to counter here all right so um [Music] we’re going to start off simple we’ll come back to this a little bit later because there’s going to be a issue with one part of this actually this part right here what if i just want to return back the counter the current value or rather the current value of count i can try that again we’ll come back to that in a minute but let’s say we create like an increment increment property and it will return a function and inside that function we can do something like count plus equal to one and uh then we can call the our print method and then just say after increment something like that we can also here let me use a comma right there because we’re going to create another property of our return object called uh reset and what this we’ll do is call a function so we’ll create another function expression print before reset then we’ll call the count and then print or we’ll set count equal to zero because that’s the point of a reset and then after reset it should always display zero but let’s just double check that all right so now we have basically our uh our module pattern we created a module which is essentially an iffy that returns an object that will expose functions and other properties like um like the current count and now here because i’ve invoked this immediately this is available it’s already been executed and counter now is fully populated and ready to be used in our application so i can do counter dot value i think wasn’t that the name of it i’ve forgotten everything already okay i value so console.log counter.value and um i could try to do console.logcounter.count [Music] just to prove that it won’t give me anything back so let’s just start there and we’ll go node module pattern and first time we get an undefined wide because count is not a property of counter uh because we didn’t it’s it’s not exposed and it’s not being returned in the return object all right so that is impossible now what we can do however or we will try to do is call counter oops counter dot increment you can see it shows up in intellisense that’s a good sign so we’ll call increment in fact let’s call it like three times whoops kind of ended up below where i wanted to go there all right great and then we’ll call counter dot reset like so all right so let’s see we get this time it’s not gonna quite be as satisfying uh because we’re gonna get a little issue on on uh on these lines here so you can see after the increment the value is one two and three but then when we attempt to get the value of counter from this property count it we would assume it would be three right but it’s zero what happened here well we accidentally created something called a closure and another little topic we need to talk about in javascript so let’s not do that we’re going to need a different way to implement this basic functionality so can’t use this technique what we’re going to need to do is take a different tact and we’re going to implement two more functions here we’ll create a set function or i’m sorry let’s start with a get function and get we’ll do something super simple it’s just going to return count and then and i did it all in one line put it down on multiple lines didn’t need to it’s pretty simple function and here we’re going to set count equal to some value that’s going to be passed in so here we’ll say we’ll accept an input parameter called value making sure we add some commas in between these new properties here that are set to these functions we’ll take in some value and we’ll set count equal to that so we should be able to come down here and now since we’ve kind of removed that let’s go counter dot get or actually let’s set it to the value of seven here we’ll do a console.log counter dot get to ensure that it is seven and then we’ll call our reset let’s see what we get when we run it this time all right this is a little bit more interesting well almost interesting i need to invoke get okay so i forgot that save it run it one more time [Music] there we go okay so here we go lines 33 through 35 will produce these three lines where we’re after increment one two and three then we call counter set passing in the value seven and so we then do console.log get counter get and we get that seven back out now we call reset and before the reset the value will be seven after the reset we reset it to zero okay so hopefully you can see that this technique of returning an object from an iffy will first of all allow us to keep some implementation deals details private like we couldn’t get to count and we didn’t try but we wouldn’t be able to get to print because only certain things are being returned um and mostly in in terms of functions uh that give us access to the private functionality and a little bit more but in addition to that we’ve reduced think of all these variables that we’ve reduced out of the global out of global scope there’s no count variable now there’s no print there’s no get set increment or reset they’re all part of this one variable called counter and so there’s less of a chance that we’re our namespaces are going to collide as a result of that now we want to pick something unique there maybe something that describes a little bit better uh what the intent of this is maybe something specific to our brand or company and and maybe pick something fairly unique there but as a result of that we’ve protected ourselves and written our code a little bit more defensively now there’s one more thing that i want to talk about here and that is that uh okay so keep in mind this this technique that i’ve just demonstrated here is so popular that it has a name this is the module pattern there’s another variation that was created on this called the revealing module pattern you might see this used as well let’s go ahead and create another file and i’m going to call this reveal revealing module.js all right and i’m just going to paste some code in so that we can kind of compare and contrast the two versions all right so it’s it’s nearly very similar in so much that we have an iffy that we’ve defined inside of that iffy we have some private stuff just like we had before here we have some more private stuff these are the implementations of get set increment and reset but i’ve created these as uh function declarations with names now here at the bottom we have this is the revealing part of the revealing module pattern here i’m revealing publicly accessible uh functions by including them as properties in this return object so i can call counter dot get in counter dot set exactly the way that i could before but behind the scenes they’re calling the implementations that are defined here and so there’s a couple of benefits and a couple of downsides first of all it what makes it a revealing module pattern is that it reveals the public functions through these properties in the return object okay and it’s a clear a cleaner clear presentation of what actually gets returned but there is a downside and that is you can accidentally overwrite these are just properties so i could set the value to the get equals seven and not and forget the method invocation operator and as a result i can pretty much just break the association between get and the function name getcount and so that’s a downside we could accidentally break this whereas in our module pattern um you can’t really do it that’s not possible okay so um that’s the module pattern the revealing module pattern it brings together a bunch of techniques we’ve learned all to the greater good of removing or reducing rather our impact on the global namespace by removing variable names and function names from our from the global scope okay and we’ll see why that’s important on the web development side of things as we move in that direction but wanted to kind of bring all that to a head all right so let’s uh continue on in the next video we’ll see you there thanks as you’re getting started closures can be another mind-bending topic in javascript but they don’t have to be if you understand them you can really unlock the power of javascript now having said that personally i don’t rely on them very often when i write code but i’m not a javascript ninja so your mileage may vary you’re going to see a lot of articles and tutorials out there that talk about closures and i think sometimes they make things more difficult than they really need to so i hope to provide a really simple uh explanation that will simplify this topic for you and you can get into some of the more advanced stuff a little bit later on but basically a closure allows you to associate some data with a function and then use the function with that data already kind of baked into it from that point on in my mind it’s kind of like this i’m basically taking a function and i’m marrying it to some data through an input parameter an input argument and then they live happily ever after in their own variable and from that point on they work together as a team whenever i want to invoke that function with that data already pre-filled i guess you could say into the input parameters i can call that new variable all right that’s all it is um and then well okay there’s more to it than that but for the most part that’s all there is so let’s just create a really simple example or two and and hopefully it’ll clear some things up so uh let’s create a new file called closures dot js and let’s start with just a function i’m gonna create something super simple say hello and then inside of here i’m gonna return a function because that’s kind of the point of this and it’ll just say howdy and i guess we’re going to pass in a name so howdy plus the name all right all right so that’s really step one i create a function that returns a function looks like i got a little problem here whoops i return a function there we go uh so here’s the function returns a function and i’m passing in a argument called name that i’ll ultimately use in the body of this return function all right so then i can actually make a call so for example let bob equal say hello and passing in bob now from this point on um i call bob well we’ll see what happens here node closures all right howdy bob all right so um by itself it isn’t all that impressive but that’s really kind of step two and three all in one shot so i can pass in some variable that slightly modifies the way that this return function operates so in this case it’s pretty simple i’m passing in a name and it will change what gets printed out every time whenever you call this function in the console.log all right so this value is basically um saved off in a variable outside of the returned function so we’re lying relying on how scoping works in order to get that closure behavior that name kind of follows along this return function everywhere it goes bob gets passed along from that point on and then this is step three where i save that off in its own variable so that i can call from that point on and i kind of get this say hello with bob prefilled right so i can do the same thing with um conrad say hello and then grant say hello and that’s all a closure really is so let’s those and there you go three versions of the same function that get returned we modify the operation by taking advantage of how scoping works in javascript by kind of giving it this value that it’s going to hold in its own in its own context from that point on uh in stored in the these separate variables all right so this is really uh just the binding process uh that binds these together and then stores them off that’s all it really is so another way to look at this the say hello method has finished executing and it returns a function but in the environment in which the method originally ran it preserved that so that whatever value we passed in is preserved inside of this return function the environment or in this case just the name input parameter this variable name remains available so now in step four i guess you could say if there was a step four i basically use the new variable which represents a call to the method and a preset input parameter to conveniently call that version of my function now all right so um the important lesson to take away is that each closer closure creates its own what’s called lexical environment and you’ll see the term lexical used a lot in javascript uh whenever you’re learning about scope i’ve tried to steer away from that term because i feel like maybe it clouds the issue a little bit it’s basically just a fancy word for everything that we learned about in the scope basics here previously where if you define a variable outside of a function it is available inside the function but if you define it in a child code block essentially it’s not available outside of that child code block so that’s basically what i mean by lexical scope it basically defines how a parser resolves variable names and functions when they’re nested and the word lexical refers to the fact that lexical scoping uses the location where a variable is declared within the source code to determine where that variable is available from that point on throughout the rest of your code so nested functions like we have here in our sayhello that returns a function have access to the variables that are declared here outside of it as well as any of the input parameters that are declared outside of it and uh outside of their original scope right and that’s just how the lexical rules work like we learned about in scope basics.js so when we create a closure each closure gets its own lexical environment meaning that they get each time we create one like we do here in lines 8-10 they get their own set of variables their own name variable and anything else we were to define outside of the function in this case we don’t have anything else and there’s more to closures you can get in some pretty advanced scenarios they’re a powerful concept in javascript the ability to retain or bind to the lexical environment of the variables that enclose the returned function like in lines three through five to create a version of the function with some values already pre-applied is pretty powerful if you don’t completely understand that that’s okay don’t get discouraged for now just understand that whenever you return a function from a function you also glue any of the variables that were defined outside of the return function including in this case our input parameters all right that’s all you need to know about closures well for now anyway all right so let’s continue on in the next video you’re doing great see you there thanks if you think back to the lesson on object literals i think we were working in the object.js file i created a car object with several properties and functions and you can see that i’ve created a new file called this dash keyword dot js if you’re pausing the video to follow along then you might want to go ahead and create this dash keyword dot html yeah that’s right we’re going to write some javascript in an html page for the very first time in this course here in lesson number 18 because i want to show you how this works in different contexts this keyword but getting back to the point at hand if you recall that example that i’ve pasted in from that object.js file into this keyword.js uh you see line number 10 and at the time i didn’t even proffer an explanation as to what this dot make and this dot model actually mean in our in our application uh the fact is that this keyword can be a little bit challenging uh so even people with a little bit of javascript experience from time to time get a little confused about this keyword and one of the reasons people get confused about it is because it means something different in javascript than in most other programming languages so you actually have to kind of fight your existing knowledge so if you’re coming from another programming language the best thing you can do is kind of just leave everything you think you know about ja about well a lot of topics but in particular about the this keyword at the door and if you are just coming to javascript as your first programming language then you might even have a slight advantage here because you won’t have to fight yourself in what you think you know but simply put the this keyword in javascript represents the way a given function is called the way a function is called will determine what this represents okay so you essentially bind this keyword to a given context uh and we’ll explain what that means based on how you call the function all right so up to now we’ve not really paid much attention to how we call functions i told you there was really only one way to call a function using the method invocation operator so we would do something like this a little bit later on right like a car dot print description all right and i used the method invocation operator and i didn’t even hint to the possibility that there would be another way or multiple ways to actually invoke a function but that’s actually pretty important when you consider what this keyword represents all right you’re going to learn in this video at least that there are other ways to call a method that allow you to set or rather bind this keyword to something so that you can do something interesting inside of in this case your object or your function or whatever the case might be now you may never need to do this but it’s important to understand the basic rules and how that this keyword gets bound to a context and gets referenced inside of your object or your function there’s an entire book written about how this functionality works and all the permutations and and it’s awesome it’s a little bit over my head at times so i’m going to give you an absolute beginner’s explanation as to how this all works but it should serve you well as you’re getting started and then you can refine your understanding a little bit later on but let’s start off and by commenting out everything and you know what there’s a really easy way to comment out everything that i haven’t talked about yet alt shift and a on your keyboard will add a uh beginning and an ending uh code comment character operator to whatever you have selected so that’s a nice quick way to do that great all right so let’s start really simply i’m just going to create a function called first and this function is going to return the value of this what is the value of this well um here if you go console.log first is it equal to the global object inside of node so the global object we’ll talk about that a little bit later i guess it is kind of the the most basic context of things that get uh executed inside of so when we create something in the global namespace a global variable we would create it essentially attached to the global namespace it’s available everywhere in our application all right so let’s see if when we call first from line number 20 is this which gets returned equal to the global the global object so let’s go this dash keyword and it is true all right so when i call the first method basically from the global context because i haven’t created it inside of uh using the module pattern inside an iffy remember what we talked about previously so i’m i’m basically just calling this here out in the global namespace and what gets returned back is the fact that this is equal to that global namespace all right so now let’s try something else actually let me just do this let me copy this little comment that i have in my notes because it might be helpful to you for reference all right so let’s start with another code example now function second and the only purpose of this is just to show that there is this little flag called ustrick there’s a strict mode in javascript we’re not going to go into it much but this will change how the this keyword is bound and so if you have ustrict turned on and you try the same thing that we just did here let me comment all this out using that alt shift a technique and we essentially do the same thing here where we go console.log and then um second equals global let’s see if we get what we think we’re going to get from the first time around false all right well i happen to know that it will equal undefined and that is a true statement what gets returned from this when we use you strict an undefined value it gets bound to essentially nothing all right so just keep that in the back your mind this the rules around binding to this keyword change depending on the context in this case the context is you strict it will fundamentally change how it works all right so with that out of the way let’s move on to the next example here let my object equal and i’ll create a property called value and set that to my object and then i’m going to use this um use create a global variable called value and i’m going to set it on the global object by doing this global.value at this point i’ve created a new property on the global on the global object and i’m going to call this global object all right again in node this has special significance if you’re doing web development it’s actually window and we’ll look at that here in just a little bit all right so now let’s go function third and we’ll return this dot value and then we’ll do a console.log third so by default what do you think will get printed out will we print out the value of the global object which i set to the string global object or the value of my object which is set to my object well hopefully based on what we learned in this first example you already know where i’m going with this and because we called third from the global namespace when we reference the this keyword it’s referencing this global variable so when we grab the value property it’s grabbing the value property of the global variable thus printing out global object let me show you that there are other ways to actually invoke the third function and we can control the binding of this keyword like so so here we’re going to console.log and then i’m going to call third but i’m not going to use the method invocation operator i’m going to use the call method or the call function of the third function all right so it has a built-in method called call and there i can pass in my object and this is how i will bind the this value to my object so the value will be pulled from my object not from the global variable so let’s save that here let me actually comment this one out save it and let’s run it okay hopefully that makes sense there’s another similar function called apply and they’re very similar um and in this context won’t be obvious how they’re different because i don’t have any additional properties to send in or rather input variables to the third function so if i had something like a name i would use then like called on you know bob but this can also take an array here in the apply which could include bob so just do this see what we get i haven’t tried this beforehand so yeah object bob okay now just out of curiosity what would happen if we did this probably nothing at all just be blank yeah object undefined alright global object with the word undefined next to it okay so hopefully that makes sense what i just added on there that’s really to illustrate the difference between call and apply and so if i had multiple input parameters in the call i would just add them on there if i had multiples i could add them on inside of an array all right that’s the only difference okay but let me just kind of annotate this and talk through it just for a moment so just to kind of recap this this keyword depends on how a function is called and an object can be passed as the first argument to call or apply and the this keyword will be bound to it like we did here in lines number 54 and 55 all right and so just to kind of remind you about this i’m going to go ahead and say this property is set on the global object and then kind of works inside of here this will return something different depending on how we call this method right and then i just want to add this little annotation here as well both call and apply allow you to explicitly set what you want to represent this or how we want to refine this the difference is how the additional arguments are passed in like i show you here okay so when it comes to calling a method of an object the call site will be the object itself and all of its properties are available to this in fact if we take a look back here that’s what happened that’s how i did this and why i use this.make and this dot model again when it comes to calling a method of an object in this case print description the call site in this case car dot print description will be the object itself and all of its properties like make model and year are available to this inner function only when i use this keyword because this represents this context all right because i’m calling print description using the car object all right so to call the function i would use the object reference that object reference car gets bound to this keyword so to further illustrate this idea let’s do this i’m going to actually select everything we’ve done from here down [Music] and shift alt in a and so let’s go function fifth and uh here i’m gonna go console.log and this dot first name [Music] and a space and this dot last name and hopefully this will make a lot more sense all right so now what i want to do is create two objects so uh let customer1 equals and they’ll go first name colon bob last name colon tabor and then i’m going to create a print property that’s going to point to the fifth function like so all right and i’m going to copy this and just duplicate it i’ll make this customer 2. call this richard bowen [Music] all right and then finally we’ll go um customer two dot print customer one dot print all right so now look at how this works what is the context how do i call the print method that’s pointed to fifth well in this first case i’m using the object if it’ll let me get in there object customer 2 that is the context we’re going to bind this keyword to customer 2 because i’m calling it as a property of customer two i’m going to bind next in line number 85 the this keyword of the print method to customer one so let’s go ahead and so to me this example is really interesting because the call site is the object’s reference to the function and this keyword can be used to reference the various properties of the object that was used to call the function so it becomes an interesting and elegant way to essentially pass values into a function without defining a bunch of input parameters to the function itself all right so now what i want to do is kind of stop working with node for a little bit and look at this keyword in the context of a web page so i’ve created a new this dash keyword dot html i can use the term doc you can see that when i type in the word doc it’s an emmet abbreviation if you’re not familiar with emmit just search for it online it’s basically basically a shorthand um syntax for i guess you could say for snippets for code editors right so when i hit enter on the keyboard it kind of creates this bam this whole document outline for me and um it has some replaceable areas like the device width and the initial scale and the content and all that business i don’t want to change any of that stuff what i do want to do is add a script section here near the bottom for reasons i’ll talk about in another video and then what i want to do is above that create just a simple button so here we go button and inside the button i’m going to say hey click me and then i’m going to set a on click equal and we’ll come back to that in just a moment here i’m going to actually create a function that i want to call whenever the button is clicked so function and i’ll give it a name click handler like so and inside of here i’m going to go first of all i’m going to allow something to be passed in i’m going to allow uh a value to be passed in and then i’m gonna print out whatever that is to the console so console.log arg all right now we’ll come back to this in just a moment i’m gonna leave a space and go console.log this all right and then in here i’m going to say the button on click equals click handler so i’m going to call the click handler i’m going to pass in this this keyword all right so if all goes well here i should just be able to right click on this and say reveal an explorer and then when it’s in the windows explorer i can just like hit the enter key on the keyboard to actually open it up in my default browser and what i want to do is i want to use the f12 tools in an edge i’ll bring up this little window at the bottom here and i want to look at logs so make sure that you’re on the console tab and select the logs sub tab now click the click me button and we’ll see the results of both of our console.logs in the first case what we get back is the this that was passed in as arg and printed out directly to screen and so in this case the this keyword will reference this entire element all right so let’s take a look at that again here you can see how button on it gives me the whole thing so i can do something like this which if you’re familiar with web development should not blow you away i should be able to do arg.inner text and if you’re familiar with web development at all you would expect to see what there let’s refresh the page click the click me button again and you see click me all right that’s the inner text of that button so i’m able to get to all the properties of this button but the key here is that that this keyword represents this entire button and i’m passing this keyword in so that i can look at this entire button inspect it grab a property out but when i use this keyword inside of my click handler function what do i get i get the global object now we said in node the global object the name of it is global in a web browser the global object’s name is window so i can actually just like use this little arrow this little carrot chevron right next to object window and it will allow me to view all of the objects the child objects of the window and there are literally maybe if not hundreds definitely dozens of different objects and properties uh that we can that we can inspect and and change programmatically we’ll come back to some of those ideas a little bit later but basically the takeaway from this is that whenever code is called from an inline on event like on click on event handler it’s this is set to the dom element on which that listener is defined that’s why we got back this entire button including the text including the closing button tag but we’ve not taken any special steps to bind this inside of this function we’ve defined here the click handler so it defaults to the global object the window object okay so the moral of the story is that what the this keyword is bound to is not always obvious it takes a bit of detective work more so than this keyword and other programming languages but it has to do with how a given function is called and the site from which it is called so in this case this keyword is used at the call site is at this element level in this case the this keyword is used at the global level all right and that will change the value of this and what it’s bound to but by default functions that are called using the method invocation operators alone will use the context in which the call is made so if the call is made in the global context then this keyword will be bound to the global object if the call is made in an object then like we saw here near the end the this keyword will be bound to that particular object and we were able to use it to grab out the values of the given object all right and you can take control of what the this keyword is bound to by calling it using either a call or the apply method of a given function and we talked about what they do and how they’re different and finally whenever you use them in a use of this keyword in a browser once again what this is bound to depends on how it’s being called and who is calling it alright so hopefully that clears up what this keyword is i’ve given you a lot of examples i’ve tried to speak a little bit more slowly and and hopefully you can wrap your mind around what this actually is and um hopefully from this point on you’ll be able to identify uh what this is in your code all right hopefully that helps all right you’re doing great hang in there we’re getting close to being more we’re more than halfway done and you’re doing awesome see you in the next video thanks in this lesson i’ll briefly demonstrate how to use destructuring which is a fairly new technique in javascript for unpacking values from arrays into individual variables or i guess into other array elements of a different array but you can also use it to unpack properties from objects again into other distinct variables or a different object so use this term unpack you’ll see what i mean here in just a moment let’s start by creating a new file called d structure ring dot js all right and the first thing i’m going to do is create a bunch of loose variables here just a b c d e will wind up using most of these at some point and then i’m going to borrow that array that we created a while back maybe recognize some of these names all right and then next up uh let’s start by just destructuring this names array into um a a set of variables so i’m going to start off by using names which i know is an array and i’m going to use this bracket syntax and say take the first element of the names array and stick it in a whoops whoops whoops there we go an a take the next element stick it in b you know c d and i could even change the order instead of um [Music] d and e i’ll go e and then d all right and so let’s just do um console.log a console.log b and then console.log d because that’s a little bit more interesting now we’ll just go ahead and print out c as well why not and then we’ll go e all right and so here we’ll go node d structuring all right so take a look at what happened we have this array we destructured it down to a set of individual variables and we start off with a representing david the first element of the original array eddie the second element of the original array alex because we’re grabbing them off in sequence i did something a little bit interesting here and so much that i switched e and d so that e will represent michael and d will represent sammy when i print them out going back to alphabetical order d then e sami is first then michael all right so but the key to this example is that i’ve taken everything inside of an array and using this style syntax i’ve destructured it down to individual variables all right so that’s just one example there’s some other interesting ways to to work with this let’s uh let’s just go here i’m going to take all this alt shift a comment it up and the next example i’ll do a let others so i’m adding an additional variable here in addition to the other ones that we created originally and here i’ll go um a b and i’m going to use this weird syntax of dot dot dot others all right equal names so now um console.log a console log b and then let’s see what gets put out into others all right so this time a is from david b is eddie just like before but this time i said basically everything else just go ahead and stick them in a new array called others all right so that’s what we see here printed out from line 21 we get this array uh representation in our console.log including alex michael and sami together all right so that’s just another twist we can basically take some elements one by one we can then also kind of combine together entire groups of elements together let’s move on to another interesting twist on destructuring so in this third case what i want to do is actually work with an object and so whenever you’re working with object in objects and you’re destructuring out one object into variables or even into another object it’s really like a form of projection if you’re coming from other programming languages grabbing out the parts that i want of the original object and putting them into a new object with a different shape all right without having to take all the contents of the original object so i may only want one or two properties where the original has 10 or 20 properties so here let’s start off with just saying let year and model then i’m going to start off with car equals but i’ll get rid of that here pretty soon we’ll start with let car equal but it won’t matter because we’re going to remove that and i’m just going to create a typical old object um like let’s say it’s bmw the model will be a 745li year will be 10. the value will be 5 000. all right and in order to destructure this what i’m going to do is actually remove this and say hey i want to take the year and the model and put that into a new object of its own and then what i’m going to do is wrap this whole thing in a set of parentheses and then an end of line character like so so now we’ll do console.log here that’ll be the value here that i’m pulling out and my model it’ll be that value there that i’m pulling from the original object and printing it out so let’s see what we get all right so 2010 from line 34 and the 745li from line number 35. all right so that’s just some examples of destructuring um pretty simple concept it really is just a compact syntax that helps to clean up code whenever you’re trying to map from one data structure into another or into a set of variables and that’s all that it is alright so hopefully that made sense in the next video thanks another new feature of javascript allows you to create better literal strings through the use of templates so the term template literal is a kind of oxymoron parts of the string will be literal and parts will be templatized they’ll be variable based on an expression and so you can inject in other values variables or you can actually run entire expressions and we’ll see the use of a ternary operator in just a moment let’s start off pretty simple begin by creating a new file called this template literal [Music] literals.js inside of here i’ll do something really simple uh let name equal bob all right that’s not the template literal this will be console.log and now i want to use the backtick characters usually over the tilde if you’re not familiar with that region of your keyboard it’s usually right next to the number one two three one right next to the number one you’ll have to hold down the shift key to get to it so there’s one back tick whoops i’m sorry you’ll you don’t need to shift the back tick key all right usually above the tab key on your keyboard and so inside of there i’m going to use hi and then whenever i want to add something variable that will get kind of injected in from the outside it’ll be interpolated from outside of this i’m going to use the curly braces and right before the curly brace i’m using the dollar sign character you can see that the syntax highlighting in visual studio code changes the color of this to this bright blue color that’s cool and so then i can just say hey i want to use the name variable inside of there like so okay so we should be able to do something like a node template literals like so and i get high bob awesome so um the other cool thing about temple literals is that they will allow you to create multi-line strings now before this you would have to do a lot of using the append operator and so on but in this case you can do something like and i’m just going to copy and paste this because i want to type all this out you can see here that i start my template literal with a backtick and i end it with a back tick down here at the bottom so i’m setting this sentence or sentences actually this paragraph equal to this whole string and i’ve split it up on multiple lines and there’s no append character or anything like that what i can do is console.log sentence and the neat thing too at least from what i’m concerned is that it preserves the indentation level and the line feed character so you know i could do something a little more i guess artistic here come on let’s do this just with spaces like that like that and it preserves that indentation level that i have pretty neat right all right and then the other cool thing is that you can do anything inside of the expression interpolation area that you can do in a normal expression so and let me comment all this stuff out control i’m sorry alt shift a and here i’m going to create a function real super simple function get reason count just a very pithy silly idea here and i’m going to hard code this to return the value 1 all right and i’ll change it a little bit later so you can see the difference here but i’m going to create a variable called interpolation interpolation equals i’ll use the backtick character give me dollar sign curly braces we’ll come back to those in a minute to try this all right inside of here make some space for myself i can create any expression i’m going to use the ternary operator and so i’m going to say hey if get reason count just because i wanted to make things a little bit more interesting so i’m actually calling a function if it is equal to 1. and here’s where the ternary operator comes in i’ll say one good reason otherwise a few reasons all right and this is starting to pop over out of the viewable area but hopefully you can kind of keep track of using this syntax coloring you can see where the expression interpolation begins and ends inside of that here i’m going to evaluate the call to get reason count and if it’s equal to 1 i’m going to inject that part of the string in here otherwise i’ll inject this part of the string inside of my template literal and now i guess the only thing left to do is just a console.log interpolation like so let’s go ahead and actually run this so give me one good reason to try this well maybe we should try two give me a few reasons to try this all right so you can and i see the need for this all the time especially in web development where you may have one item in your shopping cart or two items in your shopping cart to change up the the string that gets outputted to for the end user based on a quantity all right and probably other good uses of that as well so string template literals are a nice addition to the javascript language here again they can make your code more compact and readable allowing you to do some interesting things in line that would require a lot of appending of strings previously all right so doing great let’s continue on see in the next video thanks regular expressions allow you to create a pattern to determine if a given string matches that pattern that you created regular expressions or they’re often just referred to as regex or regex are not exclusive to javascript they’ve been around forever they can be used in just about every programming language and i absolutely hate talking about them because they make my head hurt i’ve not committed the syntax of regular expressions to memory and so pretty much creating a pattern to find something is hard for me and i’ve developed a few little crutches through the years so that i can you know approximate or fake my way through the usage of regex and i suspect you’ll probably find yourself doing that as well unless you’re one of those really annoying people that just commit to learning regex inside and out and then you know can impress people at parties based on that knowledge so um i i try everything i can do to avoid memorizing it or learning the syntax usually if it’s something simple like making sure that a string matches the pattern of a phone number a zip code some something that’s fairly common especially with data in the united states i can usually find a good example of what i’m looking for online using a search engine or stack overflow but if it’s something custom for the given project i’m working on then i have to go and relearn just enough regex to get through that project and then i tried to purge it from my memory again so i’m going to show you where to go how to find the answers and and cobble together your own little regular expression but i’m not going to pretend like you’re you should go out and memorize any of this i know people have done it but but i usually wind up hating those people because they’re smug know-it-alls but i digress let’s just take a super simple regic example and use it in javascript so i’m going to start by creating a new javascript file called regex.js and here we’re going to say i’m going to create a simple variable called pattern and you can create a regex pattern by beginning and ending with a forward slash so in this case i’m just going to say hey search for this pattern where there are the exactly these three characters x y and z all right super super simple pattern you would almost never use something this simple unless you were looking for specifically the letters x y and z inside of some long string that you want to search through or a series of strings all right but there’s my pattern and so before we get started in earnest let’s just say hey what are you really first of all um i want to print it out and then i want to console.log see if we’re working with a new data type or is this just a data type that we already know so let’s go um node regex and uh looks like just attempting to print it out will just be a string representation of the pattern the type of the pattern is object okay so it’s a special built-in object to javascript we’ll talk about some of those global objects this is just a shortcut to creating one an instance of that global object for regex patterns okay so um here let’s continue on now and actually create some text that may or may not contain that pattern that we’ve defined so let value equal and we’ll go up this is x y z a test all right and so what we can do is there’s a couple of um of methods built into both strings and regular expressions that allow us to use regular expressions against a string or use our pattern against this value in this case this variable called value so we’ll start with the console.log and we’ll use our pattern dot and intellisense shows us there’s actually quite a few interesting things that we could use i’m going to keep this example simple and just say use the test method and so intellisense tells us that this will return a boolean value that indicates whether or not the pattern exists in a search string so what i’m going to pass in is the string i want to search through so in this case value and i would expect to get back a boolean a true or false if we can find xyz in that string so let’s save it i’m going to comment out these guys now i’m going to save it and i’m going to get back here and go node rejects and it is true we do find x y z our pattern inside of this string so let me comment that out the next thing that i might want to do is actually replace that pattern that we found in that string with some other string that’s pretty useful and i do that sort of thing a lot in software development this time i’m going to start with the string itself say value.replace and so that strings replace method has the ability for me to give it a um a pattern and then i also want to give it the value i want to replace if i find that pattern replace it with this string and i’ll just use the word just all right like so this is just a test so i’ve removed xyz and i replaced it with the word just by using the replace method of the string passing in the pattern and the word okay there are a couple of other things those are the two that i find myself using most often here you can do something a little more interesting i guess log value.match and this match function will return back an object that it gives some information about what the string was what the pattern was if it was found what the indexes in the string like if you were to split it up uh into individual characters at what point in the string would we find an instance of that pattern match so here we’re going to pass in uh the pattern itself so i’ll save that and you can see it gives me back this this array with the pattern we’re searching for the index where we can find it so i think zero is t so zero one two three four five six seven and eight so the x the beginning of that pattern is found at the ninth character uh index uh eight oh i guess it would be seventh character ninth character index eight right so um at any rate and then the original input was the entire string itself so we can actually modify this or you know actually grab that object out and work with it individually so value dot match pattern now that i have that array that we saw down here i can grab an individual part of it so console.log and here i’m going to go match dot index so just shows you how to get an individual part of it so here i can grab the index itself and i could use that to do some sort of custom replacement logic if i wanted to do that i’m not sure i would ever want to do that okay so now this comes to the part where i teach you how to cheat and if you really want to cheat you go out to your favorite search engine and you type in something like zip code regex and then if you’re lucky bing will pop it up to the top uh whether it be from stack overflow or just gives you a nice little usage example right there in line that’s a little dangerous because you don’t know if this particular example was uh voted up or down you might want to go and actually search through the comments and see the one that gets the most up votes and the selected answer and the one that doesn’t cause any argument in the community the other way is to go and kind of trudge through this yourself by looking at this page that and there’s plenty of references out there i prefer the developer.mozilla.org website personally i think their documentation is awesome and here you can learn about the various special characters and regular expressions and try to cobble together your own regular expression to find what you’re looking for but that’s all you’re going to get out of me that’s all i can tell you about regex because i’m not a big fan of it but anyway just to recap what we talked about in this video you can create a regular expression um literal with forward slashes you can use the regex’s test method passing in a string to see if that pattern exists in that string you can use the match method to find more details about the match you can use the replace method of the string to replace a given match with some other string like we did when we replaced xyz with the word just and then like i just showed you here at the end i showed you how to cheat you already know this look online whenever you need regex whenever you need regex help okay so let’s continue on we’ll see in the next video thanks up to now we’ve looked at a number of types can you remember them off the top of your head we looked at string number boolean object undefined and function as its own type and there are a couple of others that we haven’t talked about yet we’ll talk about null later and then there’s symbol which is new uh in the latest version of javascript probably won’t talk about that in this course but um what i wanted to point out though when we were using string in particular but this is true of the other of some of the other types that we worked with it seems to have some methods that are available to it to do some interesting things so for example whenever we looked at uh regular expressions and let me just create a new file here called natives.js whenever we looked at the the regular expression lesson we did something like value which is a string set to this literal string this is x y z a test and we did value dot replace well how is it that this value has this dot replace method we really never address that how is it something like a string can have a method after all we said that methods are really just functions that are defined inside of an object so that would make a string an object right or no but a string is a string how can that be well actually both of those are true statements the fact is that the types we’ve been looking at so far like especially string and boolean and number are known as primitive types these primitive types that have corresponding built-ins or natives that are functions that return objects with a bunch of cool methods that are added to them by javascript so behind the scenes javascript does something interesting it the javascript compiler will coerce your primitive in this case primitive string into an object that’s returned from a native string function with all kinds of cool stringy type functionality included so actually although we haven’t demonstrated this yet you could create a string using the actual string function to do something like this and let me comment this stuff out here and so notice what we did here let string equal new then here’s our function that built-in function string notice that has a capital s we’ll talk about that in a moment all right and then if we were to save this and then um let’s go ahead and get down here and type in node natives it works well kind of works almost exactly like a normal string we’ll get to that in just a moment so uh before i address that specifically i’m going to work with strings in this particular video and with the string capital s string function the built-in the native string but what i’m about to say about strings is true whether we’re talking about numbers or booleans or other other primitives that have an equivalent uh native associated with it all right so i want you to notice a couple of things and we’ll work through this first of all this starts out just like any other variable that we’re assigning to a string except we use this new keyword and i’m going to explain what the new keyword means in the very next lesson when we talk about constructors but basically this is what creates a constructor call to this function and then here we are calling a string function capital or uppercase s in string but isn’t that bad form didn’t you didn’t you say bob that we should create our methods with uh camel casing and so string should start with a lowercase s uh actually this is a special situation it’s still a convention indicating that this is a function that should be called using a constructor call again more about that in the very next lesson so you’ll get a part two to this but just keep that in the back your mind we’ll come back to it all right so whenever we run this as you can see here when we ran node natives we didn’t get an actual a literal string output instead we got basically an object that has a string property and a value set to howdy we actually need to call a method on this native that’s returned from the string function to convert it into a primitive string for the proper display inside of a console.log so we’ll need to do something like um i’ll just comment this out and we’ll go to string like so and now there we go we grab uh we convert that native that object return from our native string function back into a primitive string and then display it on screen okay so and while we’re looking at things here um just out of curiosity let’s go console.log and then go type of my string what would you expect to see here well it is a type of object all right so again what’s going on here is that these built-in native types provide extra functionality like this tostring method like this replace uh method and others that we’ll look at in other lessons um and they provide this extra functionality to their corresponding primitive types and so just real quick here is a list of those built-ins those natives all right so it includes kind of corresponding to the primitive string lowercase s and string number boolean there’s also an object a function in a symbol and then there are built-in natives that do not have primitive versions um the primitive version as you know of array is object and the same with regular expressions here regex but it does provide this native built-in with extra functionality for our arrays so the same kind of thing happens it’s just not with directly back to a primitive it’s to an object but it still works with any time we’re working with arrays and then there are some other built-in natives that provide foundational data types i guess you can say uh for important features but are essentially just objects whose methods implement a lot of logic uh for their features so things like the date function and the error function we’ll look at these a little bit later but in this lesson i want to focus solely on the relationship between primitives and built-ins so whenever we do something like this and let me just copy and paste some more code in here so here we’re creating a literal string and then on this literal string i’m going to call this method to lower case behind the scenes what’s happening is that javascript’s compiler is coercing is wrapping it’s boxing that primitive string my primitive into a built-in native equivalent in order to provide that rich set of methods that transform the string in this case to all lower case letters instead of all uppercase so if javascript is coercing wrapping boxing our primitive into this built-in native equivalent then what happens whenever we need to get a value back out of it well the javascript compiler will do the opposite it will unbox that object back into a primitive without you having to do anything special it manages all on its own so in this case let’s just uh kind of see what what happens here just out of curiosity let’s get the type of here we’ll put the type up there all right and we’ll see that when we run this let me make sure there’s nothing else here let me comment all this stuff out too at the very top of that file all right so now let me save that and we can see that it treats this literal string as a string here in line 31 then in line 32 it does that unboxing thing that we talked about to take string make it into an object so that we can call the two lowercase method on it and then what do we get back well at the point when we attempt to find out what the type of my primitive is it already has for our purposes essentially unboxed it back into just a primitive string all right so it’s recommended that you stick with with using the primitive and you allow javascript to do its magic the compilers can do this sort of thing without breaking a sweat so don’t worry about all this boxing and unboxing and the pro its impact on performance but but let’s suppose that just for the sake of argument that you wanted to start out with a built-in native and you want to explicitly convert that built-in native version of a string into a primitive string how would you go about doing that well let’s take a quick example and let’s go ahead and move away from strings just to numbers but the same idea will apply no matter what so i’m going to comment all that out let’s go let my number equals new number notice capital n or uppercase n in number and then in the constructor argument we’ll pass in the actual value that we want to set that number to all right so at this point let’s do a console.log and let’s find out what the type of number my number is have any guesses on what it will be let’s go ahead and stop right there and let’s make sure we understand it’s a type object at this point now i want to take it out of that built-in native and i want to grab just the value of my number out and put it into a primitive so here we go let my primitive i’ll just reuse that variable name here equals my number dot and then to grab the value out regardless of whether we’re working with string number boolean whatever the case might be we’ll use this method on this object called value of so the value of method and now we should do a console.log my primitive actually we know what the value will be what’s more interesting is the type of so now let’s run that and so here in line number 36 we’re going to get it’s an object but we use value of to retrieve the actual value of our built-in native object into a regular number and we print that out in line number 38 okay so to recap the point of this lesson is to explain what these functions are that have the same name as our primitive types but with an uppercase letter they are built-in native functions that are intended to be constructor called we’ll learn about that in the next lesson and the javascript compiler uses these functions to return an object that supports lots of rich features to each primitive data type and we’ll see those in upcoming lessons but the javascript compiler will box and unbox your primitive types into these built-in native equivalents as needed and will do so without any help from you and we’ll do it all behind the scenes and you can explicitly create instances of these objects and then use the value of method like we saw here just a moment ago to convert them into their primitive equivalence but it’s not really necessary so you know what’s this new keyword all about and what’s this uppercase letter in this function name all about well i’m going to explain that in the very next lesson we’ll see there thanks so previously we saw how to create an object literal using this style of syntax and you’ll note that i’ve already created a file called constructors.js go ahead and take a moment to create that yourself if you want to follow along i’m just going to paste in the car that uh the literal car that we created in a previous lesson here with the make model and the year property uh set to bmw 745 li and 2010 respectively now there’s actually another technique for creating an object and that’s through the use of what are called constructor functions so let me go ahead now comment this out and then let me go and create a new function and i’m gonna name a car and it’ll have some input parameters uh one for each of the properties that i want to initialize upon the creation of the object that gets returned from this function so make model and year and then we’re simply going to say hey the object that gets returned set its make property to the make input prep parameter that was passed in as the first input parameter and you’re going to add a model property to that object and you’re going to set it equal to the model parameter that was passed in and then you probably guess what this next line of code will do same thing with year right and most importantly whenever you’re creating an object using this this function it requires the new keyword so let my car equals a new car with a capital c did you notice that i named my function with a capital c car i’ll explain that in just a moment and intellisense tells me that it requires three input parameters into this function so here we’ll go uh bmw 745li 2010 all right and so what’s really going on here and let’s just go ahead console.log just to prove there’s nothing up my sleeve here my car and here we’re going to go uh node constructors and there you go we get a car object that has the properties make model and year populated all right so what’s going on here is that the new keyword creates an empty object calling the function in this case car it will take that empty object as the this remember our discussion about how the this keyword gets bound to the context from which it’s called well in that case that new object gets kind of becomes the context for this function call and so this empty object starts receiving new properties on lines 8 9 and 10 with new values set to those new properties what gets returned from this whole thing with the call to this function is an object with properties make modeling your already set all right so it’s important to remember that the functions themselves that we define here beginning line seven are not constructors although if you’re coming from another programming language like java or c-sharp you might be inclined to think in those terms because that’s how they work but rather in javascript it’s the new keyword in front of any normal function any function that makes it a constructor call all right it creates a uh a new empty object and it will pass it as the this to that function call that you make so the new keyword kind of elbows its way into the execution pardon me excuse me i need to get in here and it uh and it says to the function first before you execute i need to create an empty object and give that to you into this so it’s bound so this is bound to this new empty object and then it says okay now you can continue to do whatever you were going to do now the function itself could ignore that new empty object or it could use it like we have an 8 9 and 10 here all right so just to kind of prove that let me go ahead and comment all that out and let’s create a function my function and i’ll just do something simple like hey uh i am a simple function [Music] right and then we’re gonna go var my function equals new my function and then we’re going to go console.log type of my function [Music] or actually let’s go lowercase m or my function i’ve got some things wrong here like there we go that’s what i want to do and um so let’s all kinds of problems with that line of code but i caught them before i executed it so that’s good all right so you can see here in line number 21 we are creating a new empty object and then calling my function my function executes but not before a new empty object is kind of passed to it into this now this is not used in the body of my function so it’s returned back to this variable of the same name but with a lowercase m probably should have chose a different name if that causes any confusion i apologize just remember lowercase m my function is different than uppercase and my function in this particular case but when we take a look at the type of my function it is object all right and so at this point you know it’s an object so you can’t really do anything interesting with it it’s no longer a function so you can’t do that in fact here let me just um kind of copy and paste this little note i put to myself in my notes here you can’t really do anything with this particular object it’s certainly not a function reference anymore it used the function as a constructor but the constructor function didn’t really do anything to populate the properties of it and you know this will not actually do anything in fact if anything let’s just see what happens if we run this yeah we get an exception here that my function is not a function so we really can’t we can’t do that all right hopefully that makes sense the right reasons why but the only thing you can do with you know what gets returned here my function is that you can attach properties and methods to that empty object which is kind of the point of the new keyword entirely all right so what about this upper case first letter convention i said that it was a convention what’s a convention what is this particular convention you know specifically well you’re basically saying my intent is that this function be called using the new keyword that’s what the convention is basically i am a function but i should be called uh i should be used as a constructor so you should only use a new keyword on me and i’m expecting an empty object be passed to me so i can set some properties on it or maybe add some methods as the case might be all right so just keep in mind that in javascript what makes a constructor function has nothing to do with the function declaration itself but rather how the function is being called it must be called using the new keyword in order to be a constructor function so in the previous lesson we learned about the built-in native constructor functions that return objects with properties and methods to wrap around the primitive types and give them essentially superpowers giving them new properties and methods that will operate on the primitive value new functional new functionality like the two uppercase uh the two lowercase the length property and others that we’ll learn about but that’s why they’re defined as uppercase s in string uppercase n in number uppercase b and boolean and so on that’s why you can explicitly create one of those built-in natives if you use the new keyword like we demonstrated in that previous video so hopefully that all makes sense uh if nothing else i hope you’re learning how javascript is all about functions first of all and secondly how you call a function really changes the the the meaning of the function and what it’s intended to be used for it changes even in some cases the functionality that’s defined inside of the function like in the case of this or perhaps changes the purpose of the function like we saw here um with the new keyword and calling into the function all right so doing great let’s continue on see in the next video thanks javascript has objects and we’ve seen how to create a literal object and we’ve seen how we can construct an object using a constructor function and the new keyword like in the previous video in some of the most popular programming languages you create an object using a pattern called a class or construct called a class in other words you create a class named car and then you create individual instances of the car class as individual separate objects now furthermore you can create specialized versions of one class borrowing all the properties of that parent class in the new child class so you have an original class and you say i want to inherit everything that that original class does in my new class and then you can extend it by adding properties and methods to it to make it a more specialized version of that original or parent class so to kind of extend the analogy here i may have a car class but i want to create a sports car class that extends the definition of just a normal car and it adds on things that make it sporty same thing with a minivan it’s just like a car it has some of the basic principles of a car but a minivan also has like number of passengers and cargo capacity things that make it unique a unique type of car all right and then i can create instances or objects based on that minivan or objects based on the sports car and those objects are both have similarities to a regular car but they have differences as well all right so that’s kind of the notion of of classes and inheritance and classes and inheritance are a foundational concept associated with object-oriented programming not sure if you’ve ever heard the term but it’s a pretty big deal among software developers so you might be asking yourself well first of all does javascript have classes well yes and no i mean in javascript you have objects and you can create an object and dynamically add properties and methods to it whenever you want to but objects are the focus in javascript in languages like c sharp and java and c plus you create a class and you add properties and methods to the class up front and they’re static in so much that they cannot be changed so you can’t be adding properties and method declarations to the object at run time i mean you can but it’s not the original intent of object oriented programming um [Music] they can’t be changed over the lifetime of any objects that are instances of that class so here in in object-oriented programming uh languages base languages like c-sharp and java classes are the focus javascript objects are the focus c-sharp java c plus classes are the focus the latest version of javascript does in fact have the concept of a class but it’s a weird little stop gap measure to help people that are trying to make the mental leap from an old language that they might be familiar with like c-sharp or java into the world of javascript to a dynamic object-based programming model so i talk about javascript classes in one of the upcoming lessons and we’ll get to that soon enough but i guess okay so javascript kind of supports classes kind of doesn’t support classes what about inheritance well here again javascript yes it kind of supports inheritance but not really the kind of inheritance from traditional object-oriented programming so in javascript you have something different called a prototype chain so let’s suppose that you define a literal object like our typical car example that we’ve seen so many times won’t even paste into screen you know what it looks like it has a make model in year property right and so you define this literal object like our typical car example you like the properties and the methods that you’ve already added to that object and you would like to use that car object as the basis for a new car object you’ll probably wind up changing some parts of the object’s definition maybe some new values and a few of the properties you might even add some new properties and methods to that new object and i’m going to demonstrate a technique that allows you to construct a new object based on an existing object here in just a moment but when you do that when you create a new object based on an old object something special happens in javascript there is a permanent link that’s created between those it the new object always knows who it inherited all those properties its original set of properties from how did it get created it always knows uh kind of the link between it and the prototype that came before it all right in other words the original object serves as a prototype for the new object and the new object is essentially chained to that prototype from that point on so in languages like c sharp and java and c plus those traditional object-oriented programming languages you create a class hierarchy where one class inherits from another class so whenever you create an instance of the child class there’s really nothing that’s linking that that instance of the child class back to the parent class so there’s nothing linking that child object back to the parent class definition so here again the focus is not on the relationship of individual objects that happen to be linked to each other and kind of have a brotherhood but rather more of a parent-child relationship in traditional object-oriented programming again the relationship between classes is the focus of object-oriented programming whereas in javascript it’s the relationship between uh between objects and how they’re chained together it’s a sub uh subtle but important distinction between javascript and other and traditional object-oriented programming languages so some people use the term javascript prototypal inheritance all right but i’ve tried to stay away from the term inheritance when talking about javascript because it might conjure up traditional object-oriented programming concepts that would mislead you whenever you’re considering how it all works in javascript one of my favorite favorite javascript authors kyle simpson called this style of object-based prototypal inheritance it calls it really objects linking to other objects or ulu o l o o objects linking to other objects and i really like that description and by the way i’m not sure one way is necessarily better than the other they’re different their pros and cons depending on what you’re trying to accomplish the given problem you’re trying to uh to solve so what i do want to do is have a better thorough understanding of how you know objects linking to other objects actually works and what are some of the ramifications of that so that’s what we’ll do in the rest of this video so you can see that i have a new file called prototypes.js and here i’m going to paste in my original car this looks an awful lot like the car literal that we’ve been creating object literal that we’ve been creating up to this point now i told you that there’s a way to create a new object based on an existing object and so let me do that we’re going to say hey let our new car equal capital o object dot create and then original car all right so this point if we do for example console.log car dot make for example so let’s um node prototypes okay so we have this new car and what it looks like at least at first glance it appears as though we have a new object called new car and the value of the original car has been copied in of the make property of the original car has been copied into the make property of the new car but that’s not exactly what’s going on here as we’ll we’ll talk about here in just a moment but at this point i have two objects i have the original car and i have the new car and i could do several things at this point with new car i could change the values of the existing properties that i have on new car i could add new properties to new car or new methods to the new car or i could delete the existing properties from new car all right but more interestingly i want to revisit something i said earlier about the relationship between the original car and the new car that there’s a link between the new object and its prototype its predecessor the original car and so if we do something like console.log and we say object dot get prototype of and inside of that method i’m going to say new car so tell me who the prototype of this object new car is and it’ll say it’s this object right here where the make is bmw the model 745li in the years 2010. all right so it’s pointing to this original car so let’s do this instead we can actually get a reference to my prototype get prototype of passing in new car and then i can do console.log my prototype dot make and so you can see here that i’m able to get back to that to the make property of the original car now there’s no way to really prove that because they both seem to have the same values right now but we’re going to push this a little bit further what happens if i were to add a property to the prototype in other words what happens if on original car i were to add a doors property like a doors count so if you remember all i need to do on an object to add a property is just go hey i just want a new property called doors so i do doors and then i’m going to create the value and say hey it’s for now let’s go console.log newcar.doors all right you can see that the new car gets this doors property and it seems to be copying that new property over but that’s really not true but we definitely see that there’s a link between the uh the new object and its prototype the original car but how do i know if the property is defined on the new object or on the prototype well here’s what we can do and so this is going to help us to kind of get to the bottom of this relationship right here we’re going to start with the original car and says do you have your own property does this property belong to you or are you essentially borrowing it from your predecessor so first of all it’s true that the original car has its own property called doors okay so console.log new car do you have your own property called doors and that’s false all right so kind of tying this all together and kind of explain what’s really going on here well whenever we attempt to get a property or call a method on an object javascript will go through a series of lookups to find the value or the definition of the property or the method in order to call it so after we created new car it had none of its own properties if we asked it for the value of one of its properties doing something like we did um here in line number nine it would find the prototype that new car links to and see that if it has its uh make property so we know that the new card does not have a property that we define on it called make but what about its prototype and yes the prototype the original car has a make property and it’s set to bmw okay but once we do something like this new car dot make equals audi all right so we are changing the property or we’re actually we’re creating a property on new car and we’re setting its value to audi at that point what happens is whenever we come down here and basically call the same essentially same line of code now in line 11 it’s saying hey new card you have a property called make and new car says yes i do now i have my own property called make and it’s set to the value audi all right so no longer do you have to continue and look at my prototype to find the property and its value you could look at me and find the property and its value all right so javascript doesn’t need to look at the prototype chain if the property is created and set on uh the new object that is essentially created from the prototype so if we ask for a property that’s not yet been defined so here we go let’s go here in line number 12. console.log new car dot whatever all right now think about this whatever property does not exist on new car whatever property does not exist on its prototype the original car so what happens next um well then javascript will traverse back and say hey original car what are you linked to and since we defined original car like this we’re linked back to type object actually it is the um the built-in native object function however the whatever property is not defined on that either so now what happens well finally javascript will do one final traversal asking the object built-in native object what its prototype is and by default it will return the primitive undefined so when we get to line number 12 in fact let’s go ahead and comment out just about everything else here i’m going to hit a there and we’ll get rid of all this just so we can kind of see what we’re doing here so at this point what happens we get undefined why because new car doesn’t have a whatever property we look back and the prototype original car doesn’t have whatever property it’s prototype object doesn’t have a whatever property and its prototype is undefined and that gets returned okay that’s the end of the chain so to speak and that my friends is basically how the prototype chain works in javascript you don’t have to use this you probably should know it although you could probably go your whole career and not really have to ever deal with it however this is fundamentally how all your objects work and why you get the undefined type returned when you attempt to access a property value that doesn’t exist so i tried to make this as simple as possible but this is a post-beginner topic in fact i was looking at some tutorials online and i saw that this was actually an advanced topic but if you kind of understand what we’re talking about here think about how far you’ve come in your javascript understanding to get to this point where you can kind of understand what’s going on that’s impressive so i would just recommend that you watch this again you take a look at a few other tutorials online you give it some time to sink in and you’ll probably leapfrog over a bunch of people who are trying to learn javascript but not really pushing themselves past the absolute basics you’re doing great hang in there we’re making great progress and we’re getting close to the end relatively close all right so we’ll see in the next video thanks in the previous lesson i said that javascript doesn’t have classes at least not in the traditional object-oriented programming sense nor did it have inheritance in the traditional object-oriented programming sense i explained how javascript is focused on objects and the linkage between objects that are based on objects we also looked at constructor functions that allow you to construct a new object from a function call but this really isn’t a class in the traditional object oriented sense either but technically javascript does actually now have classes or the notion of a class and it was introduced in the last version of javascript now javascript classes give you the impression that you’re working with something that resembles traditional object-oriented programming but in reality nothing has really changed javascript remains object focused and objects can still be prototypally prototyped prototype chain together i don’t know how to say it correctly javascript classes are what is termed syntactic sugar on top of the existing javascript object and prototype models that term syntactic sugar you’ll see that frequently in software development circles it’s programmer slang that means that they added a few keywords and structures in javascript but these merely map to existing features of javascript they don’t really add new features per se so the syntactic sugar might help those who are transitioning from more traditional programming languages to javascript but javascript purists are quick to point out that this new feature the class feature in javascript may do more harm than good because at the end of the day you still have to make the switch from classic or traditional object-oriented programming to a more object-based prototype inheritance if you want to use that term and if you’re working with prototypes you have to learn the things that we talked about in the previous lesson okay so in a nutshell let’s talk about what a class is and define a class it’s essentially a way to define and create objects and so just like there are function declarations and function expressions now there are class declarations and class expressions so let’s start off with just looking at a class declaration and so you do something like class car whereas an expression would be more like let car equal class and then whatever okay so fairly simple and hopefully straightforward it’s basically declaration you give it a name an expression is well it’s an expression so javascript classes can have a constructor function that gets called automatically whenever you use the new keyword so let’s go with the declaration version of this i’ll comment this out this expression all right so inside of the declaration let’s create a constructor function you have to use the term constructor then you can add any input parameters that are essentially going to map to properties that you’re going to add to a new instance of an object based on this class so here again you do something like make model and year and just like in the constructor functions that we learned about a couple of videos ago you still use the this keyword make it will make this dot model equals model this dot year equals year okay so you can see similarities here right and then uh to create a new instance of an object based on this class you would do let my car equals new car passing in you know bmw 745li and the year 2010. okay so again i want to make the point here that that word or that name of your constructor function in a class definition in javascript has to be named constructor in order for this to work and here you’re still using the new keyword new still creates an object instance it still passes it to the constructor function now in this case the name of the function is not car it’s the name is constructor but you’re passing input parameters into that constructor method and then using this this context it’s the new empty object that we’re attaching properties to and then initializing their value to the arguments that are passed into the constructor all right hopefully that all makes sense and it’s similar enough to what we’ve already learned that it kind of you can see where things are mapped again syntactic sugar on top of what already exists all right so you can also create methods on the class um in fact let me do it outside of the constructor method so here i want to create a print method [Music] and you know i can do something like console.log and then i’m going to go ahead and use our special sends string syntax interpolation syntax let’s make some space for myself here and i’ll say uh this dot make this model and um i’ll format it a little bit with some parentheses but inside we’ll go this dot here all right so here again now that i have an instance of my car class called my car i can call print like so and so let’s go um [Music] node classes and you can see i get the nicely formatted version of the information in my car class you’re calling the print method all right now beyond these basics you can actually approximate inheritance at least inheritance in the classic optic dorian programming sense so in our case let’s kind of go down here at the very bottom and i want to create class sports car and i have to use the keyword extends car all right so right off the bat when i do that and i create a new instance of sports car let’s do that so uh let my sports car equals new sports car now i don’t have a i don’t have a constructor function defined but when i use the open uh the open parenthesis notice that intellisense still sees that i have make model in year why is that because by extending sports car from car i still get the constructor method defined on car and i can still set the make model in the year so here let’s go um [Music] dodd whoops dodge viper and i don’t even know if there’s a 2011 version of it but i don’t know if they stopped making it or if they’re still making it i’m not even really sure but it doesn’t matter all right so um at this point and we can even call mysportscar dot print all right and now we get that print out here like so so we’re extending we’re borrowing the entire definition of our class and we are getting the constructor method defined in car we’re getting the print method to find a car but i can extend and push beyond the boundaries of the car’s definition by adding properties and methods so for example here let’s just add a quick method and i’m going to call it since it’s a sports car we’re going to create a method called rev engine which will be a unique printout of information so console.log and we’ll do something dot vroom goes the this dot model okay so now i can call my sports car dot rev engine and i get vroom goes the viper i guess i should have had a space right there all right now what if i were to do this i still have my car can i go my car rev engine let’s see nope can’t why because it says rev engine is not a function well it is a function it’s just not defined on the car class it’s defined on the car classes inherited child called sports car so you can’t access rev engine from the car class and you know what honestly there’s more to it than that um there are some advanced scenarios but that should be enough to show you what cla uh the class keyword and the extends keyword can do and how it operates and you can see the rough equivalence between what we did here and what we’ve done previously and hopefully you can kind of see that there’s a mapping in that ultimately what’s going on behind the scenes though is that we’re creating a sports car object and its prototype is car and we’re adding on a rev engine method but when we look up the constructor function when we look up the print method it’s still using prototypes behind the prototype chain behind the scene to manage all that it’s just javascript is kind of covering that up just a little bit with some different syntax okay so my personal opinion is that if you’re coming from a traditional object-oriented programming environment and you need to become productive very quickly because you have a looming deadline or whatever the case might be you might be better off trying something like typescript which was created by microsoft it gives you the feel of c-sharp and java more so than javascript will and it gives you more of that traditional object-oriented programming look and feel and ultimately it will transpile down to pure javascript kind of out of the context of this conversation just what you should do is go to typescriptlang.org and you can study up on it a little bit but it’s essentially a super type of javascript meaning anything you do in javascript will work in typescript but typescript gives you some extra features that will make it feel more like java or c-sharp if that’s something you need but most importantly if some of this doesn’t make sense the things that we’ve talked about here don’t beat yourself up about it again this is a feature that was added for specific demographic people coming from other programming languages it may not have been intended for somebody who is just starting to learn javascript so don’t feel like the pressure now to go out and learn traditional object-oriented programming before you can understand how to use class you don’t even need to understand this it’s just again something for a stop gap measure for people coming from another programming language um [Music] so it might not be immediately obvious to you in what situation you might find yourself using this and why you would prefer this over what we looked at in the previous lessons but at this point just focus on um the language the fact that these things exist the fact that they were added for a reason and the reason is to help somebody else maybe not you specifically somebody coming from a different background to make that transition to javascript and you know ultimately i think with a lot of the things that we’re talking about here their usefulness will reveal themselves to you later whenever you start programming and creating real applications with this language all right so uh you’re doing great just hang in there we’re making great progress um you know the fact of the matter is that learning is is iterative and if this is your first attempt to learning any programming language or your first attempt at learning javascript specifically no doubt you’re going to need to come back to some of the ideas that we talk about you know in the coming days weeks or months and you’ll continue to come back to some of these ideas over and over i mean i keep studying and kind of pushing in new directions coming back to studying the basics and then pushing a different direction and you have to do that in order for these ideas to fully sink in over time i mean i’ve been working with javascript almost my entire career and i’m still learning things so it’s just the nature of learning this sort of stuff there’s so many details and there’s only so much time in the day so don’t beat yourself up you’re doing great you’re taking great strides towards understanding javascript so hang in there we’re just kind of entering the home stretch now you’ve come so far just a little bit more and then you can honestly say that you’ve you’ve got a firm foundation of javascript to build on okay a little encouragement to get you over the hump here all right we’ll see in the next video thanks in the most recent version of javascript you can define a function using a shorthand syntax called arrow functions and arrow functions since they are just a shorthand syntax for creating a real function and functions are used everywhere in javascript as you know by now you might not be surprised to hear that there are many different ways that arrow functions are used in javascript and there are many different syntax variations to boot so what i want to do is start simple and i want to look at a few practical applications of arrow functions but we’ll start using them as frequently as possible from this point on and you’ll begin to see them pop up just about everywhere all right so you can see that i have a file called arrow functions.js that i’ve already created and i want to create my very first super simple arrow function so here we go i’m going to create a function called hi i’m going to set it equal to a set of empty parentheses what’s called the fat arrow operator so equal sign in a greater than symbol after it to kind of resemble a fat arrow i guess as opposed to a thin arrow which has absolutely no meaning in javascript this fat arrow then will point to a body defined by an opening closing curly brace and then we’ll do console.log howdy okay so far so good right one line of code an entire function declaration and we can just call hi so here we go let’s go um uh node arrow functions and we get a simple word howdy printed out okay that’s easy enough so let’s comment that out and move on to a slightly more interesting example um we can actually go let hi and inside of the open and closing parentheses we can accept an input parameter so what these really are instead of using you know the keyword function we just get rid of the keyword function but this remains and it allows us to define an input parameter name inside of or after the fat arrow and inside of the body i can go console.log we’ll use our our special backtick character and we’ll go howdy and then dollar sign open close and curly brace name add a few semicolons to the ends of some things here really probably don’t need this one per say now let’s call hi bop howdy bop okay so you can see that all we’re really doing here is just creating again a shortened version of a function and we don’t need the keyword function we just go ahead and start with the opening closing parenthesis to define the area where we can add input parameters the fat arrow points to the body of this of this arrow function and inside of there we can just do whatever we want to do just like we can in any normal function even reference input parameters like we’ve done here all right now up to this point we’ve just been kind of creating what i call void functions they don’t return anything but what if we need to use the return keyword let’s create a different version of this so we’re going to create add add equals here we go we’re going to allow this to take two input parameters a and b and we’ll just do something super simple we’ll hear once again but we will use the return keyword a plus b and now we can do console.log add seven three and we get 10 printed to screen okay can you see this same basic structure here we’re accepting two input parameters separated by a comma here we’re still referencing those in that body that we’ve defined using open and closing curly braces use the return keyword it’ll get returned to our method as a as a return value of our method call and here we’re just passing in numbers getting that value back and printing it to screen okay so far pretty easy stuff right now you might be wondering how could i ever use this sort of thing um what is its pertinence and so i think that one of the ways that i and uh see them using being used the most is whenever you need to run a function over each element of an array and so let’s use our let names equal and you’ll recognize these names once again okay this time we’re going to call the map method now this happens to be a a method defined on the array built-in native object that we learned about but we’ll talk about more of these helper methods built into the array built-in native object in an upcoming lesson but the map is a pretty cool one because what it allows us to do is to basically iterate through each element of an array and when we it iterates through it will actually allow us to call a function and this is a perfect spot for creating right inside of here one of our arrow functions so in this case let’s say you’re going to iterate through each element of names whoops i need to use the right word here names right and so here we’re going to create an arrow function that accepts a name and what we’ll do is to marry these two ideas together console.log and then howdy name all right and you can see basically in one line of code i was able to map each element of the array to our arrow function it passes in the name to the arrow function in the body of the arrow function now we can simply operate on it just like we were doing previously but as a result now for every single element of our array we’re getting a console.log with our little message okay pretty cool pretty cool let’s take this one step further as we continue to build on this idea let me grab this line again so i don’t have to retype that and then i’m going to say let i equal zero and actually let me just grab this line too because i want to do something a little bit more interesting because i want to show that you can actually do a little bit more in a single line like for example here i might increment the value of i and then use i here in the body but now i’m essentially doing you know two commands or two statements inside of the body and i’m not saying this will you’ll do this very often but it’s certainly possible all right so now let’s do uh save that get back to that so now david1 howdy eddie 2 howdy alex 3 howdy michael four all right all right let’s continue to build on this and now let’s use the return keyword kind of in the same doing the same sort of thing here so start with names uh in fact let’s go var transformed equals names.map and then i’m going to borrow some of these pieces here again i’m just going to borrow that except i’m not going to call console.log i’m just going to return that string see if we can get this all kind of lined up here okay so i’m re going to take every name in names and i’m going to return howdy plus the name and now i’ll do console.log the entire array that is going to be returned from this and saved into transformed so here we go whoops i got a spell log right all right and so you can see that what gets returned here because we’re returning multiple values they get added to essentially an array and now you can see on each element of the array is the literal string that we construct inside of this map function using an arrow function to do the construction and those individual names are now transformed and saved into a new array instead of just david eddy alex now it’s howdy david exclamation mark howdy eddie exclamation mark and so on all right so arrow functions are simple to create and they’re just a shorthand version of function expressions they really are useful whenever you’re working with functions on arrays like this map method that allows us to map each element of an array to one of our arrow functions and then basically execute that function against each element of the array and so we’ll see some other examples of this in some upcoming lessons all right pretty cool stuff all right we’ll continue on the next video we’ll see you there thanks designing a course can be challenging sometimes because when you finish a topic there’s a number of directions you can go after that topic but if you have an overarching idea that you want to get to eventually you’re going to have to kind of leave some important thoughts on the side and come back to them later and that’s really what’s going to happen in the next four or five lessons or so these are topics that could have easily been covered much earlier in the course but because i was trying to get somewhere i left those details off till now so hopefully you don’t mind that we’re going to circle back and fill in some of the or backfill some of the topics that we just didn’t cover in a lot of depth and the first that i want to talk about are these terms truthy and falsey which seem to be specific to javascript i haven’t seen them used in other programming languages maybe i just haven’t looked at the right programming language but basically it has to do with with evaluation so when you evaluate an expression like for example in an if statement or in a switch and you perform an evaluation of expressions sometimes they’re going to return absolute true or false one is greater than two that is false patently false and i would expect that i would get from that expression the false value but then there are other things that are not quite as obvious and there are rules in javascript that dictate whether an expression is truthy it’s it’s in and of itself it doesn’t look like it would be true but because of the rules of javascript it is true and things that are falsy doesn’t look like it would be false but based on the rules of javascript we’re going to call it false all right and so if you just don’t know what those are you’re going to maybe perform an a or evaluate an expression you’re going to get a true or a false and you’re going to be like what in the world’s going on there why is that true why is that false so i want to cover these cases and i hope you don’t mind that i’m just going to copy and paste these right in because it’s a pretty big chunk of code we’ll just look at these things but and the top these are things that are falsy well right off the bat line number one if you’re going to evaluate an expression if false that’s always going to be false that’s not really falsy it’s just false all right but then there are things like null if no well in and of itself no you know if we’re looking at this completely subjectively null is not true or false it’s it it doesn’t really have a connotation of being true or false it’s just null we’ll talk about null later however it’s considered by javascript to be a false c value same with undefined undefined is not good or bad it’s not true or false but javascript says that if something pops up and after evaluating expression it comes to undefined that’s going to be a false value the same with the number zero if an expression is evaluated and what’s output is the number zero that is a false c value it will return false in that expression same thing with not a number same thing with an empty string whether you use in lines six or seven single quotes or double quotes to define your your string now everything else is pretty much truthy in fact i don’t even know if there’s the notion of truthy in javascript it’s just everything is that’s not in falsie is essentially truthy but i gave you some examples here obviously just like if false is falsy if true is going to be truthy it’s just true but things like an empty object if you evaluate an expression and it returns an empty object for the purpose of of truthy and falsey it’s truthy same thing with an empty array same thing with a string that’s not empty so we saw empty strings are falsy but a string if you have something in it it’s truthy okay a new instance of an object is truthy even though there’s nothing associated with there’s no properties or methods doesn’t matter truthy same thing with any non-zero value whether it be an integer or a float which means values after the decimal point those are all truthy as is a constant in javascript called infinity whether positive or negative infinity all truthy values so here again if you ever come across something in an evaluation it returns an odd an odd value that doesn’t strictly return true or false it returns a null or undefined or not a number or a zero or an empty string falsely it’s going to the evaluate the evaluation of that expression will be false but everything else is pretty much going to return true okay that’s all i needed to say in this video hopefully that makes sense all right we’ll see in the next video thanks continuing the sentiment from the previous lesson where we’re kind of doing a roundup of topics that by all rights could have been discussed earlier in this course but we’re going to introduce them now i want to talk about the last of the data types that we’ll encounter the data type null so it basically null represents a variable that points to nothing but an object reference was expected in that case so just as a quick reminder you can create a variable and not set any value to it not initialize the value not set the value and in both cases or whenever we look at the actual value or the type of the value it is going to return undefined so the value of a because we’ve not set it to any value is undefined and the type of a is undefined all right but here that’s just a variable we didn’t set it to a primitive string number or boolean or anything of the sort all right let’s suppose that you actually are expecting the variable to hold a reference to an object so just to kind of copy a quick example from a previous lesson let me comment all this out and paste in this so here we have our regular expression example where we’re going to try and match a pattern x y z and we’re going to use the strings match method passing in the regular expression literal that we created in line five but this time there is no match there is no string x y z in my value variable so what is result set to well let’s see what we get in this case we get result is set to null all right well what is the type of results type of result all right this is going to require a little bit of explanation okay that’s the quirk with null it will actually return object not the primitive type null and that’s a known bug in javascript that will likely never be fixed because too much code on the internet depends on the fact that typeof null equals object is you know it’s it’s basically baked in and grandfathered at this point but by all rights if if javascript had been designed correctly from the start that would be null but hopefully you’ll get the idea there all right um but the interesting thing about getting a null result when we expected an object back is that we can do something like this and i’ll just copy and paste this instead of typing it all in we can check results and say are you you know and we’ll do the strict equality uh strict equality evaluation is result null and if it is then we can say well no no match was found xyz was not found in our value all right and so this can be extremely helpful whenever we’re uh building our applications all right so just to kind of recap null the primitive data type null is not zero it’s not undefined it’s not an empty string it simply means that you have a variable where an object reference was expected but it’s not set to any object reference it’s different than undefined right because undefined says i’m expecting to have a value but one was never set and it was expecting maybe a number string or boolean no no we’re expecting an object reference but we don’t have an object reference at this time uh set to our our variable okay so hopefully that makes sense and let’s continue on see there thanks it’s been quite a few lessons now since we’ve talked about the built-in native functions that return that return objects we saw at that time that there was a date constructor function and that date constructor function will return an object that allows us to work with dates and so i just wanted to take a brief look at what it can do and how you can actually work with date type information using the date object so let’s start off with a very simple case here i’m going to say hey let today equals new date and that will by default give us right now this date and time all right so what i can actually do is actually initialize that date object with a specific date using one of several different formats so i may want to like create a date that represents my birthday so i’m going to create a new date and i’m going to pass in and this is interesting right because if i look at intellisense it has an up and down arrow i can actually use the arrows on my keyboard and it will show me the various versions of constructors that are available with which to initialize the state objects so we could start off with something really simple and just kind of a full day like december 7 1969 and we’ll give it a time even at 7 0 1 23 just guessing at the actual minute and second of my birth i don’t really know exactly i know it was early in the morning that’s all so that’s one way to initialize uh the date but there’s a couple of other ways um and uh let’s just do like let bob equals date and there’s a file system date type that looks something like 1969 dash 12 for the month dash 07 and then t for time and then 0 7 because it’s you know on a 24 hour schedule colon um 01 colon 23 and that’s roughly about the same these these two will create the same basic time all right there’s also we could just kind of simplify things a little bit here using a different format just just give it um [Music] the year month base zero and day i think base zero as well though i haven’t really i’m not really entirely sure about that um and then what bob it’s kind of the same thing [Music] 11 6 and then 7 1 seven comma one comma twenty-three so i think these are about the same i may be off by one i forget if it’s zero based or one base but you can look that up fairly easily i’m not gonna use these but i just want to show you that they exist okay but we have here now today’s date and my original date my birth date and so what we can do is something interesting like get the time that’s elapsed between those two dates by just saying var elapsed time equals n equals today minus bob console.log elapsed time and what will get back to me is the number of milliseconds all right between those two between those two dates so this is the number of milliseconds and i could divide it out calculate the years the months the days the hours minutes and seconds if i wanted to all right so that’s one thing that i can do is determine the elapsed milliseconds between two dates you can also get parts of a given date so i can go console.log bob bob.getdate and um it returns seven what does that represent that represents the day of the week so in in this case monday would equal one and sunday would equal seven which seems a little backwards to me but hey that’s what you get when you create a language and you set null equal object and other kind of quirks like that moving on console. bob.gettime and this will be represented the time of day in our date object so that was uh the number of milliseconds and so that’s a little bit less useful but you can do other things and let me just paste in a bunch of these [Music] all in one shot you can get the month today hours minutes seconds and milliseconds and then there are also some additional date functions for things like conversion to utc or universal time code and local dates and times so converting back and forth between utc and local date time and that’s pretty much what you can do with the date object and so let’s continue on in the next video thanks previously when learning about built-in natives i explained how the string primitive is mapped to the string built-in native object and by boxing the string primitive into its equivalent string native object built-in string native object javascript therefore will supply us with a rich set of functions now in this lesson i want to demonstrate just a handful of these very useful string methods that are supplied to us by the string built-in native object and explain why they’re useful and i’m just going to pick the ones that i think are useful to at least they’ve been useful to me in the past but there’s a bunch more and i would just recommend that you use bing or your favorite search engine to search for javascript methods of string and you might find the mozilla developer site and it will give you a full listing of all the methods that you can get on that string object all right so first of all we’re going to need a few strings to work with just for fun and so i’m going to create some some different ones here two are quotes so the first quote is knowledge is power but enthusiasm pulls the switch and second is a famous quote from a good friend of ours do or do not there is no try and then finally a listing of random numbers that mean absolutely nothing and then you know one of the things that i didn’t really mention at the time is that um you realize that uh and i’ll just put this here you can even call these these methods on string literals like for example console.log bob loves you dot isn’t that crazy that you can just do dot on a string literal and call to uppercase well you certainly can so let’s see this message in all of his glory because i do in fact whoa it’s called strings i do in fact love you all right let’s move on all right so let’s um let’s use a couple of uh interesting interesting methods of string so we’re going to use the split method i’m just going to call set my split equal to the third this third one defined on line three with those variable with those values those numbers that are separated by commas and the split method will allow you to say hey every time you see a comma split that up and take the element in between the commas and add that to an element of a new array and so let’s go console.log my split and here we have an array with each value as a separate member of our separate element of that array pretty cool so you’ll do this a lot whenever you’re working with data and it comes to you in some sort of string like format you can split it out all right next up we can slice a string so let’s go let my slice equal first dot slice and then we give it the starting index and the ending index just to kind of pull out one little piece of the string and put it into its own variable so then we can do a console.log my slice so this first sentence we would count you know to the position 13 and then to position 18 and hopefully we’ll grab out that word and we do we grab out power same basic idea with the next one which is substring it’s just a tiny bit different so let my substitute equals first dot substring and here we’ll start with that same index but we’ll say just instead of giving you the end position just go over five five positions so this is the start and then this is the length that we want to pull from that from that first string it’s gonna go console.log my substitute and we get that same value there okay similar ideas between slice and substring moving on we want to return true or false if our string ends with a given string to compare it with so my ends with equals and we’ll use that second string that i created here try or do or do not there is no try and we’ll say hey does that string ends with true or false the word try period and then we’ll go console.log my ends with true great and um hey well and we can do sort of the same thing let my starts with equal second dot starts with and so this is just a way for me to say hey is this the string i was expecting does it have the values in it that i want so i can say does it end with this does it begin with this true or false all right so that’s true as well and then we can even say hey you know some someplace in the string [Music] does it include the sub string or the string there so is the word there used in that second string console.log whoops my include whoops there is no there all right how about capital t in there ah that’s true all right so it is case sensitive all right so let’s come in all these out interesting now let’s uh say let my repeat equals ha exclamation mark space dot repeat and the number of times i want that repeated is three and then let’s do a console.log my repeat and i get ha ha ha so the repeat method will repeat whatever the string is the number of times you tell it to and then we save that off to do its own variable and i think the last one we’re going to look at is a way to kind of clean up a string so let my trim equals and i’m going to put a bunch of spaces here and then in between i’m going to say this is bloated right and i want to clean it up a little bit so i’m going to go console.log and uh the first time through i’m just going to say trim.link this will give me the total number of characters in that string but then the second time i’m going to do what’s called chaining method chaining so my trim dot i’m going to use the trim method that should clean off all the empty spaces at the very beginning and the very end of my string and then i’m going to grab the length property so you can see dot trim dot length i’m able to since trim will return a string then i can call the next method or property on the string because i’m working again with the string type so i’m chaining those calls together to get the result the essentially the before and after so before i call trim we’re looking at 16 total characters here but when i call the trim and i get the length there’s only seven characters that means the word bloated should only be seven characters long and it is all right so those are some helpful string methods on the built-in native string function constructor function and we’ll do the same thing for array in the next video we’ll see there thanks since we gave strings methods the proper treatment i wanted to do the same for arrays so we’ll do that here and let me create a couple of arrays here i’ve got an array called names and an array called others i’ve got an array called lost and an array called fibonacci so the obvious difference is that here i’m working with strings here i’m working with numbers all right so we’re looking at methods that can be applied to arrays right so the first thing we can do is combine two arrays together so we can use the concat method so here i’m going to take the loss numbers and i’m going to concat them to the fibonacci numbers giving me a combined set of array values and here i’m going to go node array dash methods the name of the file i created and i get a long set a complete set where you can kind of see the division between the two sets now they’re all in one array okay seems like it might be helpful at some point otherwise we’d have to loop through and push or pop or i mean push uh elements of one array into the other array that might be a little bit uh a little bit of a cumbersome process you can also do something interesting like console.log and we can take combined or the combine well we don’t need that we can use fibonacci and what we’ll do is call join and i can say hey join all the elements of the array together and separate them with this string so i’m just going to use like a tilde here for no other reason than the fact that we just haven’t used utility yet and i think now we’ve used every character on the keyboard at least once all right so let’s uh save that and then run it all right and you can see that i just merely printed out the fibonacci numbers with a tilde join them together into a single string but they’re separated by a tilde now okay we’ve already talked about or demonstrated push and pop i don’t want to go back into those but there are essentially ways to add elements to the array or remove the last element from the array there’s some other ways to do that too for example here we’ve got a console.log we’ll take the loss numbers and we’ll call the shift method and what the shift method will do is re take one item off the front side of the array and it’ll return it back to us to print out but then if we go and look at the array we’ll see that it actually removed it so it’s essentially a pop but instead of working off the back end it works on the front end okay so let’s see that in action and we get that exact behavior that i described great we can do something called an unshift which is to add items to the front so it’s essentially just like a push except we’re going to add items to the front one or more items so here we go with the lost unshift and then we’re gonna say hey let’s add we can add one we can add two we can add a bunch of items right and so now we do console.log loss numbers oops we’ll see whoops what did i messed up i call it list instead of lost there we go and so now i’ve added the values 1 2 3 and 4 as new elements of my array and then it continues on with 8 15 16 23 and 42 okay let’s comment all these out moving on let’s um let’s find an element uh well first of all here uh console.log let’s take the names and reverse their order so first of all we’ll start with the original order and then we’ll tell it to reverse and we’ll print that out so originally david eddie alex michael but then we get michael alex eddie david all right furthermore what we can do is go console.log names.sort it’s a sort of method i got to use the method invocation operator so now when i run it we get the alphabetical order alex david eddie michael all right next up let’s um let’s see how you can identify where a given element is in an array by looking up its value using an index of method so here we’re going to go console.log and we’ll go others dot index of and i’m going to look up the element name mark all right and so let’s see where it’s at it should be the third element of the array so i’m going to go back up here to others 0 1 2 3. it’s at the third element so then i can go grab it okay how about we look at and find the last index of and let’s take those combined numbers remember those all those numbers we basically put them together let’s go the last index of the value one so here first of all let’s do this just so we can easily see what the current value of combined is and then we’ll say hey we’re going to search for the last time the value 1 appears in my list which array of the element is it at whoops what did i do this time i think it’s just combined right still not right ah because i commented it out now let’s try it there we go all right so you can see that our combine variable holds 48 15 16 23 42 1 1 2 3. so now i want to see what element is the last and it says it’s at the seventh element so zero one two three four five six seven zero based so the last index of one would be at seven so it’s useful if i’m looking through a large set of data and i want to find the last instance of a given value i can use last index of instead of index.which would give me the first index okay all right moving on you know previously we looked at the map function of an array i don’t want to belabor that because we’ve already seen it but we can do other interesting things too like we can create a filtered list so using arrow functions so var filter equals and we’ll go with com combine dot filter and now i’m going to give it an arrow function so for every number i’ll just say it’s x i can give it any input parameter name so here’s the body of my little arrow function if x is less than or equal to 15 then i want to return x all right and effectively what will happen is it’ll return only those numbers that match this expression so that when i do console.log filtered i should only see numbers that are less than or equal to 15 and so i get a filtered version of that of that combine array pretty cool and a good example of why you would want to use arrow functions similarly you can do something using a what’s called an iterable it’s a method called for each so this will go through each uh element of an array and inside of that i can then create an arrow function similar to things we’ve done in the past all right where i’m actually just going to for each element of the array go ahead and console.log this string and interpolate in the name that’s passed in pretty cool and then uh we can also do some checks so for example i can say hey can you tell me if every one of the values inside of my array match a certain condition so here i would go console.log and i’m going to take that filtered list that i just created here so this should contain all of the values that are less than 15 from my combine and here i’m just going to say hey let’s go filtered is every one of those values um and here’s where i’m going to create an arrow function so let’s call this num or every one of those numbers less than 10. true or false false why is that well i happen to know that there’s a at least a 15 in there maybe if we increase the number to something like 16 are all the numbers less than 16 well they better be because they wouldn’t have matched this criteria right okay so that’s the every method of an array similarly we can look at sum so tell me if at least one element of the array matches a condition so here again console.log start with that let’s create arrow function um so whoops we’ll start off with uh let’s use the fibonacci numbers so sum true or false well let’s start off here with an arrow function number are all the nums greater than 50. true or false true okay are they all greater than 100 are there any of them there’s at least one item greater than 100 that’s what we’re testing for here false there’s no items in that fibonacci sequence that we have here in our array that are greater than 100 all right so hopefully first of all you can see that there are some very useful uh helper methods on the array built in native secondly more examples of arrow functions that are used inside of some of these methods hopefully that’s useful let’s keep going see in the next video thanks you have to try really hard to force javascript’s compiler to throw an exception with the code that you write unless you simply just typed in the code incorrectly now i suppose some might consider the fact that javascript tries so hard to work with whatever crazy code you offer it uh as a positive thing but personally i wish that javascript’s compiler would throw errors more often i mean you should never be able to do something as absurd as what i’m about to do here let me paste in a little code i mean this makes absolutely no sense here we’re going to attempt to multiply seven times undefined divided by panama okay what’s the answer to that well um you know it it looks at and says well i you know i’m not really sure that that’s going to come out to be a number so i’m just going to return not a number and we can check for that not a number and you know i guess we can account for that in our logic of our application but kind of wish it would just throw an exception but i guess that’s not the way that javascript is made to work i suppose it tries to do whatever it can because it i guess figures that perhaps people come from many different programming backgrounds or that since it’s a dynamic language maybe it should be able to accommodate any of these crazy situations but when javascript does encounter finally something that it cannot work with uh we call that an error we call that sometimes an exception an exceptional situation an exception something it just can’t work with and the javascript runtime will simply a quit at that point throw up its hands and say i can’t do anything with this line of code and if i can’t do anything with this line of code that means i can’t do anything with any other lines of code i quit so it’s when it does actually reach an exception it completely bails out on any additional code that you might have written all right so when this happens and you can identify where in code these issues are likely occur you can and should build some safeguards to ensure that they never happen again like in this case we might write several lines of code prior to attempting line number one we might do things like to ensure that if for example these values were contained in variables we might try to make sure the variable was not undefined we would try to make sure that the variable had a data type of number and not string or something else right so that we could do that calculation and expect a real number to to be assigned to the variable a oh if we were working with objects we might want to make sure that the property actually existed on the object that was passed into our function and so we would look and say do you have a do you have a property with this name does it have a value okay we can work with that and so there are some safeguards that you can kind of build around your code to bolster it to make it uh to make it more resilient to the possibility that its inputs were bad and that it ultimately might throw or raise an exception so other times these things might be completely out of your control you still need to write your code in a defensive manner so for example you might want to request data maybe json data from a web server that hosts a web api and depending on what you’re requesting and depending on whether the web server is functioning correctly in that moment you may or may not receive the data that you’re expecting so this might cause your code to throw an exception well here’s another case where you should be able to kind of code defensively account for the possibility that an exception could occur because calling into another resource across the world is a highly risky proposition and it could result in an exception so an exception in an era i use those terms kind of interchangeably in my mind they’re the same thing but whenever a a problem arises an exception is raised by uh by javascript in some way the information about that exception is boxed into one of these um built-in natives that we learned about several videos ago uh that were were created in the exception capital e exception function and it will give you an opportunity to inspect that exception or that error object uh and look at for example the error message and be able to handle it gracefully and we’ll talk about that in this lesson you can safeguard your code the code that you suspect or that you know would be prone to throwing exceptions and you can do that by wrapping it in a construct in javascript called try catch so here let me comment this out and then i’m going to create some examples let’s create one where i know i can create an exception so here i’m going to create a function called before try catch so here we’re just going to create one and not not attempt to catch any issues that might be uh that might be created now here i’m going to just say let this variable obj equal to undefined and i’m going to act like obj is an object so i’m going to just act like it should have a property on it so i’m going to do console.log obj.b alright and i know that this obj does not have a property b that should trigger an exception in javascript it’s one of the few cases where we can actually force it to happen so if that happens correctly as i suppose then you should never be able to execute this line so if the previous line of code grows an exception you’ll never see this all right and just want to point this out here i’m going to have to escape this in my literal string this single quote in the contraction yule because uh javascript and in this case visual studio code doesn’t recognize it as an apostrophe it recognizes it recognizes it as the closing single quote for my literal string so to escape that character and treat it like i need to treat it as an apostrophe i’ll use a backslash right in front of it so now that little combination of characters will treat it as an escaped apostrophe instead of the closing single quote all right but any rate just an aside there line 7 should never get executed because i uh i’m expecting line number six to essentially throw an exception so um here’s what we’ll do we’ll just call before try catch and we’ll execute that and you can see that cannot read property b of undefined perfect all right now let’s let’s introduce a different function called after try catch to kind of show you how this works i’m going to comment out the call to before try catch here let’s just grab all this and copy it all but i’m going to first of all create a try and um i’m going to go ahead and just hit uh enter on my keyboard i’m going to use the arrow keys to like create a try catch statement all right see that and inside of the try i’m going to attempt to perform these three lines of code now i don’t have high hopes for 17 ever ever running however i suspect that what i can do is do something like this if we were to reach an exception in line number 16 which we will so in this case what i can do is say i caught an exception that was thrown by the javascript compiler and i can even inspect that error object and i know that it has a message property so we’ll do something like that but the key here is that this will not break my application my application can continue to execute so i can go console.log my application is still running so even if we encounter an exception like i suspect we will in line number 16 we can catch the exception handle it do something and then move on so let’s start with this then we can move on see there’s other things we can do here whoops what am i doing wrong here oh i need to actually now call my after try catch so now let’s try to run it all right i caught an exception cannot read b property b of undefined but my application is still running so it did not completely just shut down my application perfect now what i can do is actually add another statement called finally and this will run regardless of rather my try makes it successfully all the way through or whether the catch has been invoked uh so i can just do console.log this will happen no matter what all right and usually use a finally statement to clean up any resources that you no longer need i’m not sure how useful that is in javascript personally but you might find a use for it all right and so you can see that we have we have hit the catch but then it also executed the finally statement before continuing on with the remainder of the application so there’s a pretty effective software development strategy of throwing custom exceptions from your functions with the intent that those exceptions are caught by the caller so it’s a form of communication if it succeeds then it should succeed quietly but if it fails your function would then throw an exception that would be handled by the caller and it can decide what to do next so i’m going to comment everything we’ve done so far out and we’re going to create one more example here so let’s do that and i’ll comment all this out too and let’s go here okay so this time let’s go function perform calculation and this calculation will take and look at uh a object that will pass in and we’re going to say hey if that object obj dot has own property b wait if it doesn’t have its own property so i could do equals false like that or i can do a shorthand version of this by just using the exclamation mark right before the expression see that that exclamation mark it kind of makes it the negative so if has own property returns false then the entire expression will be true this is if it if not has own property equal true essentially then what we can do is actually throw a new error all right so here we’ll just describe or give it the message we want to to tell what the problem is object missing property all right otherwise if that turns out to be a truth that the object does have its own property then we can continue with the calculation and uh i might just return you know the value six or something like that okay whatever the the calculation using obj dot property b all right so here we go now we’re going to call into that function perform higher level function operation and here let’s um do let’s be j let um that value equals zero all right um and then um let’s do a try around value equals perform calculation and i’m passing in an object that’s undefined right because i didn’t set it to anything in line 41 so i know it’s going to throw an exception here i’m going to catch it i know it’s going to come back to me as a boxed built-in native error and [Music] print that out and what i can do then is kind of to show how this would work is uh if um you know value is uh equal to zero i know that the perform calculation didn’t work so i can run my contingency perhaps i can do some retry logic you know whatever i need to do to to make my application uh handle this exception gracefully and then continue with whatever logic makes sense after that so let’s see if this works i think i got this right let’s call perform higher level operation and um i’m not sure what to expect to see here but i don’t want to see any exceptions pop up other than the one that i’m printing out and throwing um here so let’s try that all right i think in this case i’m gonna need to do this let’s see if that works all right try that again all right that worked perfectly okay so in this case created an object passed it in doesn’t have property b so we throw an error remember this is a strategy for us to do some checking and then look to make sure that if an exception happens we can handle it if not we grab the value back but if the value is zero then perhaps we need to we we hit an exception maybe there’s some other flag we can use to see whether we’re getting the value we thought perhaps in the catch we can do some work maybe in the final statement it makes more sense to put it there but at any rate we can gracefully recover from the exception being thrown uh because that’s kind of just our strategy that hey this function does not have what it needs so you’re calling into it but you didn’t give us what we needed so you’re gonna have to write some logic to figure out what to do next all right that’s all i’m trying to say there so this is a good start to help you understand that you do have options when you think about how to safeguard your application against potential exceptions that could occur and shut down your code completely ideally you could think of all the ways that your code could possibly fail and attempt to mitigate those potential issues up front but after you’ve done a reasonable amount of work to perform gated checks like i demonstrated here in line number 33 34 and 35 uh then you can ultimately wrap your code in um a try catch statement try catch finally whatever works for you and furthermore you can throw custom errors from one function to another as a means of communicating failure and allowing the caller to implement some contingency like we looked at line number 50 there maybe even some retry logic to ensure that ultimately the application is performing correctly and it can recover from any exceptional situations all right that’s all we really wanted to say all right so we’re doing great almost done we’ll see in the next video thanks up to now i have avoided talking about javascript in the specific context of a web browser i actually re-recorded this entire course from scratch earlier this month because i started talking about javascript uh in a web browser from like the very first video and it became obvious as i that i spent so much time fiddling with the html explaining the dom and ultimately i was struggling to get just to talk about javascript by itself and so that’s why i took a different tact and re-recorded this so this time around as you know i started with pure unadulterated javascript and now here at the very end of this course i’m talking about javascript and how it’s used in a web browser which there are some peculiarities that i wanted to talk about and i hope the approach makes sense i hope that this approach worked for you and even if this isn’t how you wanted to learn javascript i hope you can understand understand and see the the rationale behind it all right enough of the pretense uh as we start dipping our toe into javascript in the web browser i want to talk about the amazing work of a web browser and how it will actually turn a request by just typing in an address and to the point where we’re actually viewing a page on screen i want to talk about how it begins to understand the html that it has downloaded as well as other files like css and javascript files and i want to talk about all the things that it has to consider before ultimately rendering a web page out to the end user to to see it’s it’s really quite amazing so let’s start at the very beginning i don’t want to talk about all the process of of requesting and resolving to an ip address and all that let’s just speak in very broad terms there’s a request made from the web browser to a server and ultimately an html file will be downloaded or or i should say a collection of html is downloaded to the web browser and then there are references to other resources like css files and javascript files and things that begin to be downloaded as well kind of all this happens really at the same time along with everything else i’m going to talk about here um and this isn’t really intended to be deeply technical uh i’m really just going to paraphrase that the general order of events because i’m not really privy to what goes on inside of a web browser i haven’t really looked at the source code but any rate while it’s downloading all the resources it has its html now it’s grabbing its css now it’s grabbing its javascript and it’s working asynchronously in the meantime with what it does have in hand in memory uh as it’s continuing to grab these resources down well while that’s going on the browser is beginning to construct this object-based representation of the html elements in the html page and it constructs them into a series of objects that are called nodes so it’ll create a node for a given paragraph a node for the id of that paragraph a node for the class of that class attribute of that paragraph a node for the text that belongs to that paragraph you can see where i’m going with this everything gets its own little instance of an object and ultimately it’s building this object graph that represents all of these these elements their attributes and their values the text values and so each element node could contain other element nodes as well so a paragraph could conceivably have some div tags or vice probably more likely vice versa a div tag has has a paragraph a div tag has a header has an unordered list which has list items and so on all right so there’s that just that nature of html and the the object model that’s being constructed in memory has to consider all those kinds of relationships as well as the attributes and and the text values of each of those attributes so at any rate the final result of all that work is this rich object model that represents the document that can also be accessed programmatically we’ll talk about that in just a little bit but at some point the browser considers then all the styles that it has downloaded whether embedded in the html page itself or through one or more css files that have been downloaded as well and it also has to consider any of the default styles for uh elements so these are ones that are baked right into the web browser it starts to decide which styles will overwrite the other styles which values will overwrite the other values and so now it has to then start to apply those styles to the various nodes inside of this large object graph of node objects and once it’s kind of settled on which styles to apply to each of the individual nodes it then has to calculate how much space each of those will take up on the web page all right so that it can essentially at some point visually render those onto the web page for the end user to view the next thing that it’s going to do is it’s going to start to parse through the javascript that it’s been downloading from various files and it’ll determine what needs to happen and when it needs to happen so some code can be executed immediately some code is attached to the various events of the various nodes in this object graph of nodes that represent the web document and we’re going to see this in a little bit it’ll impact how we write our code and where we write it in the html document so when we’re talking about this collection of nodes from a programmatic standpoint as well as the entire api of the methods and properties that we can access programmatically to change things about the nodes that represent our document to modify them to add new nodes to remove nodes things of that nature as well as the web browser as a whole and all the functionality that it provides to us like the ability to manipulate uh things like the history the the console window and and any of the other debugging windows that might be available take all of that into consideration and that is that essence something called the document object model or the dom all right and so we’ll talk about the dom uh in the remainder of this video in the next couple of videos but eventually after it’s taken all those things into consideration then it finally will render the page visually to the end user but its work is not done at that point now it’s listening for the user’s interaction with the various nodes inside of the document and when the user interacts it might click or hover or mouse up mouse down it might use a keyboard you know the user can interact with the various elements on the page in various ways and if the software developer or the web developer has attached event handlers functions that should be called in response to those interactions those events then it will the web browser has to say oh yeah we have uh these two functions that we’re going to call because the user clicked on this button go ahead and execute those those two functions now all right so when we create those associations html uh actually gives us a couple of ways to do the create those associations but we’re going to look at some some programmatic only ways to create those associations we’ll talk about that in the next video uh but at any rate uh as developers we can also interact with other apis that are exposed to us for example most web browsers expose the console window so that we can write to that write little error messages out like we’ve been doing up to this point so we’re primarily interested in the document object model as as javascript developers again it contains an object graph that represents every element the attributes of those elements uh the text that might be associated with those elements and the relationship between two elements you know one might contain the other or they might be siblings and so on each of these objects are referred to as nodes as i said earlier and i just want to make the point really quick that when we’re talking about nodes inside of the document object model that shouldn’t be confused with nodejs the environment that we’ve been using up to this point to execute our various little javascript examples they’re completely different they have no relationship to each other all right so at the highest level you have the document node and the document node will contain one or more element nodes and each of those could contain other element nodes but each element node will probably have some attribute nodes associated with it and maybe a text node associated with it okay so the dom also includes a rich api so lots of functions that we can call in order to access the various nodes their attributes uh the text and so on all right so we can find a specific node or a collection of node that match our criteria and then once we have a programmatic handle to a given node or multiple nodes then the api also gives us some functions that we can use to modify the values of those nodes everything from changing the text of a node to changing the attributes of the node like changing the um the class that is associated with that given node we can remove nodes we can add nodes all that programmatically the api also allows us as i mentioned a little bit ago to associate events that are raised by the web browser usually because the end user triggered the event with a mouse over a click whatever the case might be as developers we can associate our functions with those events and then finally the api provides some helper functions to perform various various things one that comes to mind is network operations like being able to call out to another web server to grab data or to grab some other code that can be executed but finally there are several ways that we’re going to talk about in this video to basically write your javascript uh in a web page or associate your javascript with a web page and if you have professional aspirations then you should be aware that not all of these techniques are are smiled upon in fact most of them are frowned upon there’s one that’s that’s not so you might see some examples and here we’ll just add this to our to our uh existing page here that i just created randomly in dom intro.html and i’m going to create a button and in that button i’m going to say click me and then here i’m going to add an on click equal i believe we’ve done this already right but i’m just going to write some javascript right here now using this technique i’m able to pop up box an alert box in the browser to just kind of execute one little simple line of code uh so let me see how i’m going to do this let’s right click on this and let’s rebuild an explorer and from here i can double click and it should open up my default web browser i click click me and i get a message box an alert that pops up with the little message the site says hi okay and i can also do something a little bit different this might be a little bit more akin to what we’ve been doing consoled console.log and i could do hi in the console all right and let’s just refresh that page so i’ll hit refresh i’m going to hit f12 on the keyboard this will allow me to see the console tab and specifically i want to look at the logs when i click the click me button high in the console okay so hopefully that all makes sense now using this technique uh you’re only gonna be able to write one line of code at a time maybe two you might have to write some you know but there’s no doubt that just keep writing a bunch of statements here inside of this on click event right in line in the button is not a great idea so your other decision is or a choice is to actually add a script tag like so now for reasons that i’ll explain a little later typically you don’t see script tags added there you would probably want to put them at the bottom of the document and the reason is pretty simple that the uh that the web browser is going to look at the code line by line and if it encounters a script tag up here and we reference elements in the body those elements may not have been loaded yet into the document object model if we put the script at the very end we can ensure that any everything above this has been loaded already so we can reference the various uh elements in our html all right or the various nodes in our document object model to say in a more programmer friendly way okay so here’s what we can do instead i can actually create a function let’s call this just a click handler and um you know i could even just add message and here i can just do something like console.log um hi and then [Music] maybe dot dot and then maybe a message like that so now in the on click i can kind of wire this up and say hey call click handler and i’ll just say from the button click event all right so we’ll save all that and with any luck you can see where we make the call to the function we’ve created and then passing in a message which will should display in the console log let’s open up our web browser again let’s refresh this page f5 i’m gonna click the click me button and we get hide dot dot dot from the button click event all right so you might be wondering well wait a second you are calling a function before it is defined in your javascript isn’t that a problem no and this is something i wanted to talk about before but never really got a chance to and this applies whenever we’re executing all of our examples in node function declarations are hoisted to the very kind of top of the execution environment so the javascript compiler will go through and look for all the function declarations it’ll put them at the top it knows where they’re at now and then it will continue to execute any additional code so this is in essence added then to the top of the execution chain so when we by the time we get to the click event handler for this button javascript’s already very aware that this function exists all right so small point there but these techniques of using this on click equal and the script tag in this manner these are generally frowned upon professionally you probably want to do what’s called separate your concerns so your javascript may it might be more appropriate to keep it in its own file and to kind of remove all of these references like this like we have there so i’m going to say don’t write javascript in your html page all right and some people might argue with that and say it’s perfectly fine and you know it just depends on how much javascript there is and what your professional aspirations are and the other programmers and what they’re doing in your group but generally speaking what you want to do is kind of just add your code to another file in this case i’m going to create another file i’m going to call this dom intro.js right and then what we’re going to do is actually wire up the event handler to um to the button click event but we’re going to wire it up in our code so what we’re going to do to start off with is to create an iffy so um remember how we to do that we’re going to create a function i’m going to wrap it in a parentheses and then we’re going to say execute immediately all right and in here what we’ll do is we’ll define our function of the click handler and then i’m also going to let’s go here to our dom intro.html i’m going to give this guy an id and i’m going to say your id is my button all right in fact i hope you don’t mind that i’m going to delete all of this out of here all right i’m going to delete all of this out of here it’s gone now and i’m going to go into the dom intro.js and the first thing i need to do is get a reference to my button alright or my button so what we’ll do is let my button equal document dot get element by id and then give it the id i want my button button alright next thing i want to do is go my button add event listener i’m going to say which event i want to listen to in this case i want to listen to the click event and when that happens i want to call click handler and i guess i could pass in a message if i wanted to at this point so um hi from my iffy right now i need to go back to the dom intro.html here i’m going to add a script tag like so script type equals text forward slash javascript source equals and then we’ll give it the name dom intro dot js so save that and now hopefully let’s load this guy up refresh and you can see i did something incorrect let’s go back here let’s get rid of all of this business right there all right now we don’t want to call that method just yet we just want to wire it up to the button and say whenever the click we want to listen for the click event when that happens then we want you to execute click handler all right all right now that we have that in place let’s go ahead and refresh click me and there we go now we get pointer event not exactly what i was looking for if it’s really important to us to pass in the message which i actually forgot about sorry what i’ll do is just kind of wrap this call inside of a function expression so go function like so and inside there we’ll make the call like that and then um hi from iffy all right that should work hopefully so let’s save it let’s try that again there we go that’s the that is what i wanted to happen okay so had a lot to say in this video about the dom and about how to attach your javascript into a web page and still access the various elements of the document object model or this document object by using helper methods like git element i by id passing in the id and now getting a programmatic reference which we can then use to add or even remove event handlers too in this case i’m just adding a function expression to make a call into another function that i created earlier all right hopefully all that makes sense and we can continue on uh in the next lesson and kind of expand on this alright we’ll see you there thanks in this video we’re going to talk about working with the dom specifically how to access dom nodes how to change attributes of those nodes how to add nodes dynamically and more so in the past i’ve created like three or four lines of code and then we would look at look at what those lines did and i wanted to change my tactic for this particular example to show you something a little bit more interesting a little more compelling so i’ve already created a dom nodes html dom node css and dom nodes js and you can see here that i basically created just a little playground it does nothing of practical values completely contrived but it will show you how we can manipulate various down nodes and their attributes uh and you might find some of the the practical side of this how did i accomplish that useful as you pick apart this program and we’ll walk through here in just a moment but again this does nothing useful it has a click me button uh a series of div tags each with a color and the name of the of the color itself and then a number beneath that and i’m just going to click the click me two or three times alright you can see that several things are happening all at once first of all we are changing every time the click me button is clicked we are changing the selected color div you can see the selections change because there’s this thick bottom border applied to that particular div furthermore that color is applied to this number and that number seems to be growing each time we click the click me button so here we’re going to click it we go to pumpkin what happens when we get to the end of our list of colors and i click the click me button one more time we start back over at the beginning of the list and so i can just continue to click this the number is growing i’m using uh relative ms rems in css using it the number of times i’ve clicked it that’s the number of rams that i’m applying to this font and so you can see that things are changing they’re very dynamic and uh i just wanted to kind of it’s a it’s a large enough application to be interesting small enough that i think you can pick it apart and kind of understand what’s going on and that’s really the intent here so let’s take a look at the source code itself and we’ll start with the html there’s really not much interesting here i’m pulling a font from the google fonts and then i’m also applying a style sheet the style sheet itself not a lot interesting in it and i don’t want to take too much time it’s just making everything look a little bit nicer than our previous examples here we’re looking at the result container and that seems to be where we have uh though basically the white area with everything else inside of it this button this row of divs and the number and so you can see that each of these have ids applied to them the click me is my button the color div will contain a series of child divs and i’ll talk about more about that more in just a moment and then the resultive is where we add the current number of clicks that continues to grow and grow here we have our script reference to dom nodes.js that’s where all the magic happens first of all you can see that i’ve created an iffy here and i can roll it up using the little plus and minus right next to that line of code in line one you can see that i’ve created a couple of functions uh one called increment counter one called update ui and then one called handle click you can see that i’ve initialized a variable called counter to the value of zero here i’m getting a reference in line 74 to the button and then i’m wiring it up like we learned about the previous video to every time that the click event is raised for my button i want to add an event listener here we have a function expression that will execute both the increment counter method that we looked at at the very top and then the update ui method that we looked at it was right below it and we’ll go and this is where a lot of the magic happens so we’ll look at that in more detail in just a moment then here you can see in line number 80 i execute update ui in order it as the page loads because again as a immediately invoked function expression i want this to happen as soon as this file is loaded into uh into our html by the web browser okay so uh let’s go here to the top and we can see increment counter is very simple it just takes whatever the current value counter is and increments it by one all right now update ui is where a lot of the magic happens first of all we start off with an array of color objects each color object has a name this is the name that you saw printed kind of in the top middle part of each of the div tags as well as the color value itself and i just grabbed these from a website that has colors i think you see the colors i’ll give you the site in dom nodes.css alright the first thing we want to do is grab the resultive this is where we’re going a reference to that element and we use the id resultive to get an access to it so that we can programmatically work with it this is the div that will contain the current number of clicks not only will we increment the display the the incremented click number but then we will also change its size and its color attributes as well all right next up what we want to do is then set the inner text attribute or property of the result object so this resulted we’re going to set a property called intertext that’s how we’re able to put one two 3 4 inside of that div tag here at the very bottom of our white section of our web page okay and then so you can see this is one way that we are getting a reference to a dom node or a dom element and then changing the attribute we’re changing the text whatever it was we’re overriding it with the current value of counter all right then what we do is additionally access the style of that div so here we’re going to the style object of the result element and then the style object has a series and i can hit the period on the keyboard to look at the intellisense all of these are attributes or properties of the style object for our div tag we can change all of these attributes if we want most of them are visual in nature and here i just want to change the size of the font taking the current value of the counter and appending em to make it larger each time that em being a uh a unit of measure in css all right so that’s how we’re making the changing the number of times that the button has been clicked in in that div tag and then also changing its size every time we click it okay so next up what we want to do is determine what the current color is in our array of colors so here’s what we do we take the current value of counter and we use the modulo or modulus operator which will give us the remainder so if this has been clicked six times and there are six elements inside of our of our um array of colors that we define as a const here at the top then the modulo would be zero there would be zero remainder so we would access the first element of that array and that would be this alizarin it’s that coral color all right and so we would use that so that’s how i’m using and being able to to kind of select each of the items i take the current counter so if it was two and there were six then that would give me a remainder of of what a four so it would be the we would grab the fourth element from our colors array and grab the value property the value property of that particular object and set that as the result style objects color attribute all right moving on now what we want to do is clear out all the existing child color div so i basically tear down and recreate this list of colors by basically removing everything first of all from the previous call to update ui and then i begin to re-implement it if the as i’m looping through each of the color objects to create a new div if it’s the currently selected one then i want to apply not only the bottom border but then also use that color here i guess i already did that part but anyway um this is why i’m setting the inner html to an empty string of the color div because i’m emptying out everything inside of the current div but now i’m going to loop through each of the colors and here i’m basically dynamically creating new div tags so i create a new div tag and then i create a text node with the name of the color for you know whether it’s the first object the second object the third object i’m grabbing that name and creating a text node i append that text node as a child to the div tag that i just created i style it up and then at the very bottom here you can see i actually append that child append that node that i’ve been styling up to the larger outermost color div so i do that six times and if it is the currently selected item then i’m going to change the styling of that particular node by adding a class the selected class and that’s what’s going to add that bottom border in fact here if i wonder if i could just go to here and find selected so there we go it is uh just adding a bottom border of five pixels with no padding all right and so um that’s pretty much it now you’ll see that throughout i’m accessing the style object or attribute of the given div tag setting its width its height and other properties like float padding left padding top and i could have just created a css style and then added it using the same technique that i’ve used here but i chose just to demonstrate that we can get at all those those style attributes in addition to the style object there are other things that we’re able to do to it like append a child to it so we want to we have a a div tag and we want to append something to it we have a div tag and we want to append it as a child to that div tag which is already a child to a div tag child to the body right so hopefully this will help you to see how this whole process works and then we can basically get at any ah any uh dom node we can modify it we can add new child nodes to it um creating them essentially out of thin air and we could even do more like move nodes around if we really wanted to and so on obviously this example didn’t call for that but essentially once we get a handle to an element then we can do anything we want with it that we can conceive of so there are so many options that it didn’t really make sense to kind of go through them in a laundry list basically this is a matter of imagining what it is you want to accomplish getting a reference to the element that you you need to start with determining do i need to create a new element and append it on or do i need to remove elements that are currently child of the existing node which attributes of that know do i want to change and so on until you kind of construct i mean it took me several minutes to to build this example and it started really simply it started by can i just increment the current number of clicks all right i got that working now let’s move on to the next thing can i create a bunch of colors and have them applied to the number can i create a bunch of dibs and apply those colors to the div and so you just keep working at it little by little until you’ve you know tackled essentially the whole the whole application and that’s how i built this all right so um hopefully that was helpful as kind of a larger example that we’re able to to dissect and understand better how to accomplish something that that we conceive of by working with nodes inside of the dom all right so uh let’s continue on i guess we’re pretty much done so let’s wrap it up in the next video see you there thanks i just wanted to briefly congratulate you on finishing this course that’s quite an accomplishment and that’s awesome and i have to say that i definitely respect anybody who puts the time in to learn a new technology or a new skill so you’re awesome i congratulate you and i wish you the absolute best i sincerely hope that this course was helpful to you in some way and that you came away with some confidence in javascript and that you have a solid foundation now to build on and i’d strongly encourage you to keep pushing forward in fact modern development with javascript will require that you learn some of the most popular tools and libraries that are currently in vogue by the javascript software development community as well as the build and deployment process for javascript applications so i i hesitate to recommend specific libraries and frameworks for you to look at because especially on the client because things are changing so rapidly in that space but i think you’d be safe at least if you’re watching this within a couple of years after i record it uh to uh to get started with something like vue.js vue.js or react.js by uh by facebook if you’re going into a corporate uh software development environment like in a big company then you may want to look at angularjs or angular i think the current version as i record this is version five i’m sure they’re going to every six months they’re trying to release a new version of that you’re probably going to learn need to learn a little bit about packages in javascript and using npm or yarn another tool by facebook you probably want to learn a little bit about webpack and parcel but again honestly i kind of feel silly recommending anything because a couple years from now it’s it’s likely that the javascript development community will have moved on past some of these sorts of things so you know at least enough now where you can follow along in those kinds of discussions and begin to stay abreast of of javascript’s frequent and fickle library preferences de jour now on the server side i highly recommend that you learn more about nodejs and if you want to use node to create websites and web apis then you may want to learn another framework called express.js which sits on top of node okay makes it easy for you to build entire websites just on the server side okay so quickly just want to give another plug to my own website here let me type it in for you developeruniversity at devview.com http://www.devu.com i’m learning new things every day and when i do learn them i try to share them on my website so definitely want to come and check it out and check it out every so often finally a quick thanks to microsoft virtual academy you guys are awesome quick thanks to you the viewer for watching this and staying with it through the entire course and i as we close here just want to say that i sincerely and truly wish you the best hope you can leverage this course and do something really awesome and if you do let me know about it so good luck

    By Amjad Izhar
    Contact: amjad.izhar@gmail.com
    https://amjadizhar.blog

  • Pakistan: Geopolitics, Conflict, and the American Establishment by Orya Maqbool Jan

    Pakistan: Geopolitics, Conflict, and the American Establishment by Orya Maqbool Jan

    This source explores Pakistan’s complex geopolitical position, particularly its relationship with the United States. The speaker suggests America has used Pakistan for its own gains, leading to internal conflict and instability. They express concern that the U.S. establishment, along with figures like Donald Trump, could instigate further conflict between Pakistan and Afghanistan. Additionally, the speaker highlights the historical context of wars fought on Pakistani soil and the sacrifices made. They fear a future where Pakistan becomes a battleground again, urging a more peaceful path.

    Pakistan: Geopolitics, Conflict, and the American Establishment – Study Guide

    I. Quiz

    Answer each question in 2-3 sentences.

    1. According to the source, what role did Pakistan play in Afghanistan during the Soviet-Afghan War?
    2. What is the “Jamia Hafsa incident,” and how is it relevant to the discussion of Pakistan-U.S. relations?
    3. What are some of the motivations that drove America’s engagement in the region, according to the speaker?
    4. What does the speaker mean when they refer to Pakistan as being in a “Prison of Geography”?
    5. How does the speaker contrast the situations of Ukraine and Pakistan with regard to U.S. support?
    6. What significance does the speaker attribute to Donald Trump’s foreign policy decisions in the region?
    7. How does the speaker describe the relationship between Pakistan’s ISI and the American CIA?
    8. What is the speaker’s view of the China-Pakistan Economic Corridor (CPEC)?
    9. According to the speaker, how have Balochistan’s borders been used during times of war?
    10. In the speech, the speaker suggests that Pakistan is a pawn in a larger game. Who are the players, according to the speaker?

    II. Quiz – Answer Key

    1. The source indicates that Pakistan, at the behest of America, prolonged the war in Afghanistan and supported the Afghan Mujahideen. It suggests that Pakistan’s actions were motivated by financial gain, but this ultimately ruined the country.
    2. The Jamia Hafsa incident is presented as a significant event where Pakistan acted at the behest of America. The speaker argues it contributed to the instability and conflict within Pakistan and ultimately hurt Pakistan.
    3. The speaker suggests that America was motivated by the desire to take back its technology, but the speaker also suggested they were interested in a much more complicated set of circumstances. The speaker seemed to believe that, at times, the American’s actions were short-sighted.
    4. Being in a “Prison of Geography” means that Pakistan’s location makes it a perpetual battleground, subject to invasion and exploitation by foreign powers. It is trapped by its geographical realities, where external forces exploit it and the people suffer.
    5. The speaker highlights that Ukraine was humiliated by the U.S., but received far more support. The situation in Ukraine is contrasted with the one in Pakistan, which was not given the aid it needed.
    6. The speaker seems to believe that Trump is a property dealer, but that he, and the American establishment, may trigger a war between Pakistan and Afghanistan.
    7. The speaker suggests that the ISI and CIA historically worked together, coordinated, and were on the same line regarding actions in the region. This cooperation is portrayed as being directed by the American establishment.
    8. The speaker believes that CPEC is no longer the economic destiny of the world because the United States controls the sea. According to the speaker, China is now seeking a better route.
    9. According to the speaker, Balochistan served as a crucial support region and base of operations for American forces during times of war. Despite harboring Taliban elements, Balochistan’s borders facilitated the movement of American personnel and resources.
    10. The speaker suggests that the players are the “American establishment,” Donald Trump, and the “military industrial complex and deep state.” Pakistan is portrayed as the “frogs” crying under their feet.

    III. Essay Questions

    1. Analyze the speaker’s portrayal of Pakistan’s relationship with the United States. How does the speaker characterize the nature of this relationship, and what are the key turning points or events that have shaped it?
    2. Discuss the concept of “Prison of Geography” as it applies to Pakistan, according to the speaker. In what ways does Pakistan’s geographical location influence its geopolitical realities and internal conflicts?
    3. Evaluate the speaker’s critique of American foreign policy in the region. What are the speaker’s main criticisms of American actions, and how do these actions impact Pakistan?
    4. Examine the speaker’s concerns about the potential for a new war between Pakistan and Afghanistan. What factors contribute to this concern, and what role does the speaker attribute to external actors like the American establishment or Donald Trump?
    5. Assess the speaker’s view of China’s changing strategy in the region, particularly with regard to the China-Pakistan Economic Corridor (CPEC). What implications does this shift have for Pakistan’s future?

    IV. Glossary of Key Terms

    • American Establishment: Refers to the network of influential individuals and institutions within the U.S. government, military, and intelligence agencies that shape foreign policy.
    • Deep State: A clandestine network of unelected government officials who are believed to influence state policy, although it is not always clear who is included within the definition.
    • Prison of Geography: A concept describing how a country’s geographical location can determine its destiny, often trapping it in cycles of conflict or exploitation.
    • Military-Industrial Complex: The close relationship between the military, government, and defense contractors that promotes increased military spending and intervention.
    • Taliban: A fundamentalist Islamic movement that governed Afghanistan from 1996 to 2001 and has since waged an insurgency against the Afghan government and international forces.
    • Afghan Mujahideen: Guerrilla fighters who fought against the Soviet Union in Afghanistan during the Soviet-Afghan War (1979-1989), with support from the United States and other countries.
    • China-Pakistan Economic Corridor (CPEC): A major infrastructure project aimed at connecting China and Pakistan through a network of roads, railways, and pipelines.
    • ISI (Inter-Services Intelligence): Pakistan’s primary intelligence agency, responsible for gathering information and conducting covert operations.
    • CIA (Central Intelligence Agency): The U.S. government agency responsible for foreign intelligence gathering and covert action.
    • Jamia Hafsa Incident: A 2007 siege of a radical Islamic school in Islamabad, Pakistan, that resulted in a military crackdown and significant casualties.
    • CPEC: The China-Pakistan Economic Corridor is a large infrastructural endeavor in Pakistan

    Pakistan: Geopolitics, Conflict, and the American Establishment

    Okay, here’s a briefing document summarizing the main themes and ideas from the provided excerpts of “Pakistan: Geopolitics, Conflict, and the American Establishment.” This document includes quotes from the original source to illustrate key points.

    Briefing Document: Analysis of “Pakistan: Geopolitics, Conflict, and the American Establishment” (Excerpts)

    Overall Theme: The speaker in these excerpts expresses a deep concern about Pakistan’s geopolitical situation, particularly its historical and ongoing relationship with the United States, and the potential for renewed conflict and instability within the region. The speaker argues that Pakistan has been manipulated and exploited by foreign powers, particularly the US, and that this has led to internal strife, violence, and ultimately a compromised future for the nation. There’s a strong sense of disillusionment with the current trajectory, coupled with a fear of being caught in the crossfire of larger geopolitical power struggles.

    Key Ideas and Arguments:

    1. Pakistan as a Pawn in Geopolitical Games: The speaker repeatedly emphasizes the idea that Pakistan is treated as a battleground by larger powers, particularly the US and, potentially, a resurgent rivalry involving the US, Russia, and China. He paints a picture of Pakistan being used for proxy wars and strategic advantage, with devastating consequences for the Pakistani people.
    • “This issue of Taliban, the Sawat issue, we broke it at the behest of America.” This quote suggests a direct intervention or manipulation by the US in Pakistan’s internal affairs.
    • “Naf is Naf, our case is that we are on that land where the big Torians of the world think that this land will always be a battlefield…” This statement encapsulates the sense of fatalism and inevitability regarding Pakistan’s role as a conflict zone.
    • The speaker invokes Tom Marshall’s books, “Power of Geography” and “Prisoner of Geography,” to illustrate the concept of Pakistan being geographically predisposed to invasion and exploitation. “It is a book in which the prisoners are always kept in Geography. The invaders always come and loot them and move ahead after looting.”
    1. The US-Pakistan Relationship: A History of Manipulation and Broken Promises: The speaker highlights a history of US involvement in Pakistan, dating back to the Soviet-Afghan War, characterized by the use of Pakistan as a staging ground for US objectives, followed by neglect and abandonment.
    • “…we wanted to prolong that war further on the orders of America and did not want peace to prevail in Afghanistan…” This accuses Pakistan of deliberately prolonging the Soviet-Afghan War at the behest of the US.
    • “American planes have flown from here 57,000 times and they have flown in favour of Afghan brothers.” This acknowledges Pakistan’s support in US operations but implies it was at a high cost.
    • “We were not even allowed to see a single shot of the Stinger missile, rather when the war was over, the Stinger missiles were returned one by one and counted.” This illustrates a sense of being controlled and not trusted by the US, despite their alliance.
    • “He even went on to say that we broke the Taliban’s Mound of Sawat at the behest of America.” The speaker describes the aftermath of the Jamia Hafsa incident as a point where Pakistan’s actions led to extreme oppression at the request of America.
    1. Internal Consequences of External Interference: The speaker laments the internal consequences of these foreign interventions, including the rise of extremism, the loss of life, and the destabilization of Pakistani society.
    • “Those people who have reached the age of 70 like me have seen the fire boiling on the land of Pakistan, have seen bodies flying off the body parts and have seen people screaming and crying out in extreme pain…” This evokes the visceral impact of conflict and violence on the Pakistani population.
    • “Explosions were going on and people were sitting in the trench. He said, ‘It is not in your hands to launch the squad. Why don’t you stop them?’ How does he know that it is probably not even in the hands of those elders who, after entering this war, forgot that they were only making money. But the entire condition of this country was ruined.” This expresses a sense of powerlessness and a belief that the pursuit of financial gain has led to the ruin of Pakistan.
    • “…after fighting the war, the sacrifice of 75,000 people was done.” This points to the heavy human cost of the “War on Terror” in Pakistan.
    1. The Threat of a New Conflict: The speaker fears that the current geopolitical landscape, with Donald Trump and the “American establishment” at odds, could lead to a new conflict between Pakistan and Afghanistan.
    • “…they can start a new war between Pakistan and Afghanistan…we can create another situation after Jamia Afsa in this country…” This expresses a specific fear of renewed conflict orchestrated by external forces.
    • “…we will gift such a battlefield to America in which Trump will be forced to agree to the words of the Military Industrial Complex and the Deep State, then it is possible that Trump will be forced, but my land will burn, fire will rain here, people will be killed here…” This highlights the speaker’s fear of being used as a pawn in a power struggle between Trump and the military-industrial complex.
    1. China’s Evolving Strategy: The speaker suggests China is reassessing its economic strategy in the region, possibly reducing its reliance on CPEC (China-Pakistan Economic Corridor) due to perceived American control over sea routes.
    • “China no longer wants to do trade through the sea routes through Gwadar because it has realized that America has control over the sea and no matter how much CPEC it builds, it cannot move forward in any way.” This suggests a shift in China’s economic priorities and potentially reduced investment in Pakistan.

    Conclusion:

    The excerpts paint a grim picture of Pakistan’s geopolitical predicament. The speaker expresses a strong sense of being trapped in a cycle of conflict and manipulation, fueled by external powers. The future is viewed with anxiety, with the potential for renewed conflict and further destabilization. There is a plea for a more independent and peaceful path for Pakistan, free from the dictates of foreign powers.

    Pakistan: Geopolitics, Conflict, and the American Establishment

    Pakistan: Geopolitics, Conflict, and the American Establishment – FAQ

    1. What is the main argument presented regarding Pakistan’s relationship with the United States?

    The main argument is that Pakistan has historically acted at the behest of the American establishment, often to its own detriment. This includes prolonging conflicts in Afghanistan, suppressing domestic issues like the Taliban in Swat, and serving as a staging ground for US operations. The speaker suggests that while this collaboration might have provided financial benefits, it has destabilized the country and created a cycle of violence. The implication is that Pakistan needs to prioritize its own interests over those dictated by foreign powers.

    2. How does the speaker describe the current geopolitical situation involving the US, Afghanistan, and Pakistan?

    The speaker describes a precarious situation where a new conflict between Pakistan and Afghanistan could be instigated by the American establishment, possibly even by Donald Trump, for their own strategic purposes. This is seen as a continuation of a historical pattern where Pakistan is used as a pawn in larger geopolitical games, resulting in suffering and instability for the region.

    3. What is the significance of the “Prisoner of Geography” concept in the context of Pakistan?

    The “Prisoner of Geography” concept, drawn from Tom Marshall’s book, refers to the idea that a country’s geographical location can trap it in cycles of conflict and exploitation. Pakistan, like Ukraine, is seen as geographically vulnerable due to its location as a land bridge and its lack of natural defenses, making it a target for invasions and a battlefield for competing powers.

    4. What historical examples are given to illustrate Pakistan’s role in regional conflicts?

    The speaker cites several historical examples:

    • Pakistan’s involvement in the Afghan-Soviet War, where it prolonged the conflict on the orders of the US.
    • The suppression of the Taliban in Swat at the behest of America.
    • Pakistan’s support for the Afghan Mujahideen.
    • The use of Pakistani airfields for American operations in Afghanistan after 9/11.

    5. What are the speaker’s concerns regarding Donald Trump and the American “Deep State”?

    The speaker expresses concern that both Donald Trump and the American “deep state” (or establishment) could trigger a new conflict in the region for their own purposes. Trump is portrayed as a pragmatic actor focused on deals and geopolitical leverage, while the “deep state” is seen as having its own strategic agenda. Pakistan is portrayed as being caught between these competing forces.

    6. How does the speaker characterize the sacrifices made by Pakistan in the “War on Terror”?

    The speaker acknowledges the sacrifices made by Pakistan, including the loss of 75,000 lives and the support provided to American operations in Afghanistan. However, they also suggest that this involvement was ultimately detrimental to Pakistan, leading to internal instability and the destruction of its social fabric.

    7. What is the speaker’s perspective on the China-Pakistan Economic Corridor (CPEC)?

    The speaker suggests that the CPEC may not be as strategically significant as it once seemed because China is realizing that the United States has control over the sea routes it would need to traverse. China may now look to alternative trade routes through Turkmenistan, Iran, and Azerbaijan instead. This implies a shift in geopolitical dynamics that could impact Pakistan’s strategic importance.

    8. What is the speaker’s plea at the end of the excerpt?

    The speaker makes a heartfelt plea for mercy on Pakistan. He urges those in power to prioritize the country’s well-being and avoid being used as a battlefield for foreign powers. He expresses fear that continuing down the current path will lead to further destruction and suffering for the Pakistani people.

    American Establishment Geopolitics: Pakistan and Afghanistan

    The American establishment’s role in geopolitics, particularly in relation to Pakistan and Afghanistan, is a complex issue, according to the source.

    Key points regarding the American establishment:

    • The source suggests that the American establishment, along with Donald Trump and the “American deep state,” could potentially instigate a new war between Pakistan and Afghanistan.
    • The American establishment seemingly dictates actions, and in the past, the U.S. White House would instruct Pakistan on what to do. Coordination between the CIA and ISI (Pakistan’s intelligence agency) was also a part of this dynamic.
    • The source implies that past U.S. administrations (George W. Bush, Ronald Reagan, Obama, and Bill Clinton) followed the directives of the American establishment.
    • There is a concern that if Pakistan continues on its current path, it might offer the American military-industrial complex and the “Deep State” a battlefield, potentially forcing Trump to comply with their agenda.
    • The American establishment may be influencing Saudi Arabia and the UAE, possibly in coordination with Trump’s instructions.
    • There is a suggestion that the American establishment wants economic and financial relations with China through Russia.
    • The source mentions a fear that the American establishment might pressure Donald Trump to stay in Pakistan and continue fighting, rather than withdrawing completely from Afghanistan, Iran, China, and India.
    • During the “war of terror,” Balochistan supported the American bases, and movements were unchecked.
    • According to the source, the U.S. military flew from Pakistani airports 57,000 times in support of Afghan “brothers”.
    • The U.S. sought the return of its technology, such as Stinger missiles, after the war in Afghanistan.
    • The U.S. is perceived to have humiliated Ukraine, despite providing aid.
    • The U.S. is seen as controlling the sea routes, which affects China’s trade through Gwadar.

    Pakistan’s Geopolitics: Relationships, Conflicts, and China’s Strategy

    Pakistan’s geopolitical situation involves complex relationships with America, Afghanistan, and China, as well as internal conflicts and historical context.

    Key aspects of Pakistan’s geopolitics:

    • Relationship with America: The source suggests that Pakistan has been significantly influenced by the American establishment, sometimes against its own interests. The U.S. has used Pakistani airports extensively. There are fears that the American establishment, possibly alongside Donald Trump, might want to use Pakistan as a battleground, potentially leading to further instability.
    • Conflict and Instability: Pakistan has experienced significant internal conflict, including the “Taliban issue” and the “Sawat issue”. The text mentions the potential for a new war between Pakistan and Afghanistan being instigated. Balochistan, a province of Pakistan, has been particularly affected by regional conflicts.
    • China’s evolving strategy: Due to perceived American control over sea routes, China is reconsidering its trade routes through Pakistan’s Gwadar port. Instead, China may prefer a route through Turkmenistan, Iran, and Azerbaijan to reach Europe. The China-Pakistan Economic Corridor (CPEC) may no longer be China’s primary destination.
    • Historical Context: The excerpt references historical events such as the Soviet-Afghan War and the subsequent rise of the Mujahideen. Pakistan’s involvement in these events, sometimes at the behest of America, has had lasting consequences.
    • Internal strife and violence: The text alludes to a history of violence and suffering within Pakistan, with references to bomb blasts and loss of life. There is concern that further conflict could lead to more destruction and casualties.
    • Prisoner of Geography: The source refers to the book “Prisoner of Geography,” suggesting that Pakistan’s geographical location makes it vulnerable to being a battlefield for larger powers.
    • Past support for American operations: During the “war on terror,” Pakistan, particularly Balochistan, provided support for American operations, including the use of bases.

    Afghanistan Conflict: External Influence and Internal Strife

    The source provides insight into the conflict in Afghanistan, particularly its connection to Pakistan and the involvement of external actors like the United States and Russia.

    Key points regarding the conflict in Afghanistan:

    • External Influence: The source indicates that the conflict in Afghanistan has been influenced by external powers, particularly the United States and Russia. The Soviet-Afghan War is mentioned, with the detail that the U.S. prolonged the war.
    • Pakistani involvement: Pakistan has been significantly involved in the Afghan conflict, sometimes at the behest of America. According to the source, American planes flew from Pakistan 57,000 times in support of Afghan “brothers”. There are concerns that Pakistan could be used as a battleground in a new war involving Afghanistan.
    • Internal Conflict: Afghanistan has been a site of ongoing conflict, with groups such as the Taliban. The source alludes to the presence of different groups within Afghanistan.
    • Consequences of Conflict: The conflict has led to significant suffering and destruction. The text references bomb blasts and loss of life.
    • Mujahideen: The role of Afghan Mujahideen is mentioned in the context of the Soviet-Afghan War.
    • Geopolitical significance: Afghanistan’s location makes it a strategically important region, with the source referencing the book “Prisoner of Geography” to highlight how the country is vulnerable to being a battlefield for larger powers.
    • Potential for renewed conflict: There is concern that a new war could be instigated between Pakistan and Afghanistan.
    • American strategic interests: The U.S. sought the return of its technology, such as Stinger missiles, after the war in Afghanistan.
    • Support for Afghan “brothers”: According to the source, American planes flew from Pakistani airports 57,000 times in support of Afghan “brothers”.
    • Past support for American operations: During the “war on terror,” Pakistan provided support for American operations that supported efforts in Afghanistan.

    Donald Trump: Global Impact and Geopolitical Strategy

    Based on the source, here’s a discussion of Donald Trump:

    • Potential instigator: Donald Trump, along with the “American deep state” and the “American establishment,” is viewed as a potential instigator of a new war between Pakistan and Afghanistan.
    • Humiliation of Ukraine: Donald Trump called the head of Ukraine and humiliated and disgraced him.
    • Relationship with the American establishment: At this time Donald Trump and the American deep state and the American establishment are standing like this and in the middle of the fight between the elephants, the frogs cry at their feet.
    • Trump’s plans: Donald Trump has an immortal plan about Israel, that strange kind of property dealer and as he thinks that in Dubai, he has built Trump Tower and the area between Block One and Block Two.
    • Impact on Pakistan: There is a concern that if Pakistan continues on its current path, it might offer the American military-industrial complex and the “Deep State” a battlefield, potentially forcing Trump to comply with their agenda.
    • Influence on other nations: The American establishment may be influencing Saudi Arabia and the UAE, possibly in coordination with Trump’s instructions.
    • Economic strategy: Trump has put India on the line of what is called its status, don’t try to buy oil, I will give you oil, now don’t try to move like this.
    • Possible pressure to remain in the region: There is a suggestion that the American establishment might pressure Donald Trump to stay in Pakistan and continue fighting, rather than withdrawing completely from Afghanistan, Iran, China, and India.
    • Trump’s immortal plan: You can think that the military-industrial complex is our fun and quest for it, but Inshallah, I will make a video in the future and tell you that this is the immortal plan of Donald Trump about Israel, that strange kind of property dealer and as he thinks that in Dubai, he has built Trump Tower and the area between Block One and Block Two.

    Pakistan and Afghanistan: Regional Instability

    Regional instability is a recurring theme throughout the source, particularly concerning Pakistan, Afghanistan, and the broader geopolitical landscape.

    Key points regarding regional instability:

    • Potential for conflict: The source expresses concern about the possibility of a new war erupting between Pakistan and Afghanistan, potentially instigated by the American establishment and Donald Trump.
    • Pakistan as a battleground: There are fears that Pakistan could become a battleground for larger powers, leading to further internal strife and violence.
    • Balochistan’s vulnerability: The province of Balochistan in Pakistan has historically been affected by regional conflicts and served as a base for American operations.
    • Impact of external actors: The involvement of external actors like the United States and Russia has contributed to regional instability, with the Soviet-Afghan War and the “war on terror” being cited as examples.
    • China’s changing trade routes: China’s decision to reconsider its trade routes through Pakistan’s Gwadar port, due to perceived American control over sea routes, reflects the shifting dynamics and potential for instability in the region.
    • Historical context of violence: The source alludes to a history of violence and suffering within Pakistan and Afghanistan, with references to bomb blasts, loss of life, and the displacement of people.
    • Geopolitical factors: The source references the book “Prisoner of Geography,” suggesting that the geographical location of countries like Pakistan and Afghanistan makes them vulnerable to being battlefields for larger powers.
    • Internal conflicts: Pakistan has experienced significant internal conflict, including the “Taliban issue” and the “Sawat issue”.
    • Past support for American operations: During the “war on terror,” Pakistan, particularly Balochistan, provided support for American operations, including the use of bases.
    • The Jamia Hafsa incident: There is a concern that a situation similar to the Jamia Hafsa incident could reoccur, potentially leading to further instability.
    • Risk of further destruction and casualties: There is concern that further conflict could lead to more destruction and casualties.
    Fight Between American Establishment & Donald Trump | Orya Maqbool Jan

    The Original Text

    امریکہ اپنی فتح کے جھنڈے گاڑ دیتا ہے لیکن۔۔۔ یہاں کی زمین گرم ہے، یہاں کے لوگ یہاں سے 57 ہزار بار امریکی طیارے اڑ چکے ہیں۔ اس نے اپنے افغان بھائیوں کے پروں کو لے لیا۔ اب یہ آپ کے ہاتھ میں ہے۔ نہیں تم رک کیوں نہیں جاتے تم بھول گئے ہو سوچا کہ ہم صرف پیسہ کما رہے ہیں لیکن اس میں یہ پورے ملک کی مکمل حالت ہے۔ یہ طالبان کا اسے برباد کرنے کا نکتہ تھا۔ ہم نے یہ کام امریکہ کی ہدایت پر کیا۔ ہم ٹوٹ گئے تھے ہم کہانیاں لکھتے ہیں لیکن اب صورتحال اور ڈونلڈ ٹرمپ اور امریکی گہری ریاست اور امریکی اسٹیبلشمنٹ یہ ہے۔ اس وقت، یہ وقت تکمیل کا ہے۔ پاکستان اور افغانستان کے درمیان نئی جنگ چھیڑ سکتا ہے۔ [موسیقی] ارے راس کریم بسم اللہ الرحمن الرحیم رصداری لیا امالی میں اپنے گھر والوں سے ایسی دو تین باتیں کہتا ہوں۔ یہ 1015 دنوں کے اندر ہوا ہے۔ اس کے بعد میرے اندر خوف کا احساس ہے۔ اور ایسا لگتا ہے کہ ہم دوبارہ مل سکتے ہیں۔ ایسی حالت میں گرفتار وہ ہے جس سے ہمیں سکون ملے گا۔ بہت مشکل ہو وہ لوگ جو میری طرح 70 سال کے ہیں۔ وہ تقریباً اس تک پہنچ چکا ہے۔ پاکستان کی سرزمین پر آگ جل رہی ہے اور تھک رہی ہے۔ میں نے لاشوں کے اطراف کو اڑتے دیکھا ہے۔ اور یہاں کے لوگ انتہا کی طرف دھکیل رہے ہیں۔ میں نے دنیا میں لوگوں کو چیختے اور پکارتے دیکھا ہے۔ لیکن اکثر ہم اسے یہ سمجھتے ہیں کہ ہم نے یہ حاصل کر لیا ہے۔ ہم جو بھی کام کرتے ہیں اللہ ہی کرتا ہے۔ تبرک تلہ سر اٹھانے کی خاطر کرتے رہیں اور کبھی ہم پاکستان فرسٹ کی وکالت کرتے ہیں۔ ان تینوں کاموں کو بنیاد پر کرتے رہیں ایسے ہیں جو دنیا کے منظر نامے پر ہیں کے لیے ایک خوفناک صورتحال پیش کر رہا ہے۔ اور میں سمجھ نہیں پا رہا کہ میں کیسے میں تھیلی کی درخواست کرتا ہوں تاکہ شاید لوگ سمجھ جائیں۔ وہ جو اس وقت عرب ہے، جس نے فیصلہ کیا۔ کرنا پارا چرار کا یہ چرچا کافی عرصے سے جاری ہے۔ اور لوگ اس کی جدوجہد کے بارے میں جانتے ہیں۔ یہ مخمصے کی جگہ کیوں ہے کیونکہ یہ واحد ایک گوشہ ہے جو افغانستان کا حصہ ہے۔ یہ اندر اور وہاں کی گہرائیوں میں چلا گیا ہے۔ ایسے دو گرو ہیں جو ہیں۔ کسی قسم کے مسالے سے تعلق رکھتے ہیں لیکن اب یہ معاملہ مسالے سے بھی آگے نکل گیا ہے۔ اور سننے کی کوئی صورت نہیں۔ جولائی 2007 کے بعد ایک بار جامعہ دوبارہ مولانا عبدالعزیز کی حفص کے سامنے جھڑپ اور اردگرد کے لوگ جو ساتھ کھڑے ہیں۔ انہوں نے مولانا کو گھیر لیا ہے۔ مجھے سمیع الحق کے بیٹے اجمل حق صاحب پسند ہیں۔ میں اسے اور اس کے چھوٹے بھائی کو یاد کرتا ہوں۔ وہ اپنے والد کی وفات کے بعد آیا تھا۔ انہوں نے کہا کہ اب ہم اس سرزمین پر ہیں۔ مجید آگ نہیں دیکھنا چاہتے اور ہم امن سے رہنا چاہتے ہیں۔ اور سکون سے رہنا چاہیے اور وہ بھی شہید ہو کر دیا اس کے ساتھ چلا گیا پاکستان کی سرحد کے اوپر کے پی کے پورے بلوچستان کے اندر جو ہماری سرحد افغانستان کے ساتھ ہے۔ وہاں کی صورتحال ایسی نہیں ہے کہ ہم اس سے آگے جا سکیں حالیہ قسم کی صورتحال ایک چھوٹا سا شخص مکمل طور پر باقی سب کا مخالف تھا۔ ایک ویڈیو ہے جو آپ نے دیکھی ہو گی۔ کہ گڑیا ٹرمپ جو یہ ہے اس نے یوکرین کے ساتھ یہ کیا ہے۔ جسکی بلا کر کس طرح صدر کی توہین اور تذلیل کی گئی۔ اس کی حالت اور ریاست بھی رسوا ہو چکی ہے۔ ہم سے مختلف نہیں بلکہ مدد کے لیے تھا۔ کے حوالے سے اس کی زیادہ حمایت کی جا رہی ہے۔ ہم نے شاید اسٹنگ میزائل کے پھٹنے کو بھی محسوس کیا ہوگا۔ نہیں اسے دیکھنے کی اجازت نہیں تھی لیکن اس وقت اسٹنگر میزائل ہی جنگ کو ختم کرنے والے تھے۔ اگر ایسا ہوتا تو ایک ایک کرکے ہر ایک مِجّا اِل کو گنیں۔ اور ملا رکات والا سارا معاملہ وہ ہے جس میں ہمارے دوست ڈی سی زیارت جو کیپٹن کو اغوا کرکے لے گئے۔ ساری بات یہ تھی کہ امریکہ نے اس کا ٹیکنالوجی کو واپس لینا چاہتا تھا لیکن یہ اسے 5000 روپے دیے گئے اور پھر اسے اربوں ڈالر دیے گئے، پھر یورپ نے اس کا کنٹرول سنبھال لیا۔ اس نے تقریباً 6 لاکھ لوگوں کی مدد کی۔ وہ تمام قومیتیں جو انہوں نے وہاں دی تھیں۔ اس کے باوجود اسے ذلیل و خوار کیا گیا کہ اب ہم یہ جنگ نہیں چاہتے ہمارا مسئلہ یہ ہے کہ ہم اس زمین پر رہتے ہیں۔ ایک ایسا واقعہ ہے جس میں دنیا کی… بڑے توریان سمجھتے ہیں کہ یہ زمین میدان جنگ ہمیشہ میرے ساتھ رہے گا۔ ٹام مارشل کی کتاب پاور آف دی جیوگرافی ہے۔ یہ ان کی کتاب ہے اور ایک اور کتاب قیدی ہے۔ جغرافیہ کا جو ہمیشہ موجود ہوتا ہے۔ جس پر جغرافیہ کے قیدی ہیں۔ جہاں بھی حملہ آور آتے ہیں انہیں لوٹ لیتے ہیں۔ اور لوٹ مار کے بعد آگے بڑھتے ہیں۔ خیط وہ ہیں جو خاص طور پر ہیں۔ ان میں سے ایک وہ ہے جو پنجاب میں اٹک سے نیچے ہے۔ اور ایک علاقہ سندھ کا ہے اور دوسرا یوکرین کا ہے۔ یہ علاقہ یوکرین کے علاقے سے ملتا جلتا ہے۔ جیسے ہمارے یہاں کوئی پہاڑ نہیں ہے۔ بڑے میدان ہیں اور پھر یورپ اور روس اور اس کے میدانی علاقے شروع ہوتے ہیں۔ گندم اگائیں اور فصلیں کاشت کریں۔ یہی وجہ ہے کہ جب بھی جنگ ہوتی ہے۔ فتح کا جشن منانے کے لیے بڑے بڑے جھنڈے لہرائے گئے ہیں۔ آپ کو یاد ہوگا کہ کریمین ایک مشہور جنگ ہے جو کئی صدیاں پہلے ہوئی تھی۔ وہ کون سی انگلش ہے جو nazm mu Byron’s there وجہ یہ نہیں ہے کہ وہاں کیوں ہے بلکہ مرنا ہے۔ کہ کوئی وجہ نہیں ہے کہ ہم نے یہاں ایسا کیا۔ ہمیں لڑنا ہے اور مستقبل میں پاکستان کی حالت بھی بہتر ہو گی۔ بالکل اسی طرح جیسے اس میں 12 ہیں۔ میں آپ کو بتا چکا ہوں، میں کسی طویل وضاحت میں نہیں جانا چاہتا لیکن میرا ملک 12 ڈویژنوں میں ہے۔ یہ ساری صورتحال گجرات میں تقریباً 60 سال سے ہے۔ اگر اس میں 50 سال لگتے ہیں۔ 1979 میں وہ دن جب سب کچھ پہلے تھا۔ روسی فوجی جوہا جو افغانستان میں تھا۔ ہم داخل ہوئے تو پھر جنگ شروع ہو گئی۔ جو بھی ہے، وہ جنگ شروع ہو چکی ہے۔ افغان اپنے طور پر لڑ رہے تھے اور یہ جنگ 1988 تک جاری رہی اور روس کا آخری سپاہی میں فروری 1988 میں چلا گیا لیکن آپ شاید ہمیں یہ احساس نہیں تھا کہ ہم وہ جنگ امریکہ کے خلاف لڑ رہے ہیں۔ مجید کی بنیاد پر اسے آگے بڑھانا چاہتا تھا۔ اور افغانستان میں امن قائم نہ ہونے دیں۔ وہاں چاہتا تھا میں مچھلی چاہتا تھا اور پھر میں اس کے پاس گیا۔ نواز شریف کہانیوں کو ظاہر نہیں کرنا چاہتے شریف صاحب نے اس وقت جاالحق کی موت کی خبر سنی تھی۔ بعد میں، آپ نے وہاں اپنی حکمرانی کیسے قائم کی اور برباد کیا؟ اور پھر اس افغان کے اندر کیا ہوا؟ وہ بھی ایک مجاہد کا کردار ہے اور پھر ہم کتابیں لکھیں جیسے ہم کرتے ہیں۔ یورپ چارلی ولسن بھی لکھتا ہے اور وہ بھائی کیا بات ہے ہم یہ اور وہ کر رہے تھے۔ امریکہ اپنے ہی جھنڈے کاٹ رہا ہے۔ لیکن یہاں کی زمین گرم ہے، یہاں کے لوگ استعمال کیا جاتا ہے میں اُس دور میں، کوئٹا شہر میں تھا۔ اور گارڈن کے اندر اور پسینے کے اندر پوسٹ کیا۔ آپ اندازہ لگا سکتے ہیں کہ اس وقت کھاد بیچنے والے وہ بنیادی طور پر بم دھماکے کرتا تھا۔ ان کی ایجنسی کا تعلق افغانستان اور کے جی بے سے ہے۔ KGB روس سے تھا، اور ایک طرف ہم اس دھماکے سے جسم کے ٹکڑے اٹھاتے تھے۔ وائرلیس سگنل نے اشارہ کیا کہ ایک اور جگہ پر دھماکہ ہوا ہے۔ یہ ہوا اور ہم وہاں گئے اور ایک لاش ملی ایک طویل وقت کافی نہیں تھا کم از کم چار ماہ وہاں بارڈر چمن پر مجھے یہاں سے ایک طرف پوسٹ کیا گیا تھا۔ بوگرہ کی دوڑ کے اندر مجاہدین ہوا کرتے تھے۔ اور دوسرا اسپن بلدک، افغانستان میں روس کے اسپانسر نجیب اللہ کے ہجے وہ مسلمان تھا اور رات کو یہاں سے فائرنگ ہوتی تھی۔ بڑی گیندیں شروع ہوتی تھیں اور وہیں سے فائرنگ شروع ہو جائے گی اور لوگ اسے چمن سمجھیں گے۔ شاید اسسٹنٹ کمشنر ایک دن اور رات میں بہت بڑی طاقت ہے۔ مجھے ایک پٹھان پشتون بھائی کا فون آیا اس نے فون اٹھایا اور دھماکے ہو رہے تھے۔ انہوں نے کہا کہ خندق میں لوگ بیٹھے ہوئے تھے۔ آپ اس دستک کو دھکیل سکتے ہیں جو آپ کے ہاتھ میں ہے۔ نہیں تم اسے روکتے کیوں نہیں میں جانتا ہوں کہ یہ ان بزرگوں کے ہاتھ میں بھی ہو سکتا ہے۔ ایسا نہیں ہے کہ جو لوگ اس وار میں داخل ہوئے ہیں۔ بزنس مین بننے کے بعد ہم بھول گئے کہ ہم صرف پیسہ کما رہے ہیں۔ لیکن یہ پورا ملک بنا رہا ہے۔ اس کی ساری شکل ہی برباد ہو گئی اور پھر اس کے بعد امن کا دور بھی آیا رات ایک بجے خانی بازار کے اندر لوگ جمع ہو گئے۔ اس وقت تک کویٹا شہر جرسی پیٹیز کھاتا تھا۔ جو فلورا کارنر ہے۔ جنگ کے ذریعے شکار کیا گیا تھا اور یہ جنگ تھی دہشت کی 11 ستمبر کو جنگ ہوئی، ہم نے ان تمام لوگوں کو بچایا جن کی پرورش ہماری گود میں ہوئی۔ ہم نے ان کی پرورش کی، جہاز پر ان کی پرورش کی۔ جنہیں روڈن ڈریگن نے گانے گانے کے لیے بلایا تھا۔ کہا گیا کہ یہ مجاہدین نہیں، یہ سات ہیں۔ امریکہ کے باپ وہی ہیں جسے امریکہ کہا جاتا ہے۔ کہ سات لوگ ہیں جن کے پاس ہے۔ یہ اس کے برابر ہیں جس نے ہمیں آزاد کیا۔ یہ حلال ہے، یہ حکمت ہے میرے دوست، یہ احمد ہے۔ شاہ مسعود واشنگٹن میں اور اس کے بعد بہت کچھ جتنا ان کا جارج واشنگٹن اور وہ دوسرے تیسرے صدر بھی ان کے تھے۔ کیا عزت اور برابری برابر ہے؟ میں نے تاریخ دی تھی اور پھر ہم سب اسے اترن لے گئے اور پھر اس دوران جن 75000 لوگوں کو ہم نے جنگ لڑنے کے بعد بچایا مشرف صاحب نے لائن میں لگ کر قربانی دی۔ آگ کے بارے میں لکھا اور کہا کہ ہم نے یہ اور وہ کیا۔ میں ان کہانیوں میں نہیں جانا چاہتا میں نے 400 لوگوں کی خاطر اپنے آپ کو قربان کر دیا۔ جو کانگریس سے تھے انہیں نمبر بے پر بھیج دیا گیا۔ پاکستان سے اطلاعات ہیں اور امریکہ کارپوریشن کی وہ کہتی ہیں۔ ہمارے پاس تین ہوائی اڈے 57,000 بار تھے۔ امریکی طیاروں نے یہاں سے اڑان بھری۔ افغان بھائیوں کے حق میں اڑ گئے۔ ہمارے ہاں دہشت گردی اور سب کچھ بیک وقت ہے۔ جو کچھ بھی ہوا، 2007 تک ہمارے پاس کم از کم کچھ تھا۔ ورنہ یہ جنگ افغان بارڈر پر تھی لیکن۔۔۔ پاکستان کی سرزمین پر ایک واقعہ پیش آتا ہے۔ لیکن وہ واقعہ جام حفاظ کا واقعہ ہے۔ اس وقت میں ایران اور ایران میں تعینات تھا۔ کیونکہ میں ایک بین الاقوامی پوسٹ پر تھا۔ او کے اندر ڈائریکٹر کلچر انسٹی ٹیوٹ تو اس نے مجھے اجازت دے دی۔ آپ اسے ٹی وی پر دیکھ سکتے ہیں اور اس کے ساتھ آ سکتے ہیں۔ 7 یا 8 جولائی کو جب یہ واقعہ ہو رہا تھا۔ چنانچہ ایران کا پریس ٹی وی پہلی بار تھا۔ انہوں نے مجھے بتایا تو وہ بند کر دیا گیا تھا فون کیا کیونکہ اس پریس ٹی وی میں مسئلہ تھا۔ ٹام ہافا کے ہونے میں میرا بھی بہت دخل تھا۔ یہ آخری دن تھا اور جب میں نے انہیں بتایا اس راستے پر مت چلیں یہ آپ کے لیے پریشانی کا باعث بن سکتا ہے۔ میرے لیے راستہ نہ ملا تو رات ہو جائے گی۔ 15 تاریخ کو تقریباً 11-12 بجے مشرف مجھے سفیر کا فون آیا اور مجھے وہاں لے جایا گیا۔ سے جلاوطن کر کے واپس بلایا گیا۔ یہ الگ بات ہے کہ اس لڑائی میں کچھ عرصہ لیکن میں نے واپس آکر دوبارہ دریافت کیا۔ میں بھگتتا رہا لیکن اس ساری جنگ کا ایک اور نتیجہ ایک کردار تھا اور پھر روتے ہوئے آنسو تھے۔ میں اسے کہانی سناتا تھا کہ ہمارے پاس یہ ہے۔ جنرل شاہد عاجز نے ان کے ساتھ کیا سلوک کیا؟ اس خاموشی کو بک کرو یہ کتاب کس حد تک خوفناک ہے۔ وہ مجھے بتاتی ہے کہ اس نے مجھے آخری بار دیکھا تھا۔ اسلام آباد کے ایک ہوٹل کے اندر اکٹھے بیٹھے سیمینار میں کہا گیا کہ ہم نے امریکہ کے مسائل پر بات کی ہے۔ بولنے والے شخص کی طرف سے انتہائی ظلم اور جبر کا ثبوت اس نے وہاں سیاہی کا برش بھی دیا ہے۔ کہ یہ شخص جو طالبان کا سربراہ تھا سوات تھا۔ ہم نے اسے امریکہ کی ہدایت پر توڑا۔ تلبہ نے صوفی محمد سے کہا کہ اسے گھر توڑنا پڑے گا۔ نہیں چاہتا تھا اور یہ واقعی ایسا ہی تھا کہ اس نے نہیں کیا۔ پھر ہم نے 4 لاکھ لوگوں کو ان سے ہٹا کر کارروائی کی۔ اور پھر ہم نے دنیا کو اس کے بارے میں بتایا نتیجہ یہ سب ہے لیکن یہ کہاں سے ہے؟ بوسہ شروع کریں۔ 2007 میں جامعہ ہفتہ سے پہلے خودکشی بمباری ہم اس چارلی ولسن کے دولہا اور دلہن ہیں۔ ہم دہشت کے نقاب پوش تھے اس لیے سب کچھ ہوا۔ ہم کہانیاں لکھتے تھے لیکن اب صورتحال یہ ہے۔ اور کیا جارج ڈبلیو بش سے پہلے کوئی کردار ہے؟ رے اوباما تھے یا بل کلنٹن سے پہلے یہ اور امریکی اسٹیبلشمنٹ ایک تھے۔ ابانی کی اسٹیبلشمنٹ نے اسے کیا بتایا وہ کرتا تھا اور ہم بھی اسی لائن پر تھے۔ وائٹ ہاؤس میں ہمارا استقبال کیا جاتا تھا۔ ہمیں بٹھایا گیا تھا ہم نے آپ کو بتایا تھا۔ یہی کرنے کی ضرورت ہے، وائٹ ہاؤس کے لوگ یہاں آتے ہیں۔ اور ہمیں بتایا کہ کیا کرنا ہے۔ سی آئی اے اور آئی ایس آئی ایک دوسرے سے رابطہ کریں گے۔ ہم آہنگی تھی، سب کچھ یہ چیز 20 فروری 2025 کے بعد ہوگی۔ لیکن آپ کو اس کے بارے میں تھوڑا سا کرنا چاہئے۔ ڈونلڈ ٹرمپ اور امریکی ڈیپ اسٹیٹ اور ابھی امریکی زور اس طرح ہے۔ کھڑی اور ہاتھی ہاتھیوں سے لڑتے ہیں۔ جو درمیان میں ہے۔ وہ مینڈک ہے اور ہم اس کے قدموں پر روتے ہیں۔ جغرافیہ کی طاقت کی جیل ہے۔ اس وقت یورپ میں مینڈک اور ہاتھی ہیں۔ اس وقت یہ ہاتھی ہے، امریکہ کو افسوس ہے، یہ روس نہیں ہے۔ اس وقت ہاتھی امریکی اسٹیبلشمنٹ ہے۔ اور ہاتھی ابھی ڈونلڈ ٹرمپ ہے، آپ سوچ سکتے ہیں۔ کہ فوجی صنعتی کر سکتے ہیں؟ رنگت ہمارے مزے کی تلاش ہے، یہ تازہ اور گیلی ہے۔ میں اس پر مزید ویڈیوز بناؤں گا، انشاء اللہ میں آپ کو بتاؤں گا کہ اسرائیل کے بارے میں یہی کچھ ہو رہا ہے۔ ڈونلڈ ٹرمپ کا ایک لافانی منصوبہ ہے۔ پراپرٹی ڈیلر کی ایک عجیب قسم والا اور جیسے وہ سمجھتا ہے کہ دبئی میں اس نے ٹرمپ ٹاور اور برین سٹارم ون اور برین سٹورم ٹو بنایا اس دوران اس نے علاقے پر قبضہ کرکے جو کچھ کیا۔ نہیں ہو سکتا لیکن یورپ کے لیے یہ ایک ہے۔ کیا اب ہم روس کو سبق سکھانا چاہتے ہیں؟ ہم اس معاملے کا فیصلہ کریں گے اور اسے بھی ساتھ رکھیں گے۔ اس نے بھارت کو وہ درجہ دیا ہے جسے وہ اپنی حیثیت کہتے ہیں۔ مجھے مت دیکھو اور مجھے خرید لو دیکھو تم مجھے تیل دو، میں تمہیں تیل دوں گا۔ اب اس طرح حرکت کرنے کی کوشش نہ کریں لیکن شاید ہم سوچتے ہیں کہ اس وقت ہم پاکستان اسٹیبلشمنٹ کے کہنے پر اور افغانستان میں نئی ​​جنگ شروع کر سکتے ہیں۔ ہم جامعہ ہیں، افسا کے بعد ایک اور شرط ہے۔ اس ملک کے اندر پیدا کیا جا سکتا ہے جس کی امریکہ کے اندر اسٹیبلشمنٹ ڈونلڈ ہے۔ ٹرمپ کو یہاں سے جانے پر مجبور کریں۔ اگر آپ چلے گئے تو آپ مکمل طور پر لوپ سے باہر ہو جائیں گے۔ آپ کی کوئی حیثیت نہیں، آپ کی کوئی حیثیت نہیں ہے۔ آپ افغانستان میں نہیں ہوں گے، ٹھیک ہے؟ آپ ایران میں ہیں، آپ چین میں ہیں، آپ ہیں۔ اگر آپ ہندوستان میں ہیں تو پاکستان کے ساتھ رہیں۔ یہاں سے لڑو اگر یہ ہمارا فیصلہ ہے تو یہ ایک ہینڈ بیگ سے کہیں زیادہ ہے۔ ایسا ہوا ہے کہ ہم زیادہ بالغ نہیں ہو سکتے اور یاد رکھو، اپنی حالت دیکھو جب دونوں جنگیں بلوچستان میں لڑی گئیں۔ پہلا بھی 1980 سے 1988 تک اور اس سے بھی آگے، پورم کھاتہ بلوچستان سے زیادہ اہم ہوگا۔ کوئٹہ میں افغان مجاہدین کا دفاع کرنے والا کوئی نہیں تھا۔ شہر میں سرانہ میں باغ میں لامان میں اس کے کیمپ محمد خیل کا کیمپ وہاں سے شروع ہوا۔ یہ دال بندھن کے بعد اور اس کے بعد ہوتا تھا۔ سرخاب میں پشین کے کیمپ سے اوپر تک تھا۔ اور وہ لوگ جنہوں نے ان کے ساتھ کاروبار کیا۔ اس کے رشتہ دار اس کے ساتھ باقی سب کچھ کرتے تھے۔ وہ وقت جب اس کے اندر دہشت گردی کی جنگ تھی۔ بلوچستان وہ سرزمین تھی جس نے آپ کو دیا۔ اس کے باوجود طالبان کی حمایت کی۔ اثر و رسوخ بھی تھا لیکن اس کے باوجود تینوں تینوں اڈے جو آپ کے امریکی اڈے تھے۔ اور شمسی کا ٹھکانہ بلوچستان کے اندر تھا۔ اس کے بعد بلوچستان کا زباد کڑا بالکل بارڈر پر جا کر ان لوگوں کی بات کرو اور آپ کی تمام حرکات و سکنات کو کسی نہ کسی طریقے سے مانیٹر کیا جا سکتا ہے۔ لیکن جب لوگ آتے جاتے تھے تب بھی اسے چیک نہیں کیا جاتا تھا۔ مجھے وہ دن اچھی طرح یاد ہے جو 911 ہوا تھا۔ سرینا، کویٹا کے اندر ہوٹل کے کمرے ملاقات نہیں ہوئی اور اس نے حال ہی میں کیا تھا۔ اندر بستر بچھا دیے اور دنیا کا صحافی وہیں بیٹھا تھا اور وہ میں دیکھ رہا تھا کہ کیا ہو رہا ہے اور مناسب طریقے سے اس Var En Terror سے اس تماشے کا آغاز سامنے سے دیکھا جا رہا ہے۔ اور پھر اس کے بعد جب بھی آپ جاتے رہے۔ اگر آپ نے اسے کہیں پایا ہم سمجھتے ہیں کہ ہم ایک اور مشروب پینے جا رہے ہیں، ہافا۔ کا احساس پیدا کر سکتے ہیں۔ تو یہ واقعی خوفناک ہو سکتا ہے، مجھے نہیں معلوم کہ سعودی عرب اور مجھے نہیں معلوم کہ متحدہ عرب امارات دوسرے لوگ اس وقت کیا تلاش کر رہے ہیں اور کیا وہ ٹرمپ کی ہدایت کے مطابق اس طرح آگے بڑھے گا؟ بی کرما ہے یا اسٹیبلشمنٹ امریکی ہے۔ میں اس سے پیار کرتا ہوں لیکن ایک بات واضح ہے۔ اس کی وجہ یہ ہے کہ چین نے اپنا راستہ بدل لیا ہے۔ چین اب گوادر نہیں چاہتا جس کے ذریعے وہ سمندری راستوں سے تجارت کرتے ہیں۔ کیونکہ اسے اس بات کا احساس ہو چکا ہے۔ سمندر پر امریکہ کا کنٹرول ہے اور اگر اس سے کوئی فرق نہیں پڑتا ہے کہ CPAC کتنا اور کس طریقے سے بنایا گیا ہے۔ وہ آگے نہیں بڑھ سکتا، وہ اسے کسی دن روکیں گے۔ ہم بھی جا کر اسے چومیں گے۔ لیکن اگر وہاں سے جائیں تو ترکمانستان ایران سے اور وہاں سے ایران یہ آذربائیجان میں ہوا اور وہاں سے آگے ہم آگے بڑھیں گے تو اس کے لیے اور پھر یورپ کا راستہ بنائیں گے۔ اگر وہ چلا جائے تو اس کا راستہ بہتر ہو سکتا ہے۔ اور یورپ بھی چین کے اندر یہی چاہتا ہے۔ انہوں نے ریلوے میں جو ترقی کی ہے۔ چین کی ترقی میں چین سے فائدہ اٹھائیں۔ اور دوسرا انگلستان، جرمنی یا فرانس ہے۔ تمام فیکٹریاں چین میں سستی لیبر استعمال کر رہی ہیں۔ کیونکہ یہ وہاں موجود ہے اور ان کی تجارت ایک مسئلہ ہے اور امریکہ کی نلی بھی موجود ہے۔ اور امریکہ روس کے ذریعے چین کے ساتھ اگر آپ معاشی اور سماجی تعلقات چاہتے ہیں۔ انہوں نے یہ راستہ بدل دیا ہے، CPAC اب تیری منزل نہیں رہی اور بار بار کئی بار کہا جاتا ہے کہ ایک سڑک بنا کر سب سے بوڑھا اب اپنی قسمت نہیں بدلتا ایک راستہ یہ بھی ہے، وہ 1956 میں نریندر مودی کا ہے۔ یا 53 میں سے 4 میرے خیال میں مجھے یہ صحیح یاد ہے۔ نہیں میں نے اسے جمال عبدالناصر سے کہا اسے قومیا لیا گیا اور اس کی آمدنی شروع ہو گئی۔ تین سے چھ اور چھ سے آٹھ ارب ڈالر سالانہ وہ پیسہ کماتا ہے، مصر کی غربت کو ٹھیک نہیں کرتا پانامہ کی جھیل جو نیویارک ہے اور یہ وہ اسے مکس کرتی ہے، وہ ایل کو ملاتی ہے، یہ بہت ضروری تھا۔ گریناڈا کے اندر پانامہ ایک الگ ملک تھا۔ یہ ہمارے طریقے سے ہوا لیکن پاناما میں ملیریا کے مچھروں کا آج تک خاتمہ نہیں ہوسکا۔ حالانکہ وہ دو ارب ڈالر بھی کماتی ہے۔ نہ صرف سڑکیں پانی کو گیلا کرتی ہیں۔ صرف موٹر گاڑیاں بنانا کافی نہیں ہے۔ یہاں ابھی بھی کوئی زیر زمین ہے۔ اوور ہیڈ بنا رہا ہے کچھ بنا رہا ہے۔ لیکن میرا درد، میرا دکھ اور میرا مسئلہ یہ ہے کہ اگر ہم مزید کچھ دن اسی حالت میں رہیں ہم نے اسے اس طرح جانے دیا اور ہم نے سوچا کہ ہم ایک ہیں۔ امریکہ کو ایسا میدان جنگ کا تحفہ دیں۔ وہ دیں گے جس نے ٹرمپ کو مجبور کیا۔ اسے فوجی صنعت کے طور پر استعمال کیا جائے گا۔ پیچیدہ اور گہری حالت کو قبول کرنا اگر ایسا ہوا تو ٹرمپ کو مجبور کیا جا سکتا ہے۔ لیکن میری زمین جلے گی اور یہاں آگ برسے گی۔ لوگ یہاں مر گئے ہم اللہ کے پاس جائیں گے۔ بہت ہوگیا اس ملک کے ساتھ معاملہ، رحم کرو اپنا کام کرو [موسیقی]

    By Amjad Izhar
    Contact: amjad.izhar@gmail.com
    https://amjadizhar.blog

  • YouTube Channel Growth: Niche Selection, SEO, and Video Strategies

    YouTube Channel Growth: Niche Selection, SEO, and Video Strategies

    “A Journey Through Grief” is a transcription of a video discussing strategies for success on YouTube, particularly for faceless channels. The speaker covers a range of topics, including niche selection, keyword research, script writing, voice-over techniques, video editing, thumbnail design, and search engine optimization. The information targets Pakistani creators, and is intended to help creators generate income. Investment strategies, tool recommendations, and common mistakes to avoid are also addressed. The overarching aim is to provide a comprehensive guide for building a successful YouTube presence without showing one’s face.

    Mastering Faceless YouTube: A Comprehensive Study Guide

    I. Quiz

    Answer the following questions in 2-3 sentences each.

    1. What is a sub-niche and why is targeting one important for YouTube success?
    2. Explain the concept of “value addition” when using copyright-free resources for video editing.
    3. What is the primary difference in content consumption mindset between viewers of short-form and long-form YouTube videos?
    4. According to the source material, what is the approximate cost range for high-quality faceless video editing?
    5. What are the two types of keyword research mentioned in the source material, and how do they differ?
    6. Why is it important to start with an outline for your video before scripting?
    7. What are time stamps and how are they used to maximize views on YouTube videos?
    8. Briefly describe how AI tools can be used to generate thumbnails and boost views?
    9. How does the RPM differ between short form and long form YouTube videos?
    10. According to the source material, what are some tools to use for audio voice overs?

    II. Quiz Answer Key

    1. A sub-niche is a highly specific segment within a broader niche. Targeting a sub-niche is crucial because it allows for greater focus, reduces competition, and increases the likelihood of attracting a dedicated audience.
    2. “Value addition” refers to making changes to copyright-free content, like background sounds or transitional video effects. This turns the content into something unique.
    3. Viewers of short-form videos typically seek quick entertainment and easily digestible content, while those of long-form videos prefer in-depth information and engagement.
    4. The approximate cost range for high-quality faceless video editing, as suggested in the source material, is between ₹800-₹8,000 per minute, depending on the specific project and editor.
    5. The two types of keyword research are:
    • Searchable keywords are the terms people type into the YouTube search bar to find content.
    • Browsable keywords are related to trending topics and rely on users being served the video through their home feeds.
    1. Creating an outline for your video before scripting allows you to structure your thoughts, ensure a logical flow of information, and create a more engaging and coherent presentation.
    2. Timestamps are clickable links in the description of a YouTube video that allow viewers to jump to specific sections. They improve user experience, engagement, and can help search engines understand and index the video content.
    3. AI tools are useful for producing thumbnails and boosting views by creating eye-catching graphics without needing a degree in design. Using AI tools increases efficiency.
    4. According to the source material, the RPM for a long form YouTube video is ten times the RPM for a short form video.
    5. According to the source material, 11Labs is a tool that creates effective audio voice overs.

    III. Essay Questions

    Consider the following essay questions, drawing from the provided source material.

    1. Analyze the trade-offs between using AI-generated content and human-created content on YouTube, specifically addressing issues of authenticity, originality, and viewer engagement.
    2. Discuss the strategic importance of niche selection for faceless YouTube channels.
    3. Evaluate the potential impact of short-form content on the long-term growth and monetization of a YouTube channel.
    4. Assess the ethical considerations involved in using copyright-free resources and AI tools to generate YouTube content, with specific attention to issues of plagiarism and transparency.
    5. Outline a comprehensive business plan for launching and scaling a successful faceless YouTube channel, incorporating key strategies related to niche selection, content creation, SEO, and audience engagement.

    IV. Glossary of Key Terms

    • AI (Artificial Intelligence): The simulation of human intelligence processes by computer systems, including learning, reasoning, and self-correction.
    • Algorithm: A set of rules or a step-by-step procedure that a computer follows to solve a problem or complete a task.
    • Average View Duration: The average amount of time viewers spend watching a particular video.
    • Browsable Keywords: Keywords related to trending topics and rely on users being served the video through their home feeds.
    • CTR (Click-Through Rate): The percentage of viewers who click on a video after seeing its thumbnail and title.
    • Engagement: The level of interaction and involvement viewers have with a video, including likes, comments, shares, and watch time.
    • Faceless Channel: A YouTube channel where the content creator does not show their face on camera, often using stock footage, animations, or voiceovers.
    • Hook: The initial part of a video or script designed to grab the viewer’s attention and encourage them to keep watching.
    • Keyword Research: The process of identifying and analyzing the terms people use to search for information online, with the goal of optimizing content to rank higher in search results.
    • Niche: A specific segment of a larger market, defined by particular interests, needs, or demographics.
    • RPM (Revenue Per Mille): The amount of money earned for every 1,000 views on a YouTube video after YouTube’s cut of the ad revenue.
    • SEO (Search Engine Optimization): The process of optimizing online content to rank higher in search engine results pages (SERPs), thereby increasing its visibility and traffic.
    • Sub-Niche: A smaller, more specialized segment within a niche, targeting a specific audience with tailored content.
    • Thumbnail: A small, clickable image that serves as a preview for a video and is designed to attract viewers.
    • Timestamps: Clickable links in the description of a YouTube video that allow viewers to jump to specific sections.
    • Value Addition: Enhancements or unique elements added to copyright-free resources to make them original and distinguishable, ensuring content stands out and avoids copyright issues.

    YouTube Faceless Channel Course: Strategy and Monetization

    Briefing Document: “A Journey Through Grief”

    Overview:

    This document provides a summary of key themes and ideas presented in the provided text, which is an excerpt from a YouTube video or course titled “A Journey Through Grief.” The speaker, Ale Milli Millionaire youtube4, discusses strategies for earning money on YouTube, focusing on faceless channels, niche selection, keyword research, scriptwriting, video editing, thumbnail design, and SEO. The speaker positions this course as a valuable, free resource based on their personal experience and success on YouTube, emphasizing the importance of utilizing readily available knowledge to achieve financial success.

    Main Themes and Important Ideas:

    • Accessibility of YouTube as an Income Source: The speaker emphasizes that becoming a millionaire through YouTube is achievable, even without paid courses or advanced equipment.
    • “I did not use any paid course. It was made for free and there was no course. In our times, we had to learn by doing. So if we are giving you convenience today, right? By collecting all the knowledge and gathering it in one place So please take advantage of it and become something inshallah all the best”
    • Focus on Free Content and Pakistani YouTube: The speaker targets a Pakistani audience, highlighting the opportunity for online earning and positioning this course as a free alternative to paid resources.
    • “Your earning from Pakistani Youtube is less than This free offer is going to be 10x more today”
    • Beginner to Advanced Course Coverage: The course aims to cover a wide range of subjects, from beginner-level understanding to advanced earning strategies.
    • “In the course we cover subjects from beginner level to Covering Intermediate level and Advanced We will go to the level and understand in detail that These faces are channels or youtube0 plus this course is for Everyone who earns money online somewhere”
    • The Importance of Taking Action Now: The speaker stresses the urgency of starting a YouTube channel, arguing that the market will become saturated soon.
    • “If not, then if you start it now so in the coming 2 years, after one year when Everybody must be jumping into it when you arrive it’s of no use you should start it Now”
    • Niche Selection is Crucial: The video emphasizes finding a specific niche or sub-niche. This includes focusing on a specific demographic, geography, or topic within a broader category.
    • “If you start a channel on health then maybe You may not grow but you are healthy Even if you are targeting only 65 plus to the people and if inside that too you Targeting only diet conscious 65 Plus give people definitely your channel If it can grow then this is what we call technically It is said that there is one sub-niche i.e. one niche And there are some secrets inside it too”
    • Faceless Channels: The course focuses heavily on creating faceless channels, where the creator’s face and voice are not required. Several examples of successful faceless channels are provided.
    • “Now I’m going to show you some case studies. In which I will give you a small comparison I’ll give you one thing friend, one guy with a face The guy is doing the same thing with his face How can you do it without example? My How is youtube2 doing while being faceless One I have uploaded 4 videos on youtube and There are almost 1.5 million subscribers what is he doing how i make it viral Talking Eaters”
    • Keyword Research for Searchable Topics: The speaker details using tools like Vid IQ to identify low-competition, high-search-volume keywords to optimize video titles and descriptions.
    • “If you want to do good SEO for them, then you want to rank your videos Now for example I am content travel I want to make it related and as an example basically i want to make them from lets should you stay in xyz i have seen this If it is finalized then I will write here wear should you stay in and I clicked enter from here when I clicked it is telling me that Its search volume is so much and so is the competition It is very high”
    • Keyword Research for Browsable Topics: The speaker also outlines methods for selecting video titles and topics that are likely to be promoted through YouTube’s recommendation algorithm, emphasizing identifying winning ideas through analyzing successful videos.
    • “The very first step is this that you go once and get some title You have to search and see what is related to it Can 100 get in ok now this is something in front of me If there are suggestions then I can search anything I take for example this one my video I haven’t finalised the title yet But once I randomly went to that niche Entered some related keyword Now after entering this, first of all you You have to open the filter.”
    • Importance of a Compelling Script: The speaker highlights the need for engaging scripts and provides tips on crafting them using AI tools like Chat GPT, emphasizing adding a human touch to the AI-generated content.
    • Utilizing Copyright-Free Resources with Value Addition: The video emphasizes the importance of utilizing copyright-free resources for faceless videos. It stresses adding unique value to such content through editing, effects, transitions, graphics, etc.
    • “The transition you use in it is You can make it unique inside It could be the effects you are using you make it unique because of that if it The video looks like this if you flip it Maybe I may also give you a video It becomes unique if you make motion inside it I will add graphics, maybe then your The video becomes unique if you If you add text then definitely it will be yours”
    • Thumbnail Design is Critical: Thumbnail design is highlighted as a very important skill and should be given importance. AI-based tools can be used for this.
    • SEO is not as important for browseable videos: Browsable videos are dependent on thumbnail design.
    • YouTube Shorts Strategy: The video touches upon strategies for succeeding with YouTube Shorts, highlighting the importance of engagement, average view duration, and consistency.
    • Investment and Tools Cost Discussion: The speaker discusses the costs associated with creating a faceless channel, providing tips on minimizing expenses and identifying essential tools.
    • Mistakes to Avoid: The video concludes by highlighting common mistakes that can hinder YouTube channel growth, such as switching between long-form and short-form content, sharing the channel inappropriately, and reusing content without adding value.

    Quotes:

    • “2+ hours of video content every minute youtube1 and just consuming content But the people who earn money from here They got 500 views on youtube in 1 minute hours of content is being uploaded and we what is the maximum people can consume it” – Highlights the vast amount of content and the potential for earning.
    • “Addiction has set in youtube0 There used to be many games but today Just for the kids I still want to watch it after youtube0 even after 10 years” – This notes the significant children’s audience.
    • “Think about yourself and your profit Is your money being made or not? Whether your revenue is coming or not He has to think about it first and then Definitely he has included the other three parties Advertise Content Creators and Content Consumers also think about them and something like this I want to make sure that everyone is happy and I make money be good now youtube1 will run as many ads as will run More youtube4 youtube4 5 but he will keep that himself” – This shows the speaker understands the various stakeholders.
    • “So there is no scope for improvement in this come down and keep scrolling you will read two-three times You can also mix and match by holding the You can pick up a theme from someone, just from someone else can pick up the text for sure yours Thumbnail can be the best” – This demonstrates how to copy and iterate.

    Target Audience:

    This course is likely targeted towards Pakistani individuals interested in creating a YouTube channel to generate income, particularly those seeking a low-cost and beginner-friendly approach.

    Overall Impression:

    The excerpt provides a valuable, free resource for aspiring YouTubers. It acknowledges the common challenges faced by beginners and offers a practical, step-by-step guide to creating a successful faceless YouTube channel. The course is tailored toward a Pakistani audience, further increasing its relevance and appeal.

    Faceless YouTube Channel Strategy: Niche, SEO, and Content Creation

    YouTube Faceless Channel FAQ

    1. What is a faceless YouTube channel, and who is this strategy best suited for?

    A faceless YouTube channel involves creating content without showing your face or revealing your identity. This can be achieved through animation, stock footage, screen recordings, AI avatars, or other creative methods. This approach suits individuals who are camera-shy, want to maintain privacy, lack resources for high-quality video production initially, or prefer to focus on content creation rather than personal branding. It is useful for creators who want to generate income without being known or recognized.

    2. How can I find a profitable niche for a faceless YouTube channel?

    To identify a niche, consider your interests and expertise. Then, research potential niches using tools like VidIQ to analyze search volume, competition, and related keywords. Look for sub-niches with lower competition and specific target audiences. Examples include “make money online for teens,” “diet conscious 65+,” or “technology news covering SpaceX.” Additionally, explore trending topics and competitor channels to identify potential content ideas. Consider a niche you can create a high volume of content in over time.

    3. How important is SEO for faceless YouTube channels, and how do I optimize my videos for search?

    While SEO isn’t as crucial for browsable videos as it is for searchable ones, it still plays a significant role. Use tools like VidIQ to find relevant keywords with reasonable search volume and low competition. Incorporate these keywords naturally into your video title, description, and tags. Start with a keyword and explore where it is naturally included in other videos and where videos are ranked. Use the exact keywords in your title and write a compelling description using a small paragraph. Include the original keyword plus related keywords that will boost video rank. Finally, you should be careful to include time stamps in the description with links for each topic, especially if your video is in the long-form format.

    4. What are the key elements of a good video script for a faceless YouTube channel?

    A good video script should be engaging, concise, and well-structured. Start with a strong hook to grab the viewer’s attention. Develop a clear outline with distinct sections and ensure a smooth flow between them. Use simple language and a conversational tone. Consider incorporating humor, storytelling, or thought-provoking questions to keep viewers interested. Utilize AI tools like ChatGPT to generate script ideas, but always add your own human touch and unique value. In other words, don’t paste it directly in your video, be sure to read it and give it a human character that is both personable and engaging.

    5. Is it better to use AI-generated voiceovers or human voiceovers for faceless YouTube channels?

    Both AI and human voiceovers have their pros and cons. Human voiceovers provide a more natural and engaging listening experience but can be more expensive. AI voiceovers are cost-effective and readily available, but may sound robotic or lack emotion. Human-sounding AI voiceovers offer a middle ground, providing a more realistic and engaging sound compared to basic AI voices. Experiment with different options and choose the one that best suits your budget and content style.

    6. How can I make copyright-free content unique and add value to my faceless YouTube videos?

    To make copyright-free content unique, focus on value addition through creative video editing. This includes adding unique transitions, effects, motion graphics, text overlays, background music, sound effects, and filters. Tell a unique story with the story blogs you are using. It is important to download video footage, then download and change the effects. Be sure to change transitions, graphics, sounds, and filters to tell a unique story with a creative license.

    7. What are some common mistakes to avoid when creating a faceless YouTube channel?

    Avoid these common mistakes:

    • Switching between different types of content like shorts and long videos.
    • Sharing your channel with friends and family, which can skew audience data.
    • Reusing content without adding value or making it unique.
    • Using VPNs or RDPs to upload content, which can affect targeting.
    • Not analyzing competitor channels to identify successful strategies.

    8. How does the monetization and audience retention work for short-form videos?

    Algorithm for youtube shorts is about engagement and avg. view duration. Hook game has to be strong with no uselessness in your content (even a second). An average video duration is 30-45 seconds. Maintain consistency to have viewers see short videos, they should be uploaded daily. Pre-monetized channels perform well, agent channels work even better. Target audiences for youtube shorts include children under 11 and adults 45+.

    YouTube Automation: Content Creation and Monetization Strategies

    YouTube automation involves strategies to streamline content creation and audience engagement. Here’s a breakdown of key aspects:

    • Earning potential: Many individuals aim to generate income through YouTube. The focus is on understanding how to monetize content effectively.
    • Content creation:Creating videos without showing your face is possible across various niches like politics, health, technology, and travel.
    • Finding a niche is a crucial first step. Some popular niches include Make Money Online, Technology, Health, Travel, Geopolitics, Personal Finance, Stories, Plants & Gardening, ASMR, AI updates, and more.
    • Sub-niching can help target a specific audience within a broader niche, increasing chances of growth.
    • Using AI tools for script writing and voice overs can save time and resources.
    • Key elements for success:Keyword research is essential. Using tools like VidIQ can help find searchable keywords with high search volume and low competition.
    • Compelling thumbnails and titles are crucial for attracting viewers. Click-through rate (CTR) is a key parameter for YouTube’s algorithm.
    • Audience retention is vital. Average view duration and watch time are important factors in video promotion.
    • Technical aspects:Basic settings for faceless channels involve selecting the country of residence and video language in YouTube settings.
    • Content strategyDifferent frameworks exist for YouTube videos, including browse features, search, and shorts. Each has different strategies for niche selection, title optimization, SEO, editing, and thumbnail design.
    • Traditional YouTube content relies on high-quality videos and attention-grabbing thumbnails.
    • YouTube Shorts require a different approach, with less emphasis on thumbnails and titles.
    • MonetizationUsing human-sounding AI voiceovers can help with monetization.
    • Cost considerations:Outsourcing video editing and thumbnail design can be costly. Training a family member or using freelance platforms can reduce expenses.
    • Tools like VidIQ, Canva, and Eleven Labs may require subscriptions.
    • Common Mistakes:Switching to short videos in confusion.
    • Sharing a channel with friends or relatives.
    • Reusing Content. Content must be unique.

    Faceless YouTube Channels: Strategy, Content Creation, and Monetization

    Faceless YouTube channels involve creating content without showing your face, and here’s a detailed explanation based on the sources:

    • Niche Selection:
    • Faceless channels can cover a wide range of topics such as politics, health, technology, food, nutrition, and travel.
    • Identifying a specific niche is the first step. 50 niches are identified including Make Money Online, Technology, Health, and Travel. It is possible to create content in any language.
    • Sub-niching is a strategy to target a more defined audience within a broader category. For example, within the health niche, one could focus on nutrition specifically for athletes, kids, or pregnant women. By focusing on a sub-niche, there is opportunity to grow your channel.
    • Creating Content:
    • AI-generated characters can be used.
    • Content can include quizzes, truck modifications, and other topics.
    • Technical channel settings:
    • Creating a faceless channel doesn’t require special measures like registering a company in specific countries, needing an RDP or VPN.
    • Basic settings involve setting the country of residence and video language to target the desired audience.
    • Content Strategy and Frameworks:
    • There are different content frameworks including browse features, search, and shorts, each requiring a unique strategy for niche selection, titles, SEO, editing, and thumbnails.
    • Traditional YouTube emphasizes high-quality videos and attention-grabbing thumbnails.
    • YouTube Shorts uses less emphasis on thumbnails and titles.
    • Essential elements for success:
    • Keyword research is critical and tools such as VidIQ can help identify keywords that have high search volume.
    • Creating compelling thumbnails and titles is essential for attracting viewers.
    • Audience retention is important and watch time is a key parameter for YouTube’s algorithm.
    • Monetization:
    • Using human-sounding AI voiceovers can aid in the monetization of videos.
    • Tools and cost considerations:
    • Video editing and thumbnail design can be costly to outsource.
    • Subscribing to tools such as VidIQ, Canva, and Eleven Labs, may be needed.
    • Mistakes to avoid:Switching to short videos.
    • Sharing the channel.
    • Reusing content.

    YouTube Keyword Research and Optimization Strategies

    Keyword research is a critical process for optimizing content and improving visibility. It involves identifying the terms and phrases that people use when searching for information related to a specific topic. Here’s a detailed discussion of keyword research for YouTube, based on the sources:

    • Importance of Keyword Research:
    • Essential for channel growth: Proper keyword research can help avoid stagnation and increase views.
    • Targeted content: Understanding relevant keywords ensures content aligns with audience interests.
    • SEO: Knowing the keywords to include in titles, descriptions, and tags helps videos rank higher in search results.
    • Types of Keywords:
    • Searchable keywords are those that users type into the search bar.
    • Browsable keywords are related to topics that attract viewers through browse features.
    • A video may get views by searching for them or they may not come up, but the majority of views are going to come from here.
    • Tools for Keyword Research:
    • VidIQ is a tool that can identify keywords with high search volume and low competition. VidIQ is useful to find good titles.
    • TubeBuddy is another tool that can be used for keyword research and SEO.
    • Google Trends may also be helpful.
    • Strategies for Finding Keywords:
    • Initial exploration: Start by entering a broad term related to the chosen niche in a keyword research tool.
    • Analyze matching terms: Identify related keywords and phrases that align with the content.
    • Filter by competition: Focus on keywords with low to medium competition to increase the chances of ranking.
    • Evaluate search volume: Ensure that the keywords have a reasonable search volume, indicating audience interest.
    • Competitive analysis: Examine the titles and descriptions of top-ranking videos in the niche to identify commonly used keywords.
    • Long-tail keywords: Incorporate long-tail keywords (longer, more specific phrases) to target niche audiences and reduce competition.
    • Steps for Keyword Research:
    1. Start with a broad term: Enter a general keyword related to the video topic in VidIQ.
    2. Explore related keywords: Examine the matching terms and identify potential keywords.
    3. Filter by competition: Apply filters to find keywords with low or medium competition.
    4. Assess search volume: Check the search volume to ensure there is sufficient interest in the keyword.
    5. Check keyword usage: Search for the keyword on YouTube to see how many videos use it. Fewer results indicate less competition.
    6. Analyze ranking videos: Examine top-ranking videos to understand their content and identify potential improvements.
    • Optimizing Titles, Descriptions and Tags:
    • Titles:
    • Include the exact keyword in the video title to improve search visibility.
    • Create a compelling title that is clear and engaging, using the keyword naturally.
    • Descriptions:
    • Include the video title at the beginning of the description.
    • Write a paragraph that incorporates relevant keywords naturally.
    • Add timestamps to the description, using keywords to describe each section of the video.
    • Tags:
    • Use a website like rapidtags.io to generate relevant tags based on the video title.
    • Analyzing Competitors:
    • Identify competitors: Find channels that create similar content.
    • Examine successful videos: Analyze the titles, thumbnails, and keywords of their most popular videos.
    • Identify gaps: Look for areas where competitors are lacking and create content to fill those gaps.
    • VidIQ Extension
    • Shows tags, description, and titles.
    • Shows the subscriber which saves you the time to check each channel.
    • Identifies videos that are performing better than average.
    • “Trending videos” can be filtered.

    By following these strategies, content creators can effectively research and implement keywords to enhance their YouTube videos’ visibility and engagement.

    Video Editing for Faceless YouTube Channels: A Comprehensive Guide

    Video editing is a crucial skill for creating engaging content, especially for faceless YouTube channels. Here’s a breakdown of video editing, according to the sources:

    • Importance of video editing:
    • Video editing and thumbnail design are important skills.
    • It is a skill that many people sell as a service.
    • Video editing constitutes approximately 5-10% of what it takes to run a successful faceless channel.
    • Tools for video editing:
    • CapCut is recommended as a tool that covers 99% of your needs.
    • Other tools include Filmora, Premier Pro, Pictory, and InVideo.
    • Copyright-free resources:
    • Story blocks is a platform for niche content.
    • YouTube is a source of copyright-free content.
    • Other resources include InVideo Elements, Motion Array, Pexels, Pixabay, and Unsplash.
    • Value addition techniques: To make the content unique and avoid copyright issues:
    • Add unique elements to the video, including background sounds and transitions.
    • Incorporate unique effects, motion graphics, and text.
    • Include voiceovers or background music.
    • Add PNG images and popup sounds.
    • Incorporate filters.
    • Learning video editing:
    • Azad Chaiwala offers free video editing courses on YouTube.
    • Cost considerations and strategies:
    • Outsourcing: Hiring video editors can be expensive.
    • Training: Instead, you can train a teenager in your family.
    • Freelancers: Utilizing platforms from free communities can connect you with service providers.
    • Fixed salary: Discuss and fix things on a fixed salary, for example, 50,000.
    • Teenagers: Find video editors who are teenagers who are happy to serve you and provide content.
    • Mistakes to avoid:
    • Do not simply download videos from websites and upload as is.
    • Content must be unique.

    Faceless YouTube: Niche Selection Strategies

    Niche selection is a critical first step in creating a successful faceless YouTube channel. It involves identifying a specific area of focus for your content.

    Here’s a detailed discussion of niche selection, according to the sources:

    • Importance of Niche Selection:
    • Channel Growth: Starting a channel on a broad topic like health might not lead to growth, while targeting a sub-niche, such as diet-conscious individuals aged 65 and above, can be more effective.
    • Targeted Content: Choosing the right niche ensures that the content aligns with the audience’s interests, increasing the chances of attracting and retaining viewers.
    • How to Identify a Niche:
    • Explore Interests: Identify topics that you are passionate about and knowledgeable in.
    • Look at Trends: Analyze current trends and identify gaps in the market.
    • Keyword Research: Use tools like VidIQ to explore keywords related to potential niches. Look for keywords with high search volume and low competition.
    • Competitor Analysis: Analyze what niches other YouTubers are using.
    • Sub-Niching: Identify sub-niches within broader niches to target a more specific audience.
    • Niche Categories
    • Make Money Online: Includes sub-niches like channels for females, teenagers, or those interested in investing.
    • Technology: Includes technology news, advancements, and gadgets.
    • Health: Encompasses health remedies, nutrition, and exercise.
    • Travel: Includes top destinations, travel scams, and reasons not to visit certain places.
    • Facts: Can be related to history, travel, animals, or religion.
    • Quotes: Can focus on athletes, entrepreneurs, or celebrities.
    • Celebrities: Can cover lifestyles, scandals, or achievements.
    • Movie Recaps: Focus on specific movie industries like Hollywood or Bollywood.
    • Geopolitics and World Affairs: Can target specific regions or countries.
    • Personal Finance: Can focus on different age groups or investment strategies.
    • Stories: Includes business, scary, crime, moral, and kid stories.
    • Plants and Gardening: Focus on specific types of plants or gardening techniques.
    • ASMR: Create videos with sounds that trigger a sensory response.
    • AI Updates: Cover advancements, updates, and new apps in artificial intelligence.
    • Crypto/Stock Market/Forex: Focus on trading or investment strategies within a specific market.
    • Pronunciation: Teach correct pronunciation of words.
    • Futuristic Concepts: Cover future trends in cars, technology, and politics.
    • App/Software Tutorials: Provide tutorials on using specific apps or software.
    • Personalities: Focus on news and updates related to a specific public figure.
    • Investment Tips: Offer advice on investing in mutual funds, stocks, or government bonds.
    • Cartoons and Rhymes: Create animated content.
    • Beauty and Makeup: Provide tutorials, product reviews, and beauty tips.
    • Nutrition: Focus on nutrition for specific groups like athletes, kids, or pregnant women.
    • Cars/Airplanes/Helicopters: Cover topics related to vehicles and travel.
    • Animals: Provide information about various animals.
    • Pets: Focus on pet care, training, and behavior.
    • Home Decor/Interior Design: Share tips and ideas for home decoration.
    • Motivation: Offer motivational content related to fitness, breakups, or business.
    • Drawing: Provide drawing tutorials.
    • Book Reviews: Review books from various categories.
    • Religion: Create content related to religious teachings.
    • Formal Education Subjects: Explain concepts related to subjects like chemistry, physics, or mathematics.
    • Skill-Based: Teach skills like sales or digital marketing.
    • Language-Based: Teach new languages.
    • Sports-Based: Focus on a specific sport like cricket, badminton, or basketball.
    • Gaming: Make videos of PC or gaming laptops.
    • Street Food: Make videos showing street food from different cultures.
    • Magic Tricks and Illusions: Make videos to show techniques for magic and illusions.
    • “What If” Scenarios: Explore hypothetical scenarios related to science.
    • Sub-Niching Criteria:
    • Targeted Audience: Instead of targeting everyone interested in health, focus on pregnant females or individuals with specific health issues.
    • Specific Focus: Instead of covering all celebrity news, concentrate on a particular industry or type of celebrity.
    • Monetization Potential
    • Some niches, like personal finance and investment tips, tend to have higher RPM (revenue per thousand views) rates.
    • Keyword Research
    • After selecting a niche, you can research keywords and apply filters.

    By carefully considering these factors, content creators can select a niche that aligns with their interests, has growth potential, and offers opportunities for monetization.

    COMPLETE YouTube Automation Course For Beginners | Make Money On YouTube Without Making Videos 2025

    The Original Text

    Ale Milli Millionaire youtube4 was very beneficial this again We have created approximately 20-22-23 new videos. There are many changes in this strategy There has been a slight change, don’t think that it is free I paid the money okay so my Minimizing the Money and the Other the thing is that this is probably you youtube.apk is one of our needs where our All Urdu courses are available for free My University of Free Taleem Cheez Takri it happens to you that you have learned no we all don’t if i say that friend i am 21 He became a millionaire at the age of I did not use any paid course It was made for free and there was no course In our times, we had to learn by doing So if we are giving you convenience today, right? By collecting all the knowledge and gathering it in one place So please take advantage of it and become something inshallah all the best so hello everyone welcome to free youtube1 At some point in your life you I was thinking about starting a channel It will happen but most of you are like this There must be those who would be saying that friend, no my face Neither should my voice go to the front nor should it be and still something happens that I Your earning from Pakistani Youtube is less than This free offer is going to be 10x more today In the course we cover subjects from beginner level to Covering Intermediate level and Advanced We will go to the level and understand in detail that These faces are channels or youtube0 plus this course is for Everyone who earns money online somewhere Want to earn through youtube1’s 2.5 years and many of my videos are in this Time Collaborate with youtube1 in 2023 as well I did it and I took that free course You can get an idea that this is my From the content to my tawassul Millions of people have learned this skill and There are hundreds or thousands of people who By working in actuality, Alhamdulillah you can earn good money so let’s get started with ourselves laptop screen and do things let’s discuss one by one so this is the youtube1 is how to earn money right from it First, you must understand one thing that you youtube1 letter why am I saying this There are some solid facts behind this, see youtube0 in this world which is number one that on google2 youtube 2+ hours of video content every minute youtube1 and just consuming content But the people who earn money from here They got 500 views on youtube in 1 minute hours of content is being uploaded and we what is the maximum people can consume it There are around 1.8 billion user visits youtube.be is the automation space They’ve been into this long before us If you are learning this thing then I will tell you this I would say that as a Pakistani I have seen many This opportunity has been grabbed too late that level is reached very soon If it is high then I will tell you that We as a Pakistani start it now have to do it after that In youtube2 we hear from every person’s mouth amazononline.in What came in 2020 Did not earn as much profit as compared to the One which came in 2018, so today you should understand that There is no youtube0 that has this many people If not, then if you start it now so in the coming 2 years, after one year when Everybody must be jumping into it when you arrive it’s of no use you should start it Now Politician Brands Organizations institutes actors athletes are already Shifting Towards not going anywhere youtube4 people are already youtube1 uz of people are making money full time Income From youtube has 1 billion user base in this world has a population more than Do you know kids how much Addiction has set in youtube0 There used to be many games but today Just for the kids I still want to watch it after youtube0 even after 10 years If you want to see then I have a big idea in this An opportunity is visible, so today What are deliverables, what are we talking about today I want to talk to you today, I am 15 I am going to talk about the chapters and you There are as many questions in your mind as When I did the last course with Azad Chaiwala All the questions were recorded there have come to me over the time As many frequencies as I get confused with you, today I saw that everything has to be cleared and this course is Going to be the best free online We might have read it here on youtube.be I want to talk about Nishas what Nishas what happens to them all There is a big question about how to find it I want to talk about it in detail, I have written here Tell you about script writing Keyword research is most important I have to tell you the frameworks of So many people are confused about youtube1 I want to tell you guys what happens I want to tell you about thumbnails tell me about video editing I will answer all the questions here today I will make it clear what the hack is and grow it How to avoid mistakes as much as possible Most people do these things today if you can understand it in this video then Make sure you don’t skip time take it out and watch it with peace of mind ok so first of all that come Whether you talk about politics or Whether you talk about health or technology Whether you talk about food and nutrition whether you are talking about traveling are you any kind of thing in the world If while remaining faceless, in any tongue Do you think that for example reality TV Many of you might know the truth What does TV do? It talks about news. Jio talks about current affairs Politics talks about what is going on in the world I keep talking about that beyond but have I ever He has come forward himself, otherwise what about his Did it make any difference to his income? Did you penalize me or not brother you are in front If you don’t come, we won’t give you that much money So and so gets more money I will give you no youtube1 guy is coming 10 guys are coming or 50 people are coming but who cares about it which content is getting views and which The content is not getting views which are not coming He will sideline him, He will not bring it in front on which he is getting views there will be something in it until endless youtube0 I will keep it niched right now You have to go into these in detail and understand things Which niche to go to and which not to Also know what are its parameters You have to understand but right now I am going to give you 50 Nishas is like that Ginwala brought forward for example make Money Online You Related to Make Money Online There are hundreds of topics on which you can create content There is technology inside technology Technology news also comes technology Advancements also come with technology Gadgets also come under technology A lot of small things come inside which you can discuss and beyond that You can cut the channel, it comes on number three Now health is inside health, health remedies Health is a separate niche within health Nutrition is a different thing within health Exercise is a different thing within health too I will give you at least 1015 sub niches ginwala we can count 10 sub niches for Example Scams in XYG City Best Restaurants in XYG City Tourist Destinations in XYG City So a small and different kind of thing on all of these Similarly these 50 can also become a channel it’s in front of you for a second Stop, read and understand, once your mind is open It would be like yes friend, one or two things from these These are the ones I think about I can create content and yes i can create my own faces channel Now I’m going to show you some case studies. In which I will give you a small comparison I’ll give you one thing friend, one guy with a face The guy is doing the same thing with his face How can you do it without example? My How is youtube2 doing while being faceless One I have uploaded 4 videos on youtube and There are almost 1.5 million subscribers what is he doing how i make it viral Talking Eaters For youtube0 Made His First $379 Online Vid youtube2 This is an AI character that it It has been used similarly I will tell you another one I show a channel by the name of Quiz Bloods Now what is this, this is a quiz related channel And it has around 6 lakh subscribers. is present and what is it doing guess the Guess the Flag Guess the Car Logo Guess the Sport Guess the XYG means what has it done basic This video editing is very difficult I will not let you know in the letter on video I will tell you now how to do this and you wood see that friend you can do this too okay then there’s a third channel now this It belongs to Pakistani and is based in Pakistan Now what is this Pakistani trucks people loves to watch people from outside Truck breaks down how to fix it The truck is running on the road, such and such truck How did you transform it into a truck? see 10 million views 10 million views 88.9 million views These people are also doing this And they are making a lot of money from it, so I’ve shown you some case studies. just to open up your mind that good yes Friend, work of this level is being done and at this level the work is being done now we come to our Chapter two where we will discuss Some basics of how do you go now the first thing that comes What settings should I do for the faceless channel? so many people ask what is this friend is it rocket science i need to go to uk usa I need someone, I need a relative You must be needing some uncle only then I can go can i create the channel again do you know I want to register a company UK USA In Canada or Australia the answer is no No RDB is required, no VPN is required only then If the content can go to USA then the answer is no which kind of a basic one A channel is created in the same way Face Edge there is no youtube0 i will tell you quickly I’ll take you to the screen and show you these three Let me show you four settings so you can get a Be satisfied now, for example this is your one This is a faceless channel, here you first came click on settings click on settings By clicking here you can click on the channel and you can enter your Country of Residence here You will select United States from Like this after that you uploaded in defaults You have to go to advanced settings and You can see the video by scrolling here select the language as english is next hum title and description We will also select the language as English Your three settings are now complete. Now from here you have to click on save. For now, I am cancelling it on fourth For setting when ever you are uploading any video like for example this one You are uploading the video from here I want to upload a video and while uploading You have to scroll down and here But you have to change two-three things in the video For example you will read the video from here convert language to english You will have to like this and the video location is here You also have to make the right to the United States So these are basically four to five settings. which you want to do in your video and you Are good to go, there is nothing more than this So these were the basic settings that you had in your Apart from this, there is no rocket to be shot in the channel Science is not something in the air or the sky it’s not something you can pick up and drag me to Only then can your face channel be created Now the next question will come and very very important question and the question is How to get views from USA audience now This is a very important question that you You have to understand it from now on, see if you are like this follow any youtuber who He who is not in Pakistan lives somewhere else but you can download its content in Urdu and Hindi Let’s watch, someone might be coming to my mind For example Sham Idris Sham Idris remains is in Canada but you can see it in front of you Content in Pakistan Urdu Hindi Those who reach the right in the language They must be sitting in India too Its content would have reached Idra which I must be sitting in Bangladesh It is possible that the content may reach even that its content is from someone sitting in America Desi Pakistani should reach there too, right Now you come to the second scenario here If you upload content from Pakistan If you do then if any friend of yours knows USA UK Canada Australia South Korea Poland Ireland If you have a friend anywhere in the UK and He subscribed to your channel and hit the bell icon is pressed or not So he has seen some of your videos When you sit here from Pakistan and your I will upload the video in Pakistani Urdu I am talking about Hindi content if you What do you think if I upload this video? is this video your friend from USA my friend from Canada will be able to see it I will definitely be able to see you guys too I will give you all a small exercise Wherever you are sitting and watching this video You must comment below if you are from India you are from pakistan right now where are you from You are sitting and watching this video from Kenya You are sitting and watching from the USA yes you guys will see that I have uploaded this Azad Chaiwala is from Pakistan has uploaded this from Pakistan But if you read the comments below, you will You will see that someone is saying that I am from Kenya I’m from Ireland I’m from Poland I’m from Denmark I’m from You can find here from every country in Europe, Germany People will be seen in the comment section below if So you can see people in the comment section below. If you are staying here then you must understand this thing It should be known that Azad Chahwala had defeated Pakistan I have uploaded the video sitting there but You can see the queens of the world in the comments If they are coming then why is it like this from Pakistan While sitting we were thinking that friend this is outside I can’t go but there are so many comments If people are from Pakistan then they are sitting in Pakistan The video should go like this If it is of youtube1 type then you are from Pakistan Upload it sitting here or sitting from India By uploading it, he has got his right audience You have to reach me tell me Sitting in Pakistan, you will never see Russian why is there no video on youtube Sitting in Pakistan you will get the job of an Egyptian Why didn’t the youtube video come though? going from pakistan to egypt but Why is this virus not coming to Pakistan from Egypt? The reason I am not coming is because Egypt’s The language in which YouTube will be available You must have uploaded the content, you will understand it don’t come, it is not relevant for you As youtube2 he posted videos from youtube she has been consumed and then she is in Pakistan if he comes and stays with you then he should go to Egypt Recommend all types of Youtube videos there are chances of it happening because he The tongue comes and the topics for it he is extremely relevant i hope so It might have become a little clear to you that if Your topic is relevant and so is your language It is relevant wherever you sit Upload content youtube0 brother you tell me that youtube0 are the things that I have told you three primary things from here which youtube3 has parameters but three Before explaining the parameters I would like to tell you a Let me explain the fundamental concept see it is from youtube0 You have to think about yourself and your profit Is your money being made or not? Whether your revenue is coming or not He has to think about it first and then Definitely he has included the other three parties Advertise Content Creators and Content Consumers also think about them and something like this I want to make sure that everyone is happy and I make money be good now youtube1 will run as many ads as will run More youtube4 youtube4 5 but he will keep that himself means that She has newly There is a youtube4 video in which he does something sometimes he is doing something, sometimes he is doing his is telling about sometimes saying look I’m going there look I’m going there Do you and I see anything in his video? I have no interest in those videos The kind of thing that is coming before us that we Neither do we know nor do we recognize that He is interested in some topic I am not interested in the quality of his videos it’s very bad the audio is very bad so what You and I will not get bored watching it and The videos are coming in front of us like that I will keep leaving and say friend what is this futile I have started recommending videos youtube shows 3 videos that we like We will see more and more of the whole We will see beyond that, we will obviously click on our Mostly in front youtube3 compromise in parameters This is the situation which I am going to give you the parameters for now. I am going to tell you then youtube1 which is the first parameter that is CTR stands for Click Through Rate If you are making a video that you I have kept the thumbnail, I have kept the title and that youtube visible to 1 person or 100 people and the whistle coming on it is below 10 coming on below 8 coming on below 5 If it is coming then youtube1 is showing it to people hmm five people are clicking on this or Four people are clicking or three people He will say that you are clicking this video friend It’s not good, people are clicking less That means that people are getting bored somewhere If you are getting started then watch this video remove it then When I show this title to youtube0 when i show or this topic basically When I show it, people will click on it So from there the video went viral The chances are higher because So this is how CTR increases on your videos If this happens then your video will go viral There are more chances but this is just one factor now comes the second factor What is Pay and Second Factor Average View Duration if average views on your video The duration is less, which means people will come to your video So we go and click but They see that friend is good click betting has it been done in the beginning or the topic is that It is not as per what is mentioned in the thumbnail If it happens, they will shut down your video. For example, there is a 10 minute video on Average people are watching it for 1 minute what does that mean youtube 1 minute video 2 minutes or 1 the minute people are ticking that means your The video will never be promoted and The third factor is the watch time now watch how is the time different watch time like this The difference is that you have made a 10 second video I just posted it and people should wait for 5 seconds on it If you are there then wait for 5 seconds on youtube2 There is an hour long video and if someone spends 20 rupees on it even the minute is ticking youtube2 it’s lasting for at least 2 minutes right it’s over Average view duration at Just 33 but youtube is lasting for 2 minutes friend what does it mean It’s good if you promote this video then this will happen Our third factor is if your video I have good CTR and good average The duration is good, if the watch time is yours The video has to be promoted, this is the basics of The chapter on basics ends here Now let’s move on to chapter three tarif which is frameworks of youtube.com pixabay.com and some from there I picked up the videos, compiled them and uploaded them. After putting on voice over this gentleman is my The faceless video is complete in this, friend You have to follow a strategy have to go with the frameworks It depends on what type of audience I’m targeting I am going to target and accordingly After making the whole strategy, you have designed the content you have to do it sometime see your youtube0 check your history if you If you have heard the songs then the songs start appearing in front of you. If you have content on any topic then you will go consumed similar topic related Videos will appear if you have subscribed to Arva News If it happens then the videos that are coming out That’s basically through the browse feature to your It is coming in front of you, okay, you should understand this that it is coming through the browse feature well there are some videos which never It is not possible that you open your app You are coming in front of me for example For example this is like a remote, how to change it sales in a remote of a light have you ever gone You must have searched if you want lights etc. use or in front for example an i it is on how to turn on death mode This never came to your attention right? When does it appear when we click on the search bar above? let’s type it and press enter then these videos would have been coming in front of you now this is the second framework, this is that There are videos which get views through search which was the first one that had the browse feature which one takes the views through which takes views through search Now both of them have different strategies We have to play different games between the two then What is the third category or third framework what if you work on youtube4 Now shorts are neither coming in search Shorts are neither available through direct browse nor You would have seen it in a short section You have to go there and you can scroll down there is no thumbnail there neither The title matters so much that one It is a different game which we are making a different we will discuss in the video ok right You got a little idea from here that yaar yes there are some videos which are just There are some that come through search comes through browse there are some which Shorts are good now that there is a browse feature we want to promote videos through that is called traditional youtube’s content has to be promoted that is through youtube’s youtube.be shorts automation now these three Its frameworks are Majeed and three others there are frameworks through which Which framework to do youtube.be automation There are different pros and cons of each framework Cons are for example which age is very short problem They are so high end oriented Editing is not required for example You have to search how to turn on dark mode on instagram2 is fit or not, its all the same You can hear the sound clearly in front of you You are getting clear screen recording are you done with it, do you need anything more than this There is no need to do SEO of these videos It is important, we will do SEO and we will rank Only then will your videos like this get views You can upload 10-10 posts six times a day You can also upload such channels as well I can show you which is 25 25 30-30 I am also uploading videos right because It is short and problem oriented On the other hand if you come across browsable videos or come to traditional youtube0 what is there You will get a very quick result Your video will go viral instantly The quality of the video is very high end Your thumbnail should be big and high end Your topic should be like a big click daughter Only then you need more through browse Views will come here, SO doesn’t matter here only the title matters If it happens then the niche of every framework is different Niche selection criteria for each framework The title selection of each framework is different The SEO criteria of each framework is different The method of doing this is different for each framework The editing style is different for each framework Thumbnail designing concept is different then you Make sure that you do this first We have to decide which one we go to in the framework and in what way have we now we have to design things here Basically, what will work is traditional I have made a total difference to youtube’s I made a chapter and the remaining three Frameworks are a little bit exclusive We are going to talk about that in this video We will not talk, so this was our chapter number three frameworks of what is about niche selection on youtube4 Now many worlds are coming here again and again You will see it again and again, listen to it, and understand it because this is the most important thing that Brother Nisha which one should I select Nisha who If you want to select C then I will explain it to you today What are the criteria for niche selection How to find out your niche what is niches what are all niches How to catch one niche and remove all its niches I find out all these things Now let me explain it to you in this chapter, ok here I will tell you about the 14 niches same but at the same time i kissed you all the way I also need to explain it a little bit that if someone is a Nisha then all the Nishas are inside him Which one is it then at the top is Nisha’s name and inside the bottom bracket I’ll write it You will also know a little about all niches. I will take you while touching it because it is actual The channel that we want to create is for any I don’t want to do anything on the target, I have destroyed all his targets We have to target because in today’s time Competition has increased a lot, I would tell you that If you start a channel on health then maybe You may not grow but you are healthy Even if you are targeting only 65 plus to the people and if inside that too you Targeting only diet conscious 65 Plus give people definitely your channel If it can grow then this is what we call technically It is said that there is one sub-niche i.e. one niche And there are some secrets inside it too, so Let’s start with your first niche And That is the Very Famous One Make Money Online Make Money Online Trend Since 2020 It has increased a lot since Covid arrived Every child knows that he can earn money online Now people become this, how do they become this Targeting youtube2 and any of its sub-niches I have to do it for example what is its sub nisch Maybe you can just create a female channel You just create a channel oriented app like this Related which lets you earn money online You just create a channel which is just targets teenagers in a way You can make money online just like this Create a channel that targets that without How to make money investing online You just create a channel that targets If you have $1000 then you can invest online How to make money, this is how you can earn money We will choose a sub niche and inside it we will create our own channel then whatever we have The second niche is that it is about technology now All niches related to technology are also wildly Are you covering technology news? You can take advantage of technological advancements You can cover as much technology as you want Big projects are underway for example SpaceX is running Tesla is running you You can cover any one project You can cover any app with blogs can cover atus atus then the third one Nisha hai that is health I told you about health I told you that people who are 65 plus You should target the children You target pregnant females It may be possible in you that only the one who People are sitting here with the issue of hurt Just cover them, you are only diabetic If you cover the patients then this like there are lot of niches inside it then The next niche after that is travel. You can also choose to travel. You can create content inside Top 10 Places To Visit In Falana City Falana city ​​so and so city you can cover top 10 Reasons Why You Should Not Visit Falana city ​​so and so city so and so city you can cover There are 10 tourist scams in this world city ​​so and so city so and so city then after that Your channel idea could be next About Facts You can create facts Are you related to any thing? You can create history related to Traveling can create facts Related You can create facts You can create facts related to health These may be animal related facts can create it maybe someone If religion related is correct then in this way your I have a lot of ideas related to facts but then after that the next niche that is Quotes Now some athletes say something Somewhere in the book people say something Politicians say some things, some old things The great leaders in history have been Sometimes they say something, sometimes someone else Entrepreneurs sometimes call it Jeff Bajus When people like Elon Musk say this, you Do not do it in such a way that you cover everybody. You want to target a domain for For example, on my channel only sports I will show you the codes of these people Shall I tell you on this channel or on my channel? Only those who are Bollywood stars I will tell you the codes or I will give you on my channel Only those Hollywood stars I will tell you the codes alright then the next niche Celebrities are at number seven now You can also target celebrities You can also target the lifestyle of celebrities Where can the celebrities say You can target those who have done scandals You can cover news of celebrities Are you covering the achievements of celebrities You can do this right now while sitting in my presence Ideas are coming, okay then celebrities Also do not do this because you have to catch a domain you are covering the news Celebrity news and you can know it all over the world Covering all the celebrities of You are no longer just from one country catch the celebrities or you are a Catch the sports based celebrities or You are an industry based celebrity grab it then the next niche is that is Movie R Caps now movies are also from Hollywood Are you from Lollywood or Bollywood? Are you among these Grab hold of any one industry Only action movies are considered important for the industry Catch me as I recap these movies for you now I will give you the next Nisha that is Geopolitics and World Affairs Now In this also you can be that in any one country You can target a region Take any two countries which are always at loggerheads with each other You can only cover those who have disputes. but you may be like pakistan And China is a great friendship between you and these two Please cover it and also tell me their history You can also know about their current relations Tell me, this is how you can create any channel then the next Nisha that is Personal Finance Now Inside Personal Finance There are many other prohibitions too, you can tell me this that people who are just 20, how can they invest money you can tell that How can people who are only 40 years old make money? invest you can tell that they people who want to retire at 60 and Never work after retirement You can tell me what I want to do People want to retire at 30, what are they do it then the next niche is stories now There are many types of stories, you can do business You can make stories, scary stories You can make horror stories yes you can make crime stories You can make moral stories and kid stories You can create any one category Choose and start his/her story channel give then the next thing that is Plants and Gardening You can also do it inside There are many types of fruits available at this time plants are like flowers and you are theirs start giving explanation here Your channel is very good on search can rank then the next channel is ASMR ASMR is such videos in which no one’s voice is coming out and you are doing a job for example you are playing with something If you are unboxing something then its This is a great listening experience by recording from youtube1 is a niche AI ​​updates these days It is becoming a big hit, again I am saying It is becoming very hit these days You know there’s a lot of A.I. What advancements are coming? Advancement is coming, what updates are coming Which new apps are available? What new softwares have arrived? What new things are going to come with all these you cover it here you will find it very good The next one that will give you a return We have a niche that is crypto stock Market Forex market means any one Capture the market and within that market go to any sub niche or you can go there teach me how to trade or you can go there teach me how to invest or you can go there on the fundamentals of those markets which These are the bases, let them teach you people, it is correct So this is how you can catch any market I can get good returns here Let me tell you that this is a very high RPM niche here You get good returns then The next niche is pronunciation based now like this There are channels, I might show you one or two videos It was shown earlier also which was just pronunciation Someone here is teaching you how to do everything Nich does not exist here you You have to play within quantity 2000 You can also make videos as many as 3000 There are words inside the dictionary, all those words that if you record the pronunciation Then maybe your two-three years of hard work will help you It will give returns throughout your life, right? The next one is futuristic Concepts now futuristic concepts What will cars be like in 2050? How will trucks look in 2060 In 2030, you will get laptops which are What will be the size in 2040? How much of these AI software are you? All these things must have become advanced for you If you want then you can cover this news It could be political news as well In this we also provide technology news We can also bring this in the news Also bring news of any project can mean that inside this also you have any one Now I want to start a category channel from that The next niche is that is app or software Tutorials Now you have seen I Bet many times youtube0 how do I work for example you that are stuck how do i delete history so you You must have gone and searched how to delete history of Google’s on Word document, this is all of us Sometimes you can go and use some app or If you search for software related things then You can also create content like this and again Within this also the matter of quantity will come up 1000, 2000, 3000 videos can be made easily Then the next niche is personality Now there are many personalities or personal brands There are those in the world at this time who are loved by the whole world Do you know, for example Elon Musk? Example Andrew Tate for Example Bill Gets for example Donald Trump you in On any one of the personalities Start your own channel and its news The one who is tweeting is coming, He is giving new reactions which are new He is giving statements, you cover them Started a whole channel related to that then do the next one which is below us that Is Investment Tips Now Investing It is such an amazing niche that you will find it here The RPM gets pretty crazy high You can also watch RPM here for $20 RPM say it can be found at 1000 The views you get can go upto youtube2 although the average This is the faceless channel for US audience it’s $5$6 you can teach this to people how to invest in mutual funds can you teach people that stocks How to invest in the markets can teach people that How do the Government bonds work in them? If you want to invest then your If you have related knowledge then this is good for you may prove to be a challenge then whatever our next nish hai that is cartoons and rhyme now yes ye It is a bit expensive but If you have a budget or you are an investor If yes then I would say invest in this niche do it because youtube0 niche can be quite good for this Inside you can take a very fit variety of views can right then the next niche is That is beauty and makeup now you can do makeup Can give makeup tutorials You can tell about the products of makeup You can affiliate products Can give tips related to beauty If you can give tips related to grooming then This niche is also very good then the next one Now nutrition is the niche of health is also a kind of sub niche but this it Self is a very big niche, there is a lot inside it too These all niches come for nutrition Athletes Nutrition for Kids Nutrition Nutrition for Grandparents Pregnant ladies can do any one of these Identify a niche and related content Let’s start and then the next one which is ours nisha hai that is cars airplanes or helicopters basically whatever There are things that you travel beyond you can cover them, people watch them a lot There are whole channels related to airplanes They are sitting with their heads open and the side of the airplane Seeing is also airplane related knowledge It also happens to those who are related to the technical If there is knowledge, people tell it like this We can make cars, we can make helicopters yes we can make trains as well as airplanes you can also make it right then the next one nash hai that is animals now from animals You can also create a related channel Tell people about elephants Tell us about lions and such animals Tell us about something that we don’t give much of Let’s see, let’s hear about them now The next one is Nisha that is about pets Now there is a slight difference between these two animals inside we are generalizing and pets Inside we only touch pets Now what is the routine of the pets how do pets think what do pets think You have to train in a way related to these You can create content and it is better You can see the pay returns here Then the next niche is that which is home decor or interior design now if you guys are females you must know that interior design and There are hundreds of topics covered under home decor. there are hundreds of things you can explain to people There are hundreds of things you can share with people on your channel if you can teach from then this is a niche for which There is a good amount of RPM inside, you will see it again can get it then the next niche is Motivation Now whatever niche is there in motivation They come that if you are fit You want motivation related to your Please give breakup related news on the channel If you want motivation, give it on this channel Give people business related motivation If you post it on your channel then next below is the drawing you can tell in the drawing can you tell me how to draw this how to draw that Now there will be no niche for it here You will have to pay within the quantity, whatever You know how to make it, just make it good searchable If you find out titles then we will cover this as well You can create your own channel and then the next one That’s for sure, that’s about book reviews now There are many categories of books in the world Not thousands, not lakhs, but crores of kinds books so you can read content related to those books You can create a channel from the next phase It may be religion based but it cannot be that you create content that Teachings of Islam in Easy Words Explain that I don’t want to do Islam, I want to do something else Religion: Do you belong to any religion? If it is then you can make it related to it, right There are many channels like this, many of us people have already seen it then from that The next channel should be an interesting idea It could be a formal education subject Your channel should be based, that is, if you Are you good at chemistry and physics? I am good at biology If you are good at mathematics then do something related to it We can create each channel individually and explain the concept to people Now there will be no end to this either If we are talking about physics then physics Small details on all the concepts of Create videos and rank them on search Let him get it done and then whatever is next is ours It is possible that it is skill based By grasping the youtube1 skill, people will Let us teach, for example, a sales related Create a channel related to digital marketing Make a channel, this is my own channel It is a skill based channel in which I teach people youtube1 niche can be language based Now there are many people in the world who are Pakistanis want to learn new languages indian bangladeshi we want us People who know good English should know English They probably wish they knew better Spanish may be that the spanish people go He wishes he knew German well. Let the German people wish maybe if they learn portugese then like this If you know any language then you can You can then create a channel related to it The next idea that we have is Sports based channel you can watch cricket related news You should create a badminton related channel You should make a tennis related channel Make many such basketball related You must have already seen the channels in which People are just talking about one sport Talk about the matches that are happening there The techniques that are used in Let’s talk about that, its analysis is You are talking about that, if it is right then you should do it then you can amazonbusiness.in making video of pc are you making a video of a gaming laptop There are a lot of gaming related The products are good and you are related to them you can make things then you can create such a channel On which you can get street food They are showing people the Pakistan Street food is like seeing the outside world The food streets of Pakistan which she wants what kind of indigenous way are they inside them Food is made and prepared This world wants to see you related to this You can create content by hiring someone can you go to Japan street Food will record the video for you I will record it and send it to you, you can edit it You will give him everything, he has his own idea It will be of and you will upload it on your channel And we can see very good growth on that too If you can get it then this is how you can eat street food You can also cover it then select the next niche We have Magic Tricks and Illusions Now you can see its clips online. If you come to know this yourself then you will go yourself You can also create content on this and this There are videos that have audience retention There are a lot of people watching the videos, that means people Start from the beginning and watch it all the way to the end Because of which your videos become very viral and last but not the least who Our Fort niche is that is what if scenario i.e. what if the size of our sun is what if our meaning becomes 2x what if the water in it runs out The mountain that is above what we mean This whole script should end You can find it online in Science If you have a little interest then you can do this You can create channels here as well Videos can go viral very quickly. Till here we have heard everything about Nishas and Nishas We have discussed it above but now In the next part of the video, we We will discuss all niches technically How to find out which one is which Those are the strategies that we can use to These parts help to find out the niches It might be a bit long but I wood suggest you watch it in full We have to look at things in detail and understand them so that You should understand this strategy here But the difference between one niche and all niches We will go to all the 13, 14, 15 nights will explore but it’s not like that This is related only to this particular niche All the information is there but if you Find out all niches of any niche other than If you want to do it then I will tell you two methods Here I will tell you the same two methods that will be used ok so now let’s go to the next video In the part where we all know Nishas Strategy to find out technically Now we will discuss first of all what we have The work that needs to be done will be done by keywords Understanding whatever niche you go into it has some keywords unless You may not know his keywords, we all I am unable to find niches, what are keywords that the people related to that niche who go Let’s search, let’s take an example A little deep dive into travelling niche today Let’s go and explore that traveling niche What basically is going on and What can we potentially do now? If you feel like traveling I I will create content on niche or traveling niche If I start my channel inside then you Like this without any research on any topic You should not start making a video You have to do this research, the research I am going to tell you about now I am going to show you so that you can become a big You can avoid competition and grow your channel A little early as possible now for example I talk about traveling traveling After listening to this I can assure that yes People sometimes relate these things to traveling You must be searching for example places in Put any city ahead, it’s ok places in karachi places in japan places in I would have used Pakistan as an example. hmm istanbul okay it’s a big tourist this is the city amy i just wrote this I did not keep in mind that on this Will there be competition or not or is this good the keyword is bad the keyword is it is just a The keyword is ok, I have entered it now. what should i do after searching this Some initial channels will appear before me There will be small ones as well as big channels. So it doesn’t matter, just start with these Open the channels in one of your external links I will keep it okay you have opened this also You came below this, you also opened this channel Now you have put the first filter in this I want to put that for example I have six You have opened channels, right? Out of these, those four channels Channels which should be crossed out immediately Complete travel related content not making it i.e. from half of his video It is related to travelling, rest it might be something else I’m working on a little overview Let me take a look at all these six channels whether these people are posting travel related content If you are making it then I get the idea from the topic jaega vietnam travel beautiful places ok garden rood south africa 10 high lights on a garden rude road trip ok This channel is related to travelling come into this and here also once briefly Let’s take a look at it and see that yes this too It is traveling related, videos come here in section a yes this is also good this sometimes talking about restaurants okay okay it is basically travelling related People travel somewhere or the other Get some idea of ​​restaurants too If you take it, then this is a little mixed channel But ok, I’m keeping it in my mind now Now I’ll keep all six of these, one by one. Let’s explore the channels and watch If yes then maybe we will have to remove some channels did you read it or not or all our 10 are from here Now definitely any channel should be finalised which You have finalized that you want to open that channel Her popular videos include Aana Popular After coming on the videos you saw what he These are titles, you have to judge a little Check out the top 15 videos here their titles are similar what are they like After all what kind of videos will get maximum views have come so you can see a little pattern You will see the 25 best among all these Places to Visit in USA 25 Best Places to Visit in Europe 25 Most Beautiful Destinations in Europe: 10 Best Places to visit in Italy i.e. one of You will find common keywords here, best places to visit in x yg city to First of all, note this down on your notepad. Get the Best Places to Visit in XYG That means you can set up a complete channel The only channel on which we can talk is this Hogi 10 Best Places to Visit in Europe 10 Best Places to Visit in America 10 Best Places to Visit in Istanbul Even if you make 300 videos here So it’s not like you have a video You will run out of ideas, see this here This channel has only 119 videos How many subscribers has he taken now? this is our all niche now here and so on No, we are not seeing any pattern, let us go ahead with this They also analyze on the channel that someone And there is a pattern that we can analyze here. Its top 25 most beautiful destinations in europe yes this could be a sub niche that Let us talk about the most beautiful on our channel of destinations and you can note this down as well Take the most Beautiful Destinations in x yg ok you can watch videos here Can make it the most beautiful destination In Canada’s Most Beautiful Destination Inn Europe’s Most Beautiful Destinations in istanbul in thailand in ex waji city ok i told you that x waji Means there are at least 100 cities here can fit this one lets us see the pattern or this is our most popular inside got a good keyword okay then there’s 30 Most beautiful cities in the world are on this We won’t be able to talk much until next time come on the channel come on the next channel from here its Open popular videos and there is no Start finding patterns View 10 Best Things to Do in and Around X Wise City: 10 Best Things to Do in Andaman and Nicobar Around x Waji City 10 Incredible Things To Do In And Around X Waji city ​​yes from here we know that Its most popular videos are around this idea where it talks this is the best thing to do in x was sure ok If so, we will take a note of this as well We got a third idea, this one This is a channel which is getting more traction Things to do and places to visit such as My take on the keywords is cross this out too Now let’s come to the next one and its popular Let’s check the videos now, this video it is not like that this concept was picked up that I should set up a whole channel no what will I do and see the top 10 Bali Travelers Paradise Top 10 Bali No Millionaire for a week this can’t happen how to travel yes this is one i noticed as a keyword aaya how to travel siago okay this is it How to Travel Bali Let’s see what Have any other such videos gone viral? a how to travel how to travel yes this one How to Travel the Philly Pines What That Means that we found this one more keyword number four How to travel and check here I get something now here’s another one and I’m on the pattern I am noting and that is top 10 Bali Top 10 Philippines Top 10 Thailand Now you can see these See this guy here has made these three made videos and all three of them are most popular I have gone so what is this doing that best Telling about Of Certain Cities That means best of Philippines best of Bali so This can also be a good sub niche, you can try it Also note the Fi Top 10 XYG and He is using some techniques here as well I am not writing just this small title Rather there is nothing inside the brackets ahead of it Click baiting is writing something attractive Get to the Right Your Dream Destination Here it is written Travelers Paradise It was written here best of Thailand so this We also got a good category and then more Let’s see if there’s any pattern in this Now this is the keyword that he has used In my opinion this is a big fate, is x YG worth the hype okay you can be any city Write for example is Istanbul worth the Hype is Thailand worth the hype so is this It could be a pretty good idea in my opinion yes, let’s note this down as well x Wazir worth the hype ok now do it with them what is the object to do after that vius i will tell in the letter or video but My first goal is to score at least 10-12 I should keep out such keywords about which we can discuss it later ok So this is a good keyword and with proven As a result its video has also gone viral hai ok the best of thailand can you Travel Bali with $ yaar this is also very good I have an idea, I’m noting it down right now can you travel x x vaji with $100 ok this is $100 also basically it is called as a x vaz ok we can make videos can you Travel Istanbul with $100 We Can Make Can you travel Bangkok with $500 can you travel lahore with $50 ok so like this It’s a sub nesh I tell you that why is it how is it that too later on hum video When I do research, we got it from this channel. I have got a lot of ideas, now I am doing this Let’s cross over and move to our next channel pay and see what this is discussing things is ok its not and Bali are the most popular videos Indonesia Travel Guide OK Best Things to Do Things to do in Bali: Best Things to do in this Best Things to Do I Think We’ve Covered If we have taken it then now it is an obvious thing I will not write again about the best travel destinations best things to do well this The keyword is this is a good travel guide ok number eight comes x y g travel guide okay now this is a little anchor videos why that Look at this you will see here that it has 39 A minute long video has been uploaded in which she Providing complete travel guide That’s right, another travel guide is the most popular 27 minutes end in section come down This is another travel guide that is 40 minutes long Means it is proven that this is a good I have found the keyword, this is a good one All niches have been removed XWJ Travel Guide now I have explored this channel quite deeply. We have done it but this target is only for two Only three keywords are said to be the best Things to Do Best Places to Visit and Travel guides would have crossed this as well then the next channel is there, you should check it you will appear in its most popular videos And let’s see what keyword we are looking for here I can lift it, I could not lift it the first time try can first time try can turkish Can’t we even afford street food? Why? Can’t pick it up because this is a personal channel that is why it is easy for this kind of making videos but when we do faceless channel If you go that way these things will become a bit difficult India Travel Guide will become a travel guide We have already picked up the things to do as well I have taken a road trip, I can’t even use this cant you where you should stay in bali yes this happened and then we have to check that Are more people searching on this or no but let’s not note it down wear should you stay in x vaji ok i have done this Okay, we noted down all the channels. We had taken out the maximum from them earlier I have put some more ideas aside now let’s see from there let’s scroll from there Come to where we searched earlier Places in Istanbul Maybe we should also visit here get some good ideas okay so this is a We got the video Mistakes Tourist always make in istanbul yes this is a good Idea number 11 tourists come here Scams in ACYG and How to Avoid It They got it right, this is our 11th idea These are the ideas that I’m coming up with right now I found this just by searching a keyword has taken it out and that keyword is places in Istanbul right now if I tell you this As many keywords as I am taking out from here no i just wrote it on notepad And I go to everybody youtube0 new and new ideas If it is right then mistakes will keep coming out Tourists always make a note of this too I’ll do it, from here I came to notepad and wrote Mistakes Tourists Always Make in Eks YG Ok, basically it’s tourist mistakes the channel is talking okay good here We Were 20 Things Not to Do in Istanbul yes this is also a good niche and a good Keywords Things Not to Do in XYG City I will note down these 13 things not to do in x waji this has also been noted ok So I think we have chosen a keyword very well I have squeezed out one more keyword now I can practically squeeze you in front of me I will show you then you will get the idea How to explore keywords and how new ideas emerge from there are generated ok scams in a I searched for use because it I had a keyword and you saw it here I might have kept a note of this as well Now I have opened five new channels The first of these five is this We will see which ones are in actuality Creating travel related content which We are making them, we will keep them and remove the rest If you give then I think that this channel is Not much travel related content was created because it is the nightlife here Discussing Indian Pickin Up German Girls this is ours who is blogging about it If he is also doing it then cancel it for now. Let us know about these hacks in videos yes this channel comes only and only for immols I am talking about this only, let’s talk about this a little bit We will analyze it next time we come on this channel go to the videos and see that Is this just travel related content Yes, he is making this, we will keep this with us okay remove this as well then this Go to the video section and watch it here What kind of content is We Found This creating? first impression honest first impression yes this is something related to travel ok so let’s explore this first The first keyword I like is a little bit of this It seems common that this first impression talking too much of x yg city it’s right i know that with this face There is a channel but still this work is without face It can be available on the channel also so bring it here Write number 14 first impression of aces Waji City then we came down so you can see this You can make this comparison video is like so and so city vs so and so city which is better this is a great niche You must have done your research on this I must do a Vaji vs ExYG well what you can do is you can Capture the country i.e. Switzerland Grab it and start comparing it Switzerland versus the whole world Norway Switzerland vs Pakistan Switzerland vs x vs any city catch it okay so this is also a good niche can you okay then I like this more on this channel Nothing was found, just a first impression got a good keyword ok so this too If we cross it, then we will check it all now. Now I will tell you another way Rather than selecting some channels going in to There is a video section where you can find the most popular videos videos a better one instead would be this You can come here and apply a filter After typing your keyword of view count You apply the filter here and you will get it here Those videos will start appearing on which Things not to do if you have too many views Do things not to do, this channel has come Open this The Dark Side of Dubai What They don’t tell you that this is also a very fit type of person it’s nice ok note this down as well 16 di The Dark Side Of X Waji What Can $ Get in dubai yes this is again a good niche what Can XYG Dollars Get In XYG Okay, let’s write down the number 17 here. what can x vaji [music] get you in x waji okay so this is also a it’s a good niche then let’s come down how am I Escape the Dark Side of Dubai Again This One And the things you will only see come out of the shadow c in xyg city so this is also here Note down number 18 Things You Will Only See in XYG City okay so this is another niche so I told you Two methods have been explained, the first one is that Start with a keyword and As many videos against are coming on top You should open those channels side by side By opening those channels and their most popular go to videos and see some patterns there Find out the patterns you notice Write it down, this is one way What is another way that you can search for a keyword Search here and apply filters Click on the view count in the filter and Then you are getting good ideas which You say yes friend it will cost around 100-150 rupees videos i can make this pattern While following you should note that also so You never run out of content ideas hoga let’s move forward to our chapter Number five which is keyword research Let me tell you this The most in the space of youtube.be The important things are yours Check out the keywords if your channel is at all Stuck, 0 views, 100 views 200 1000 1500 there are so many views and above no your views are going overall your entire I am 100% grateful to you for your channel without even watching it I can predict that you are searching for keywords If you are using it wrongly then understand this today that there are two types of keywords, numbers Which ones for One Searchable Topics Keywords should be number two browsable What keywords should be there for the topics I should have shown you in the start of the video Initially it was said that different kinds of Some videos are such traffic sources There is a search on which people can see that video they reach there and some videos are like this which when youtubers are shown their app when you open it or open the website then it is there If he starts showing his weight then both of them The strategy is going to be totally different In the first portion of the video, I will tell you this Explain the keywords of searchable topics How do you go about finding that out Totally a different game and browsable How did you select the keywords for the topics? This is a totally different game If it is ok then let’s go to youtube2 and see the things So Guy as you know that we had taken out all these 18 niches where We were finding out what travel niche it was How are all the niches taken out, one was the best places to visit in x yg here where It also has XYG written on it, its meaning Is there any tourist spot or tourist city Right, in the world I am 100, 200, 300 Tourist cities exist in those cities We will put our name here and this is one of our All niches will be completed, now you have added one in it Something has to be noted, all of these are definitely like this which are There is youtube0 which will take the views and browse So I can quickly go through these 18 features. I will divide it These are youtube’s, you will get views by searching on them or they may not come but The majority of views are going to come from here. Whatever I mentioned about them Let’s start with the search traffic How to find niche keywords now Although, to extract keywords from search traffic There are many ways, not just one but two No, there are not three but many ways. But in today’s video, I’m going to show you two ways I will tell you first that we use Vid IQ tool Second, we will find good keywords We will find out good titles okay so first of all let’s go from here Now this tool is very important on Vid IQ If you want to find good keywords If you want to do good SEO for them, then you want to rank your videos Now for example I am content travel I want to make it related and as an example basically i want to make them from lets should you stay in xyz i have seen this If it is finalized then I will write here wear should you stay in and I clicked enter from here when I clicked it is telling me that Its search volume is so much and so is the competition It is very high but definitely I have just No further whistle was blown due to this reason I thought that I will take out only that person on whom Competition is the lowest so I click from here View all six matching terms here I can see competition from this I will apply the filter Very Low Let me start first if I show you then this is telling that if you If you want to make this video then make it where are you should stay in Bujan now this must be some city If it is definitely correct then you should make a video on it competition is very low on this then this telling where you should stay in korea this You can make it on this as well, I think there is less competition on this and now I have entered where you are instead of should stay it is where i should stay in correct so now let’s see here that What are the terms on which videos can be made? I can come here for the competition Let me apply a filter and see what this is There are three ideas, there is very little competition here and the search volume is also appropriate, then this A video will be made on this as well, a video will be made on this It will be made on this as well It will be made on this as well It will go, it will be made on this as well and it will be made on this as well It will go on this as well, as far as our Competition is medium till then we can take our If I make videos then I will present it in front of you Have you selected any 13 yes 13 keywords? And you guys can go here and make videos and Chances of ranking your videos on this There’s definitely another idea in my mind It is coming that I write here where to stay in just i write this and Let’s see what’s here Ideas are coming, now see this is what happened in reality You will find more than 300 keywords here. Keywords are being seen and ideas you are not going to end here ok so what do I do here is filter I put my focus on the competition and whose competition tell me the lowest one that is wear to stay Overnight in Jeddah Airport you can do this Make a video if you have to stay in Japan You want to party, make a video on this You have all these keywords now all this Pay yes, videos can be made on all these I am selecting as many as I can Competition is very low, see how much The keywords have come out oh my goodness this see even till very low if we even reach here If you select then at least above this At least no more than 50 keywords I have given it to you, okay then If we come to medium competition then there also there will definitely be a lot of them If you see, the competition is not ending It is in front of you that you can even watch videos so I just made this I have found the matching terms, then come here there are its questions sometimes these questions Different matching terms are coming Different things are coming up related If the keywords are different then you can use these Explore everything and become different from the different If you can generate ideas then this will happen I just touched this one of ours and that too of search traffic now its other than that how can we do that here Come, write here where to stay in this I am going to tell you another way how to Ayaz can now find as many as you want Ideas are coming to you starting from The top one which is on the top, people are the most on it Search more, its search volume it is the highest but definitely its There is a lot of competition to see as well If you get it then how to eliminate that competition I’ll tell you that right now, what it means there are too many ways right it’s good For example you have Istanbul related you want to make it okay then you should not do that you Title a video Where to Stay In Istanbul there will be a lot of competition on this Let me show you how the competition is You searched for it, then you pressed Control F Press OK and then press Ctrl+F By doing this you have copied your search term and paste it here you press enter if you do it you will see that there are more than 30 People have made videos on this so that means it’s too much It is competitive and I have to make videos on it right now Maybe I shouldn’t make it, okay, so something else Let’s search and see how much competition there is beyond that Let’s remove the betel and pay for it here If we look at the example completely, then copied this and then pressed control-p f That is, it is used to find Then I pressed control v and this too About 26 people have made videos So let’s leave this as well and come back again and Let’s close it from here and from here We write Singapore and let’s give space further okay so Now when I give space then some new and Long tail keywords show me these will start it in which Singapore will also be If it will be included then now I will make a video I make you wear to stay in singapore on a Budget Edge Compare to I Make Video Where To stay in Singapore is my long The video with the tail keyword is its rank There are high chances that I will try this once Let me hit enter and show you how to do this But after all how much competition is there which is right It was going to have 26 searches, that means 26 searches. The results were coming, now check it once Let’s see how much is coming for this Here you can see that there are only three People have made videos on this thing. You can also make your own video on this You can rank your video on top here If not on top, it will come second but third It will come but it will be in the top three positions At least you must watch your video you will get it so this is a good title on which Your video can be made, let’s do this Close from here and now come some more searches let’s do it okay where to stay in Istanbul Now write Istanbul here After I will give space and after giving space I will I will write for tourist and now I am here I will come again and search for it, okay so this See if anyone has written anything on this topic. The video was not actually made wear to stay in istanbul for tourists alright so this is a it’s a good title if you make a video on it If you make it, your video can come on top. if you have done good SEO but if your title is not good so forget it go away your title is bad so score is good If your score is 100 then your video is not ranked it will but if your title is good and Use SO Score with IQ Extension Or use Tube Buddy’s extension By doing this your donation is coming close to 7080 Even then your videos will rank on top I have just presented these keywords to you. I have shown it to you again, I will show it to you again I’m finding control and here I am I have pasted this in front of you and here you can see that there is one by one result i.e. At only one place on this whole page keyword is used so this is a Excellent keyword on which you made this video If possible, we have learnt till now that The way you would research a topic is by using keywords. Will do research for searchable videos now Next we’ll move on to how we Topics of videos need to be found out If we make our videos viral do you want to go or our videos are such that Views are going to be taken through the browse That’s right, you already know the difference between these two. I have explained earlier that we have searchable Now we have talked about the topics of the videos Discuss topics in browsable videos If you are interested then let’s start with the same the niches which we had kept aside for these Today we will discuss a little about that friend if I select my niche is a what can $100 get you in x vaji I will make videos on different cities and I’ll tell people you can get this for $100 What can you get in the city for $50 What can be got in that city? Related How do I find out the title what should I title my video Should I search so that I get maximum views? The very first step is this that you go once and get some title You have to search and see what is related to it Can 100 get in ok now this is something in front of me If there are suggestions then I can search anything I take for example this one my video I haven’t finalised the title yet But once I randomly went to that niche Entered some related keyword Now after entering this, first of all you You have to open the filter. By opening the filter you have You have to click on view count and view Click on the count to make sure you have it Vid IQ extension is mandatory install It should be because if you have a Vidak key If the extension is not installed then your time will be wasted There will be a lot of consumption of Vidak How to install the extension googlegroups.com [music] Since I already have it installed I don’t have the install key but the remove key the option is coming to do it okay now What is the benefit of installing it, see for example I just google2 is also showing up and this is very important It is more important if you have an extension If it is not installed then the subscriber will show We won’t have to check each channel one by one You will have to open it to see its subscribers You will come back again and read the views here If we have to see it, it will become a big issue now I did a random search on this, now I search I will see if I can find a channel like that. No matter how many subscribers he has, The views that he has on that video are less less than multiply by the number of There should be subscribers for example It has 10 million subscribers so I Can I find any video that has 30 I may not even get a million views, maybe it won’t happen now It has around 8 lakh subscribers. Its views are 5 million yes it is mine It is completely meeting the criteria, that is the number of subscribers it has Multiply by three or more than that views then I come down and here But I will see that yes it also has 1.2 million subscribers and its views are 3x this is at least greater than then come down 2.2 million yes this is the video of this Views as truth is not that much at least Not more than 3x but we’ll see If it’s random then we’ll know yes friend 3.7 Even millions are a lot so the first did you understand the criteria that Videos that have as many number of offs There are subscribers, multiply that by 40% three he got views of the idea he came up with I have used that idea and it is winning If you use that idea then your The video also went viral because of his channel That means if you have 5000 subscribers right now So your video also has 15000 views, right? Will she be able to keep the potential to go, now see this That how many people here want a winning title I can bet a lot of people might be using it You might be using it like what can $1 get in vietnam worlds cheapest country now Maybe this title and something else comes below People have used it, see what can $1000 Get in Vietnam World’s Cheapest Country means this is also the same title and this too That’s the title, okay, just one guy copied it 100 L has been created by another person Go for $1000 and sell the same video idea Even brackets have been created by copying them The same words are written inside as well – Worlds You can get the idea of ​​the cheapest country from here It is known how many times a winning title is earned People use it, now see how much it is I got a great idea that I will earn 8 lakh rupees Subscribers are and 3.8 million views If yes then this is a winning idea, you can invest in Dubai remove it to Thailand remove Thailand that you make it Maldives by removing Maldives You do something else, similarly you withdraw $100 Let’s make it 1000, let’s make it 500, let’s make it 50, this is not an issue either but actually here psychology has been used that is winning You can use this or any other from below Let’s see if you find another niche of yours For example, things you will only see in Eks YG City now this is a little let’s explore here i come and I write things you will only see in And here I will put Dubai for Examples come from here, applying filters yes we put the view count we put the view count We are posting this because we are getting viral We have to create ideas that go viral If you want to find out videos then go viral We will get the videos only if we filter them We will try to find out the most viewed videos Right ok so after applying the filter see this It has 44 million subscribers and 14 We have millions of views but we are not content oh my goodness its 4 lakh subscribers and it has 14 million There are views that mean this is crazy Now see the idea when videos go viral That is the thing, there are many topics there too It is important and the thumbnail is also very it is important means I absolutely I will give equal priority to both Your videos will only be aligned together If there are chances of it going viral then The video has gone viral to such an extent Nor is its thumbnail amazing anywhere okay then let’s go down a little bit and this See if its just one lakh or 5 lakh subscribers and has 5.7 million If you have views then this idea is a winning idea 11 Things Not to Do in Dubai That Must See before you go but the thumbnail is also very important It is important as I told you earlier If the thumbnail is not good then why will it not get so many views will not come now see this idea has 1.3 million subscribers and 4.6 This is the exact title as it has millions of views The guy has also used it, come down Maybe other people have also used a let me See, this guy has also used it it is there and this guy has also used it and One more thing I’ll show you is this thumbnail see this one and come up and these thumbnails See this one see its title 10 things you can only see under a microscope and its View title: 10 Things You Can Only See Under a microscope, this thumbnail looks the same The title is the same and so is its video It has taken good views and when you come up you can see Its videos are also getting very good views if it has gone then definitely one of these two He must have uploaded his video first did the research but the one who later I have uploaded it, he must have seen that friend this is a This is a winning title This is a winning thumbnail ok let me also print it as it is and I also show it as it is on your channel If I upload then its video also again It took very good views, now you see this He is also using the same title He is using the title and everyone’s videos Everything is going well means everything is good Even he is performing, see him here The channel is also the same, that is, the same channel has the same This type of video has been uploaded twice Dalia 2 years ago A Dalia 3 years ago He knows this is my winning title My videos perform well here The 18x that is written on it means that Its normal videos or average ones There are 18 times more videos than this one It has performed well and on the same channel Same video with same title 15 His performance has been much better From the average video, here you will get the first Technique revealed to know how to win titles after that if you enter the same thing and apply a filter apply a filter that you click on this month and with If I click on the view count then here From this also you will understand that friend, someone A video that definitely doesn’t have 3x views But even if we get at least 1x views goes i.e. the number of its subscribers If it has got that many views then That is also a good title and that is also a good performance There is a winning title here, it will do wonders It has happened i.e. there are 25000 subscribers And it has got 6 lakh views and that too in 1 month inside then it will copy the title or Video of the idea which this guy will copy This is an extreme will go viral Winning titles then come down and down Let’s see that it has 21000 subscribers No, it doesn’t have 21000 views yet If it happens then let’s leave it and then come down Come down and see us 291 of whether you get the winning title or not It has 128 subscribers so far leave this as well leave this as well let go of this as well let go of this as well No, we just need a good title here. so this is another way that you Apply Filters Click on View Count Pay this month and if you want then you can pay between 4 to 20 Also click on the minutes and see that The number of subscribers you see If it got that many views that is also enough inside me We don’t need to go any further than that We don’t need 3x or 4x more Collect videos with lots of views then make another one I will tell you the method, let’s go back and By going back you can download the Vid IQ extension you can also find out which one How long does the video last longer? like I told you earlier for Note the example here which is this one Signal provides extension of Vid IQ Tells you how much better than the average If performed then 10x or more Are you seeing any video more So that too is a good winning title for you could be like this is 8.9 one not very good this is more than 100x then this is a Very good title, this should also be a criteria maybe this is 4.2 this is two this is 49x so This could also be a good title then below oh this is 14x this can also be a good title You can find the names of your cities under these titles You can change the name in these titles Make some small word changes It is possible but the concept must remain the same OK, so I have told you these three methods now. I will tell you another method, you can find it from this channel Open this channel and you will see this to analyse whether this entire channel Is this related to travelling, if so? If it is related to traveling then it is very It would be good if it is traveling related If not, then go to its videos and By going to videos you will find most popular If you want to click on the videos then If it is related to traveling then we have to know everything You will find only traveling related videos If it doesn’t happen then you should see that if traveling Any idea related to this became most viral If so, I’ll copy it If you see anything related to traveling then it’s okay If it doesn’t come then move to the next channel If among the top 30 most popular videos Are you seeing someone saying yes friend this is mine If it might be useful, pick it up and Start copying that one, then another one The way could be that with the help of Vid IQ You can go here only with the help of extension And click on view trending videos Do it and it will give you videos that The views are coming regularly and the You are getting the most views on the video will show first then find out from these Tell me friend which is that video on which It is still getting views even after 5 years It is old, even if it is 10 years old We don’t want to see this thing, we want to see that You can see in blue how many views this is getting It appears to be written in colour that It is getting 2374 views on this on video again similarly this 1 year ago It has been uploaded and still it is getting 1300 views then we look for something old like This is a year old video and still It is getting 624 views per hour so if If it is related to your niche then you should so these are the ways for which through we can find the ways that Your videos can go viral You can ask me one or two very quickly Even within three-four days, your Videos can grow at a very fast rate As we saw in the previous example That within four weeks his video got 6 lakh views has also crossed it, if it is correct then like this You can also find out these things easily If yes then Vid IQ is very important role If it plays then it is in browsable videos if you want to go then its extension will work If you want to go to searchable videos then go to Vid You should use the IQ tool to its fullest So our chapter five will end here. This is complete about keyword research Hope you got maximum value It will be related to keyword research and whether are your videos now searchable or your Trending videos are your greatest Curie would not have been straight forward now Let’s jump to our chapter number six on the side where we will understand that the videos How the script is crafted See if your video has a script It’s not good, it’s not engaging, no matter what you will get good CTR like I explained it to you in the first video, CTR is very very important but along with that average view duration is also important and watch time is also It is important if your script is good If not, you will get average view duration It’s too bad if people enter your videos So I will do it but they will say friend how much This is a boring video, let’s leave it are so for that we need to understand that How to write a good script Understand things that if your video If the duration on average is 10 minutes then your The total number of There will be around 1400-1500 words you will know the number of words You can further prepare your script accordingly will do craft okay so first of all I Let me tell you what the tools are using which you can write a good script Right now we can get it written down and we will sit and copy it And you can’t write a script with a pencil Infact what we have to do is to get it written You have to find out such tools online we have to use the tools because of which our The script is a little quicker and better If it can be written then there are many tools for this I am also giving you my personal recommendation I will tell you later, but let us understand that Which are the number one tools that we have right now We have GPT 3.5 and GPT 4.0 Jamna we have many blogs On the internet, we can refresh them and Do good by adding your own value we can get the script out then we have Quill Boat which is a refreshing And it is a very powerful tool also we have Agistify there are five resources or something inside them There are tools that you can use to get a good Now you can get a script written for a video A bigger frequency And by creating your visuals according to your needs, Should I stick the blog back in? youtube2 brother with those who ask youtube2 can do plus which of this content They are the owners, you can also find them here Panelized Pick Up By using youtube4 or any such tool By using it if you are saying that I have done this You have taken a very big step so I will tell you I would say that you should not do this also with human touch You have to add your own value in this You have to add some time to this I have to put money on it because it is the ultimate The game is that your piece of content is nowhere It must be somewhere unique How to use youtube.co? for him to get the script out Straight Forward Lee Let’s Go Chat GPT and go there and do this thing properly I understand ok so I will chat I have already come on GPT for example There is no video whose title is written that is around just taking it as an example discipline is ok let us make a video on discipline but firstly i need to know about chat gpt I have to give him instructions that I should work with him What am I going to get done with Chat GP If you will directly tell me that I have to do this like this If you write it down like this, maybe its result will be may not be as optimal as the good result You can get it when you use Chat GPT first give him some instruction and then Realize what kind of experience we have from him I have a small book for that I have copied the C line which I have posted here I will paste it on you guys even after reading it. I will tell you and you will see from it that The memory will be updated, I will tell it this I am saying that hello charge pati act as the Best Script Writer As I Need To Write a script for my youtube’s youtube3 engaging use as much easy as wading age you can and make it human sound a video On what do they do that now you can see it I will tell you the topic and it will tell you the whole story. I will take out the script and give it to you first Let me tell you what the wrong way is I’ll tell you what would be better If you had done this for example my Video topic is power of discipline now you Let’s see what script he will give us It wouldn’t be as much fun So I will tell you the other way I will teach you and tell you how to be a friend what is it then you will get to know that good I’ve been making this mistake before I want to implement it in second method well he gave me the script here you can see it first he gave an intro hey welcome back to the channel today we are talking about something that has the potential to completely transform your life it’s not money it’s not luck bla blah blah okay then after that he said that I have made the sections myself The Difference Between motivation and discipline then that he is explaining it then why Discipline matters here, these time stumps He is also telling me that you should carry it like this ok then he did this this is exactly It will not work, it is neither engaging nor there is no really good hook in it, right? The outline is defined by what we have discussed earlier Do I want to say anything about it? Do I want to say anything about it later? The first thing we need to do is this I would say that it is craft and outline of this video for me first give me proper sections of the video you are going to talk about it first then i will Ask for the complete script I am I will get the entire outline written first I will get the sections defined for our video What type of sieve is it? Will it be told first? will it be said later then which of them I will feel fine about that, I will do more than that I will take the description which does not seem right I can manipulate it in the same way and I won’t even ask, okay so this is how it made me I have given you the complete structure that this is your First of all we will have a complete outline we will do the introduction, there will be a hook in it where But we will grab attention and then we Who will introduce the concept of Discipline as a Key then we will say differentiable in this Video We Will Explore the Real Power of Discipline: How It Works and Why It Works Secret Ingredients We will come back to the story in part 2 Then we will define discipline The difference between motivation and discipline We will go and then we will tell you why motivation Relying on pay often fails us okay after that there will be section three then There will be section four, then there will be section five, then There will be section six and then there will be section seven it will happen then it will be at and at the end you will see that there is a conclusion and a call to action if you Are you ready to start your journey towards a More Disciplined Life Hit the Like Button and Subscribe for more videos like this See now I have it all sorted out The outline is ready, now I will do this one by one I will define the outline for example I need an introduction to this I would say that first of all tell me this thing what is this let’s copy this and paste it here Let’s paste it here and write give me A The hook which should grab attention with a powerful Statement and Relatable Question do not start with hi hello this We have entered here, now see this Ever Wonder Why Some People Seem to Achieve Succeed Effortlessly While Another Struggle Year After Year The Truth Is It’s Not About Luck and talent it all comes down to one thing That is discipline and if you muster it you can change everything in your life now from this I took out this one thing that I liked the most first i have to tell you this ok now this is good enough I am going to get everything removed at the end. I’ll do some editing later I will add things as per my requirement but So far it has given good results then I will call it brief Introduce the concept of discipline as a of differential now it gave me this but I would say keep it a A Bit Short and More Interesting End Motivational Only if there is an ad in it, people will watch it and we will engage on this so here it We should have found a much better statement than that. You have given the discipline yourself is a silent force that drives success and What is discipline saying here? What Separates Dreamers From Achievers It’s Not About Working When You Feel Like It It’s About Pushing Through When You Don’t So this is enough Motivational scriptwriter blah blah bla you copy this then you I have to tell him to draw an outline for me two about this particular video topic In which you have to give me proper sections Once you have your outline in front of you You have to see which thing suits you in it You do what suits you each and every one and get it written from him but directly do not go and paste this thing as it is Take it and see if he is giving the wrong answer so he has to do it like I told him here I corrected it saying yaar keep it a little short And keep it interesting and a little motivational Keep it because this was the demand for my video So you’ll have to apply a bit of your mind to this You will have to spend less time to extract the script of the video at least at least 15 20 minutes or half You will have to pay the hour only then you can go and get your work done It will be very efficient and of better quality It will happen so I hope that you have got it wrong here You must have understood what the method is And what is the right way to make a good script You must have understood this way of taking it out, okay So here goes our script chapter. It is complete now let’s move on Chapter Seven Pe Which Is About Voice Over I hope so many people’s minds I do a lot of voice over related work. There will be questions that you will not understand Also brother, should we use voice over or not If you want then which AI voice over should you use? If you have to do it then which character should you use? Which character should not be used in this In this chapter, I will tell you all your thoughts. I will clear all this in my mind, so tell everyone First, let us understand that human voice Over AI voice over and human sounding voice What is the difference between an over and What is number one for us, better than all others What is human voice over which voice over is now are you listening to my own voice or We will call it the voice of any human Over human voice comes number two AI voice Over now you must have seen the wildest tools like this Which offers you AI voice over in today’s time We are doing a complete list of those tools right now I will tell you more in the next video I will also tell you about my favourites But you know that nowadays this thing is very common. There are many people using AI voice overs but there is a difference between these AI Voice Over and Human Sounding AI Watch the voice over that you hear through AI They generate overs, some of them are like this which have a very robotic feel It seems like a robot is speaking, a machine she is talking but some voice overs are like this There are those who, after listening to them, do not understand that Dude is this a human talking or is this AI Voice over is generated through Although it was generated through AI. it happens but no one can These are the voice overs that are different today Most of the people are working on this Be it Pakistan, India, US or Canada Whichever country it is, maximum people right now Are you using human sounding AI voice overs? Because their cost is extremely low There is very little effort in this and whatever you have The output is too much in very less time It enters your mind after that The question will be that friend with AI and O See if you are monetized or not if you Robotic aeos will be over used as i Definitely explained to you in the previous slide. Your videos will not be monetized but If you use a human sounding voice over Your videos will be easily monetized It will go but there is a small catch here that if you Out Voice Overs Are you channel monetized that means there is some voice over behind there is no sign of you driving anything in front of you Is there any presentation, any natural scene? is recorded or any scene in which If voice is not required then why such things It gets monetized, friend, this is very very tricky this is a very tricky thing in this if If you are an absolutely experienced person then You should try that with voiceover go ahead but if you have a little If you have experience then you will know that voice Channels would have been monetized even without overs Yes, videos get monetized but very That thing needs to be looked at more sensibly what alternate am I using am i recording a scene In which the background noise is so good or is it so different and unique that it Exact sound in someone’s video If not, then that video will be monetized by you. will go away if you play background music They are relaying too youtube0 free music download and recorded any scene from the front If you put that thing in the background then friend that I would recommend that you start with don’t go in that direction now let’s come to that Also brother what are your favorite tools The tools I use to make my videos If I can monetize then these five of mine There are some favourites out of which priority wise The most favourite one of mine is that is 11lbs which is very expensive and its The quality is also extremely good m.o. a is again play.in there is ways labs.com These tools you You can also use and eVoice from here You can generate some voice overs You can generate it for free anywhere It will cost money too, that is the next question that friend Saad bhai is there any Jugaad that somehow I can use free AI voice overs for anyone If at least I can save my money like this then I would recommend that you guys Post if you have any solution for this You will obviously find it inside the community Because of youtube4 we can directly know this thing can not disclose here Right, till here things are clear to you Now I will take you to another website On which most of the people’s question is it happens that brother you use 11 labs There are so many characters in it Are there more people or more AI There are characters among these that I don’t understand Which one should I use and which one should I not use so brother can you tell me something which ai character should i use I will definitely say no to you but I will give you that too I will explain it to you, okay then let’s go First 11lbs come on first let’s go 11 in the labs and inside the 11 labs that I have The most first pay favorite is that is Antony Logic Will Get You From A To B Imagination will take you wherever you listen that you already heard its voice Lot’s of People have also played many long formats This is the voice over that is used so if you If you want, you can also use this Using it will lead to demonetization of your channel A little voice Let us also understand the settings of 11 labs Inside we find these few voice settings out of which the second thing is Do not touch it as it is by default let it remain as it is whatever is above if we move it a little on the left side If you bring it then write the result to us here Do not even take the extreme left side and Do not take it too far to the right a little bit to the left ok 45 to 65 I’ve tracked us down here The best results are obtained after My second most favourite is that is at the and name as t th now this is what we call it Read out the paragraph for us we recorded the paragraph here ok so just listen ae voice overs have revealed Shanaz The Content Creation Landscape Now It gets a little bit particular where you need to speak a little slow where you May I also talk about some meditation or Are you talking about a big spiritual level? are you there to find this voice over artist you can use keep this in mind that Every voice over artist is not for everyone In any niche we will do a voice over Artists use it in some cases So now you have to do this yourself according to your niche. I have to select from it is correct that was my The second most favorite now moves on to his third on the most favourite side which is michael you Listen to this, trust yourself, you know more than that you think you do what is the matter friend at all I can’t imagine that this is a human being’s Is it a voice over or is it some AI speaking this? ok so this was my third most Favorite Now let me tell you the fourth one that is Josh as an organizer I started from here The World as it is is Not as I’d Like It has to be amazing friend, it is amazing you too You can use it for your videos here From this I select Josh and once I will also read this paragraph to you I give you a aa voice overs have revolution the The Content Creation Landscape Provides a Seamless and Efficient Way to Generate High Aya that it’s not fun what does it mean friend The thing is here we have four male voice overs Artists are now a little complete So let’s discuss females as well The Most Favorite One for Females from my side is rachel this is really great one if you listen to this then see a voice over is there Revel The Kant Creation Landscape Provided Seamless and Efficient Way to Generate High Quality Dio is best if you are watching female oriented channel If you are making it then you can use this voice over in it you can use the artist after that if Let me tell you my second most favorite The female voice over artist is Sara this knowledge has its origin in our perception He is the voiceover artist that you have seen a lot. You must have heard on the channels, I don’t know that your how much exposure but I have seen it a lot From anon this is a good one after this seventh voice is an over artist meti ma a voice overs have revolution the The Content Creation Landscape Provides a Seamless and Efficient Way to Generate High Quality Audio Kya Baat Hai Yaar Extremely Human Sounds so here in our 11 labs Here are my favorite AI voice overs from So I told you okay so this chapter You must have understood well that What are voice overs AI voice overs Which characters to use and which not to use I have to use it, how to use all the things I gave you the link to my community. I gave it to you as well, there too someone came and said something more If you have any question, you can ask it there too so now moving on to chapter number eight What is video editing about first? First of all let me tell you these things Watch video editing and nail designing This is a complete skill, that is, people Many people sell separate services for this thing There are many video editors in the market thumbnail designers are in the market but The guy who knows how to design thumbnails It is not necessary that he runs his own Facebook channel Any person who knows how to edit videos It is not necessary that he runs his own faceless channel Because running a faceless channel is totally something different and video editing that’s it Small one having weightage of 5 to 10 This is a subject which is definitely for you people You must know video editing if you If she does not come, then there are separate big ones for her. There are courses if I start teaching here If I give you one hour, we will just do video editing. If we keep discussing that part only then Where to learn video editing skills Definitely you are Azad Chai Wala Free video editing from youtube0 The courses are already available and there is also one more I will tell you the resources right now Let’s go to the video but before that you Understand what the tools are copyright After picking up the free material, see if we can I am not going in front of you with my face right now I’m in front of you with my face There will be no one in this world who Record the exact same clip and youtube0 is it real or is it my real one I have my own identity, I have my own way of speaking I have my own style, anyone has their own ambitions The whole world cannot copy this But when we have to go faceless, right? We are looking for copyright free Resources are those resources on which someone’s it should not be copyrighted so that we can use it and We should add our value to it Because of this our content looks unique and that Let it be monetized t free material website so right now I I am telling you but the material from here How to make it unique after picking it up We will now discuss this in the next slide. First of all, let us see that Where to pick up content Basic content Number one story blogs which is the best Platform Mostly Niche content here You will get what I gave you first It is written that this is most important and the second The most important thing is that you also need it now let me tell you, anyway the second option is Inviting elements is third and motion is fourth is pexels.com pixabay.comunsplash.com youtube0 number one story blogs and jo I told you at the end youtube has all the content which is copyright free if it happens i can use it too you can use it too how to use it i you These are the number of videos that are coming I can use their clips easily Nobody hit me with a copyright trick I told you earlier that I could but keep this in mind just told that Now after that comes what tools do we need You need this much to do video editing People will be aware of the cap cut committee from this fara prer p pic tree in video you can see you can use it but the best one which I have always used it and you guys I would also recommend that you use it That is cap cut cap cut is a great kind A tool that almost covers your 99 per cent needs can cater and i would recommend that you use this only ok so value addition How can you do these video editing I have written six, seven, eight things in front of you. why do you have to do this again i told you It has also been stated earlier that youtube0 many free videos you can choose You I want to do youtube0 for example The sound in the background could be You can make it a little unique in some way The transition you use in it is You can make it unique inside It could be the effects you are using you make it unique because of that if it The video looks like this if you flip it Maybe I may also give you a video It becomes unique if you make motion inside it I will add graphics, maybe then your The video becomes unique if you If you add text then definitely it will be yours The video will become unique only if you add voice A nice background with over Music a little unique background Even if you add music, your The video can become unique, you can say something above Even if you add PNG, your video You can add some popup sounds to make it unique Even if you do this, your video will still become unique. You add some filters Even then your video becomes unique now For example, I took one story from the block. downloaded the video you did the same and The third guy also posted the same video, exactly the same I downloaded the video but I tried different Effects on transitions While doing different types of editing I installed different motion graphics put background music in it There is a third guy who has applied PNG filters. He put text, she also put motion He applied graphics with different transitions When I put it, that same video of yours became my unique one also became unique and that guy’s also became unique gay this is called value addition in copyright free resources that you can use when you You are not going to get any strike Obviously because it is copyright free and no more youtube0 don’t understand that friend four websites I downloaded four videos from and added them This faceless video of mine will be uploaded like this Your content will never be monetized because it is not unique now i will tell you I’ll take you along and tell you that if You should learn faceless video editing properly so where did you want to learn from There is a 2 hour video in this youtube Complete, I have taught you how to You want to do faceless video editing from How to use these things It is very important to make these things unique in some way There is more value and it lasts for 1.5 hours This is a master class so if I spend an hour and a half If I start teaching you this course here then Video editing will take too long something different and you can see it here who will get it so till here our video The chapter on editing is complete now Let’s move forward to chapter nine which It is about thumbnail designing, now you have read this Keep in mind that in letter on video I have just read a big chapter, one of the most We have to discuss important chapters now what was about this business here How much does the investment in tools cost Which ones do you have to buy? The chapter is very interesting, move forward and many more things in the next video Particular frequency is a separate skill which is very expensive and This is a great skill if you have some You can’t even do that if you just want thumbnails If you learn designing then you can do many such things From can provide services to and You can charge them regularly because Whoever has a faceless channel, this week I need thumbnails from next week too I need it next month as well as after a year and 2 years If you still need it then this is a good service which that you can give and make money from it now understand this that this is very very It is very important the first one which is most The important thing is that it is keyword research or title selection topic selection thereof After all, the most important thing is that it is your Thumbnails If your thumbnail game isn’t good especially if you want browsable videos Heading towards Browse through views are coming then if your thumbnail is good Your video doesn’t have that many views you won’t be able to come and if you are in to what is the kava now kava in pro1 150 pro1 you can also use cava for free Use the one that is free Your thumbnail could be made here then the second most important that is and you will find many types of thumbnails If you do professional work then it makes it if you are going towards such work are where you get the views browse from then i would suggest you to do this or don’t go towards kava phra then you go The question would be that brother, if we use this AI If you create a thumbnail using the tools will our channel be monetized Definitely your videos will also be monetized Everything will happen inside the thumbnail through AI Using any tool related to this is not a problem There is no restriction I have to write YouTube’s by myself Good colors have to be used to get good fun If you have to use it then you must do it and you have to do that manually Now you can design your thumbnail yourself I have a skill, I will sit and teach it, it will take a lot of time If you go, I will give you another resource I will try it, link is below I should put the video in the description as well More thumbnails of the resources you are editing It is mandatory for you to describe the person once as well check it ok what do you need to do youtube0 25 minutes long approximately 26 minutes in which training will come I have taught you that this kind of how do you create thumbnails or the way that’s how i make thumbnails How to create and make faceless thumbnails That is also taught in this video If that’s right, then you have to watch this training. It takes approximately 26 minutes to complete You will get good value that nice thumbnail What happens and how is their editing done? how to make this in photoshop You will get all these things in this particular 26 minutes You will understand it in the training so let’s go now here we are moving on to chapter 10 which is about If you want to take YouTube’s viral then SO does not give us any work at all Then those keywords work. Infact if we have banked the videos it happens then SO gives work and this to Are totally different things browsable Videos and youtube0 is close to zero in terms of views that is that two million 3 million 4 million Practically it’s too much, I’ll tell you Taking it to the laptop screen also made an I will show you such a video so that your Be assured that yes friend for every video SO is not that important now I am here After searching youtube4 cars car here I click on Filters on Filters I go from here by clicking on Most Now here on popular i.e. view count Many videos are coming in front of me, one video It is coming which has 2 billion views for For example, I open it, friend, how many Niche will be any SEO that is why its The video has 2 billion views i.e. 2000 million views okay now from here its SEO I will try to find out the score To find out the score you have or So Tube Buddy extension should be installed Do you need or have Vid IQ? I must have the extension installed Here is the overview of Vid IQ I will click and scroll down to End You can see that its SEO score is that is zero out of 100 means 2000 million Despite the views it gets, its SEO score he is zero i.e. the one who created this has not done any SEO on it yet it is 2000 Have you got a million views or two billion views? If you have come then from here you have your You must have been convinced before your eyes that Dude, if I want to get views then I will do it every time SEO is not necessary or not necessary in every case It is not necessary to do SEO on your own Matters when you rank your video on search well now on the other hand I would have been I will show you a video that I am searching for the ranking on search. I do it for example how to change instagram2 97 out of 100 97 its ao This is the score, that is why it will be released in two months It has received so many views and its video You can see this in front of me at the top The video is ranking on top just because that its seo score is very good from here You understood one importance that Where to do SEO and where not to do SEO now I’ll take you along and tell you this how is SEO done which are those There are six points you need to cover then will your SEO score be maximum or your SEO will be really good so let’s Discover that now first of all we discuss We will use keywords because these are the most It is going to be more important when it comes down to The first point is understood, after that what The second point is that it is a 10/1 What is a keyword? A 10/10 keyword we That is called the one in which number one is his Search volume is there, that number should be good So his competition should be low And number three keywords like that at least Channels must have used the questions now This will come with us brother, how do we find it out Let’s find out which keyword is being searched for Which keyword has good volume? If the competition is low then I use only one tool for this I will recommend it to you guys and that is Create a free account on VidIQ After that you will click on keywords and Now you can enter your keywords by clicking on keywords will start searching for example I want to make video editing Related I am good at editing I am just finding out some keywords i am working on If I can make a video then I will first post it here I will come and do a broad term search, which is it After searching editing editing I From here I will click on the matching terms and I’ll see which one suits me best which of these things should I choose and use I can create a video below I am coming, I think what suits me That is this I will click on this and By clicking on it I will come back here again I will click on matching terms. By clicking on the terms I will see that I what of this might be suiting if this suits me more then I I will click on this now I will click on this After that I think this is the one on which My video can become yours once You got the keyword of your choice and you did it. copy it from here and by copying you have made a You have to open a new tab from here we’re going to need vid iq if you go for the extension google3 hajj is there then when we come down on second That channel has only 19000 ranked videos If you go below the number of subscribers The video which is ranked on the third page is only There are around 1000 subscribers, that means that we don’t see much competition here I can’t find the one which is on number fourth He has 11000 subscribers so from here It has been confirmed that yes there is a lot of competition There are not many videos even on small channels Here we are ranking, after that the number There is something in the second, we have to see that friend Are people even searching for this? Pay views are coming consistently here So you see a tag here. In which it is written 16 VPH VPH stands for views on our that means that joe Top ranked video every hour 16 views coming in That’s Pretty Decent Then if you come down then you will see here that The video is ranked on the second and it has got 23 views but ours again which is very decent After that, even four views is not much Not bad, then 16 views So from here we got the idea that Its search volume is also reasonable and good Now we have also seen the competition of this keyword Which was low, we also saw its search volume I saw that it was pretty decent, now we This is the third thing and the last thing to see whether this keyword is used anywhere else People have copied it exactly from somewhere so what will I do from here is copy it I will do it and I will type tomorrow f so that here But my search bar will open, I will click on this I will paste it here so that I can paste it here Some results are visible which is it 1/3 means it is present only in three places Keyword is used and that too in a search bar I am a Vid IQ telling this and again vid iq show here on right hand side that means that someone is doing it directly Use this keyword as the title of your video which shows that this a perfect title if i Exactly this keyword in your title If I use it then my video potential will be top How can she now come to the title jana hai which is our second part after keyword there I’ll tell you How do we use it in the title? ok so for the title you have to try that Exact keywords in your title This is where you will get your keywords from We will copy it from here and bring it here You will paste it and after pasting you will it has to make sense that somehow this Your actual title should also be there For that there are two-three things which we You can paste it before or after it For example you can paste it here You can either write on how to do 3d after effect video reels editing either you You can make your title like this or you can can make 3d after effects video reels Editing Tutorial 2024 or you can write tutorial for Beginners, this is how you make sense of a title How can we know what to make Again you write your keyword by writing the keyword You give a space ahead, after giving a space you will see that What do you find makes sense? Write it and then give a space So you write all these things in front of your keyword. can you complete your full title Same like this as I told you here I showed you how to do it, okay so now let’s move on towards your description which is ours Third part after title now description how to write first of all whatever is yours This is the title, you have to copy it from here And you have to bring it here and paste it. After pasting you have to press enter and You have to move to the next line and Let us write a small paragraph here. We will write a file which will be filled with our keyword Now where to find keywords again Again we will go to Vid IQ and from here You have to click on the related keywords By clicking on the related keywords you will get There are keywords coming that you can potentially You can use it in your description and Also share your video against these keywords Can I get you ranked from here? I select three or four keywords that but i want my video in Now rank against these keywords as well I have selected four keywords from here. I’ll copy these and Use it like this in your video description I will do it so that it looks a little natural and also this Don’t think that I am spamming here It has been done just like this, you should see this I wrote this small paragraph In which I used some keywords I have liked the keyword this one is mine This is my first keyword, this is my second keyword This is my third keyword and this is my fourth The keyword is you see how I put it Naturally used in this video we will be learning how to do 3d after effect Video editing you will also see after Effects Tutorial We Will Be Discussing Motion Graphics and Viral Instagram’s Video editing is now just like this you can write a paragraph You have to make it which should look absolutely natural and then the seconds you have to work In your video description, write That’s Time Stumps Now what are time stumps You have my HBA Services are here youtube-dl designing ok so like this You have also added time stamps to your videos Now I have to add this video in the description What types of time stumps can there be I will give you an example of that here we go here you can see that for example just Taking as an example my video 3 minutes in which in the first 1 minute I Intro to After Effects Video Editing Then I showed you by editing the video And in the third portion I gave you a motion Now I have explained the graphics like this You have to write the keywords here as well It gets entered and it doesn’t look like spamming again this LegalQuest Make your video in the form of Mas Can you add it again in the description This was our description part now move we will do our third part on which is video tags now video tags are so It is not important but still I will tell you Let me tell you a small way to do this how do you putt you come up your Copy the title of the video from here and There is a website name as rapidgator.net do it so you are done with your tags you are Done with your title you are done with your video Description You are done with your keyword Now only two things are left for selection point number five and point six of which Point number five is how your video is What things should be in the video There should be a reason because of which your video will rank You can do this now before moving on to the video You can see here that Vid IQ tells me I hope your SO is already very good Now it has given us a score of 48.1 out of 50 I have also given the report of which if I give you If I show you, the tag count is five out of four The keywords are 5/5 5/5 5/5 i.e. everywhere It has given me very good marks right now Our SEO was not completed because Only title description and tags are good By doing this our SEO does not improve. Our video should also be very good Our video should also have life The video should also be problem solving It should attract the audience what do we have to do we have to simply come to them On videos that are already ranking We have to open these videos one by one we have to watch the whole video I want to see what is in these videos explained and what are the shortcomings How do you know what is missing? also open the video and comment on this video In the section you will see that some people have told dude you should have done this I should have done this, I didn’t like it This can be improved so whatever you find here You should see good feedback on your use in the video and there is room for improvement there you have to improve so that your audience which is more valuable than your video take it away and then come to your last butt not the least point number six which is About Thumbnail Now Thumbnail How should we be Thumbnail should also play a very important role When it comes down to ranking Your videos are through SO now for that again Have you been to the place where these videos are Some rankings are being done, you have to see that friend Thumbnails of ranked videos what is the similarity and what is the Improvement proof can be done first of all we If you see the similarity then look at this here 3D Viral Reels is also written on the thumbnail The second one is also written 3d viral It is written on the reels third one that go viral The fourth one is written 3D Viral Reels So I understand that if I too am thumbnail pe likhoon 3d viral reels to that would be pretty enough means my video too There are chances to rank but points will never come It also does not happen that you go and meet someone Copy a thumbnail or a concept copy your purpose is that I Can I improve it a little bit? Can I do some value addition? because of which my video is not visible to him If you outperform then here you are See if there is scope for improvement in this come down and keep scrolling you will read two-three times You can also mix and match by holding the You can pick up a theme from someone, just from someone else can pick up the text for sure yours Thumbnail can be the best so now Let’s move forward to chapter number 12 which is it about It’s going to happen friend, now the fun will begin YouTube can become faceless in the same way Short videos can also become faceless now If we were to make faceless shorts then Pure Post it on any platform like youtube1 we can if we want to but if we isn’t it so Youtube2 behaves totally differently If it does, then we will move ahead from this perspective. we will talk about everything that is to come youtube1 to get early success yes many I know such YouTubers myself. of the students of the friends of the Those who played silver within 50 days Buttons have been purchased i.e. 100000 within 50 days Subscribers 1 lakh subscribers He has achieved and Even if you are a little new to Datchi You will also get 1000 subscribers in 50 days If they are coming then that is enough, but now this How does success work? What is the duration, is it long term or not Now let’s go ahead and talk about it, okay ok now if I give you a one liner that How the Algorithm Works for is on youtube0 is it 100% or above 100% Then definitely you will see success here. You will get millions of rupees on your video You will get views but if your video is liked by everyone Someone is skipping Your skip ratio is quite high If it is more then you will get good results here Not to see substantial results I will meet you with my own personal invited people from youtube0 People who did an interview or podcast with working in shorts and believe me It was shocking anyway if I told you this one liner like i said earlier if If I tell you then it’s all about engagement and It’s about your average view duration Assalam Walekum Guy in short Hello Guy Welcome to our channel Welcome to our shorts saying nothing of the sort is not an attempt To the point your hook is very hooky Very interesting very much You should be catchy and there is no useless thing in your video There shouldn’t be even one second of useless talk in it There should not be an average joe of your shorts The length is from 30 seconds to 45 seconds It should be no more than this If you make this hook game strong yes and we don’t talk uselessly in between So you will get 92% 100% of your average ration It will come and only then will your shots go viral And we have to follow the same pattern here too. that’s if one of our shots goes viral then keep this in mind that you have There are other shorts that I have to try you have to make it the same way it is not that you have made one Made it viral on short x vaji topic You have left now and you can go in some other direction They are lying there and saying that my short Why are the views not coming? That is only because that you are most popular with your short And also not creating that type of content You also have to see how your competition is Which shorts is he making? if a particular video of her is going viral This type of shorts is going viral for you too as a beginning I have to try that because that There is a proven thing, if it goes viral youtube1 short gets 200 thousand 300 views I will also go to next short above 1000 If your views don’t go down then there are many shorts It also gets removed on zero views and many more Shorts get removed even after 10000 views so this This is a common problem if you face this If it is there then it has multiple solutions that I’ll tell you about right now For example you will find extreme here you have to be kind of consistent if your There is no consistency if you watch a video every day Not uploading for example you among I skip a day in shorts so I am talking about youtube2 will definitely help you in the next step which you take I will upload a short story, there is something significant in it If we get to see decrees of views The number one thing you have to try It is that the consistency that you have should be maintained and number two you have The thing you need to make sure of is that absolutely You did not do shorts work on fresh channel do some ad, the channel is a bit old Whatever the channel, shorts perform well on that channel and the third one is that pre monetize You should not leave the channel at all is there a difference between pre monetized channels And an agent channel you go to the agent channel Do not go towards pre monetized channel After that the next thing you need to understand is That you have more target audience here Who are the people who are more into shorts? I prefer to see the number one Kids Under 11 Your Content Here are going to consume too much and Number two are those who are 45 plus or 50 plus They are the ones who consume your shorts here You are going to do it, so accordingly you have You have to take out the niche according to this you have I have to select the topic whether this is for me or not I am targeting the same people who wear shorts Do you actually see it or are you like me are targeting who may be on youtube4 I don’t watch it that much or it’s not at that level Kids of that level don’t watch youtube4 do they watch it or do older people watch it and if I am in any of these two If I give priority to them then they are the children All over the globe right now only on youtube4 If you are mostly consuming this then you your content or your niche accordingly You have to plan, after that the next question comes brother please tell me that on the same channel I upload shorts and longs on the same Can I or not, now this is a big thing This is an important question and a very deep one This is a question whose answer you need to understand Need to see people watching shorts The mindset is totally different long Mindset of people watching videos Totally different hai main agar long video I am watching and subscribing to your channel hmm that means i expect this from you I hope that your upcoming videos also yes it is going to be long for For example your video was top 10 Destinations to Visit in Istanbul OK I liked your video I subscribed to this channel friend No, it shows videos of very fit people it is travel related and my own My hobby is also traveling, now I have told you I have subscribed to your next one The video is coming, I’m watching it But in between you get short In which you are very pressa is a small thing I do it whether I relate to him or not is there a chance that I might skip it It is too much but your long video should come and It is not possible for me to skip that Now on the other hand we can do this voice versa take my shorts you like it very much I am small for example my face I have a channel with you I will tell you some funny I will tell you some tricks or tell me some funny hacks Let me tell you something related to children I can provide entertainment from any such channel In which I am uploading shorts now If I upload a long video So my audience is already built there ups are those who subscribed me Those people who have pressed the bell icon are now mine will never watch long videos because The mindset of these two audiences is different okay i accepted that friend its good it is different it is different then Why don’t we bring this audience also to our channel Audience should cut this too collect them on the channel now this is not possible because when we for example We’ve built a strong Shorts audience I have 1000 subscribers out of which 800 People are such that they look at shorts or shorts Because of that they blocked my channel had subscribed now when i am on my long When I publish the video, it will be there These thousands of people should know the impression I need these 800 people when they don’t click on it If you do it then potentially as I told you I mentioned my CTR in the previous chapters Click through rate will decrease Click through rate will decrease Now these friends after watching long videos My channel was subscribed to by these Not everyone will click on 10 also If you take some of this then definitely this is a very If the number is big then 10 per 200 is just 20 and if I take 20 out of 1000 then That’s just 2 but my CTR is this much inspite of being good i.e. There was a dedicated audience out of which 10 per cent If you clicked then it was very good right? But the dedicated audience was so small Because of which my overall CTR decreases did and that went to just 2 slowly slowly my channel is dead here The end event will come into position to happen Succedence Content will not work, only one There is a possibility in which this can work And that is how you can choose long format of content you work and you use shorts as a fuel for your long form of Videos how is it possible for example you make money online yay automation wala jo mera There is a channel on that if I show long format off I am making videos, okay I have made 20-20 videos. 30 min 30 min 40 40 min videos it’s posted there now what do I do and For example there is a video in which I Told five mistakes to avoid for your Faceless youtube0 long format of video is 10 It is of minutes now I made a short in which I said you know that you youtube1 ji ye ye ye ye I have shorted I pointed out a mistake inside which was very thoughtful. yes friend i am making this mistake and what did you say about your short [ __ ] He said you are making four more mistakes like this which you can see in my video is where I have explained it in detail I have explained it, now if that short of mine Even if it goes viral, I won’t be afraid friend Irrelevant audiences should not come to my channel Or I know my channel might go dead If this goes viral, people should watch it till the end. are the most like he came out of this Come and watch my long video also because the The ultimate game is that of my long form The content will run and if it is in short format The shorts can help a little are more than welcome we will welcome him very well it will be right i hope you like it here you must have understood now the next The question is whether SEO of youtube4 It is important to not do it at all, you are your shorts The title can be the same for all the shorts All your shorts can have the same tags Here are the descriptions of all your shorts Same Ho Jaaye It Dozen Even Matter Shorts Mein the only thing that matters is that you How are you engaging your hook? What are you carrying and how are you Increasing the average view duration okay so the last question is with Bhai shorts vs long videos what is the difference in revenue means if I I am earning ₹ in one place by posting long videos In short I am of the same views How much money can I earn against you I will not tell you I will give you an example of this for your example. A video is a long form of content and it is in a suitable niche on which You get RPM close to $ i.e. You get $ for 1000 views For example, if you get 1 million views How much money did you make on that niche? $4000 from just a single video which has given you around 1 million views coming now On the other hand are your short videos? and it gets 1 million views and that is in the same niche which is a good choice It is considered niche i.e. the one whose long If you are getting $ in videos then on the the other hand here instead of your $4000 You will earn just $400 and your the rpm would be 0.4 So Ruffle this is my personal experience My personal observation is that almost 10x That means 10 times difference of income is short Niche too in shorts vs long Niche depends on how much money you have There are some shorts available where you can pay $1 RPM can be obtained upto that also but if the same Niche if you make a long video then There you can get RPM up to $10 Potentially youtube4 has such niches too where you get 0.1 rpm but if If you come to long videos of that then You might be getting up to $ there, so this This will be plus minus niche to niche together That means those niches with low RPM They will have both long and short term work and Those which have high RPM niches Both short and long will be more But there is a 10-fold difference between these two. We have to be here A lot of content related to youtube0 youtube4 You will find it on my channel where I called people who have worn shorts Silver Play within 50-50 days through We have also bought the buttons, so now let’s go to our Chapter Number 13 Pe Which Is Extremely Extremely Important and That’s What It’s About Investment and tools that we have here Basically how much money will it cost If we apply then our face channel will become different Then our channel will not be able to become this now This is a very interesting question The answer to this may be very subjective This video has been viewed by thousands and millions of people If a million people watch it, then even if there are thousand people So there can be thousands of different answers to this. There can be a different answer for every person why see some people will be for For example those tutorials went in the mise what to do in which how to change Background of inside the animation niche You can have up to 00 minutes per person I might have to pay for this animation niche I am talking and this is a video per minute in just one minute I am telling you It has to be done, I have put it aside I told you about the extreme, I told you about the other side now let’s talk about the middle the middle thing is that If you create any faceless channel Good quality editing in it If you want faceless editing then go there You will have to pay Rs 800-000 per minute Now you will have to pay 10% of your monthly salary again There are 15 videos There are 30 videos all things are subjective for everyone Now different rates are going to be applicable for these methods What is it and how can this cost be minimised? How can you make the most of your money You can spend less, I will tell you this thing I am first of all if this is your first channel Don’t try to do it like you would a script There is writing, there is title research, there is voice over Video editing and thumbnail designing SEO is all these are its departments Out of these, you can do three to four departments yourself. handle it and most important is video Editing If you are into video editing Your department takes care of itself, right? things will become much easier for you now They will say that if I am not with you brother then I will do this work myself I can’t do it, maybe I’m overseas or I am 30 plus or I am 25 plus I’m done now, maybe I have enough time I don’t have a full time job or I manage my business myself You tell me I can’t do this anymore How to be the cheapest in less than a minute 800000 is too expensive for me Tell me a cheap Jugaad, ok let’s come now Towards the agricultural jugaad the agricultural jugaad is that At the end we have to keep this game to ourselves You will have to keep this department with you We will have to keep it but we will not do it ourselves We will train a teenager from our family may be our sibling may be our cousin anyone your nephew your nephew your niece your Niece, is there any such child in your family? or the girl who is 181 years old you You will have to train him yourself, maybe you My video editing master class I can also show him some online course Get him to join editing We ourselves will have to teach him the basics You should have a laptop and then you can buy it Even if you give them 10-15000 rupees per month, right? The Very Beginning Then He and She Will Be Happy to serve you she will be happy to Provide you may be in 10 videos per month b12 videos because that’s it right now not as professional as professional Obviously people from the market are here to you Obviously professional will be available at least There is a lot of talk about skills too There will be compromises but your budget will be very Too many cuts can be short you say No brother, I have no problem with the budget I need a professional guy please tell me Where will I find a professional guy for that? You are my free community youtube4 I think there are people close to Hajj who that I am definitely sitting here for this work There are service providers there If there are people providing services then you are there I will post you there, good guy I can get a good resource now I will suggest that the one who has a lot of money But the video does not keep any account Video: Do ​​not make commitments with anyone Discuss your things on a fixed salary For example, friend, I will hire you I make 10 to 12 videos every month On average their length would be 10 to 15 minutes hogi and i will pay you straight away 50000 50000 is a very good number to pay the one who I have been editing that for the past one and a half years And again I keep mentioning one thing again and again I will do that as it plays a very important role If you are a 25, 26, 27 year old video editor who are hiring on which responsibilities that one has to undertake throughout their career I’ve already come a little way ahead Then he will charge you more money Have to find the editors who are either female yes because she believes that it is appropriate Dislike di does your work for money Guys who are 25-26 years old, this is for you Teenagers 2021 Maximum will have to be found 2021 year now come back to what I told you I said in the beginning that if your tutorial The based videos are very basic and very short Maybe if you want 180 videos per month I told you that this video is available for ₹1 How can cost be behind this The trick was that we had to find children who Right now there are teenagers for whom 5000 or 10000 is a big deal. more than enough he doesn’t have 3000 in his pocket If we are giving them 10,000 then they will give Be very very happy, she gives you six days a day The videos will be recorded easily which It’s just a matter of one minute, here’s your resource Kept it for screen recording for voice over and you kept one resource for Thumbnail and video editing and a resource You kept it for uploading the videos Even if we give them Rs. 55,000, which I am telling you it is practically possible again age matters and the guy is living in the area that area matters okay if You are from Lahore DHHM will not do it year to year find a kid from the Three Cities who He is a little skillful, his skill is good He has a laptop, I will give you many I guarantee you will get a lot of them I am talking about the children who are happy even with Rs. 5000 I have been here and it is not as if this Jugaad is yours Will not work over the period of two to three years Those kids too, slowly a little bit You will become wise, 00 will come from Pa to 10 15000 will come to Datsa it will continue now again i am coming this I can sum up the matter of very different niches I am just giving an overall perspective on the whole thing Although every niche has different calculations The content to be picked up in each niche is different I have to pick it up from some place youtube’s talk about the tools watch the tools So I have counted you so much that right now I will give you 10 tools while standing. Ginwala Ginwala Essentials Which are Very Which are the very supreme essentials brother Please tell us that so that if we rely on tools If you want to do it also then we use the same tools Just acquire it, nothing else don’t do it again let me tell you that the tools It is not absolutely necessary in every niche It is definitely not necessary in some niches If it is necessary then in those niches where it is necessary Which tools do you want to take among them? One You Have To Purchase The Subscription Of Story Blogs that will help you on a shared basis You get your number on Rs. 00 per month have to go for what pra which is shared with you You get the number on basis of Rs. 50 per month Three, if you want, for script writing Or for a good title selection you can use flat You can buy 4.0 at its actual cost So I think it is close to 6000 but shared You can get that too very cheap on basis there are then 11 labs which are almost absolute which is necessary for your voice overs This will help you a lot in most of the areas This is important so you’ll have to buy it And these are also its different plans as The cost of the plan will be written there. You will get it for almost half of the cost This can be obtained on shared basis through IQ again if you want this is your personal You can subscribe to whichever is better very low and if you want you can do this also You can take these five on shared basis There are tools that are almost necessary But even out of this, Chart GPT is so You are not necessary if you know how to play So you can manage with charger 3.5 also Of the Kawa Pra and Storage Blocks Even if anyone takes one, I will give you too It might work but 11 labs are obviously If it is very necessary then the total cost of these Even if we put all five in, even if you take If you take it on shared basis then Its cost is not more than 5000 per month And in some niches you don’t need any tools at all Like not even a single Tool and I also did an interview with him With a prince he told that right Now He Is Earning Like Around $600 Today He did not invest even a single rupee till now Overall in youtube3 because it was working On youtube3 and the same sowar that use of cap cut I was doing it and he was sorted out even one rupee He didn’t have to give anything to anyone nor did he have any had to buy the tool now last but not the Least which is your thumbnail designing I would prefer you to consult an expert in that. Hire only those people where you have completed your basic level I don’t want to go because That will not be good, your content will be good not gonna let go thumbnail designer you my come to the group again where someone Hire experts only at the basic level You haven’t tried a thumbnail designer yet A good thumbnail maker will cost you Rs 1500 I can make a thumbnail for Rs. 1000 that if you want a thumbnail of the month Definitely need that higher end charge Will do if you need 20 thumbnails a month Its cost will also be reduced You can invest Rafi Idea here 1000 1500 end age minimum age if you have more If you want then you can send it to anyone in 7008 also I can close this, I am a professional I am talking about a guy but the one whose age it’s a little less and also the one which is on f Not sitting which is not sitting on Upwork It happened that people charge more money there or You have to find a Desi child and this will help you My community is Tashan Pakistan you will be able to sleep comfortably I have told you about those things, right? Have to calculate which niche you are going into What level of editing is required in that niche? Will the one for Rs. 700-00 work or the one for Rs. 1500-2000 work? will it work or the edge basic edge 00 one will work but I’m talking about a minute and then you See if your quantity is more so I’m not gonna keep that on the minute I I will hire an editor for Rs. 40,000, 0000, 50,000 Otherwise, I will learn this skill myself or I To any housewife in your house I will teach you or I will teach some teenager I will give you all these options now it’s up to you that you do so smartly Let’s take these things with us so that was all for chapter number 13 now let’s move forward to chapter number 14 which is mistakes to Now I will tell you some such avoid the mistakes that you make because of your channels do not grow and definitely You understand that in this field, no one There is no scope, this field is very boring I can’t even grow my pay here So let’s understand some basic mistakes in numbers Forest Combining [music] youtube2 will give you back your growth quickly In a fit of confusion, I switch to shorts But then your long video gets 20 views Views 50 Views 100 Views 200 Views This you can’t go much because you Gather irrelevant audiences on your channel If you have taken it then you should not make this mistake at all Number two sharing your channel now I hope so that There is so much awareness that this mistake So at least 90 people must know that Do not share your channel with anyone your relative with any of your friend with Any of your exes Your content is not consumed organically will do and you know about it from him you have your If you don’t want to share the channel then it’s me Or any trustworthy person close to you person because that person is also from your channel that first video of yours is irrelevant for you I will see it, I will see the second one, I will see the third one But will he watch your 50th video? If it comes in front of him then he will click on it he won’t do it because he doesn’t want to see it yes your channel is about trucks I have never driven a motorcycle in my life why would he click on it if he clicks on it Your seat will not click or come down he will do it too, if he doesn’t see it completely then your The average duration will come down and your watch time will increase So your channel will be shared with anyone not to share and number three which is your The mistake is that it is reusing the content See, now you must have understood this much That No, understand this thing that by reusing content We have to avoid doing this, just do these two I added only four videos and uploaded it No friend, add some input to it yourself You will have to add some value Only then will your content be monetized It might not be that difficult, but then I have also put forth an emphasis on this I mentioned it so that it stays in your mind as you go Let this thing settle down, okay? After that again this Uploading Content Using a VPN Uploading Content Using RDP Datchi Comfort Content Your USA UK Canada Australia Germany France wherever If you want then hit that language Hit the topic there, that thing there It will reach on its own as I told you It was also explained correctly in the initial chapters Now this is the mistake that I have started telling you am I not thatchi of the videos for each and everything On I’m thinking let’s do that Although the game is completely opposite to this, you We have to see what the data is saying what youtube2 is saying youtube4 lad But which packaging is going viral Which title and which thumbnail is more viral? This is going to happen to you through your computers only. I will tell you and youtube1 I know how to speak on things my address no what is the interest but if that The thing is not youtube1 and not that it is successful If it has happened then it won’t be yours even if you You can say as much good as you want about it. You have to lift your brain and put it to the side You just need to do research on it use your brain for this Have your own mind for content creation do not use it at all i hope that It’s making sense for you to use your mind How is it not okay to use it After last but not the least ours came think so the seventh mistake is that not Analyzing your competitor or your competitor I myself follow what I I love my own comparator so much is dearer than the channel because Everything tells me that this friend is a follower of this nation. what’s going on inside what’s not going on What things have I failed at? I have become successful in which thing My If he is doing asar then what do I need my Thinking about it or doing things yourself Make your time money by experimenting so that was all to waste resources for this particular course i hope so that You might have learned something new Learnings must have happened now, one of mine to you The message is to see the economy of Pakistan He is already getting worse and worse day by day It is getting wet no matter what Whatever political changes may come We have to change the things that we have It is in everyone’s hands to change this thing ourselves It is fate that a man writes with his own hands Allah sends our fate in writing How does a person write the fate of his decisions The person who takes good decision on the basis Definitely his luck would have been better than better It goes away so I want you guys to also keep your The one who is destined takes this decision himself Make it as good as possible that yes friend I will do it it’s for me for my family for my Parents for my upcoming family I I will work on improving all these things I will do it, there is no guarantee that it will take time No person will give you any such guarantee from I cannot say that this will happen in 15 days This will happen in a month This will happen in two months It will take some time brother you tell me In achieving the job you are in If your XYG is particular any Be it salary or business, whatever you earn You made a struggle to earn this Initially you might have suffered a loss or It takes you two to four months to find a job It took eight months to get the job You must have studied for at least 4 years Everything matters here, right? The same rules are implemented either way This is not a get rich quick scheme but it It’s a lazy thing, it will take some time It will take time but if we are consistent We will stay if we put in effort everyday Friend how is it possible that you come here Those people who are already sitting here may not get success Are they different from us after achieving it? is he an alien no he is also like us As everything demands persistence Right Knowledge Right Mentorship Right Actions Right strategy after learning all these things What big thing can you get in this Just have to be disciplined and consistent It’s a little difficult to stay in it and nothing is difficult i am telling you so i hope you guys liked it You will like the video as much as possible Like so I know you have How many people have benefited from it Let me know your opinion in the comments is there any question i will definitely I try to put your every comment in your favor there is a question, can you answer it as well guys can you come to my instagram2 If you have any questions for me then ask me there can you watch my content on my There is a lot of knowledge on youtube2. value is provided already you can come to My Till then in some other video of mine allah hafiz

    By Amjad Izhar
    Contact: amjad.izhar@gmail.com
    https://amjadizhar.blog

  • Flask Web Development: From Basics to Deployment

    Flask Web Development: From Basics to Deployment

    The text offers a comprehensive guide to constructing and deploying Flask web applications. It begins with the essentials of setting up a virtual environment and creating a basic “Hello, World!” application using Flask. The guide then demonstrates advanced features such as URL handling, request methods, response customization, and Jinja templating, which dynamically generates HTML content. Furthermore, the text details incorporating static files and integrating frameworks such as Bootstrap. The text advances to explore user authentication and databases and further enhances application structure through the implementation of blueprints. The explanation culminates in directions for using Docker to containerize applications for deployment on remote servers.

    Flask Framework Mastery: A Comprehensive Study Guide

    I. Quiz: Short Answer Questions

    Answer each question in 2-3 sentences.

    1. What is the primary reason for creating a virtual environment when developing Flask applications?
    2. Explain the purpose of the requirements.txt file in a Flask project.
    3. Describe how to activate a virtual environment in a command line interface (CLI) on Linux or macOS.
    4. In Flask, what is a “route” and how is it defined?
    5. What does the debug=True parameter do when running a Flask application and why should it be turned off in production?
    6. Explain the difference between URL processors and URL parameters in Flask.
    7. How can you access URL parameters within a Flask route function?
    8. How can you specifically handle POST requests in Flask, and why is this useful?
    9. Explain how to return a custom status code along with a response in Flask. Give an example of a use case for this.
    10. What is Jinja2 and how is it used to generate dynamic web pages?

    Answer Key

    1. Virtual environments isolate project dependencies, ensuring specific package versions don’t conflict with other projects or the system’s global packages. This isolation creates reproducible deployments.
    2. The requirements.txt file lists all the packages and their versions required for a Flask project. It enables others to easily replicate the project’s environment by installing these dependencies.
    3. To activate a virtual environment on Linux or macOS, use the command source venv/bin/activate. This command sets the environment variables to use the virtual environment’s Python interpreter and packages.
    4. A route in Flask maps a URL endpoint to a specific function that handles requests to that endpoint. It is defined using the @app.route() decorator.
    5. When debug=True, Flask automatically reloads the server on code changes and displays detailed error messages. It should be turned off in production to prevent security vulnerabilities and improve performance.
    6. URL processors are dynamic parts of the URL path captured as function arguments, like /greet/<name>. URL parameters are key-value pairs appended to the URL after a question mark, like /login?username=user.
    7. URL parameters can be accessed using the request.args object. The code example uses request.args.get(‘parameter_name’) or directly accesses request.args[‘parameter_name’].
    8. POST requests are handled by specifying methods=[‘POST’] in the @app.route() decorator. This is useful for submitting form data or sending data to the server to create or update resources.
    9. A custom status code can be returned as a second value in a return statement. For instance, return “Created”, 201 returns a 201 Created status. This is useful for indicating the success or failure of an operation to the client.
    10. Jinja2 is a templating engine that enables developers to embed dynamic content within HTML templates. It is used to generate dynamic web pages by combining data from the Flask application with HTML markup.

    II. Essay Questions

    1. Discuss the advantages of using a modular structure, such as blueprints, in large Flask applications.
    2. Compare and contrast sessions and cookies in Flask, detailing their purposes, implementation, and security implications.
    3. Outline the steps involved in building a user authentication system in Flask, including hashing passwords and managing user sessions.
    4. Describe how static files (CSS, JavaScript, images) are served in Flask and explain how to structure your project to effectively manage them.
    5. Explain the process of deploying a Flask application using Docker, highlighting the benefits of containerization for deployment.

    III. Glossary of Key Terms

    • Flask: A micro web framework for Python, designed to be lightweight and flexible.
    • Virtual Environment: An isolated environment for Python projects, managing dependencies and package versions.
    • requirements.txt: A text file listing all the Python packages required for a project, used to recreate the environment.
    • Route: A URL endpoint in a Flask application, mapped to a specific function that handles requests.
    • Decorator: A Python feature used to modify or extend a function’s behavior, often using the @ symbol (e.g., @app.route).
    • URL Processor: A dynamic part of a URL that captures values as function arguments (e.g., <int:id>).
    • URL Parameter: A key-value pair appended to a URL after a question mark (e.g., ?key=value).
    • POST Request: An HTTP method used to send data to a server to create or update a resource.
    • Status Code: A three-digit code returned by a server indicating the result of a request (e.g., 200 OK, 404 Not Found).
    • Jinja2: A templating engine for Python, used to embed dynamic content within HTML templates.
    • Template: A file containing HTML markup and Jinja2 syntax, used to generate dynamic web pages.
    • Session: Server-side storage used to persist user-specific data across multiple requests, using a cookie to maintain state.
    • Cookie: A small piece of data stored on the client-side, used to remember information about the user or track their activity.
    • Blueprint: A modular component in Flask, used to organize and encapsulate a set of related views, templates, and static files.
    • Docker: A platform for developing, shipping, and running applications inside containers, providing isolation and portability.
    • Container: A standardized unit of software that packages up code and all its dependencies, enabling applications to run quickly and reliably from one computing environment to another.
    • Docker Image: A read-only template with instructions for creating a Docker container.
    • pip: The package installer for Python, used to install and manage packages from the Python Package Index (PyPI).
    • flask-login: A Flask extension that provides user session management for login/logout functionality
    • bcrypt: A password-hashing function designed to be computationally intensive to prevent reverse engineering by brute-force attacks.
    • flask-sqlalchemy: A Flask extension that simplifies using SQLAlchemy, a powerful ORM (Object-Relational Mapper) for working with databases.
    • flask-migrate: A Flask extension that uses Alembic to handle database schema migrations in your Flask application

    Flask Application Development and Deployment Guide

    Okay, here’s a detailed briefing document summarizing the key themes and ideas from the provided source.

    Briefing Document: Flask Application Development & Deployment

    Overview:

    This document synthesizes information from a series of tutorials on developing and deploying Flask applications. The tutorials cover core concepts, best practices, and practical steps for building, containerizing, and deploying Flask applications to a server. The emphasis is on modularity, maintainability, and security.

    Main Themes & Ideas:

    1. Virtual Environments:
    • Theme: Isolating project dependencies.
    • Details: Creating a virtual environment ensures a project uses only the necessary packages and versions. This prevents conflicts and simplifies deployment.
    • Quote: “The reason you want to create a virtual environment is because you want to have an isolated uh project where you only have the packages and also the package versions that are relevant to this particular project.”
    • Process:Navigate to project directory in the command line.
    • Create the environment: python -m venv venv (or python3 -m venv venv).
    • Activate the environment: source venv/bin/activate (Linux/Mac).
    • Configure IDE (e.g., PyCharm) to use the virtual environment’s Python interpreter.
    1. Basic Flask Application Structure:
    • Theme: Building a minimal “Hello, World!” application.
    • Details: Creating a simple Flask application to demonstrate the core components and workflow. This covers importing Flask, creating an app instance, defining routes, and running the application.
    • Process:Import Flask: from flask import Flask
    • Create app instance: app = Flask(__name__)
    • Define a route: @app.route(“/”)
    • Create a function to handle the route, returning HTML or text.
    • Run the app: if __name__ == “__main__”: app.run(host=”0.0.0.0″, debug=True)
    1. Routes & Request Handling:
    • Theme: Defining and managing different URL endpoints.
    • Details: This covers static routes, dynamic URLs (using URL processors), URL parameters, and handling different HTTP methods (GET, POST).
    • Dynamic URLs:Use angle brackets to define variables in the route: /greet/<name>.
    • The function handling the route takes the variable as a parameter: def greet(name):.
    • Type casting parameters (e.g., <int:number>) to enforce data types in URLs.
    • URL Parameters:Access URL parameters using request.args: request.args.get(‘name’).
    • Check for the existence of parameters using if ‘name’ in request.args.keys():.
    • HTTP Methods:Specify allowed methods in the route decorator: @app.route(‘/login’, methods=[‘GET’, ‘POST’]).
    • Use request.method to differentiate between GET and POST requests.
    • GET requests are typically used to display forms, while POST requests handle form submissions.
    1. Templates:
    • Theme: Separating presentation logic from application code using Jinja2 templates.
    • Details: This covers rendering HTML templates, passing variables to templates, using loops and conditionals within templates, and template inheritance for creating reusable layouts.
    • Process:Store HTML templates in a “templates” directory.
    • Use render_template(‘index.html’, variable1=value1) to render a template.
    • Access variables in templates using double curly brackets: {{ variable1 }}.
    • Use Jinja2 syntax for loops ({% for item in list %}) and conditionals ({% if condition %}).
    • Use template inheritance to create reusable layouts with {% extends ‘base.html’ %} and {% block content %}.
    1. Filters:
    • Theme: Modifying data within templates using filters.
    • Details: Using built-in filters (e.g., upper, lower, replace) and creating custom filters to manipulate data before displaying it in the template.
    • Custom Filters:Define a filter function: def reverse_string(s): return s[::-1].
    • Register the filter: @app.template_filter(‘reverse_string’).
    • Use the filter in the template: {{ my_string | reverse_string }}.
    1. Static Files:
    • Theme: Serving static assets like CSS, JavaScript, and images.
    • Details: This covers how to serve static files from a dedicated “static” directory and referencing them in HTML templates.
    • Process:Store static files (CSS, JavaScript, images) in a “static” directory.
    • Reference static files in templates using the /static URL: <link rel=”stylesheet” href=”/static/style.css”>.
    1. File Uploads:
    • Theme: Handling file uploads from HTML forms.
    • Details: This covers creating a form for file uploads, accessing uploaded files using request.files, validating file types, and saving files to the server.
    • Process:Create an HTML form with enctype=”multipart/form-data”.
    • Access uploaded files using request.files[‘file_field_name’].
    • Validate file types using file.content_type.
    • Save files using file.save(‘path/to/save/file’).
    1. Downloads
    • Theme: Allowing users to download dynamically created files, such as CSV exports, through the web application.
    • Details: The process involves generating the file on the server, creating a unique filename to avoid conflicts, and using Flask’s send_from_directory function to securely serve the file for download. The tutorial demonstrates generating a CSV from an uploaded Excel file for download.
    1. Sessions & Cookies:
    • Theme: Managing user data and state across requests.
    • Details: This covers the difference between sessions (server-side storage) and cookies (client-side storage), setting and retrieving session data, setting and retrieving cookies, and the security implications of using each.
    • Sessions:Set app.secret_key to enable sessions.
    • Store data in the session dictionary: session[‘username’] = ‘value’.
    • Access data from the session dictionary: session.get(‘username’).
    • Clear the session using session.clear().
    • Cookies:Set cookies using response.set_cookie(‘key’, ‘value’).
    • Access cookies using request.cookies.get(‘key’).
    • Remove cookies by setting expires=0.
    1. Message Flashing:
    • Theme: Displaying temporary status messages to the user.
    • Details: This covers using the flash() function to store messages and retrieving them in templates using get_flashed_messages().
    1. Database Integration (SQLAlchemy):
    • Theme: Interacting with databases using Flask-SQLAlchemy.
    • Details: This covers setting up Flask-SQLAlchemy, defining database models, creating tables using Flask-Migrate, and performing basic database operations (CRUD – Create, Read, Update, Delete).
    • Models:Define models as classes inheriting from db.Model.
    • Define columns using db.Column(db.DataType, primary_key=True, nullable=False).
    • Migrations:Use Flask-Migrate to manage database schema changes: flask db init, flask db migrate, flask db upgrade.
    1. User Authentication (Flask-Login & Bcrypt):
    • Theme: Implementing a user authentication system.
    • Details: This covers using Flask-Login to manage user login and logout, using Flask-Bcrypt to hash passwords securely, creating user models, and protecting routes that require authentication.
    • Security:Hash passwords using bcrypt.generate_password_hash(password).
    • Verify passwords using bcrypt.check_password_hash(hashed_password, password).
    • Flask Login:Import and create a LoginManager instance, setting up user loading callbacks.
    • Implement a function @login_manager.user_loader to load users from the database based on their ID.
    • Protect views with login_required.
    1. Blueprints:
    • Theme: Organizing applications into modular components.
    • Details: This covers creating blueprints, defining routes and templates within blueprints, and registering blueprints with the main application.
    • Process:Create a Blueprint instance: blueprint_name = Blueprint(‘name’, __name__, template_folder=’templates’).
    • Define routes using @blueprint_name.route(‘/route’).
    • Register the blueprint with the application: app.register_blueprint(blueprint_name, url_prefix=’/prefix’).
    1. Deployment with Docker:
    • Theme: Containerizing and deploying Flask applications using Docker.
    • Details: The process involves creating a Dockerfile to define the environment and dependencies of the application, building a Docker image, and running the image on a server.
    • Docker File CommandsFROM defines base image
    • WORKDIR sets the working directory
    • COPY copies files from host to container
    • RUN executes commands to configure the environment
    • The process further involves building, saving, uploading, loading, and running the docker image on the server.
    • The importance of using pip freeze to export packages with exact versions is highlighted, making it easier to rebuild the container elsewhere.

    Key Quotes:

    • “(Virtual Environment) the reason you want to create a virtual environment is because you want to have an isolated uh project where you only have the packages and also the package versions that are relevant to this particular project.”
    • “(For deploying you) need Docker on the server and that’s it.”

    Conclusion:

    This source provides a comprehensive guide to developing and deploying Flask applications, emphasizing modularity, security, and best practices. By following these tutorials, developers can build robust and scalable web applications using the Flask framework. The focus on using virtual environments, secure password handling, and containerization ensures that the applications are well-structured, secure, and easy to deploy.

    Flask Development Essentials

    General Flask Development

    1. What is a virtual environment and why should I use one when developing Flask applications?

    A virtual environment is an isolated project workspace that contains only the necessary packages and package versions specific to that project. This prevents conflicts with other projects and ensures that your application has consistent dependencies across different environments (development, testing, and production). Using a virtual environment also streamlines the process of creating a requirements.txt file for easy deployment and containerization.

    2. How do I create and activate a virtual environment for a Flask project?

    Open a command line (CMD on Windows, terminal on Linux/Mac) and navigate to your project directory. Create the environment using python -m venv venv (or python3 -m venv venv, depending on your system), where “venv” is the name of the environment directory. To activate it, use source venv/bin/activate (on Linux/Mac) or venv\Scripts\activate (on Windows). Your command line prompt will indicate the active environment.

    3. How do I install Flask and save the project dependencies to a file?

    With your virtual environment activated, use pip install flask (or pip3 install flask) to install Flask and its dependencies. To save the list of installed packages and their versions to a requirements.txt file, use pip freeze > requirements.txt (or pip3 freeze > requirements.txt). This file can then be used by others (or yourself on another system) to easily install the exact same dependencies by running pip install -r requirements.txt.

    4. What is a route in Flask and how do I define one?

    A route in Flask is a URL path that is associated with a specific function. When a user visits that URL, the corresponding function is executed. Routes are defined using the @app.route() decorator above a function definition. The decorator takes the URL path as an argument. For example:

    from flask import Flask

    app = Flask(__name__)

    @app.route(“/”)

    def index():

    return “Hello, World!”

    5. How do I pass and handle dynamic URLs in Flask?

    Dynamic URLs can include variables that are passed as part of the URL path. You define these variables using angle brackets <> within the route. The variable name inside the angle brackets becomes an argument to the associated function. You can also specify the data type using <int:variable_name>.

    @app.route(“/greet/<name>”)

    def greet(name):

    return f”Hello, {name}!”

    @app.route(“/add/<int:num1>/<int:num2>”)

    def add(num1, num2):

    return str(num1 + num2)

    6. What are URL parameters and how do I handle them in Flask?

    URL parameters are key-value pairs appended to the end of a URL after a question mark (?). For example: /login?username=john&password=secret. You can access these parameters using the request.args object.

    from flask import Flask, request

    app = Flask(__name__)

    @app.route(“/handle_params”)

    def handle_params():

    name = request.args.get(“name”)

    greeting = request.args.get(“greeting”, “Hello”) #Default value if greeting is not provided

    return f”{greeting}, {name}!”

    7. How can I use HTML Templates in Flask?

    To use HTML templates, you must first place your HTML files in a directory called “templates” within your project directory. The directory will be located in whatever file runs the application, commonly app.py. Use the render_template() function from Flask to load and render these templates, passing any necessary variables as keyword arguments. Use Jinja2 syntax ({{ variable_name }}) within the HTML templates to display these variables. This requires importing render_template from the flask package: from flask import render_template. Here is how you would return an HTML template in your app.py file:

    from flask import Flask, render_template

    app = Flask(__name__)

    @app.route(“/”)

    def index():

    return render_template(“index.html”, message=”Welcome!”)

    Within the index.html file you would have the following:

    <!DOCTYPE html>

    <html>

    <head>

    <title>My Webpage</title>

    </head>

    <body>

    <h1>{{ message }}</h1>

    </body>

    </html>

    8. How do I deploy a Flask application using Docker?

    1. Create a Dockerfile: This file contains instructions to build a Docker image for your application.
    2. Define Base Image: Start with a Python base image (FROM python:3.10-slim-buster).
    3. Set Working Directory: Create a working directory inside the container (WORKDIR /app).
    4. Copy Requirements: Copy the requirements.txt file into the container (COPY requirements.txt .).
    5. Install Dependencies: Install Python dependencies using pip (RUN pip install -r requirements.txt).
    6. Copy Application Files: Copy the entire Flask application code into the container (COPY . .).
    7. Run database migrations: Change the working directory and run database migrations (WORKDIR /flaskapp/blueprintapp, then RUN flask db init, RUN flask db migrate, RUN flask db upgrade, then WORKDIR /flaskapp).
    8. Expose Ports: Specify the port that the Flask application will listen on (EXPOSE 5000).
    9. Set Entrypoint/Command: Define the command to start the application (CMD [“python3”, “run.py”]).
    10. Build the Docker Image: Use the command docker build -t <image_name> . from the directory containing the Dockerfile.
    11. Run the Docker Container: Use the command docker run -d -p <host_port>:<container_port> <image_name> to run the image as a container.

    Understanding and Using Python Virtual Environments

    A virtual environment is a tool used to create isolated project spaces containing only the packages and package versions relevant to that specific project. Here’s a breakdown of why and how to use them, according to the sources:

    • Purpose
    • Isolation: Virtual environments isolate projects, ensuring that each has its own dependencies without conflicts.
    • Dependency Management: They allow for specifying and managing exact package versions, which is crucial for consistent performance and avoiding compatibility issues.
    • Requirements File: Facilitates the creation of a requirements.txt file, which lists all project dependencies and their versions, simplifying deployment and containerization.
    • Creation & Activation
    • Command Line: Creation is typically done via the command line using python -m venv <environment_name>. For example, python -m venv venv.
    • Activation: Activating the environment makes it the current Python environment for the terminal session. On Linux and Mac, this is done using source <environment_name>/bin/activate.
    • Usage
    • Package Installation: Once activated, packages are installed using pip install <package_name>. For example, pip install flask.
    • Dependency Listing: The command pip freeze lists all installed packages within the active environment, which can then be saved to a requirements.txt file using pip freeze > requirements.txt.
    • Replicating Environments: Others can install the exact dependencies of a project by using the requirements.txt file and the command pip install -r requirements.txt.

    Flask Application Development: A Minimalist Python Web Framework

    A Flask application is a web application built using the Flask framework, a Python microframework known for its simplicity and minimalism.

    Key aspects of Flask applications, based on the sources:

    • Minimalistic Approach: Flask provides only the essential tools and features needed for web development, leaving developers to implement additional functionality as required or by installing extension packages.
    • File Structure: A simple Flask application can be created with just a single Python file. However, more complex applications typically use a directory structure that includes templates and possibly blueprints.
    • Virtual Environments: It is recommended to create a virtual environment to manage project-specific dependencies.

    How to create a basic Flask application, according to the sources:

    1. Set up: First, import the Flask class from the flask library: from flask import Flask.
    2. Create an instance: Create an instance of the Flask class, which will be the WSGI application: app = Flask(__name__).
    3. Define routes: Use the @app.route() decorator to define routes, which map URL paths to Python functions. For example:
    4. @app.route(‘/’)
    5. def index():
    6. return ‘Hello, World!’
    7. Run the application: Use the app.run() method to start the development server. You can specify parameters such as the host, port, and debug mode.
    8. if __name__ == ‘__main__’:
    9. app.run(host=’0.0.0.0′, port=5000, debug=True)

    Key components and concepts in Flask applications:

    • Routes: Routes define the different URLs that the application responds to and the functions that are executed when those URLs are accessed.
    • Templates: Flask uses Jinja2 templating engine to render HTML files dynamically.
    • Static Files: Flask applications can serve static files such as CSS, JavaScript, and images from a designated static directory.
    • Blueprints: Blueprints are a way to organize larger Flask applications into reusable components.
    • Requests and Responses: Flask handles HTTP requests and provides objects for accessing request data, such as URL parameters and form data. It also provides mechanisms for creating custom responses, including setting status codes and headers.
    • Sessions and Cookies: Flask supports sessions and cookies for managing user-specific data across multiple requests.
    • Database Integration: Flask can be integrated with databases using extensions like Flask-SQLAlchemy, allowing you to define data models and perform database operations.
    • User Authentication: Flask can be used to implement user authentication systems, using extensions like Flask-Login and Flask-Bcrypt to manage user sessions and password hashing.

    Docker Containers: Application Standardization and Deployment

    A Docker container is a standardized unit of software that packages up code and all its dependencies so the application runs reliably from one computing environment to another. Here’s a breakdown based on the sources:

    • Purpose
    • Consistency: Docker containers ensure applications run the same way regardless of the environment, eliminating “it works on my machine” problems.
    • Efficiency: Containers virtualize the operating system, allowing for smaller sizes and faster startup times compared to virtual machines.
    • Isolation: Docker containers isolate applications from one another and the underlying infrastructure, providing security and preventing conflicts.
    • Creation
    • Dockerfile: A Dockerfile is a text file that contains all the instructions needed to build a Docker image. This includes the base image, dependencies, environment variables, and startup commands.
    • Image: A Docker image is a read-only template used to create containers. It’s built from a Dockerfile and contains everything needed to run an application.
    • Build Command: The command docker build -t <image_name> . is used to build a Docker image from a Dockerfile in the current directory.
    • Deployment
    • Docker Hub: Docker images can be stored in and distributed from registries like Docker Hub.
    • Run Command: The command docker run -d -p <host_port>:<container_port> <image_name> is used to run a Docker image as a container. The -d flag runs the container in detached mode (in the background), and the -p flag maps a port on the host to a port in the container.
    • Docker Compose: For more complex applications, Docker Compose can be used to define and manage multi-container applications.
    • Key commands
    • docker build: Builds a Docker image from a Dockerfile.
    • docker run: Runs a Docker image as a container.
    • docker ps: Lists running containers.
    • docker stop: Stops a running container.
    • docker save: Saves a Docker image to a tar archive.
    • docker load: Loads a Docker image from a tar archive.
    • docker images: Lists Docker images.

    To deploy a Flask application using Docker, the process generally involves the following steps:

    1. Create a Dockerfile that specifies the base image, installs dependencies, copies the application code, and defines the startup command.
    2. Build a Docker image from the Dockerfile using the docker build command.
    3. Run the Docker image as a container using the docker run command, mapping the host port to the container port.

    By containerizing a Flask application with Docker, you can ensure it runs consistently across different environments, simplify deployment, and isolate it from other applications.

    Flask Database Migrations with SQLAlchemy and Flask-Migrate

    Database migration, specifically in the context of Flask applications, involves managing changes to the database schema in a structured and organized manner. It is a way to evolve the database schema over time as the application’s needs change.

    Here’s a breakdown of database migrations using Flask-Migrate and SQLAlchemy, according to the sources:

    • Packages: Flask-Migrate and SQLAlchemy are essential packages.
    • SQLAlchemy is an Object Relational Mapper (ORM) that facilitates the interaction with databases using Python classes and objects, rather than raw SQL queries.
    • Flask-Migrate is an extension for Flask that uses Alembic to handle database migrations.
    • Avoiding Circular Imports: To avoid circular import issues when working with databases and models in Flask, a common approach is to use the factory pattern, where the application and database objects are created within a function.
    • Steps for Implementing Migrations:
    1. Initialization: Use the command flask db init to initialize the migration repository. This step is done only once.
    2. Migration Creation: Use the command flask db migrate to automatically generate a migration script based on the changes made to the models. Flask-Migrate detects the changes in the models and generates the necessary migration script.
    3. Applying Migrations: Use the command flask db upgrade to apply the migration to the database. This updates the database schema to match the current state of the models.
    • Workflow: The typical workflow involves making changes to the models (e.g., adding a new field, changing a data type), generating a migration, and then applying the migration to the database. This process ensures that the database schema is always in sync with the application’s models.
    • Database Types: Flask-Migrate and SQLAlchemy support various database types, including SQLite, MySQL, and PostgreSQL. To switch between databases, you only need to change the connection string in the application configuration. After changing the connection string, you need to migrate and upgrade the database.
    • Model Definition: Define database tables as classes that inherit from db.Model. Each attribute of the class represents a column in the database table. Specify the data type of each column using db.Column and the appropriate SQLAlchemy data type (e.g., db.Integer, db.String, db.Text). You can define the table name using the __tablename__ attribute. You can specify the primary key for a column using primary_key=True. You can specify whether a column can be empty using nullable=False.
    • Making Changes: To make changes to the database schema, modify the models, then generate and apply a migration.
    • Benefits:
    • Version Control: Database migrations provide a way to version control the database schema, allowing you to track changes and roll back to previous versions if necessary.
    • Collaboration: Migrations facilitate collaboration among developers by providing a standardized way to manage database changes.
    • Deployment: Migrations simplify deployment by ensuring that the database schema is automatically updated when the application is deployed to a new environment.

    Flask Application Server Deployment Guide

    Server deployment involves making a Flask application accessible on the internet. Here’s a breakdown of key aspects and methods, according to the sources:

    • Methods
    • Manual Deployment: This involves copying the application files to a Linux server, installing the necessary dependencies, and running the application.
    • Docker Containerization: This involves packaging the application and its dependencies into a Docker container, which can then be run on any server with Docker installed.
    • Cloud Services: Docker can be used in combination with cloud services.
    • Docker Containerization Deployment Steps
    1. Create a Dockerfile: A Dockerfile contains the instructions to build a Docker image. This includes specifying the base image, setting the working directory, copying the application files, installing dependencies, and defining the startup command.
    2. Build the Docker image: Use the command docker build -t <image_name> . to build the Docker image from the Dockerfile.
    3. Save the Docker image: Save the Docker image to a tar archive using the command docker save -o <image_name>.tar <image_name>.
    4. Upload the Docker image: Upload the Docker image to the server using a tool like SCP. For example: SCP <file_name> root@<host_name>:<path>.
    5. Load the Docker image: Load the Docker image on the server using the command docker load -i <image_name>.tar.
    6. Run the Docker image: Run the Docker image as a container using the command docker run -d -p <host_port>:<container_port> <image_name>.
    • Key Considerations for Docker Containerization
    • Virtual Environment: Use a virtual environment during development to manage project-specific dependencies and create a requirements.txt file.
    • Base Image: Specify a Python base image in the Dockerfile. For example: FROM python:3.10-slim-buster.
    • Working Directory: Define a working directory in the Dockerfile. For example: WORKDIR /app.
    • Install Dependencies: Copy the requirements.txt file to the container and install the dependencies using pip install -r requirements.txt.
    • Copy Application Files: Copy the application files to the container. For example: COPY . ..
    • Database Migrations: Run database migrations inside the container to ensure the database schema is up to date.
    • Port Mapping: Map the host port to the container port when running the Docker image. For example: docker run -d -p 5000:5000 <image_name>.

    By using Docker, you can ensure that the Flask application runs consistently across different environments, simplify deployment, and isolate it from other applications.

    Full Flask Course For Python – From Basics To Deployment

    The Original Text

    what is going on guys welcome back this video today is a full flas course combined into a single video it covers everything from the very basics of flask like working with HTML files rendering templates handling post requests working with files working with static files integrating bootstrap two more advanced concepts like sessions and cookies database interaction user authentication up until stuff like blueprints and even deployment and Docker so this is a very comprehensive course and it consists of 10 individual videos compiled into one big course so often times you will hear me referring to the previous episode or to the next episode uh in this case I just mean earlier or future points in the video so don’t be confused by that and I do this because most of you guys prefer to have one big course instead of 10 individual episodes so this is now the full flas course uh on the neural 9 Channel as I said it’s quite comprehensive so you might want to split it up into multiple sessions but yeah let’s get right into it I hope you enjoy it not a g all right so we’re going to start in this first episode today by creating our first simple flask application a simple hello world application just to get to know the process of creating and running a flask app so it’s going to be very beginner friendly and simple now as I already mentioned flask is a python web development framework and it’s often times also referred to as a micro framework or a microw web framework because it’s so simple and minimalistic compared to something like Django when you create a new flask application you don’t have any functionality out of the box you don’t have an authentication system or anything like that you basically have to implement everything from scratch or you have to install additional packages that implement the functionality we’re not going to go into the advantages and disadvantages we’re not going to compare here Jango versus flask we’re going to go into flask but it’s important to know that flask is very simple and minimalistic you can basically built an application with a single file you don’t have some uh project structure that has to be in place in order to run a simple hello world project we’re going to see that this is the case in a second here so the first thing we’re going to do is we’re going to create a virtual environment and the reason you want to create a virtual environment is because you want to have an isolated uh project where you only have the packages and also the package versions that are relevant to this particular project there are many reasons you want to do that but one reason is that it’s very uh convenient to then create a requirements txt file to then deploy the application to containerize it and so on uh but there are also other benefits so what we’re going to do first is we’re going to open up a command line so on Windows CMD on Linux and Mac the terminal and we’re going to navigate to the directory that we’re going to be working in in my case this is the current directory and here now we’re going to create our flask uh project directory so we’re just going to create a directory I’m going to call it now first app and in this directory here in this first app directory we’re going to create a virtual environment for this you don’t need to install any python packages this is something that works with python out of the box it’s part of the core python uh installation and what we need to do is we need to say python or Python 3 depending on your operating system- mvmf and then the name of the virtual environment directory I like to call itvn which makes it a hidden directory and once you have this once this is um created you can see that we have this virtual environment here and depending on your IDE depending on the editor that you’re using you will have to configure that now the environment that is being used is this environment because by default it’s going to use the environment it always uses uh in my case here in py charm what I have to do is I have to click here um on the python interpreter and I have to oh actually I’m blocking this with my camera let me just move this for a second I have to click on the python version down here I have to add a new interpreter a local interpreter and then basically I have to go to Virtual n environment existing and then I basically have to look for this so I have to in this case I have my prepared projects here uh I have to go to python current VN bin and then I want to use Python 3 this is the executable or the binary I’m interested in I click on this I click okay and now my pie charm uses this virtual environment um in addition to that the terminal that I want to use I also want to activate this environment in so I want to say Source at least on Linux and Mac source and then vnf bin and then activate and now you can see it’s using the vmf environment how can you check if this is actually working you can just type pip or pip 3 freeze and you’re going to get a list of all the packages that are installed in this case no package is installed now once you have the virtual environment running and activated what you can do or what you have to do is you have to install flask so pip or pip 3 install flask and then this is going to install uh everything that’s needed for a basic flask application I can run pip freeze again and now you can see I have a couple of packages here installed in this environment so after this what we want to do is want to create a python file called app.py and this is actually all we’re going to need for this video today we don’t need any uh directory structure we don’t need models we don’t need anything like that we can just have a simple python file and this is going to be our whole application of course when you build more complex projects you still have a directory structure you have templates you have Blueprints and so on we’re going to talk about this in future episodes but for a simple flask application one file is enough so what we’re going to do here now is we’re going to import from flask flask with a capital f so from flask import flask and then we’re going to create the application by saying app equals flask ask and we’re going to pass here uncore name uncore uncore so this is how you create the application and now what we do with this application is we add end points or routes you could say we’re going to talk about routes in the next episode but for this video we’re going to just create a simple uh default route a simple index route so what we’re going to do is we’re going to use the decorator so at app. Route and we’re going to specify the rule so basically the path that this uh route is going to to belong to and the default is just slash so app route slash and then below that we want to create a function that is going to return something uh which is what we’re going to see the HTML code we’re going to see when we go to that endpoint so here we’re going to say now def to create a new function index and here you can return something now later on we’re going to render HTML templates we’re going to do it professionally but for now you can just return any text you can just return hello world for example and this is what you’re going to see when you go to that specific endpoint now this is now the endpoint to actually run the application what we’re going to do is we’re going to say if uncore name uncore equals uncore maincore that’s just a basic uh python main section um what we’re going to do here is we’re going to say app.run and we can provide a couple of parameters here the three important parameters that we’re going to provide here are the host the port and whether we want to run this in debug mode or not so we can say host equals and what you want to do is you always want to run the application on the Local Host so on the host of The Machine uh not necessarily on Local Host but on the local IP address so if you’re running this on a server you can provide the IP address that you can find with the terminal so for example something like 1 192 168 and so on um or you can provide Local Host if you just want to run this locally or you can provide both by passing 000000 this is going to basically use the local IP address and Local Host so you can keep it simple and just provide this and then you can also provide a port I’m not sure what the default Port is we can actually see what the default Port is um and then you want to provide debug equals true now you don’t want to provide debuck equals true when you’re actually running this on a server when you’re actually deploying this but while you’re developing this application you want to run it in debug mode because then you don’t have to constantly restart the server you can just keep it running change the code and it’s going to update automatically uh and you’re also going to see the error messages and stuff like that uh but you want to turn this to false once you deploy the application so um right now I can just run this I think the default Port is yeah 5,000 but we can also change this for example you can say Port equals 5555 if you want to then you can run this and you can see it’s running now on Local Host and also on the private IP address and when I click on this it will open up a web browser and this web browser goes automatically to the default route slash and I get hello world as an output here and you can of course also change this to be HTML code so you can say here H1 and then H1 um yeah and and then this is going to to when you save this it will update because you’re running this in debug mode I can click on it and you can see now I have a heading here so this is the basic idea of a simple flask application what we’re going to do now in the next episodes is we’re going to add more routes we’re going to handle different types of requests we’re going to add uh Dynamic routes we’re going to add post requests and Status codes and templates and blueprints and all that but this is where it all starts this is the simple basic hello world application uh in flask and of course what you can also do is you can run this in the terminal you can just say Python 3 app.py this also works and uh just as one thing up front you can now take all the packages let’s say this is now your application you want to deploy it somewhere all you have to do for example to push it to GitHub so that people can uh use it you want to do something like um pip 3 freeze and then you want to pipe this with uh with the greater than sign with the close closing angle bracket you want to uh feed this into a requirements.txt file and when you have that you have this requirements txt file and then people can just go ahead and say pip 3 install dasr requirements txt and they can install all the packages that you have installed in this particular virtual environment all right so let us briefly recap what we did up until this point we created a virtual environment for our application so that we only have the packages that are relevant to this project that we’re building here and we created this simple hello world application in flask the idea is we import from flask flask with a capital f we create an application and then we add this index function which just returns hello world as a heading this is just some HTML code here and then we map this index function to the default route slash and then all we have to do is we have to run the application with the host 000000 which is automatically local host and also the private local IP address then we also customized the port to be 5555 and we set debug to True which has the effect of us not having to constantly restart the application to make changes or to apply changes uh it happens when we change the code and we also see the error messages instead of something like internal server error without any context so what we’re going to do in this video is we’re going to learn about routes we’re going to learn how to handle different types of um URLs so how to handle Dynamic URLs also also how to handle URL parameters and we’re going to learn about the different types of requests like post and get and put and so on um and we’re going to also learn how to return custom status codes so let us start with a very simple thing first let’s just add another endpoint here which has a different route so we can say here another function let’s say hello and this function will also return just a simple hello world maybe not as a heading this time uh what we can do easily we can just say app. route and the route can be something like SL hello the important thing is every route want it has to start with a slash so we have to say slash and then something and you can call this route whatever you want you can call it hello you can call it hello world you can call it ABC it doesn’t matter and it doesn’t even have to match the name of the function so I can call the route XYZ and I can call the function hello this is also fine and by doing that you can basically add as many end points as you want so what you have to do is you have to run the application and then you can just say slash hello and then you will get to this end point uh that is mapped to the function or that the function is mapped to now this is all static so I can add a bunch of those and they’re always going to be the same however what I can also do is I can add certain or so-called URL processor so I can have variables in the URL itself that I can handle in the function so so for example what I can do is I can create an endpoint here a route uh which I can call slash greet and then what I can do is I can add uh a name here so I can say I want to greet a certain name and how I can do that is I can use angle brackets to specify name here so now it’s not greed and then slash angle brackets name this is not the endpoint but name is now a variable that can be dynamic so I can say greet Mike greet uh Bob or something like that this and the way I handle this is I create a function and the function takes the parameter name so in this case what I could do is I could say fstring hello and then name so the idea is now in the URL itself I have the parameter name and I can go to the route greet SL mik and I would get a different response then when I go to greet SLB for example and uh we can see that this is the case by just going to SLG greet SL Mike and there you go hello mik SLG greet SL Bop hello Bop so this is what is called a URL processor now there are certain things that we can add to these URL processors so for example if I have a route um let’s call it at so slash add and what I have here is number one and number two then what I can do is I can Define the function add which takes the parameters number one number two but you’re going to notice something if I return for example an FST string saying number one plus number two is equal to number one + number two what you will notice is that when we go to the application and I actually go to add sl10 sl20 you will see that the result is 1020 and of of course this is because what happens by default is that the parameters that we pass are considered to be strings so they’re just concatenated so the string 10 plus the string 20 is of course 1020 that’s a string concatenation if I actually want to do a calculation I have to typ cast these parameters so what I can do of course is I can say number one equals int number one but I can also just specify the data type of the parameter of the um of the it’s not a URL parameter of the um value that is passed here as part of the dynamic URL I can specify it here in the route already so I can say it’s an INT colon number one and it’s an INT colon number two so what happens here now is that this is considered to be uh an integer already so I can say at 1020 and you can see 10 + 20 is 30 what happens now is though when I pass something else so when I say 10 hello I get not found because this is now obviously a string it cannot be typ casted into an integer and this route is only for integers so if I pass something that’s not an integer it doesn’t even have the route it doesn’t find the mapping so those are or this is how you do Dynamic URLs those are URL processors what we can also do is we can pass actual URL parameters and maybe you’ve seen this or probably you’ve seen this um on a couple of websites you go to something like uh login now hopefully it’s not done like this this is very secure uh but you usually have something like login and then question mark username equals and then something and then you have an ant and then you have password equals and again hopefully it’s not in clear text in the URL but these are URL parameters if you see them somewhere so how can we handle those in flask what we can do is we can do the following app route and then maybe let’s call this handle uh the suggestions you see here are by the way from my prepared code it just thinks that I’m going to write all the stuff again and I actually am uh so handle query or handle URL params let’s call it that way uh handle URL parameters and the function is going to be handle PMS or something like this uh now we don’t need to pass anything here now as a parameter the parameters here are taken from the URL so if I have uh these URL processors year they’re going to be part of the function signature if I handle the actual URL parameters it’s happening by uh using a so-called uh or using the request instance so what I have to do is I have to say from flask import flask and also request and then it’s going to be part of the request uh object so I can do here or actually I can return uh the string version of request do arguments so I can just return this as a string version and then I can go to handle uh what was it handle URL params and you can see it’s an empty dictionary so it’s an empty immutable dictionary but if I add now some parameters so uh question mark name is equal to mic then you can see I have name and mik in here and if I say ant greeting is equal to hello you can see I have name mic greeting hello so what I can do here is I can say that I want to handle the following thing the greeting is going to be equal to request. ARs doget and I can say here greeting and the name is going to be the same thing with Name by the way this is a dictionary so you can also instead of saying get you can just do this this also works um and then we can return for example an F string that says greeting and then name so when I go back I can just go to slash handle your url parameters and then name mic greeting hello hello mic so this is how you handle the URL parameters now of course if one is missing this is going to give me a bat request key so it makes sense to check if we have all the parameters available we can do something like if greeting in request arguments. keys and name in request arguments. Keys then we do all this otherwise we return some parameters are missing uh so now if I do this I get some parameters are missing and if I go to this I get hello mic all right um so this is how you handle the uh URL parameters now if you have a post request you actually get uh a form we’re going to talk about this I think in the next video so we’re not going to handle the post parameters yet so not we’re not going to handle forms that actually um include uh include information that we pass with a post request however what we are going to do is we’re going to learn how to handle different types of requests because all these routes all these endpoints that we Define here are by default only handling get request so we can see that this is the case by opening up a terminal uh I’m not sure if this works out of the box on Windows it does work on Mac and Linux uh you can use the tool curl and if you don’t have curl just install curl using your package man manager uh and curl basically just sends a request so I can say HTTP colon sl/ uh then Local Host slash hello for example and of course I need to specify the port which is 5555 uh and you can see I get Hello World here uh as an answer so I can just send a simple get request to an endpoint and I get whatever this endpoint returns to me now what I can do is I can also specify the method so I can say curl – x so capital x and then post to specify that now I’m sending a post request to the same same endpoint and what you can see here is I get as a response 405 method not allowed so the post method is not supported by this endpoint now if we want to change this if we want to allow for post requests we need to Define this in the route definition so for example if I want to allow for post requests on the endpoint hello what I have to do is I have to say methods equals and then I have to pass a list of all the methods that I want to support on this endpoint by default this list looks like this it’s just get however I can also say it’s just post if I specify it like that get requests are no longer allowed so I can save this I can open up my terminal and I can say curl um HTTP colon1 27001 5555 and then SL hello you will see it now tells me method not allowed even though didn’t specify post or exactly because I didn’t specify post whereas if I say DX poost you will see I get hello world so if I want to support both I just have to say get and post and then I can run the same thing it works and I can also run just uh now the displaying is a little bit messed up there you go I can also do it with get and I also get the same response now the difference between get post put delete is not really uh a technical one primarily it’s primarily a convention you use get when you want to get a resource when you want to get information you use post when you want to submit information so when you want to create something uh you use put when you want to update information so when there is for example uh if you have a to-do list application you already have an existing to-do you want to change something about it you use put and if you want to delete it you use delete so those are the four main methods there are also others but we’re going to to focus on those four uh and you can basically just specify that you want to allow for put you want to allow for delete and so on maybe you only want to allow for delete but this is how you use them get to get information post to create information or to submit information put to change information delete to delete information um now let’s say you support multiple of these methods on the same endpoint how can you differentiate between the two uh or between the three or four let’s say I have get and post here what I can do is I can say if request. method is equal to get then I want to have a certain kind of behavior so then I want to return for example here um you made a get request then I can say l if request method is equal to post then I can just print you made a post request now you can also if you want to add an else Branch but this is not going to be relevant because the proper message here is you will never see this message because of course we cannot send a put request or a delete request or anything else to this endpoint you will always only get a get or a post request so I can go again into the terminal maybe let’s go ahead and also add a back sln Indian just so we have a line break so that we don’t have to constantly mess up the formatting in uh in the command line so I can send this request you made a get request I can send a post request you made a post request and what you usually do later on we’re going to learn about templating and using HTML files and so on uh what you usually do is you have one endpoint that does something and when you send a get request to that endpoint you get the HTML template so you get basically the form to fill out with maybe create a new to-do you get uh when you send a get request to this create to-do page you get the form that allows you to create a word top specify the new to-do and then when you click the submit button you send a post request to the same endpoint to actually create um the to-do so in the get Branch you would serf the HTML file and here you would actually process the information from the form um all right so this is how you handle the different methods now last but not least I want to show you how you can return a custom response so how you can uh specify the status code that you want to return and for this we’re going to actually also use the hello here let’s go back and just return hello world and let’s only allow for get again um what we can do here this is the simple way to do it we can just specify the status code by passing uh or by returning it as a second value here so I can just say comma 200 and this will return a 200 status code now I think 200 is the default we can see if that is the case by just going again into the terminal and let’s just add again here for formatting reasons back ACC in uh we can go ahead and say curl but I can also specify here Dash uh what was it I wrote it down here um I think it’s- i- capital I to get the response header so you get HTP 200 okay and then you get also the content type the content length you can see it’s text HTML uh it’s content a Content length of 12 and so on now I can change this by just saying comma 2011 which is created so usually use that after a post request I can just curl again and you can see here now I get 21 created I can also change this to 202 and then you get accepted I can also change this even though it doesn’t fit here I can also change this to 404 which is not found and you can see I get not found I can also change this to 500 which is I think internal server error there you go I can also change this to 51 which is something else not implemented and I can also change this to something like 936 uh which I don’t even know what it is unknown there you go or I can change this to something like this I’m not sure if this is going to be rejected uh yeah unsupported Response Code and HTTP response so I have a video on this channel where I explain the different status codes when to use which one and what they basically mean I’m not going to go through all this here just know 200s are basically to tell you that uh everything worked fine 300s are for redirection uh 400 is telling you you did something wrong and 500 is telling you the server messed up something that’s like the most important thing to know um now we can also go ahead and create a full custom response so we can go and say from flask import flask request and make response and then we can craft a full response we can say response is equal to make response and then we can do things like response do status code is equal to 202 for example and then we can also say response and I can actually or response. headers and I can actually manipulate things like content type is going to be equal to and I can change this to application SL octet stream for example or Json or text plane or something like this so I can go now and you can see we get actually we don’t get this because we were still returning hello world we need to of course return the response there you go you can see now 202 accepted content type application octet stream uh and of course now we we don’t have any text so we would have to add here hello world back sln to have the content there you go and we still have content length 12 and if I just do it like this I still get hello world um we can also change this here to text/plain which is more fitting I guess there you go text plane 202 accepted and this is the content so this is how you can craft custom responses all right so we’re going to cover a couple of different concepts in this video today as I already mentioned we’re going to learn how to render HTML files we’re going to learn how to work with templates in addition to that we’re also going to learn how to redirect we’re going to learn how to dynamically get the URLs for specific end points and we’re also going to learn how to work with the Ginger 2 templating engine how to use filters how to create custom filters so it’s going to be a quite comprehensive episode today now what we have here is a very basic hello world project we just have a simple index endpoint and that’s it and up until this point every time we had an endpoint we returned some string some Json object something like this but not an actual HTML file and this is the first thing that we’re going to change now so what we’re going to do is we’re going to create a directory full of templates full of HTML files and then we’re going to render them instead of just returning a text and the first step to do that is in the definition of our application we’re going to add a keyword argument called template folder and we’re going to call the folder in this case templates this is what it’s usually called now this folder this directory now needs to be created here in our app application so I can rightclick new directory and I can call this here templates now to keep it very simple what we can do now is we can just create an HTML file in here let’s call it index HTML and in my case here I already have some basic structure just doc type HTML HTML head uh characters set defined a title and then an empty body and we can say the title is flask app and uh then I can just you know have a heading here hello world or something like this this is now an HTML file in my templates directory a very simple one now in order to return the HTML file and not just some text I need to import a function or a method called render template and now what I do is I render the template instead of returning hello world so I say return render template and then just the name of the file we don’t need to specify the path because we already know that the template folder is templates so all I have to do is I have to say index HTML and in this case when I run the application when I go to the browser you’re going to see Hello World the HTML file has been rendered now the good thing is now we can do a lot of things here that we can usually not do with HTML files we can dynamically uh change what is happening in this HTML file we can change the content of this HTML file and we can do that for example in a very simple way by just passing certain keyword arguments so for example I might have uh my value here and my value can be hello world or let’s change this to something else like uh uh let’s just call this neural 9 and then I might have some calculation my my result is equal to 10 + 20 I do some stuff here in this method I call some functions I do some processing and then I want to put these two values these two resulting values I want to feed them into the HTML file and I want to dynamically render them in the HTML file what I can do for this is I can just pass keyword arguments whichever keyword arguments I want I can say my value equals my value I can say my result equals my result and of course they don’t have to be the same name I can also say uh XYZ equals my value this is not a problem the important thing is that the name that I choose for the keyword argument so the left one is the one that I have to access in the HTML file the right side doesn’t really matter this is just a value um so now I have these two values and I can easily just go into my HTML file and all I have to do to display them is I can use some tag so for example a paragraph and in order to access these variables these values I just have to use double curly brackets and I can uh now specify the variable name so my value for example and I can copy this and change this to my result by the way I think that if you’re working in pyrum you need to set up the templating language I think you need to go to settings um template is there something like template language yeah you have to go with template language and change this to Ginger 2 because this is the templating engine of uh of flash but I think this only works in the professional Edition I’m not sure about that uh but it’s only about syntax highlighting you can also do it without that so you have these two um things here now and what I have to do or what I can do now is I can just go reload the page and you can see I get the values in the page even though I didn’t explicitly say neural 930 I get whatever I passed from the function here so that is how you use values that you pass now you can also do some more advanced stuff so for example what I can do is I can say my list equals and then I can have some elements in here 10 20 30 40 50 and I can say that I want to pass the list so let’s just pass the list only my list equals my list let’s delete these two things um and what I can do now is of course I can go here and I can just say my list this is easy in this case um what would happen is I would just get the list but I can also uh use certain other structures of the templating language so I can go ahead and say I want to have an unordered list so ul and then I want to have certain list items and I want to list all the individual elements of the list how do I do that I can do that with a Ginger 2 full loop so I can use a single curly bracket not not double single and then percent and then I also close this with percent curly bracket and here I can say now four and I can call this whatever I want item in my list now I need to close this with curly bracket percent and for percent curly bracket and in between now for each element in the list I will do something so I can also just say hello then I’m going to do this five times uh this also works as you can see uh but it makes more sense to have a list item and to have the content of this list item be double curly brackets item so what we do here is percent so single curly bracket percent for a full loop also for if statements and so on and we use double quot uh not quotations double uh curly brackets for individual variables or values then you can see here I get a list of the values so this is what we can do here um what else can we do now we can do a lot of things we can um do conditions so for example I can say uh curly bracket percent if item is equal to 30 uh what I want to do then is again also here end if then I can say if that is the case I want to have a specific list item where the style is color red item and I also need an else branch and I can just copy this here there you go uh and in this case now this one is red because I have this condition in here uh now of course I can also take this and make it more efficient by just not doing it like this by just saying here uh within the the list item I can just go and say percent if item equals 30 then add the style and if and otherwise don’t this has the same effect it’s just uh another way of writing it so basically we have the if here and then this is what happens if the condition is met so this produces the same result as you can see um all right so that’s like the simple stuff um this is the basic idea of templating um or at least of of of using values in the templates now what we can also do and this is now very interesting is we can inherit templates so let’s say I want to have the same navigation I want to have the same uh header I want to have or the same head section I want to have the same Imports I want to have the same content on every single page I have on my page uh or on my uh application uh and I don’t want to rewrite it all the time so actually the only thing that’s different about this index HTML compared to all the other files in my application is this content here I don’t need the rest this is just what’s unique about this everything else should be the same everywhere else maybe the title not what we can do for this is we can create a so-called base template so I can go ahead I can I can create an HTML file base. HTML and in this base HTML file I can now Define the structure so I can say we have this doc type HTML again HTML language English uh we Define a character set I have a body and so on um and the title now we can make Dynamics so we can say if you inherit from this template you will be able to fill in certain blocks so you will have certain sections that you can change and as such a section can be defined as curly bracket percent block and then we can choose a name for this section so title for example and then I also need uh end block the idea now is that when we inherit from this template we’re going to see how to do that here in a second when we inherit from this template we can fill in this section so depending on which page you’re in you’re going to get a different title however I can also put a default value in between so I can say default value for example this is going to be the default title if I don’t actively fill in the title in the sub page that is inheriting from this template uh and then I can do another block here in body I can say um again curly bracket percent block content and I can close this here end block and then I have some content here so this is now the basic structure and of course if I want to I can have a navigation here on each page and this is now always the same it’s not part of the block it will always be there um or maybe just to show you that this is the case I can add a paragraph here this will always be here because it’s not part of the uh of the block content here or of the block content here um and now what we can do is we can go into our index file and we can extend from this template so I can go here I can delete all of this here and at the top of my index HTML file I can say now uh curly bracket percent extends and then base. HTML like this so now it extends from base HTML it has the same structure and I can fill in the blocks now I can do the same thing block and title and block and in title I’m going to say here just index page and then I can say block content then I have my content here and I can close this block there you go so now what I can do is I can refresh the page you can see this will always be there and I still have the same content and I can do this now with a different page as well I can copy this I can call this other HTML um I can change the title to other page and I can you know maybe just have a heading here other something like this then I also need an endpoint for this so let’s copy this let’s call this other let’s put around to other and then just render other HTML there you go and now when I rerun this you can see here first of all we have um again here index page and then I can go slash other and this is still here and we get other Pages a title here so this is very useful because you don’t have to constantly uh make all the changes everywhere imagine you don’t do that and you want to include a new CSS file or a new Javascript file or you want to import bootstrap or something you cannot just do it here once you have to do it at every single HTML file you have and chances are you have hundreds of them depending on the size of your application so it makes a lot of sense to have this base HTML file um for the basic structure and then to just extend it here uh with with the other HTML files all right so now let us move on to a concept uh called filters now I have a video on this channel separately a separate video about filters in ginger um and I’m just going to briefly go through them so I’m going to create here a new or actually let’s use the other page for that let’s call it filters here um what we’re going to do now is we’re going to explore the effect of filters so very basic here let’s say I have uh some text that I pass to this to this endpoint I have a text and let’s call this text just hell World Su text equals Su text now as we already saw I can just display this in a paragraph here in a very simple way by using double curly brackets some text just to see that this still works there you go hello world now what I can do is I can say I want to have certain operations applied to that a very simple one is I want to have everything in uppercase now what you do in Python is you call the Dot Upper function or you call other methods of the string this is not really possible here in ginger what what you do in ginger is you use templates and to use templates uh not templates sorry filters uh and to use filters you need to pipe the text through a filter so we use the pipe symbol and for example one filter is upper this is a built-in filter you need to to know that these exist there is a there’s a list of them in the documentation but this is a built-in filter and now if I go to the page you can see we get hell World in uppercase I can do the same thing in let’s maybe just keep all of them to compare them I can do the same thing with lower so now if I go here you can see it’s all lowercase and there are also other filters so for example I can do title I can do stuff like uh replace where I can also add parameters so I can say replace all the else by uppercase lse for example this works so here you can see title case is just default and then we have here the replace filter active um and then we can also do uh or actually you know there there’s a huge list of different filters that you can use but what I’m interested in showing you here is that you can also Define your own custom filter so you can say uh let’s say you want to have a a filter that reverses the string for example for some reason you want to do that um this is not a filter as far as I know that is available by default so you have to implement yourself and you can easily do that by going into your appy and importing from flask here um or actually I don’t even think we need to import anything sorry uh we can go down here and we can create now not a route so not app. route but app. template filter uh and we can call this filter for example reverse string then I can call the method reverse string and it takes something as a parameter um and this parameter is just our text so our string s and what I can do now is I can just return s and then I can reverse it like this colon colon1 this is just how you reverse the string in Python and now what I can do is I have this reverse string here I can go to my other HTML and I can say reverse string and now I can go here and you can see it reverses the string it’s my custom Behavior I get some input and I return some output this is my filter I can do other filters as well I can do a filter called uh what did I have here repeat is a very simple one repeat also takes additional parameters so I can say repeat um and repeat takes a string and I can also say it takes times and Times by default is two but it doesn’t have to be it can also be 10 and then I return just s * times so I can go here I I can copy this I can say repeat and I can say repeat five and then you can see Hello World hello world and then I get it five times as well um maybe another thing that we can do is we can alternate the case is just now one more example here we can go and say app template filter alternate case basically everything that’s uppercase will be made lower case and vice versa so alternate case of s and now we can return here MP string join I’m going to use a list comprehension character upper if I or actually uh no this would be swap case alternate case means uh you have uppercase lower case uppercase lower case uppercase lower case so what we’re going to do actually here is we’re going to say if the index is um modulo modulo 2 is zero so if it’s an odd uh if it’s an even number we’re going to do c. uper else C do lower for i c in enumerate s and then what we get is of course we need to apply it as well let’s go to other alternate case there you go we get this uppercase lower case uppercase lowercase uppercase and so on so this is how you use filters now one last thing or actually uh two things that I want to show you here now is uh one the redirect and two how you get Dynamic URLs so how you can get um Dynamic how you can get the the the URL of an endpoint dynamically without having to specified statically because of course it can change so first of all let’s do the redirect um or actually first of all let’s do the the dynamic URL because the redirect can then use the dynamic URL for the redirection uh now let’s say on my index page I want to have a link to other so I want to have a link to the endpoint other now the endpoint other might have actually this URL here but I might uh I might change this over time so I might say this is something else now I don’t want to manually Define that this is the endpoint uh or that this is the route to this endpoint so what I can do here in the index pages I can have a link I can have an A an anchor tag uh with the following destination and now I can use double cly brackets again and I can say URL or4 and then I just pass the function name other and then I can say here other now you can see I didn’t specify the route at all but if if I now go to to this and I reload the page you can see I have a link to other and you can see in the bottom left that it actually gets me to this page so you can see here that the link is going to this URL here to this endpoint dynamically if I change it it’s going to change as well so if I go here and I change this again back to other it will also change in index HTML without me having to do anything there you go still works uh now this can also be used for redirects and this can also be used in the python code not just in HTML not just in the templating engine so for example what I can do is I can say let’s add a new endpoint here app route redirect endpoint and then I can say redirect endp Point here uh what I can do now is I can return instead of returning a template or a text or something I can just return a redirect and for this I need to import the redirect function and I can just say return redirect and the location now I can of course say just slash other but I can also do and for this I need to also import URL 4 I can just call the URL 4 function here URL 4 and then other for example redirects me to other um so if I now run the application again and I go to slash redirect endpoint you can see I end up at the other page so yeah this is how you can do that this is how you work with templates this is how you render HTML files how you can use uh filters in ginger how you can extend templates and uh how you work in general with actual HTML content not just text all right so we’re going to cover a lot of different things in this video today primarily we’re going to focus on handling post requests in the back end in a more advanced way than we already did in episode two we’re going to learn about forms we’re going to learn how to handle forms data we’re going to learn how to send post requests using JavaScript with Json data we’re going to learn how to handle that Json data we’re going to learn how to upload files how to process uploaded files how to respond with a file download for the user uh and stuff like that and what we have here now for the beginning is a very basic flask application which just renders an index HTML file this index HTML file just has a heading hello world and it extends a base HTML template nothing too fancy here very simple we already know how all of this works I can run this so that you can see what this looks like again just a basic hell World page and what we want to do now is we want to handle a post request but we don’t want to do it the way we did it in episode to with curl with a command line tool we actually want to have an HTML form where I can input some data where I can press a button and then the post request is sent and something is done based on that post request so what we’re going to do here is a very simple example is a uh dummy login page so we’re just going to have username password and then we’re going to send a post request with username password and if they match some static string then we’re going to say success otherwise we’re going to say fail so this is of course not an authentication system it’s just a dummy page that you know processes username and password and Compares them to Strings but it’s a good start to understand what is happening here or how this works so we’re going to use index for that and what we need to do first is we need to specify that multiple methods are allowed here by default remember get is already allowed but we still need to specify it here if we want to change this uh and we now also want to allow for post requests here so the idea is with a get request we want to get the HTML page to display the form and then when we submit that form we want to send a post request and then we want to process the data that was sent so what we’re going to do here is first of all import request and we’re going to distinguish two cases between two cases if request. method is equal to get then what we want to do is we want to just render the index HTML file otherwise if request method is equal to post we want to do something else that we don’t have yet so I’m just going to return an empty string for now uh we’re going to implement that once we have the form so what we want to do now is we want to get into index HTML and we want to create a simple form so I’m just going to say here form and now we need to specify a couple of things we want to say method is equal to post this is a post request that we’re sending and the action is the target URL that we’re sending this to here for this we’re going to use again double curly bracket URL 4 and the endpoint that we’re sending the post request to in our case index now of course what you can also do if you want to you can also create a separate endpoint login that only accepts post requests and then index only accepts get get requests and then of course you can also send the action to another page you don’t have to send it to the same page you can also send it to a different endpoint uh but we’re going to do it like this now and in this form we’re going to have two basic fields in input type textt now the important thing here is the name we don’t need an ID this is more for CSS stuff or styling we don’t need a class we need a name the name is important because the name is what we’re going to get as a key uh for the key value pair in the backend so we’re going to say that the name is username here uh and then we’re going to define a placeholder username and then we’re going to copy this type password name is going to be password and placeholder is going to also be password like this and then finally want to have an input type submit with the value login and probably we should add some line breaks here so when I run this here you can see we have this basic form I can enter some stuff and I think if I just do something I’m going to get an empty response here because remember if we send a post request which we now did we just get uh an empty string as a as a result here so what we would actually want to do is we would want to compare the username and password to our quote unquote actual username and password so what we do here is we say username equals and now we have to get the username from the post request that was being sent so we’re going to say request. form now this is important if you get the request from a form the post request comes from a form we get request. form Dot and then get key or you use it as a dictionary however if you send a request with JavaScript and you send a Json object you have to use request Json we’re going to look at this here in a second request form and now I can access the key username like this or I can also say form. get usern name whatever you like it’s the same thing it’s just a different way of writing it then password request form get password so now we get these things from the post request and of of course if you have some optional stuff uh it makes sense to first of all check if it’s part of the form so you can say if and then before getting it because in this case you would get an exception if you have something that’s not part of the form that was submitted and you try to access it you’re going to get an exception it’s going to crash your application what you should do is something like if username in request form Keys only then get username but in this case there’s no way uh to not get to not get the username because we’re going to use the application properly so for now we’re going to ignore this but this is how you get the two things now from the form and now we can say if username is equal to let’s say neural 9 and password is equal to uh let’s say password then return now we’re just going to return a text success otherwise we’re going to return failure like this so I can go here again I can type some nonsense there you go failure and now I can go and I can say neural n password success so this is how you handle very basic form data now what we can also do is we can upload files this now gets a little bit more advanced because you need to consider a couple of things when you upload files you have to to uh provide specific types of in puts you also have to change stuff about the form itself and you have to also access the files in a different way so this right here is a very simple way you just have some input stuff you have some text password number whatever and you just name them and you just access them this is how you handle basic form data you can now add a bunch of other fields here with type number and stuff like this doesn’t really matter it’s the same way of handling it you just get the form dictionary and then you get the individual keys and again if something is optional you just say if whatever key you have some key in request form Keys then get it from there to keep it safe now we’re going to handle files and for this I want to actually create a new uh a new endpoint I want to create an endpoint file upload so we’re going to say app route slash file upload file upload and and here now we want to handle what happens when a file is being uploaded for now I’m just going to return an empty string because first of all again I want to handle this in the HTML file so we’re going to create another form here let’s maybe add a heading in between to know the different sections we’re going to add a new form here and we’re going to start the same way method is equal to post action is going to be equal to now of course different URL so URL for the method or for the function file upload and the important thing now is that we need to specify an encoding type we need to say that this is now uh we we need to add this parameter here en type is equal to multiart form data because we’re going to pass files now so it’s a different type of encoding that we have to use here multiart form data this is important then what we can do is we can say input and the type of the input is file however this is not all of it because file is very generic what kind of file are you expecting are you expecting any type are you expecting any kind of file or are you expecting maybe just plain text or just uh Excel files or just CSV files or something like this uh depending on that you’re going to have to specify uh a different keyword here or or a different uh parameter here in a second so we’re going to say the name is just file nothing too fancy uh and what we want to do now is we want to say accept equals and accept equals now you can specify certain uh content types now what these content types uh content content types are exactly you have to Google most of the time here in py charm I have uh all the suggestions which is very convenient but um if you have a certain file type that you want to uh allow for here you need to Google what the content type string is actually uh what I want to allow here now is I want to allow uh Excel files so basic Excel files XLS and xlsx and also plain text so how do I do that I have to know what the proper um content type is for Excel and I think it is um application vnd D and then we need open XML formats so you have to scroll for a while here oh actually I don’t think that we have it here so I have to type it out applications SLV and. openen XML formats Dash Office document uh do spreadsheet usually you want to copy that you want to you don’t want to type this out actually I’m going to copy this now because that that’s no uh there’s no value in uh in doing this here so let me just mark this and then copy this to my clipboard then I’m going to just paste this here so the idea is you get the content types in this case I have three content types this is one then I use a comma to separate them then I use another one and then I use a comma again another one so here I have uh Excel Excel again and then uh text PL so txt files so that’s basically it then I can also set this to required equals required even though I think required in of itself should be enough let’s do it like that and then I can use again input type submit or yeah submit and then the value of that is upload file so let’s go ahead I can browse the file I can use data xlsx I can upload the file and in this case it tells me method not allowed because in my file upload here I didn’t specify that the method that I want to allow here is equal to post let’s go again upload the file and I get nothing in return because of course we had return an empty string so now it’s about handling that file let’s say what we want to do here in this case is we just want to uh in the case of a text file we want to to return the content of the file so we just want to display the content of the text file in the case of an EXO file we want to uh render the table we want to load it into a data frame and we want to render the table um to the HTML file so we want to show an HTML table off the data frame for this of course we need pandas so if you don’t have pandas installed uh this is now just an example by the way if you don’t care about pandas you don’t want to process Excel files just skip this you don’t need to work with that that’s not part of the course but we’re going to do this here now as an example in this case you would have to install pandas like this pip or pip 3 install pandas uh and of course we need to also then import pandas SPD um and now what we would do here is we would first of all get the file so we would say that the file is equal to request do files this is now a separate field it’s not form it’s not Json it’s files specifically for files and here want to get file this is again the name here file uh what we now want to do is we want to look at the content type of the file and decide what we do with that file so we’re going to say if file. content type is equal to text/plain if that is the case all I want to do is I want to return file read read the content of the file decode it so that it’s a string because it’s binary data I think uh by default since we have uh the encoding type um and that happens when we have a text file otherwise if the file content type come on file content type is equal to the Excel stuff and I think for this I’m going to just do it like this or file. content type is equal to that so just a two different uh content type strings if it’s one of those then what we want to do is want to say data frame is equal to pandas read Excel and then uh the file like this and then what we want to return is just df2 HTML which is a method in pandas that allows us to turn the data frame into HTML so that we can easily just uh display it all right so that is it and we can actually see now hopefully that this works so I have data xlsx I can upload it and you can see I get the content of the Excel file this is the content of the Excel file uh as HTML here rendered now I can also go here now and I can create uh a text file let’s call this hello.txt and I can say hello world this is a text file with some text and then I can go here I can browse I can get hello txt upload file and there you go now the line braks are not displayed properly but that’s okay uh and you can see we can distinguish between content type and get different responses so this is how you handle file uploads you get a file from request files this is just whatever file you submit here is input type file you accept certain file formats you can check for them you can process them in different ways depending on what the content type is so that’s actually quite straightforward and simple let us now actually go and Implement uh a use case that might be interesting let’s go ahead and convert um an Excel file to a CSV file so we take an Excel file and we take the content that we displayed as a table here in HTML and we want to return so this is now also about a file download as a result of the request we don’t just want to display something we actually want to return a CSV file to the user that the user can download so how can we do that for this what we’re going to do is we’re going to create an endpoint app route we’re going to call this convert CSV by the way the reason you already always see uh the names that we’re going to use is because I have all the code prepared so it already knows what I want to call the functions or the routes at least so convert CSV is going to be the endpoint um and here now all we want to do is we want to take the file and we want to return the converted version so the csb file and for this now again we’re going to just copy this part going to paste it down below I’m going to change this to convert to C vsv and now we’re not going to allow for text plane we’re only going to allow for EXO so we have um and also we’re going to not send this to file upload we’re going to send this to convert CSV and it’s important of course to specify here again methods is equal to post we accept post requests on this endpoint and uh the idea is the same now we get the file we say file equals request files file and in this case it’s always going to be an Excel file we don’t even need to to check for this it’s always going to be an Excel file because those are the two things that we accept um by the way let me just I hope this can be run right now you can see which types are supported down here you can see now since I in the first form allowed for Excel Excel and text file these are the supported types and only these are actually displayed here uh whereas here now I only have Excel and Excel um all right so we know that this is going to be the file type what I can do now is I can load this into a data frame again pd. read Excel file and then I can craft a response that I can give to the user and in this response I’m actually returning a file how do I do that I import from flask response with a capital R and then I do the following thing response is equal to response and here I specify a couple of things first of all what am I responding with and what I’m responding with is a CSV file so df2 CSV I’m taking the data frame and turning it into a CSV file and since I’m not specifying a path here I’m getting the object itself as a result so df2 CSV then I specify the mime type which is the content type and the string for CSV is just text SL CSV and then what I do is I say header equals and here I pass now a dictionary with a key content disposition and we pass uh the value attachment and file name equals and now now you can choose the file name of the CSV file now this is important this optional but this is important because the file itself uh doesn’t have uh or actually I’m not sure if this is uh in this case is even optional maybe it’s even mandatory but the thing that you’re returning you need to also specify a file name for it and what you can do with this header field is you can specify what the download name is going to be because there’s also another use case which we’re going to look at in a second where you actually have the file stored on your system and the file might have a completely random file name but you want to return it as result CSV for example so this is why you need this header and now what we do is we just return the response itself so again we get the file we load it into pandas we turn it into a CSV file we specify the type we specify the header with a file name and that is it so now this should already work I load the Excel file upload file and now you can see that for this I’m going to now navigate to my uh directory here result CSV I don’t want to do that come on current save result CSV and now I have a CSV file with the information from the Excel file so this is one way to serve a file this is one way to return uh a file for download we can find a second way now or we can do a second way now uh which is you get the file you download the file from the user so the user uploads the file and um you you process the file and what you do is the result you don’t return it immediately you save it in a downloads directory and then what you do is you return to the user a download page with a separate button so the user uploads an EXO file clicks on convert and instead of just getting the file as a result he’s redirected to a download page and at this download page uh the file is then loaded from the system from the server uh and download it this is in my opinion more professional most of the time you don’t want to just return the file immed medely you want to have a download page uh and then you can download the file from there but of course it depends on the use case so we’re going to call this convert CSV 2 um and the function is going to also be called convert CSV 2 and of course this takes methods equals post and what we want to do now here is let’s copy this convert to CSV 2 convert CSV 2 uh we’re going to have to add a couple of things here because we need a download template in our application we need to have here a download HTML file which actually I’m going to just copy index I’m going to call it download HTML and for now we’re just going to have downloads as a heading here and actually nothing else I’m going to add the stuff later on um and in our convert to function now we’re going to do the same thing file equals request. files file then we’re going to load this into a data frame so PD read Excel file and now what we’re going to do is we’re going to see does the download directory that I want to store this in uh the CSV file in does it already exist if not we’re going to create it and then we’re going to place the CSV file there so that it can be downloaded later on uh for this we’re going to need the OS module or package so import OS uh and we’re going to say if OS do path. exists or actually if not OS path exists downloads we’re going to do OS make deers downloads and then we’re going to create a file name we’re going to say file name is equal to and the important thing now is we want to have some file name that’s completely random it doesn’t really matter but we want to make sure that we don’t use the same file name that’s maybe already there and for this we’re going to import another uh python Library uu ID which is basically generating a random ID which is almost certain to not be the same as one that you generated uh already so it’s very unlikely that you’re going to generate something that you already have so we’re going to say file name is equal to uuid uuid4 and then CSV so just some generated file name and now what we’re going to do is we’re going to save the file with this file name and then we’re going to return download HTML and we’re going to pass the file name as a parameter to the HTML file so that the HTML file when you press download knows which file to actually download um so we’re going to say df2 CSV and then um OS path join downloads and file name and then we return render template download HTML and the file name is equal to file name now the important thing about download is now it has to actually download from an endpoint so it actually needs to call an endpoint that makes the download that performs the download so we’re going to create this one app. route download slash download actually and then we’re going to just call this download and here what we’re going to do is we’re going to return and this is now a function that we need to import again from flask it’s called sent from directory so we send from directory and this is now the directory downloads the file name file name which uh we need to pass here or we want to pass here as a URL parameter so I’m going to just call this file name I’m going to pass this here as file name this is now again these uh URL processors we passed a file name here and then the downloador name is what we want the file actually to be called so again we have some random file name some numbers and letters mixed together CSV but the download name should be result CSV all right and then finally what we need to do is we need to go to download we need to create an anchor tag with the following url url 4 download and the file name is equal to file name then download file so if I’m not mistaken this should actually be it uh I need to run the application there you go now this is not the best styling I know uh let’s go ahead upload data xlsx upload file now I’m redirected to download we can see here behind the scenes a downloads directory was created with some random file name you can see here the uuid it’s the CSV file and now what I can do is I can download the file and and I get result CSV I can save it replace the existing file and I now have the same file here and if I do this again I’m going to get a different file so I can do this again upload file and now you can see I have a second file here and I’m going to download it and it’s going to be result CSV again and of course uh you should probably on a regular basis clean the downloads directory otherwise you’re going to get a lot of different files that you don’t need anymore maybe once a day you should clean it uh but yeah this is how you can do that um then finally I also want to cover how to post Json data with JavaScript so this is now no longer python in HTML now we’re going to actually use JavaScript to send a post request with a button click now why is this useful it’s useful because sometimes you’re going to have um some button or some chat or something that you want to use to send request to the backend so a very simple example of that is you have a chatbot you have a chat window and you have an AI model in the background answering uh the request you have an endpoint that you need to communicate with but you don’t want to actually send form data so to chat with a chat bot you don’t want to send you don’t want to fill out a form with your message send uh the request and then be redirected to another page to get the response you want to do this dynamically in the same window you want to just send a request using JavaScript get the response update the HTML and so on this is why you want to do that so for this let me just close all of this let’s go to index again we’re going to do down below H1 JavaScript Json request and all we’re going to do here now is we’re going to have a button and the button will have an ID this is now important the ID is important because now we’re working with JavaScript JavaScript works with ID and ID is a unique identifier for a specific element in HTML and we’re going to call this post button and we’re going to say send post request and what we need now is we need an endpoint that we’re going to send a request to this is going to be the endpoint that handles the Json data and for that we’re going to go to appy we’re going to create an endpoint app route let’s call this handle post which of course needs to take method post and we’ll post and what we do in this one here is we get the ad Json data we expect this post request to be a Json uh to have the content type Json so we say here um what we’re going to do is we’re going to have a greeting and a name and we’re going to process a greeting and Name by writing it into a file and then returning that the file was successfully written so we’re going to say greeting is equal to um to request. Json and then greeting I can copy this name equals request Json name and then I want to say with open file.txt in writing mode SF fite and then just greeting name and then we want to return just adjacent object saying that it was successfully written so key message and value successfully written so I can just do it like this message and then successfully written now the best practice way to do this is to jsonify this to make sure it’s actually ajacent object so you want to import jsonify from flask and you just want to call the function on this so jsonify on this dictionary that’s it so this is our endpoint and now we’re going to send a post request to that endpoint using JavaScript so script we’re going to create a script tag down here script type is text JavaScript and the functionality is going to be the following we’re going to get the con uh the button is a constant here so const uh post button is going to be equal to document. get element by ID now this is core JavaScript you probably want to use something like J query if you’re actually doing some JavaScript stuff but this is now core JavaScript get element by ID postore button uh then const Json data is going to be equal to and now let’s just go with name or actually we don’t need quotation marks your name is going to be equal to Mike and the greeting is going to be equal to hello and of course in the case of a chatbot you would not just statically Define adjacent data you would actually get it you would get the content off a text box that contains the data you would get the content from the chat window you would update the content of the chant window but we’re keeping it simple now we have some static Json dictionary here some static Json data and now we’re going to add an event to the post button we’re going to say post button. add event listener and the event listener that we’re targeting is Click so when you click on the button the following is going to happen we’re going to have an an anonymous function here just uh parentheses then equals and then the greatest uh greater than sign so an arrow basically then CI brackets and in here now we’re going to call the fetch function and the URL is again we can get it dynamically URL 4 and the URL 4 is going to be handle post so that is where the request is going then again k brackets to say the method that we’re using here is post and we need to specify the headers because of course what we’re sending is Json data but we need to also specify it’s Json data so we’re going to say content type is application SL Json then semicolon character set is equal to utf-8 encoding basically and the body this is now the content the body is equal to json. stringify Json data um this is basically sending the request what we want to do now also is we need to respond or we need to to we can respond so we can say here uh dot then what happens then response is response. Json and then do then we can say data console lock and we can lock that this was successful success is uh success data here so success colon data um and then finally we can say catch if there is an error we can also uh we can also come on not used to JavaScript I don’t like JavaScript so I have to constantly check my second screen console do error and we can just lock the error message yeah that’s basically it and uh I think this needs to be closed and this also needs to be no actually is this where is this closed this is actually closed here I think I messed up something in my code yeah of course because we need it like this all right so to just go over this again we Define the element post button to be the element in document that has the ID post button which is our button here we have some static Json data in an actual application you would read this from the text boxes then you add an event listener to the button when the button has the event click then the following thing happens we fetch to the URL of the handle post endpoint with a post request we have the content type Json we get the Json data we stringify it that’s the body then we get the response we get the data we lock the data if it was successful if there’s an error we lock the error message that is what we do here so let’s go ahead and go to the site let’s go ahead and open up the console let’s send a post request there you go success successfully written then I can see I have file txt hello mik so this is how you can handle Json data from JavaScript script post requests all right so we’re going to learn how to work with static files and flask in this video today which means we’re going to learn how to work with images CSS files javascripts and so on how can we load these things into our HTML files how can I specify the path to an image how can I link to a stylesheet how can I load a JavaScript from the respective directory how is this done in flask properly and how do I work with static files in general in addition to that we also going to use that knowledge to integrate bootstrap into our flask application just so you see how you can integrate something simple like a CSS framework uh and yeah this is what we’re going to do in this video today so this is our starting point we have a simple flask application just an index endpoint rendering the index HTML file which just extends the base HTML template we just have a simple hello world heading here and now let’s say my goal is to display an image here so let’s say I want to have an image Tech down here this is basic HTML I have an image the image has a source and uh the image also has an alternative text so something like this here um and that is basically our image here how do I do that now in flask so where do I put the images how do I link to the images because for our templates is very simple we have a template folder and we just specify the name of the HTML file so we have the templates all the HTML files here in the templates directory and then in order to load the HTML files I just have to specify the file name how do I do that now with static files the way you do that with static files is very simple to the way you do that with templates you define a static folder so you have to add an additional parameter here an additional keyword argument called Static folder equals and then you can choose the name of the static folder usually you call the static and then in addition to that we also want to specify a static URL path so how do we uh get there and what I like to do or what it’s usually done is you just pass slash so simple slash and then you can access all the different directories uh from the static directory just after the slash so in addition to templates now here we add an additional directory called Static and in this directory what I like to do and what is usually done is you have different directories for the different types of static files that you want to serve so you can have something like IMG or images you can call this whatever you want I like to call it IMG then you have maybe another one for uh CSS and then maybe you have another one for scripts or you can call it JavaScript or JS whatever you want to call it so CSS IMG JS again you can call this uh CSS images scripts something like this doesn’t really matter but now you have the static directory the static folder which is also defined here in the application and when I now uh put an image here so for example I have here the prepared logo. jpeg just in theal 9 logo I can just take it drag it into IMG and now this image is in the static folder and all I have to do to display it in the index HTML file is in the source I have to say SL IMG SL logo. jpack and it’s automatically going to recognize since I have static as the folder and the URL path is slash I can just go into slash IMG because I’m already in static when I go slash I can go IMG logo JPEG and that’s it so I can run this application and you’re going to see that we have the neural 9 logo here very simple and this now works of course with stylesheets with scripts whatever you want to do you can do that uh so for example I can go ahead and I can create a file called style.css and here maybe I can create a class special and this special class here I want to say that the color of the text in that class has to be red and the font size has to be I don’t know 18 PT and then I can go into my index HTML file I can create maybe uh span or something give it a class special and I can just add hello here then I can go to my application uh and of course we’re not going to see anything for uh first of all let’s let’s make this a paragraph uh but of course we also need to uh to include the stylesheet sheet into our uh HTML template so let me just show you again that we have hello down here so The Styling is not applied even though I had the class uh set to special of course we need to also include this CSS file and how you usually do that is you go to the Head section which is of course in our base template not in our index file uh and here I do a simple link Rel equals stylesheet type equals text CSS and The Source or the path is equal to/ CSS SL style CSS like this then I can load the page again and you can see the styling is applied because it loads the static files from the static directory um what else I can do is I can create a JavaScript so for example I can go and I can say um I want to have a simple JavaScript that displays some popup after 5 seconds so I can go ahead and I can say uh hello.js and I can Define window onload is equal to a function that is called when the window is loaded and this function what it does is it sets a timeout and there’s another function in here and what we basically do is we just alert which is just pop up the warning hello world and we do that after 5,000 milliseconds so after after 5 Seconds basically uh that is our JavaScript now this alone won’t do anything if I open the page and wait for 5 seconds nothing’s going to happen because of course the script is not loaded in the index HTML file I have to load the script again from the static directory uh for example here at the bottom I can just say script and then um source is equal to uh sljs hello JS like this not sure if I have to specify a type I don’t think so now we can wait for 5 seconds and we should get a popup after 5 Seconds there you go hello world and yeah this is the basic idea of how you load images and CSS files and JavaScript files everything that’s static can be just placed here and you can just access it because you defined in the app py file here in the definition of the app you define the static folder and the static URL path so we can use this now of course to also integrate bootstrap so we can go to the bootstrap website which is this one here um and basically you can just download the compiled CSS in JavaScript you can just uh download the zip file which I have here then we can go and open files I can just open this and here we can see we have Js and we have CSS so all I have to do is I have to go to static JS I can take all these files here I can extract them I can go back I can go to CS CS we can go up here CSS take all these files drag them in here and now we have bootstrap basically installed uh in our flask application that was already it the only thing that you need to do now to actually be able to use bootstrap is you have to of course uh link the stylesheet and uh load to JavaScript so I can say link real stylesheet type text CSS and then SL CSS slash and then bootstrap.css and then also here I can go and I can say script source is equal to sljs SL bootstrap.js there you go and now in index for example I can go ahead let’s remove the image uh I can go ahead and add a button or an anchor tack so I can just say going nowhere let’s just use a filler here um I want to have some button text here and I can go ahead and I can say class equals and now BTN BTN primary for example which is these two are bootstrap classes that Define uh The Styling of the button you can see this is now a bootstrap button and of course if I change this to button uh danger I will get a red button that is bootstrap as you can see loaded and working all right so we’re going to learn about session management and cookie management and flask in this video today and we’re also going to learn about message flashing now let us get started with the first two sessions and cookies the basic ideas here are quite similar because in both cases we want to keep track of information we want to store information that is relevant for multiple requests so we want to keep information across multiple requests because HTTP in general is stateless which means we have a request and a response and we don’t have a state that keeps track of information uh about the overall exchange so if you want to do that you have the two basic ideas or the two basic methods to have a session or to have cookies to use cookies on the client site or to keep track of session information on the server site that’s the major difference the location of the storing and also for security reasons if something is sensitive and you want to be able to trust it you want to keep it in the session you want to keep it on the server side and um if something doesn’t really matter it does really matter if it’s changed it doesn’t really matter if the user sees it you can store it in a cookie on the client side so in the browser because whatever you store in a cookie on the client side can of course be changed by the client can be seen by the client whereas if you just provide the client with an ID with a so-called session ID and then you store the information uh for that session ID on the server and you do all this with a secret key you sign it with secret key and so on uh this is more secure so these are the two things we’re going to talk about out here now this is again our basic starting application we have an index endpoint rendering the index HTML file quite simple and we have the base HTML template here uh that is extended by index HTML very simple now the first thing we want to do here in order to be able to use sessions is we need to set a secret key for the signing for the encryption basically so app. secret key has to be set to something now in practice you want to use a good secret key here um for learning purposes for testing purposes you can use whatever you want just some key here uh again if you have an actual application you want to definitely uh set this to something yeah proper but you have now this secret key and with this secret key now you can uh issue basically uh session IDs and you can keep track of information uh of individual users of individual clients on the server site so for example if I want to do this in the index endpoint or actually let’s create individual endpoints for all of these things we’re going to talk about here um let’s do slash set data and let’s call the function here set data as well and what we want to do here is in the session and for this we need to import from flask import session here uh in the session dictionary you could say we want to set now some field to something so for example I can go and say name equals mic now these are just examples you can of course do whatever you want here in reality in actual applications as I mentioned the session data is something that is usually sensitive or that should not be changed by the user that should not be seen by the user maybe something that is not um yeah something that you’re supposed to be able to trust on the server side that’s the basic idea so session name equals mik and then session maybe something else let’s call it other equals hello world whatever you want to call it so this is now information stored in the session dictionary in this case um and this will be associated with a specific session ID so what I can do here now is I can say return render template and I can you know return index HTML maybe what we’re going to do here is just so we see the difference because I’m going to return here a couple of times uh I’m going to add a paragraph here and in this paragraph we’re going to just have some mess message and the message will be passed uh here so I can say message equals index and here I can say message equals session data set or something like this uh and then maybe Also let’s go ahead and have a couple of anchor Texs here with URL 4 so that we can have some buttons to play around with URL 4 set data and then set session data so let’s run the application and let’s open this up there you go so now I can click on set session data and it says session data set and I can actually see that in my browser if I right click go to inspect and then I go to storage you can see that I have a cookie here so I have a cookie here uh in Firefox and the name of the cookie is session and the value is something that I cannot really read you can see I don’t have any information here I don’t see the actual values for name and other I just have a session cookie and the server has the information for name and for other and I can just get it the server can provide me the information if the server wants to but I don’t have the information here on the client side I just have this session cookie um that I can identify myself with basically so now I can make another end point I can create a route app route um get data and here now I could just go ahead and render the data as the message or into the message so I can say that the name is equal to session name that other is equal to session other and then I can just return render template index HTML and the message will be a formatted string and F string where I have this information so I can say something like name name and other other whatever and then of course I also want to add an anchor tag for this so that we can easily do these things interactively so here I have set session data get session data set get now the interesting thing is I can go now into my memory uh or actually storage and I can delete the session cookie so I can delete my identifier that the server needs to know who I am that the server needs to understand that this is the same session so I can just go ahead delete this and now if I go to get session data I get the key error name because there is no session for this I don’t have a session uh cookie I don’t have a session ID so there is no data that the server can provide me with so actually what would make sense is to say something like if name in session do keys and other in session. keys if that is the case do this else just return with the message uh no session found so in this case now get session data no session found set session data get session data there you go so again this is all happening on the server side this is for security reasons this is what you want to do if you have some sensitive information and you want information that the user cannot change now we can do the same thing now uh or actually before we go to cookies let me show how you can clear a session you can also create an endpoint um app route and then uh we can say clear session and then clear session is also the function what I can do here is I can say session. CLE and then this basically clears the session uh the sessions entirely so it clears all the session data and uh I can then again just copy this and return the uh the message session cleared so now when I run this I don’t have a link to this so let me just add this maybe also with a line break to get a better overview um clear session clear session data then I can clear it now when we look at the storage I don’t have anything here I can set it then I can look again I have a session cookie I can get it still still have the session cookie I can clear the session data and I don’t have the session cookie anymore uh and now I cannot get it because it tells me again no session found so that is how you work with sessions now cookies are quite similar the important thing again is cookies are um cookies are stored on the client side now actually one more thing before we get uh on you can also just pop individual Fields now I’m not going to run this now to not spend too much time on this but if you don’t want to clear the whole session but you only want to pop individual um individual Fields you can also do something like session pop and then name for example so you can pop the name key value pair from the session but then you would still have other so if you have some mechanism for only reading certain parts of it you can also only clear certain parts of it so let us move on to the cookies now let’s say we have a route we want to call this route uh set cookie and the method is also or the function is also so set cookie and what we do here now is we make a response the response instructs the browser to set a cookie again this is client side so now we cannot just set the cookie we need to instruct the browser to set the cookie on the client side and then the client has control over the cookie so I can say response is equal to and for this we need to import a function called make response I think we talked about this already uh make response and the response we make is just render template index.html with a message cookie set that is the response and to this response now we can attach a cookie or we can set a cookie so response set cookie and then we just pass the key and we pass the value so we pass a cookie name and a cookie value so in this case the name is Cookie name or the key is Cookie name and the value is Cookie value and then I can just return to response and then I can also just copy this paste this set cookie set cookie and I need to run the application there’s a problem because I didn’t use a slash there you go now we can rightclick inspect look at the storage look at the cookies we don’t have cookies I can also set a session cookie there you go and now I can set cookie and now you can see we have cookie name cookie value you can see that this is now clear text I can see the content of the cookie I can see cookie name cookie value it’s not like with a session where the server has the information I have it here in my browser um and now we can have an endpoint get cookie so I can copy this down here I can change this to get cookie get get cookie and now what we want to do is we want to say cookie value is equal to request now do we have request imported no we need to get from request we need to get the cookies and in in particular here we want to get the cookie with the name cookie name of course you can have multiple cookies you can set cookie name cookie value then something else uh but in this case we’re interested in this one cookie uh so we get the value and then we can return a response in this case it’s going to be render template index HTML and the message is going to be formatted string cookie value is equal to cookie value so let’s load this and of course we need to have a link here as well so just copy change S to G and now let’s go ahead and see get cookie cookie value so you can see again the cookie is still here now the thing is since I have control over it I can change it it’s my browser I can do with it whatever I want and now if I go to get cookie you can see that the value has changed which shows you why the session might be a better choice in certain cases if it’s my choice whatever I want to do with a cookie it’s my choice I can I can uh you know manipulate it maybe it’s not sensitive maybe it doesn’t really matter but if the server needs to have control about something or over something if the server needs to be able to trust the information uh then of course use the session uh and don’t use cookies because cookies I can do with them whatever I want I can set new ones I can change them I can do whatever I want with cookies because they’re on my system they’re in my browser where’s the session of course I can also change this but I cannot change it in a meaningful way I cannot uh change the value of name and other just because I changed this cookie uh session cookie here um all right what else can we do we can also invalidate cookies so we can remove cookies uh let’s copy this here remove cookie uh and the way we do that is we basically make a response and we instruct the browser to expire the cookie to say the cookie expires in uh immediately basically so we can actually copy this here it’s almost the same we say cookie removed and what we do here now is we set cookie cookie name but we don’t set a value to it because the default value is just an empty string we set expires equal to zero and then we just return the response let’s go and I always forget to add the new endpoint here it is remove cookie remove cookie there you go and if I go and get the cookie I have it here remove the cookie get cookie and there you go bad request so here also again you should check for the key um but we can see in the storage now we don’t have it then again we do have it then again we don’t have it so this is how you can remove a cookie you just let it expire now last but not least I want to show you message flashing which is something in Flash that we can do it is basically you you display a message um that can be flashed using the flash function which can be useful uh if you want to have the field up there on every page for specific status messages for example you locked in or some event happened and uh this is something you could add in the base template for example so the idea is that we have the base template and in the base template what I can do is I can add a section in the body and of course you should style the section properly I’m not going to style it now so it’s going to look uh bad but what we can do here is we can use ginger with Ki brackets percent and I can say with messages being equal to get flashed messages and I can also use an endwith in between what I can do is I can say if there are messages and then of course I have to close it off with an end if if there are messages I’m going to iterate over the messages and show them in an unordered list again this is going to look bad but if you style it properly you will have an info box at the top showing relevant messages that have been flashed so we can say here for message in messages and for we’re going to have a list item with the message so this is how you display the flashed messages now you can flash a me a message in flask by just using the flash function so you import Flash and then let’s go ahead now and create a login page let’s go ahead and say we have an app route SL login and what we do here is we return render template login HTML so this of course needs to be created login HTML there you go then we can or actually let’s go ahead and copy the content of index and just replace this stuff here login page and then the content is going to be a form so we’re going to have a heading One login and we’re going to have a simple form which is going to have an action equal to URL for login and a method being equal to post and then we have some basic input type text name is going to be username placeholder is going to be username then we’re going to copy that we’re going to say this is password this is password this is password then we’re going to have an input type submit that value login very simple that’s basically it that is our login page and what we want to do now is we want to go to index um when we successfully logged in but of course we want to flash the message that we’re now successfully logged in or that the login failed depending on what we do so what we’re going to do here now is we’re going to say if request method and of course we need to allow here for methods being equal to get and to post so if the method is equal to get that is the case just render login HTML otherwise if the method is equal to post then do the following get the value for the values username is equal to request. form doget username password is equal to request form get password and then if username equals noral 9 and password equals 1 2 3 4 5 if that is the case we return render template index HTML and the message will be uh yeah not going to have any message or actually let’s go ahead and say message is going to be empty like this and otherwise we can copy this and also redirect to index the only difference now is going to be our message flashing I’m going to flash in this case successful login and in this case I’m going to flash login failed so the flash function is the only difference here and this is what we display here in the base template at the top so I can go now of course one more time let’s go ahead and add here the login there you go login and now I can say neural 9 1 2 3 4 5 login successful login and now do something else login failed this is the message flashing again usually you want to style this you want to design this properly so that you can have just an info field at the top all right so we’re going to learn how to work with databases in flask in this video today and for this we’re going to create a new project or application from scratch because we’re going to slightly change the structure of the files and of the code because in this case here since we’re working with databases and with models we have to avoid circular Imports because the idea is if you have an application file an appy file for example and you define a database object and this database object is then used in the models file where you define all the models and then you also import the models back into the application file you can end up in an endless Circle in a circular import and that can cause some issues so we’re going to adjust the structure here we’re going to use a factory pattern uh we’re going to talk about this here in a second but first of all what we need to do is we need to install two packages that we need for working with databases and for this you can open up your terminal of course use your virtual environment in this case now for the sake of the tutorial I’m just going to use my base environment but you want to do pip or pip 3 install Flash and then SQL Alchemy and flask migrate these are the two packages that you need to install for this video today let me zoom in a little bit there you go these are the two packages and once you have them installed we can go ahead and we can create now a new application directory let’s call this DB application and let’s let’s create now an app py file now this app py file in order to avoid circular Imports we need to now change the idea a little bit because what we’re going to have here is we’re going to have a DB object now let’s say this DB object is now an empty string but this DB object will be needed in another file that we’re going to have called models.py now why do we need a models py file think about it that way in our flask application we don’t have database tables we have classes so for example what we’re going to do in this video is we’re going to define a person Class A person can have an ID a person can have a name an age uh and other attributes but this is all just a class in python in the database if you’re connecting to a sqlite database or to a postgress database or mySQL database you are connecting to database tables now what the omm does an object relational mapper which is SQL Alchemy in this case what it does is it converts it migrates so to say the class CL into database tables it connects it to Worlds so that you can work with classes and flask and you can basically translate all the actions all the updates all the Creations all the insertions and so on in database language so that it all ends up in tables and that you can also select tables and get uh python objects as an answer now in order to Define that what we need to do in the models file is we need to create a class and so on but we also need to import this DB object in the models file now however once we have the the model defined here we also need to define or we also need to import the model from the models file into the application and then what happens is you import models in app you import app and models and it creates this circular import so we’re going to use a design pattern uh I think it’s the factory pattern where we have a function that creates the application then we have a separate file called run py which is going to run the application so the basic idea here is we’re going to import from flask import flask from flask SQL Alchemy we’re going to import SQL Alchemy and from flask uh migrate we’re going to import migrate these are the Imports now and what we do now is we Define a database object we say DB equals SQL Alchemy so that we can import it in models but then what we do is we create a function which we call create app and this fun function creates the application and returns it as an object so that it’s not always executed when you import this um this appy file because when you import something you execute all of the code however if it’s a function you don’t call the function so what we’re going to do here now is I’m going to say um equals flask uncore uncore name uncore template folder equals templates as we did it before now what we need to do here is we need to configure the string for the SQL database so I need to say okay what am I going to connect to and we’re going to start here with a simple SQL light database because if it doesn’t exist it’s just going to create it it’s the most simple database if you want to connect this to mySQL or postgress you can do that I can show you how to do that with postgress I’m not going to go through the installation of postgress and setting up postgress if you don’t have postgress already running it’s not going to work but you can connect this to any type of database so you can say here app.config and then you have to say SQL Alchemy uncore database _ URI is equal to and then you need this string and in the case of a sqlite database you can use it out of the box already you can say sqlite and then colon SL SL slash and then the path to the database so if it exists the path to the database otherwise just the name of the database so in this case we can say current directory and in this current directory I want to have a test T db. DB for example so this would now create a database test dbdb in this directory here that is the config now what we also do is we say DB initialize application so DB init app app and then what we do now is uh we do a couple of imports now we we’re not going to do the Imports yet um because we don’t have uh the stuff written out yet but what we’re going to do here is we’re going to import the routes so the views that we had before like app route Index app route create something or so on uh and we’re going to have in these routes they’re going to import the models which is again where the circular input uh import would happen uh but for now we’re going to leave this empty so we’re going to say here Imports later on and then what we want to do is we want to say migrate is equal to migrate app and DB and in the end we return the application so what we want to do in our run file is quite simple all we do in our run file is we say from App import create app and then we say flask application here is equal to create app and then we just say if uncore uncore name uncore uncore is equal toore uncore maincore uncore if that is the case just do flask app run host is equal to 000000 and debug equals true that’s down this is how you run the application so now instead of running the appy file We Run The Run py file it’s as simple as that so let us move on now to the model uh the model is going to be whatever you want to have in the database so you can either create the database first and then connect uh your application to the database or you can also create the database tables using uh SQL Alchemy and flask migrate so what we’re going to do here is we’re going to say from App import DB and then we can define a class let’s call it person and this class has to inherit from db. model so we’re defining a database model now and we need to have a double under hcore variable here called table name like this and this is basically the name of the table in the database let’s call table in the database people and all you have to do now is you have to define the field so I can say p ID is equal to db. column and what I do here now is I specify the data type DB integer for example and then I can also do some stuff like primary key equals true which makes the P ID the primary key integer column in the database table um then I can do name equals DB column and then I can say DB and then text now it depends on the database type what you want to use here so for example in the case of sqlite I think there is only text you don’t have something like varar or something but if you’re working with postgress you might want to do something like string and then I don’t know 255 or something or 128 I don’t know whatever you want to do here but I’m going to keep it simple here with text and I can say nullable equals false so it’s not allowed to be empty then I can do something like age is equal to DB column DB integer and then maybe job is equal to DB column DB text like this then I can also Define a representation Dunder method here just what happens when I print this so I can see more information I can say person with name self. name and H self. H that is just a string that you get uh when you when you print a person object here all right now this is a model I have in my application what I need to do now is I need to somehow create a database but in order to do that I first need to use this model in my application and for this we’re going to create a fourth F python file which is going to be routes. py you can also call this views pii it doesn’t really matter and this routes py here is going to import from flask uh render template and request but it’s also going to import from Models the person class and in order again to avoid circular Imports we’re going to do this now with a function again so we’re going to say def register rout takes the parameter app and DB or the parameters app and DB and to this we pass now the application and here we can register the route so we can say app route and by the way this is not necessarily the the only way you can do that or even the best way it’s one way you can do that while avoiding circular Imports it’s not the only way and you can uh try different patterns and different approaches here well let’s just let’s just go ahead and say we have the index function and all we want to do here is we want to say people is equal to person query all then maybe I want to print the string version or actually not print I want to return the string version of this people result here that would be now using the model uh now we don’t use any of these but we’re going to use them here in a second uh let’s also maybe create here a templates directory but now what I can do is I can go into my application here and I can say in appy um in the function this is important now I want to do the Import in the function this is how I’m avoiding the circular import I’m not doing it all the time I’m doing it when I call the function so what I do here now is I say import or actually from routes import register routes and then I call register routes with app and DB like this so I think if I didn’t mess up anything I mean it’s not going to work because we didn’t uh create anything but I’m not sure if we can even run the application let’s see it should probably cause some issue though there you go because we don’t have a table people so what we need to do now is we need to somehow migrate this to a database for this we’re going to open up the terminal in the directory of our uh project for this I’m going to actually open up this terminal here I’m going to navigate to um to my working directory so to current here let me just zoom in a little bit and actually I’m going to go into DB application now here I’m going to run the following command flask DB init flask DB init and you can see that this worked and then I can do flask DB migrate and then you can see detected added table people and in order to now actually create the migration to actually upgrade it I can say flask DB upgrade there you go it’s running the upgrade now the important thing is you only do this flask DB in it once and you do the migrate and upgrade every time you make a change in the scheme add a new class add a new model change a field you can always do that here you have now the database I can always change something I can always say I want to have an additional field or I don’t want to have the job field anymore or or I want to change the nullable or the data type I can do all of that but I have to migrate and upgrade every single time so I can open open up here this sqlite database can open up a connection and I can say select everything from people and you will see that I have P name AG job in the database which is of course great so now what I can do is I can just run this application and you can see that I get an empty list but it loaded all the people from the database because we don’t have any people in the database now what I can do is I can open up again the connection here and I can say insert into people and I can specify the fields uh Fields name H for example values and I can say I want to have Mike being 25 years old and maybe Bob being 30 years old then I can run this and then I can say select everything from people again you can then see I have these entries in the database and now I can again go run my application actually it was running already I can open it up and you can see I have these two people loaded from the database into flask mapped into a class now I have the objects that I can work with that’s the most simple way to do that so you have again a run file you have an app file where you have a function that creates the application just in order to avoid circular Imports here because routes think about it routes import models models Imports uh from App Imports DB from app and app itself again Imports routes routes Imports models models app and so on if we don’t do this in a function here it’s going to cause issues so that’s the basic idea what we’re going to do now in this video is we’re going to Define um or we’re not going to Define we’re going to create a base template again we’re going to create an index and we’re going to create a uh Details page where we can actually create users we can or create people uh delete people and also show more details about the people so we’re going to say here base HTML and we’re going to have the same uh layout that we had before so for the title we’re going to have here a block which is going to be the title block end block and the default title is just going to be default and then here we’re going to have a block content and we’re going to end the block um yeah that’s basically it now for the index what we’re going to do is we’re going to have index HTML the index HTML is going to extend this template extends base. HTML and we’re going to fill first of all the block title with the value index and we’re going to have also the block content and in here we’re going to put our content which is going to be a heading index page and then we can have uh we can list all the people from the database so we can say give me an unordered list and I want to do for person in people and for I want to have a list item here and this list item will be just the person and of course for this to work I need to pass first of all I need to render the HTML render template index.html and I need to pass people come on need to pass people equals to people so then there you go we get all the people from the database now what we want to do is we want to provide a form that allows for the creation of a new person so I’m going to go down here I’m going to say now heading of size three new person I’m going to create a form I’m going to say that the action of the form is going to go to yourl for index HTML um and we’re going to have a post request so we’re going to say method equals post like this and of course for this we need to adjust a route to also accept post so methods is going to be equal to get and post this is all stuff we already covered nothing new and we’re going to go ahead now and say we’re going to have the following fields input type text which is going to be the name placeholder is also going to be name and it’s going to be required like this then I can copy this and I can say I want to have also a type number which is going to be H with a placeholder H not going to be required and we’re going to have also job with a placeholder job and it’s also not required and then I want to have an input type submit with a value create all right so that’s quite simple um and I also want to have line breaks here there you go so that will not work because we need to say URL for index not URL for HTML but now you can see we have this form here and all I have to do now to use the information of this form and create a new user is I have to go into the route I have to distinguish between the two cases so I can say um if request. method is equal to get then just do this and otherwise if the request method is equal to post then what I want to do is I want to create a new um a new entry in the database how do I do that first of all I get all the information from the form so request. form. getet name I do the same thing for age I do the same thing for job age job and then all I have to do is I have to create a new instance of person so I can say person is equal to person name is equal to name H is equal to H and job is equal to job like this uh what’s the problem here yeah of course we need to type cast this into an integer there you go and now this object here this python class instance this python object basically I can just add it to the database by saying db. session. add person and db. session. commit and that is it so I can just copy these two lines here as well so that I can get again the full database table and display it but that is all you need to create a new database instance so let me just rerun this run it open it and then I can say I want to have uh Sarah 29 programmer create there you go we have a new in in the database I can say uh John 89 clerk something like this there you go I can create Now new instances which are also of course in the database they’re not just in my flask application so I can actually select from people and you can see that they’re part of the database and this works not only with sqlite it works with um postgress so I can easily go ahead now since I have postgress configured I can say create uh DB Flash tutorial DB there you go created it and now I can change the connection string to be something else uh I can easily change it to let me just copy this comment this out and say that the string is now going to be postgress ql colon postgress the user postgress the password very creative at localhost Port 5432 SL flash tutorial DB now I can run the full application again or actually I need to first uh I think I need to to where is it I need to migrate so I need to say flask DB migrate class DB upgrades and then I can just uh run the application here so stop and rerun open of course it’s going to be an empty database but I can create new entries here as well there you go now I’m connected to my postgress database not to my sqlite database and I have a new database with a new table with new data um this is how easy it is to switch from one database to another one you can do the same thing with mySQL you just need to know how to configure the uh database of course installing post setting it up might be a little bit more complex but once you have a database running you can just easily change the connection string and everything St is the same I don’t need to adjust anything about the model here um yeah so that is the basic idea uh what we’re also going to do now is we’re going to get we’re going to create two more routes and the two more routes are going to be for getting details about a person and deleting a person so I’m going to say here down below Define delete and delete is going to be an app route which is going to be delete and then we’re going to pass a p ID so a person ID and this is only going to take the method want to keep it professional here delete so this endpoint will only accept the delete method and what we pass here is the PID so we delete a specific user with an ID and all we have to do in order to accompl accomplish this is we need to say person query filter and we need to specify which person are we looking for we’re looking for person with a p ID that is equal to P ID and for this person we want to delete it there you go that’s it and again the only thing we need to do is we need to commit the session like this and then we can return render template index HTML with uh probably we should go and say people equals person query all then we can say people equals people as simple as that so let me just reconnect to the MySQL not the MySQL to the sqlite database because we had some data there let me just rerun this um what I can do now is I can just go ahead and say slash delete one for example uh of course this doesn’t work because I’m using a get method when I’m doing it in the browser so we’re not going to do it in the browser we’re going going to do it directly uh as a JavaScript function so we have this method here uh this route here this function and what we need to do is we need to send a delete request from the front end so from the python uh from the HTML file so we’re going to index and for each entry that I have here I’m going to add a button or a link we could say and this button or link I’m actually going to do it I’m going to make it a button uh this button is going to call a JavaScript function that takes the ID of the specific person and deletes it so we’re going to say here button the onclick is going to be equal to delete person and the parameter here is going to be the person. PID that is what this button does and the text is going to be just delete so for every person we have a button that has an onclick event which calls delete person with the ID of the specific person in this row now we need to Define this function so we’re going to say script type text JavaScript and we’re going to define the function delete person with PID as a parameter and what we need to do here is we need to fetch so we need to send a request we’re going to say I want to send a request to URL for delete I think this is what we called it right where is it routes delete and we can say also that the uh or actually we should use quotation marks here uh we can also say that the PID is equal to P ID because that is a URL parameter we need to pass it here and then we’re going to say plus P ID um and I’m going to say here that the function is going to be or actually the method is going to be uh Delete now please excuse that I’m looking at my second monitor a couple of times I’m not a JavaScript fan so I have to double check my code here um but this is what we do we sent a delete request to this URL endpoint and what we do then is we if it was successful we get the response and we forward it to the if statement if response is okay then we’re going to just say window location reload so that we can reload the page and see what happens uh so we can see the changes and otherwise we’re going to log into the console an error message console error failed to delete item with PID and we’re going to display the P ID here and finally of course we’re going to say catch if we have any errors here we’re going to say what we want to do is console error error during fetching P ID or let’s just do it like this error during fetching and then we can print the error message as well so I hope this works let me just indent this properly but the whole Magic happens actually here we’re fetching the URL for delete and we’re sending uh we’re using a delete method to do that uh yeah so that’s basically it let’s see if this works now let’s open up the application and let’s press delete there you go it deletes the entries from the database I can create some entries here delete oh actually doesn’t work when I just posted so let me just load the page again delete there you go so the entries are now gone from the database and you can also right click inspect and see that the delete button actually contains the ID so delete person 4 delete person 2 depending on the row so this is how you delete the object now finally what we want to do is we want to also display some more details so we want to say app route details and want to get the details for a specific person so for this we’re going to also get here the p and we’re going to define the details method that takes the P ID and all we’re going to do here is we’re going to load the person object from the database and we’re going to show the information so we’re going to say person equals person query filter where the person P ID is equal to the P ID from the URL and we get the first of these it’s always going to be one since the p ID is unique but in case we have many we’re just going to do uh we’re just going to get the first one and we’re now going to render actually the details HTML which is going to be a new one and the person is going to be equal to person like this and here now we’re going to just copy paste the index we’re going to call it detail. HTML I think I use just detail right details actually okay let’s just call it detail then um and here now what I’m going to do is I’m just going to say [Music] person and then person P ID and I can list some information something like name going to be person name H is going to be person H and job is going to be person job like this and the only thing that we need to do now is we need to add a button or actually this time we’re going to use an anchor tag so we’re going to use a link uh for each individual person here we want to have a link to the details page so a ATF is going to be uh URL 4 details and the P ID is going to be equal to person uh person do p like this and we’re going to say that the text for this is going to be details that should be enough to go to The Details page of the respective person and that’s it basically this is how you work with databases in flask this is how you can migrate how you can use any database basically the important thing is again to avoid circular Imports this is one way to do it with a factory pattern you have a create app you have a register uh routes meth method but that is one way to do it you just have to swap out the connection string here and you can use any database you like as long as you set it up properly you define models you migrate them with flask DB migrate flask DB upgrade and that is how you work with databases in flask all right so we’re going to learn how to implement a user authentication system for our flask application in this video today and for this we’re going to continue working on the application from last time remember the structure was slightly different because we had a separate run file which calls the create app function which is defined in the app py file where we use this sort of factory pattern in order to avoid circular Imports and basically all we’re going to do in this video is we’re going to add a class or we’re going to replace the class depending on what you want to do uh you can either replace person and create a user class or you can just add a user class you can have multiple classes as well and we’re going to build an authentication system around this user class so we’re going to be able to log in a user we’re going to be able to register or sign up a user and we’re going to be able to keep a user logged in and see which user is sending a request so that we can um you know show different content depending on the type of user or depending on the exact user that is viewing a certain endpoint so for this we’re going to need an external python package called flask login and we’re also going to install another one called flask bcrypt and the reason we install flask bcrypt is because when you have a user uh and you have user information in the database like a username and a password usually you don’t want to store the password in clear text in the database you want to store a hash of the password in the database and the good thing about a hash is it’s a one-way street so you can take a password you can hash it you get something that is very hard uh to reproduce almost impossible to reproduce with a given input string but you cannot reverse it in any way so you cannot decrypt it it’s not encryption it’s hashing uh and this is what bcrypt basically does so what we’re going to do first now is we’re going to install the packages we’re going to open up the command line and we’re going to type pip or pip 3 install flask-login and flask Das bcrypt like this and once you have this installed we’re going to go to our appy file and we’re going to import from flask login we’re going to import the login manager on and from flask uncore bcrypt we’re going to import bcrypt now let’s go ahead and create a user class now in my case here just to keep it simple and to have a better overview I’m going to remove the person class however you can do everything we do in this video and keep the current functionality from last video so you can actually keep uh all the routes all the models that you have and you can just add a user model but for the sake of Simplicity I’m going to just have one class here so we’re going to say class user and this is obviously going to be a DB model but it’s also going to have something else and for this we need to import report from flask login the user mix in this is something that we’re going to add here to The Inheritance so we’re going to say user mixin here in the parenthesis and then we’re just going to do the same thing as with a person we’re going to say table name let me just zoom in table name is going to be equal to users and then we’re going to say uid is equal to DB column DB integer and primary key equals true and then username is going to be a DB column DB string nullable is going to be equal to false then we are going to say password is also a string nullable false the RO is also going to be a string I’m going to keep it simple here no enm or anything it’s going to be nullable though and then we can say something like description you can add whatever you want here this is basically a user profile so table name is users actually we don’t want to do a comparison here we want to actually assign this uh description is going to be equal to DB column DB string as well and then what we’re going to do is we’re going to Define again the representation Dunder method we’re just going to return here a formatted string maybe with some angle brackets here and we’re going to say user and the user is going to be actually sorry this is a string I want to do user and in in here what we want to do is we want to show the username so self. username and maybe the role as well self. roll all right and one more thing we want to implement a method get ID which is just going to return self U ID just so we can access users by ID easily so that is our user class now of course we need to do the same thing with migration and upgrading so we need to open up a terminal we need to navigate to the directory that we’re currently working at which is here and then I need to say flask DB init or actually this is going to actually not in it we need to use uh first of all we don’t need to use in it because we already did it we need to use um migrate and upgrade but also we need to First of course sanitize all the code we need to remove everything that uses the person uh model so we can replace this here by user uh we can basically get rid of all this so we can just say uh return something here we can also get rid of the detail HTML in the index we can get rid of almost everything actually let’s get rid of everything and then here we don’t really have anything here we have just a model so now it should probably work flash DB migrate then you can see here remove table people added table users and then flask DB upgrade to actually make changes there you go so one thing that you need to understand about flask login is it doesn’t Implement any login procedure it doesn’t Implement any logic whatsoever when it comes to how you want to log in whether you want to do it with a password whether you want to do it with a token whether you want to do it without any uh secret or any any security measure at all all that flask login does is it locks you in it keeps you locked in it handles the user that is currently locked in and it locks you out how exactly you do that is up to you so you basically just use the login manager to say now you’re logged in now you’re logged out and now this is the currently loged in user how or when you log in a user is up to you so you need to implement all the logic with comparing the password hashing the password and so on so we have this models py file now this is just a user and what we’re going to do now in the application so in the app why is first of all since we’re working with sessions here this is what we’re doing behind the scenes we’re working with sessions we need to again Define a secret key so app. secret key as we did it already in the session management is going to be equal to something of course here you want to generate a good secret key I’m just going to use some sample key here some key and then what we want to do is we want to create a login manager so the login manager is going to be equal to login manager and we also want to say login manager init application we pass the application and now what we want to do is we want to Define um a certain we want to Define for the login manager what it means to load a user so what we do is we say and here now we Define a method inside of a method so when you just say uh let’s say the the method or the function is going to be called load user based on a given ID the logic here is to say return user query get uid and for this of course we need to import up here from Models import user otherwise we cannot do that now the important thing is this is now just some function here we need to say that this function is actually how the login manager loads users so we need to give it an annotation here login manager. user loader like this this basically now means said when the login manager loads a user it does it like that it gives you a user based on a uid that is how it’s done um what we also want to do afterwards here is we want to create a bcrypt object so bcrypt is going to be equal to bcrypt and we’re going to pass app here um as a parameter and the important thing now is that we also want to pass the bcrypt object to the register route so we pass here bcrypt to register routes which is remember this function here uh so we pass bcrypt here and we need to do that because of course we need to Hash passwords when we create users and also hash them when we log in users so that is important now we’re going to leave appy for now we’re going to add something later on but now let’s go ahead and try to just Implement a very basic login so no password no fancy stuff just an endpoint where I can go and I can log in a user and another one where I can log out the currently logged in user very simple uh for this let’s go ahead and Define just a simple endpoint let’s call it login um and then a p ID or uid actually so I can just go to an endpoint and when I go to that endpoint I can just log in a user how do I do that uh well all I have to do basically is I have to call the login user function and this is a function provided by flask login so we can say from flask login import log in user I also have log out user which I’m going to import I can also get information about the currently locked in user so current user and I can later on this is I’m going to import it uh now but we’re going to use it later on we can also say that for certain endpoints a login is required so we’re going to import these four things login user logout user current user and login required so all we’re going to do here now is we’re going to Define this login function with pi ID or actually uid as a parameter here and this function will just log in a user so we’re going to say login user uid done that’s it that’s how you log in a user and then we can return success and let’s say for the index page what we’re going to do is we’re going to return current user username as a string so we just want to know what is the username of the current user this is what the index um endpoint gives us and then I can copy this and I can say I want to have also a log out log out endpoint lock out without any ID I’m just logging out the current user and for this we’re going to just say lock out user very simple nothing too fancy let’s run the application and see what happens so first of all I have of course the problem that there’s no uh logged in user so what we’re going to do is we’re going to say for the sake of Simplicity we’re just going to use a try except or actually let’s do it properly let’s say if current user is authenticated I think that is the proper Boolean here we’re going to do that otherwise we’re going to just return no user is logged in let’s do it like this let’s go back no user is logged in now let’s go to slash login oh actually I don’t have a user so let’s first of all before we do anything go to the database and select everything from users you can see we have no users so what we’re going to do is we’re going to say insert into users and here we want to have username password values and then I’m going to just say neural 9 the p password is going to be 1 2 3 4 5 I can run this then I can run this and you can see now I have this user so let’s go back let’s run this and then let’s go SL login one now what’s the problem here login user user is active string has no attribute is active what’s the problem here let me just double check l in user oh of course sorry uh what we need to do actually I didn’t uh write this properly what we need to do is we cannot just log in a user based on the ID we need to log in a user object so what we need to do is we cannot just pass the U ID we need to first get the user that has this uid so user query get uid and then we can pass the user and log in the user so let’s run this again or actually it’s still running Let’s Go slash login one success now let’s go back to index there you go neural 9 is logged in as you can see now I can go to SL logout success let’s go back and no user is logged in so this works you can see that there was no password checking there was no hashing all flask login does is it allows me to log in a user to log out a user and to work with a current user and do some stuff with it but it doesn’t say what the authentication process actually has to be this is what we have to implement ourself so what we’re going to do now is we’re going to just create a basic login system here so we’re going to return render template here I’m just going to say index HTML is going to be the start page nothing too fancy we’re also not going to do any post requests here so just a simple endpoint um and then what we want to do is we want to have a sign up we want to have a login and a log out so we’re going to say app route and here we’re going to say sign up methods are going to be obviously get and post because we need to get the form and then with the form we can sign up and here we’re going to do now if request method is equal to get then we’re going to return render template and the template is going to be be sign up. HTML we don’t have it yet otherwise if the method is equal to post we’re going to do some stuff uh same is going to be true for login so I’m going to just copy that and I’m going to replace this here I’m going to change this to login we’re going to change this to login and we’re going to also load the login HTML now login and signup are going to be very simple HTML files they’re just going to have some basic form with username and password and that’s basically it um of course you can also add for the sign up maybe the other fields if you want to I’m not going to do it here now it’s not really complicated to do that you just add more Fields uh the important thing you need to consider is the hashing so let’s say or actually let’s go ahead and first create the signup so for the sign up uh we literally just need sign up page we literally just need a form that has an action equal to URL for signup method is going to be equal to post and the fields here are just going to be type text name username placeholder username required equals required copy change the type to password change the name to password and change the placeholder to password and then a simple sign up button input type submit value sign up that’s quite simple and that’s also what we’re going to have in our log in page so actually this is when we copy pasted login HTML um this is going to be the same thing the only difference is we’re going to go to login here and the text is also going to be login and here login page now maybe you want to add some breaks here for design reasons here as well but that’s basically it we’re done with the HTML part the interesting part is now how do we actually create a user how do we actually have the password and for this we’re going to go to the routes again and here now if it’s a post request we’re going to get username and password from the form so request form get username request form get password password and now the important thing is you don’t want to store the password in the database you want to store the hash of the password in a database so what we do is we Hash a password we say hashed pass password is equal to bcrypt do generate password hash of password and then what we do is we say user equals user username is equal to username password is equal to hashed password now and then all we have to do is we have to say DB session at this new user and then DB session commit the session and then we can just redirect for this we need to import redirect of course we can just redirect to and we need URL 4 here as well can redirect to index for example um which is going to show the current user or you can also redirect to a profile page if you want to it doesn’t really matter you redirect somewhere where you’re going to see some uh information that is specific to the user in our casee the index HTML file uh will display the user so here what we’re going to do let’s do it right away we’re going to say um if current user is authenticated we don’t even need to pass it if that is the case we’re going to do something otherwise we’re going to do something else and then we’re going to do end if down here and what we’re going to do here is heading of size three hello current user username and otherwise I’m going to just do hello like this so we can easily see if there is a user locked in or locked out maybe we should add also two links here pointing to URL for [Music] login like this and then we should also have one for sign up and maybe also one for log out there you go all right so this is how you create a new user this is done this is the signup process now how do we log in very easy we do the same thing we get username and password from the form we hash the password so we can actually go and copy paste this so we get username and password from the form uh we hashed the password and then we compare the hashed password uh that was hashed now from the user input to the hashed password from the database and if it’s the same we’re going to log in the user so we’re going to say user equals user query uh and then we’re going to use filter because now we’re not going to just get the ID we’re going to say the username has to be equal to the username passed in the form I want to get the first um the first entry we’re going to assume it’s Unique maybe we should set that up in the model but I’m just going to get the first user now and we’re going to say okay if the password of this user the hash password is the same as the hash password here we’re going to lck in the user and we’re going to do that here by saying if bcrypt check uncore password hash user password and password actually we don’t need a password hash here I’m going to do it like this um if that is the case we’re going to say login user and we’re going to return render template index.html and otherwise we’re going to return failed just like this okay so that is the login process again just repeat we sign up by getting a form providing username password hashing the password creating a user with the hash password in a database committing the session showing the index uh maybe we should also redirect here and not just render template I think that’s better uh for the login what we do is we get again username password We compare is there already a user with this username if yes get him does the password hash match and if yes log in the user otherwise just say failed no user was logged in and then finally we’re going to have log out which is just going to log out user and we’re also going to just redirect to index here and keep it simple so I think this should already work let’s see if it works we’re going to run it and now I have sign up log and log out let’s go ahead sign up let’s say I want to have a user mic with password password sign up there you go now I’m not logged in as you can see I’m just getting a hello here I can log in now as Mike with password login hello Mike log out hello log in uh now for neural 9 it’s not going to work because we didn’t have a hash so maybe I want to create uh another one John here and John will have the password 1 2 3 4 5 sign up there you go log in John 1 2 3 4 5 there you go log out and now if I try for example John with some other password I’m going to get failed and if I look into the database you will see that except for the one that I created manually here in the database you can see that the password is always a hash not the clear text password so even if someone hacks a database they’re not going to see the passwords that is important of course for security reasons all right so that’s almost everything but I want to show you something else I want to show you how we can protect certain endpoints uh or at least require for certain endpoints that the user is authenticated so let’s say I have an endpoint Here app route let’s call it secret yeah let’s call it secret def secret is going to be the function and here we just going to return my secret message this is what we get at this end point nothing nothing uh fancy here and of course what you can also do is you can also check for roles you can say if the current user uh Ro is equal to and then you can say admin only then show that otherwise return no permission but I’m not going to implement this now this is very simple you just have to set the role when you sign up or on an edit page um but then you can also check for rle you can do whatever you want here but the only thing that we want to do is we want to require a login so what we can do is we can say add login required and you want to put this below the app definition uh before the route definition here so app route Secret login required and now we can also go to index and add a link here to secret secret and then let’s go and run this now I’m not logged in if I try to go to secret I get this default message unauthorized the server could not verify that you’re an authorized uh that you’re authorized to access this URL if I log in now as mik what was the password I think password log in I’m now Mike secret my secret message okay so when I’m logged in it works um now as you saw when I’m not logged in I get this default error message so I can log out secret unauthorized how can I change that how can I change the behavior of this redirection if I’m not authorized um it’s actually quite easy to do that we just have to go to appy here and we have to add a function and this function will be a call back for this uh unauthorized uh scenario so we’re going to say here that the method is called or the function is called unauthorized callback and we’re going to decide what happens when uh what happens when I’m not unauthorized when I’m not authorized when I’m unauthorized to uh visit an endpoint because I’m not logged in what I’m going to do in this case is I’m going to to do redirect URL for index like this and of course we need to import this redirect URL for and in order to associate this with a login manager we need to again add a decorator login manager unauthorized Handler and um yeah that’s basically it so now when I’m not logged in I’m going to be redirected to index so if I try to go to secret you can see I’m ending up at index if I log in mikic password login secret it works and I can of course also do something else I can also just return some string here custom Behavior so it’s really up to you what you want to do I can log out secret custom Behavior so you can decide that but yeah this is how you build an authentication system in Python flask using flask login and using flask bcrypt all right so we’re going to learn how to work with blueprints and flask in this video today and this is going to make our applications much more professional and much more modular the main idea behind blueprints is that we take the functionality of our program we take our application and we split it up into multiple different components or blueprints which are for the most part independent of one another now of course you can still reference them uh between each other you can still interact with them so you can redirect from one blueprint to another one for example but the idea is that I can work on blueprint a you can work on blueprint B and we don’t have to really uh change the same files we don’t have to constantly interact with one another to merge some uh differences because I’m working on the files of blueprint a you’re working on the files of blueprint B and maybe occasionally we have to adjust some things because I changed the function signature or the name of an ENT point or something but for the most part we can work on these separate Blueprints and then all of them are combined into a central application so you can have one blueprint for a to-do list application uh or a to-do list blueprint uh or section you could say you can have one for a calender you can have one for a habit tracker you can have one for a login page or for authentication in general uh that’s the basic idea and then you can merge All of These Blueprints into a central application and this is just much more structure and uh everything is much more modular and professional now because of that we’re going to do everything from scratch here because we’re going to have a different directory structure and the first thing we’re going to do is we’re going to create a directory I’m going to call this now blueprint app call this whatever you want this is going to be our flask application and outside of this directory I want to run or I want to create a run py file and this is important because we’re going to use this as a package so right away I’m going to say init dot soore nitpy is going to be placed in that directory to make it a package because in all the files we want to have absolute paths we want to say blueprint app do blueprint name do uh module do something whatever you want to import you always want to use the absolute name here of the package blueprint app this is going to be our application now inside of this application I’m going to have an appy file this is going to be our Central File where all of this stuff is going to be merged and created and here what we’re going to do is we’re going to say from flask import flask obviously we’re going to also import URL 4 or actually I don’t think we need that we don’t need URL 4 and I also don’t think that we need redirect we’re just going to import flask uh we’re going to also import from flask SQL Alchemy import SQL Alchemy because of course we’re also going to work with models here so each blueprint will have its own model file models file and also its own routes file so we’re going to have everything that we have in an application we’re going to have in a blueprint other than maybe the database connection itself uh and then from flask migrate we’re going to import migrate so we do the same thing as before we create our database uh object here and then we Define our create app uh function and what we’re going to do here is we’re going to do the same thing as before create a flash application let me just zoom in a little bit create a flask application uncore name uncore the template folder is going to be templates now this is another thing each blueprint will uh each blueprint will have its own template uh folder so app is going to be that app config even though I don’t think we need to have a secret key um but yeah we need to have of course a um a database connection so actually this is not like this app config like this and then the field is SQL Alchemy database URI I’m going to set this equal to sqlite and then three * SL current directory SL test db. DB or call this whatever you want we can call this for this video today blueprints do DB for example um and I don’t think we need the secret key so we’re going to skip that and we’re going to say DB init application app and what we want to do then is here in this section we’re going to uh import and register all blueprints which we don’t have yet so we don’t have any blueprints yet but here we’re going to merge everything together and once this is done we’re going to say migrate is equal to migrate app DB and we’re going to return the app and in our run file this is also not we’re just going to import that from blueprint app.app import create app and then flask app is going to be equal to create app and if uncore uncore uh name uncore is equal toore maincore uncore then we want to do flask app run poost is going to be 00 0 debug equals true there you go so this is our run file you can see we use the absolute path here as well from blueprint app app and um that is our app file here here we’re going to merge everything but we don’t have anything to merge yet so what we’re going to do is we’re going to create our first blueprint and let’s actually just use a uh to-do list blueprint as an example here so we’re going to create now a directory which I’m going to call uh todu this is going to be our to-do blueprint and our to-do blueprint will also or or actually will it be a package let me just double check yeah it will be a package um we’re going to also add an init file here as well to make it a package just keep it empty this is just a file that needs to be present and here now we can create the two files routes py and models py and this is going to be the structure of each blueprint so I can create another one here I can create the blueprint people for example and I will do the same thing I can copy these files I can put them in here uh of course the code is going to be a different one later on but we’re going to have models and routes and then I can make another one we’re going to do three blueprints in this video today uh which I’m going to call Core core basically to just be the homepage the default blueprint which just displays an index page um and here I’m not going to have any models but I’m going to have also routes and I’m going to have anit py file all right so these are now three blueprints but we don’t really have or these are going to be our three blueprints but we don’t have them yet so what we’re going to do first is we’re going to create uh the toce uh routes file here so we’re going to say from flask import request render template the usual stuff uh redirect URL 4 and then what’s new now blueprint with a capital B this is a class blueprint um and then we also want to sa from and now we need the absolute path now this is something important if for some reason your development environment doesn’t show you that this is possible so if I say from blueprint app import DB if that doesn’t work if it somehow um says that this is you know an invalid path or something chances are you have to right click your directory at least in pie charm for example and you have to mark the directory as sources rout then it should work um just if you have the problem in case you have the uh problem and then if if it doesn’t apply right away you might have to invalidate the caches and restart the application and maybe we will have to do this here as well but for now it works so from blueprint app. blueprints do too. models import and here now I’m going to create a uh to-do model so this is nothing new this is just from blueprint app. app import DB class is going to be to-do it’s going to be a DB model we did that already nothing new here table name is going to be equal to uh toos and the fields are going to be the T ID the to-do ID basically it’s going to be a column it’s going to be an integer and it’s going to be the primary key then we’re going to say um that the to-do title is going to be equal to a column it’s going to be a string and it’s not going to be nullable and then we’re going to just copy this I’m going to do the same thing for description but it’s going to be nullable and then maybe done is going to be DB column DB Boolean and it’s also not going to be nullable because it’s either going to be true or false uh and then we can just uh Define a representation Dunder method here so we can just return some stuff like angle brackets to do and then we can use it to do title and whether it’s done or not and of course you want to have this as an F FST string here uh and then we need also get ID even though I’m not sure if we need that or if this was just for the user not sure right now let’s just add it here won’t hurt um and this is now our to-do model which we want to import here to work with it and the functionality itself is not going to be too fancy we did all of the stuff that we’re going to do in this blueprint now we already did so I’m going to go through it quite uh quite quickly the new thing here is that we now are going to create this as a blueprint so we don’t say app equals flask what we do is we say Todo equals blueprint and now we have to name the blueprint it’s going to be todos we’re going to pass here uncore uncore name uncore uncore and we’re going to define a template folder which is going to be templates the same way we did it for um for the application so this is what we do for an application here we just add a blueprint name and this is what we’re going to register now later on in our app py file so this is the blueprint and I can do the same thing now to dece instead of app. route to do. Route and the default route here is going to be slash and we’re going to say that we want to have an index and uh all we want to do here is we want to get all the to-dos from the database so to-do query all and then return and we’re going to render a template now what’s important here is um the structure or the convention the best practice way to do it is to create a directory templates here like this and then inside of it to use the same name of the blueprint again so to-dos templates to-dos like this and here now we place our um index HTML file for example now this brings us to another point we have a base template now let’s let’s just return an empty string for now to not have an error here um we want to use a base template for all the different Blueprints and because of that we’re going to create Also let’s close the blueprints here we’re going to create here in the application itself a directory templates and this templates directory will contain the base HTML template base HTML now this one I’m going to copy because I don’t want to waste too much time writing code that we have already written before so that is that we have again just our simple uh actually we don’t need this because we don’t have bootstrap and we also don’t need this uh but this is basically our blueprint we have uh or not blueprint our template we have here the base uh template with the title and the content block and then we just fill it up with um the other HTML files and here now what I’m going to do is I’m going to just extend so I’m going to say here extends base HTML nothing new here we did that before also again I’m going to fill the block title end block the title is going to be todu and then we’re going to fill up the block content and we going to do end block and what we want to do now for the index routee is we just want to get all the to-dos and then we want to say return render template and here now we need to say to-do /index HTML because remember we have a todu directory in the templates directory itself and we pass people equals people uh sorry not people to-dos equals to do like this now this object we can now use again here and display so we can say unordered list and then I can do four to-do in [Music] todos and four and I can just use list items here to show all the toos individually of course so that is a simple index route and then uh just so we have another endpoint here as well we’re going to use a create endpoint so we’re going to say Tod do. route we’re going to say the endpoint is slash create and uh we’re going to allow for methods get and post we going to say create like this and we’re going to say if request method is equal to get we’re going to just return an HTML file otherwise if request. method is equal to post we going to do something else so here I’m just going to return uh render template and I’m going to return H2 do create. HTML which we don’t have yet so I’m going to copy paste the index HTML I’m going to call it create I’m going to delete all this here um and I’m going to have a simple form that I can use here so I’m going to say H1 create too form again I’m rushing through this because all of this we have already done this is just a repetition the new thing is the blueprints now so I’m going to say here URL 4 uh Tod do. create and method is equal to post and then we’re going to have our field here so we’re going to have input type text which is going to be the title of the to-do so the name is going to be title the placeholder is going to be title and required is going to be equal to required then we’re going to say here input type uh text [Music] description come on description description not required and then we’re going to have a check box with the name done and here we’re just going to say in the end done and finally input type submit and the value is going to be equal to create all right so this is going to be our form and all we have to do now is we have to get the attributes title is going to be equal to um request form get title it’s mandatory so we don’t have to check if it’s there or not and for the description we’re going to say um request. form get description and for done we’re going to say it’s true if done is in request form keys so if the checkbox is checked it’s going to be part of the keys otherwise wi not so we want to set it to false if not um and we want to set also the description to null if it’s empty so we’re going to say description is equal to description if description is not equal to an empty string otherwise it’s going to be none so that is that and then we’re just going to create a new to-do like this we’re going to say that the name is equal to name the description is equal to description and done is equal to done and then then all we have to do is DB session add Todo DB session commit and of course we don’t need name we need Title there you go and then we return a redirect to and now this is also important when we do URL 4 now we need to say it’s not index it’s Todo index because we might have another index and another blueprint and that’s a different one of course so everything you see here except for maybe this blueprint line is stuff that we already did I think in two videos and also this is not not new and this is also not new so all this is already something that we have done before also the model now what’s new is how to get this into the application and how we do that is we register the blueprints so we do that in the create app function we just go ahead and say from blueprint app.app uh not app sorry blueprints do toos routes import um Todo now Todo is not a file to-do is our to-do blueprint that we defined up here this is what we want to import and this is also what we want to register so we have to say now app. register blueprint and we register our to-do blueprint and the important thing now is you want to uh you want to uh associate a prefix with it so URL prefix because you will have multiple of those and what I want to do here for example is just SL toos what this means is that in order to get to my index here I don’t have to say just slash I have to say to-dos slash and to get to create I cannot just go to URL SLC create I have to go to URL SL tocreate that is what the prefix is for uh now I’m not going to run the application yet we’re going to finish all the blueprints before we look at this and the good thing is that all of this can be easily just copy pasted at least for the person uh or for the people blueprints I’m going to delete all this and I’m going to just copy paste everything here uh so from here to no just just this stuff here copy and paste now somehow it doesn’t work so let me do that into files Explorer toce seems to be a bit buggy now it works there you go um and all we have to do now is we have to adjust the obvious parts so for example the model is not going to be to-dos or to-do is going to be person the table name is going to be people it’s not going to be a t ID it’s going to be a p ID it’s going to be a name instead of a title um and it’s going to be an AG which is going to be an integer instead of the description and it’s going to be a job um it’s going to be a job instead of a done and it’s going to be a Str string and it’s going to be down here a person and the person will have a name and H like this and it’s going to be a return P ID so that is how we Chang the model for the routes of course what we need to do is we need to change that it’s not the todu blueprint it’s the people blueprint it’s not the name Todo it’s the name people um it’s also not import from to-do models it’s import from people models and it’s going to be import person let me just adjust my chair it’s making some noises here uh it’s going to be the person model uh it’s not going to be add to doce route it’s going to be add people route down here as well um and here it’s not going to be to doce equals to do query it’s going to be people equals person query all and it’s going to be not to do/ index it’s going to be people slash index and it’s going to be people equals people we of course also have to rename now here this name it’s not going to be people templates to do so it’s going to be people templates people and um I think this is now done down here we’re going to do also people create HTML and here of course we need to also get the different field so it’s going to be get name it’s going to be AG is equal to request form get H and we have to type gas this into an integer again rushing through it because we already did it job is going to be equal [Music] to job and we’re going to say that this is going to be job job is going to be job if job is not empty otherwise none here we’re going to say person is equal to person and here we’re going to say name equals name H equals H and job equals job I’m going to add the person and we’re not redirecting to todu index even though we could do that here um we will do to we will redirect to people index uh now this should already be okay now we only have to change these two things we need to change this to people here we need to change this to person in people we need to change this to person and then for create we have to adjust a little bit more first of all again people create person then people create and then here we want to have [Music] name name then we want to have input type number H H then we want to copy this which is going to be job job job and just submit there you go so this should be it now we have our second blueprint what do we do to register it we go to appy we say from blueprint app. blueprints people. routes import the people blueprint and then register to blueprint people with a prefix SL people so we have in both files here you can see we have index and create index and create and they have the same uh pattern here but they’re different because they have different prefixes now finally what I want to do is I want to um implement the core blueprint which is not going to be super fancy it’s just going to be a simple HTML file uh that is rendered by default um so we’re going to go here we’re going to create also here a uh templates directory with another core directory in it and we’re going to copy here the index and we’re going to also copy the routes just so we don’t have to write every basic stuff from scratch but what we’re going to do now is we’re going to say that the blueprint is called core for not people and we also don’t need to import any models here so we’re just going to call this core and we’re going to have core route which is going to be index and this is just going to render the core index HTML but we’re not going to pass any objects and that is going to be our blueprint that’s it we don’t even need a database so just like this and we also don’t need all the Imports we just need render template and blueprint and our index file will do nothing but just uh link to the two other Pages just so we have a landing page a homepage so a h reference is going to be URL 4 and here now we can say todos index toos like this and then we can say here people index for people and that is actually all I want to do here I think maybe we can add a heading H1 homepage or something and we can say here core something like this and now all we have to do is we have to register this and we’re done um so since this is going to be our default default page I’m going to say from blueprint app blueprints core uh routes we’re going to import core and now I’m going to register this and it’s going to have no URL prefix just a slash so this is going to be our default index so to say now of course what’s important is we need to create the database so let’s go ahead and navigate to our current directory let’s go to blueprint app let’s do flask DB init no module named blueprint app blueprints why is that the case oh I think this is one thing that I forgot to do I wanted to place all of them in into a blueprints directory just to have a little bit uh more of an overview so blueprints is going to be a directory and I’m going to copy or I’m going to move core people introduce into this directory now I did this in my prepared code which is why I did the Imports like that blueprint app um and then blueprints core routes and not just blueprint app core routes uh but now it should work so we do we do here flash DB init flash DB migrate Flash DB upgrade and once this is done we can go into our run py file we can run it we can go to our application here and we can uh click on to do now to do is empty uh oh one thing that I wanted to do maybe this would be um useful is we can go to templates we can go to index and we want to have a link that links to URL 4 todos create I can copy this into the people index as well just so we don’t have to use the URL bar to make these changes so let’s restart the application go here to doce create and now I can say test whatever done create stuff stuff not done create there you go then we can go back we can go to people create person there you go so you can see this works and this is how we connect All These Blueprints you can see the URL patterns here people create and then if I go back to dos and then to do create so this is how we integrate All These Blueprints and this is the core blueprint here so yeah this is how you work with blueprints and flas this is how you make your applications more modular and professional all right so finally we’re going to learn how to deploy our flask application to an actual server on the internet and we’re going to also learn how to containerize our application using Docker in order to do that now when it comes to deploying an application there are multiple ways in which it can can be done for example you can also just copy paste all the files upload them to a Linux server install all the dependencies and run the application this is also an option you can use Docker you can use Docker in combination with some cloud service there’s not one correct way to do it what we’re going to do in this video is we’re going to containerize our application using Docker we’re going to upload the docker image to a Linux server which I have rented for this video uh we’re then going to load the docker image on the server we’re going to run it there and then the application is running on the server without us having to install any dependencies without even having to install python we just need Docker on the server and that’s it now if you want to follow along you will need to have some or if you want to replicate the results you will need to have some server that you can work with so you can either do it locally you can open up a virtual machine if you don’t have an actual server on the internet you can rent a server maybe you can find some free alternative I’m using a paid server that I’m paying for monthly uh but you will need to have some SSH access to a Linux server if you want to follow along if you want to replicate otherwise you can just watch and and learn how it’s done so the application that I’m going to deploy today is going to be the blueprint uh the blueprint application from last video so we’re not going to add any new code here we’re just going to take this application and deploy it now since we didn’t do it properly in the last video since we didn’t use a virtual environment we’re going to create one now just so you see why it’s important to have a virtual environment here so I’m going to open up a terminal down here I’m going to navigate to current and I’m going to uh do the following here I’m going to say python 3-m vnf dovm I’m going to create a virtual environment called vnf then I’m going to say source. vnf bin and activate as you can see now I’m using the environment and if I try to see which packages I have installed you can see I have no pip packages installed here so what I’m going to do here because we need it for the application is I’m going to say pip 3 install flask flask um SQL Alchemy and flask migrate and then this is going to install all the packages now why do we need that because we don’t need the virtual environment for Docker we’re not going to uh to add this to Docker we’re not going to add the virtual environment to Docker why do we need that um because now if I have been working on this for maybe months I will have all the packages relevant for this project in this virtual environment and I can do pip three freeze and I can see all the packages with the versions that I have to make this work so I want to have these exact versions to have the exact behavior of my application so what I can do is I can say pip free uh pip three freeze and then requirements.txt and now what I have here is a requirements file with all all the packages and all the versions that I need uh to make it work on any system basically this is the exact configuration I have in my virtual environment with which it works now for the sake of Simplicity what I’m going to do is I’m going to delete um first while I’m going to delete this I’m going to delete the database itself and I’m going to delete the migrations just so I can start from scratch so the application is still here we still have all the blueprints all the files but we don’t have any data already in there so we’re going to deploy an empty application without a database um now what do we need to do in order to turn this into a dock container what we need is we need to have a so-called Docker file so I need to go up here to current I need to right click and I need to say Docker file and this Docker file now will have the instructions that are necessary um to to build the image to build the docker image so the first thing I want to do is I want to specify the python version so I’m going to say from and then I’m going to say python colon 3.10 I’m going to use slim and Buster here so this is the python version that I’m going to use here 3.10 this is the one that I used uh during deploy uh during development as well and now we need to say okay what exactly has to be done to make this application work first of all let’s define a working directory let’s call the working directory flask app like this um what we want to do here is we want to copy the requirements txt file so we want to say copy requirements txt and the file should be requirements txt in the container in the docker container as well once I have requirements txt uh in the container what I want to do is I want to run the following command pip3 install dasr requirements txt now if you don’t know that pip install – R installs the dependencies from a requirements txt file so it’s going to install all these packages with these versions with these exact versions now once I have all the dependencies installed I can just go ahead and copy all the files um of the application so I can just do copy everything to everything so or current directory to the current directory on the server so copy everything that’s in this directory um and place it on the server as well now we don’t need the virtual environment we can delete that I think it has read only so I need to delete it in my uh my files applications here application here uh but we copy out all the files all the blueprints templates uh run file and and all that also the requirements file we copy all this uh into the container and then we change the work directory to flask app and then slash blueprint app now why do we do that we do that because we need to run some commands remember since we’re working with databases and we don’t have the database here we need to run all these flask DB commands and we have to run them inside of this directory because if I run them here they’re not going to have any effect I have to run them in here where the appy file is located so I have to change the working directory and then I can say run flask DB init run flask DB migrate run flask DB upgrade and then I have to change back to flas because of course I need to run the following command Python 3 run py this is running our application and that is the docker file that we need to create our uh image for our application so what do we do we Define a python version We Define a working directory we install the requirements we copy all the files we go into the application we do all the flash DB commands we go back and we run the py file the the Run py file that’s basically what we need to do here now in order to actually turn this into an image now we need to use our command line so I’m going to open up my terminal here I’m going to navigate to the directory here where the docker file is located and now we need to use Docker in order to build um the image now the important thing is that you need to have doer installed you need to have Docker running in the background the docker Damon has to be active so in case of Docker desktop you just need to run the application then the docker Damon is going to be up I’m not going to spend any time here now uh going through the installation process of Docker or showing you how to uh you know get Docker onto your system first of all it’s not that complicated second of all I think I have a video on this channel already where I do that I’m only going to show you how you can actually uh go through the steps uh that are necessary for deployment so I expect you to have Docker already on your system um so what we’re going to do here is we’re going to say Docker built– Tac and we can call this for example blueprint Docker or something like this uh and we need to pass uh a a DOT here because this means that we’re using the current uh the current uh directory for this Docker um this Docker process so there you go you can see it did all the steps it ran all the commands and the docker image is written so what I can do now is I can list a Docker images that I have using Docker images but in my case I don’t need to do that because I know uh the docker image name that I provided Docker Tac which is blueprint Docker so I can say Docker run- d-p now this is important we want to map Port 5000 depending on which Port you used to Port 5000 so the port 5000 in the docker container should also be the port 5000 on this machine that I’m running this on and then blueprint docker so I run this and now as a result of that I should be able to go to Local Host 5,000 and see my application is running and I should be able to do all the stuff that I was able to do before as you can see my application is running and it’s running as a Docker container so I can now say uh Docker PS what is running you can see here old Lama seems to be running and this is also running so I can just say Docker stop and I have to provide the container ID which is this one I think it’s enough to just say something like this that it recognizes which one I’m talking about uh and now if I try to reload you can see it’s down it’s offline basically so we do have our Docker image um we do have our Docker image ready now what we need to do is we need to upload this Docker image to um to the server and for that we need to first save it somewhere we need to save the docker image into a tar file so what we’re going to do is we’re going to say Docker save – o and now let’s call this blueprint Docker doar and what I want to store here is the blueprint Dash Docker image so this is going to take a while and then we’re going to create this tar file there you go and this is now the file that I want to deploy or that I want to upload to my server this is the whole thing this is my whole whole application as a Docker image so in my case here I do already have an SSH connection to my virtual machine now how do you get this file onto the server it depends on how you want to do that maybe you have some FTP access uh the simplest way to do that is to do that is to use SCP so SCP is basically just let me just zoom in a little bit here SCP is this command here you can also use tldr to see what SCP does it basically can just upload a file it can upload whole directories uh all you have to do is you have to say SCP then the file that you want to upload in my case blueprint uh Docker dotar and then you have to specify the uh host and user so in my case it’s root at and then the server host uh I’m not sure if I’m going to show this here maybe you see it right now uh maybe I’m going to censor it but I’m going to just enter here um um I’m going to enter my host and then you want to specify after the host name colon and then slash uh the path where you want to store this now in my case I’m here on my server in the root directory so I want to store it at root and then slash and then also the same name Blue Print Docker tar so this is how you do that in my case it’s going to ask me for a password now and it’s going to upload the file as you can see see it’s uploading the file to the server now and once this is done I’m going to be able to use that file on the server so I think I should already be able to see it it’s being uploaded here um and then all we have to do is we have of course we need to have Docker installed on the server as well again go to Docker installation guide to see how to do that it’s just adding uh the repository and then installing some dependencies it’s not too complicated um and what you want to do now when this is uploaded let me just close this here what you want to do now is you want to say Docker load dasi blueprint doer. tar and then I have the blueprint Docker image on the system and I just have to say Docker run uh and then blueprint Docker or actually not not just run sorry we need to say Docker run and then what we did before we need to say Das d-p we want to map again 5,000 to 5,000 uh and then blueprint Docker like this and now you can see it’s running and I can go to my um to my server which is public which is on the internet now this is not local anymore and I can use the application I can create people there you go I can use the application the flask application is now deployed on an actual server using a Docker container and this is how you do that you just need to have have a server you need to have Docker as I said again what you could do is you can use SCP to just upload all the files and you can then install all the dependencies using Pip this would also work probably but that’s a more convenient way to do it so that’s it for today’s video I hope you enjoyed it and I hope you’ll learn something if so let me know by hitting a like button and leaving a comment in the comment section down below and of course don’t forget to subscribe to this Channel and hit the notification Bell to not miss a single future video for free other than that thank you much for watching see you in the next video and bye for

    By Amjad Izhar
    Contact: amjad.izhar@gmail.com
    https://amjadizhar.blog

  • Kolkata and Partition: A Conversation

    Kolkata and Partition: A Conversation

    This text comprises a conversation between two individuals, likely a filmmaker and an interviewee. The discussion centers on Kolkata and the partition of India and Pakistan, exploring the lasting impact of British colonialism and the resulting societal divisions. The speakers reflect on the complexities of identity, communal harmony, and political realities in the aftermath of partition, drawing parallels between historical events and contemporary societal issues. Their conversation highlights the enduring pain and lingering consequences of this historical period.

    Kolkata: History, Culture, and Memory

    Kolkata is described in the sources as a city with significant historical, cultural, and emotional importance. Here’s a breakdown of its significance:

    • Historical Importance: Kolkata was once the capital of British India [1, 2]. The city’s infrastructure, including buildings, roads, and train systems, reflects the story of British rule [1]. The British also established the world’s first supermarket in Kolkata, known as New Market [2]. The city’s history also includes being a site of assembly for the British [2].
    • Cultural Significance:Kolkata is portrayed as a city with a diverse population where people of different backgrounds and religions live together and celebrate each other’s festivals [1].
    • The city is described as having a unique culture, with a variety of languages and issues [3].
    • Kolkata is also associated with the arts and cinema, with references to old Indian films [2, 4].
    • The city has a rich culture, with a unique blend of spices and dishes [5].
    • Emotional Significance:For some, Kolkata holds a deep emotional connection and is considered a “love city” [1]. It is also referred to as a city that “beats in my heart” [1].
    • The city is remembered for its humanity and the ability of its people to connect with others [4].
    • The city is a place of memories, and there is a wish that the quality of life there could be as good as “home grown chicken as good as daal” [2].
    • The city is remembered as a place where Mother Teresa did her service [2].
    • Significance related to Partition: Kolkata is also mentioned in the context of the partition of India, with discussions about the suffering endured by people there [4]. The city is also mentioned as a place that Gandhi went to when attempting to prevent Hindu-Muslim conflict [6].
    • Symbolic Significance: Kolkata is a place of great interest and love, with some people having interests and loves that are fulfilled by the city [4]. It is seen as a place that was home to a variety of people who lived together peacefully until the British rule [5].

    In summary, Kolkata is presented as a city with a rich history, a diverse culture, and a deep emotional connection for many, particularly those with ties to India or the pre-partition era. The city’s significance extends from its historical role as the capital of British India to its cultural importance as a melting pot of diverse communities.

    The Partition of India and Pakistan: Trauma, Blame, and Lasting Consequences

    The partition of India and Pakistan is portrayed in the sources as a deeply traumatic event with lasting consequences, stemming from hasty British decisions and the exploitation of existing tensions [1, 2]. Here’s a breakdown of the key aspects discussed:

    • The Partition’s Impact:
    • The partition resulted in immense suffering, with both Bengal and Punjab being divided and the nation being “torn into pieces” [1].
    • The immense suffering experienced by the people during the partition is emphasized, with the claim that “no one else had to bear” as much [1].
    • Families were displaced and continue to face difficulties in traveling between the two countries [1].
    • The division caused lasting pain, and the effects are described as reaching “till the veins” and being present until “doomsday” [1].
    • The emotional toll is significant, with the speaker stating their “heart does not allow” them to celebrate the division [2].
    • British Role and Responsibility:
    • The British are blamed for the hasty nature of the partition [1].
    • The partition is described as a result of British self-interest, as their power and army were weakening [1]. They were under pressure to leave and did so without a proper plan [1].
    • The British are accused of making two major mistakes: ending the Mughal government and partitioning India. The British are blamed for humiliating and punishing Bahadur Shah Zafar and for the way they left the country, creating long-term issues [2].
    • The British are criticized for creating a system that led to corruption and division, and for creating a system in which people have to bribe others for their needs [3].
    • The British are seen as having a policy to “earn their political bread” by keeping different groups troubled [2].
    • Underlying Tensions and the Two-Nation Theory:
    • The seeds of division were sown when the British started ruling and tried to create India from their own perspective [3].
    • The “two-nation theory,” which posits that Hindus and Muslims are separate nations, is identified as a key factor in the partition [4].
    • Some people on both sides of the divide started to believe in the two-nation theory which increased the religious tensions between Hindus and Muslims, contributing to the division [4].
    • The Muslim League, which was based in Dhaka, is mentioned as an organization that was not influential across all of India at the time of the partition [5].
    • The Nature of the Violence:
    • The violence is described as indiscriminate, with no distinction between Hindus, Muslims, Punjabis, or Sikhs, with the claim that “the English will burn your houses” [5].
    • The violence was also characterized by the demolition of Hindu and Sikh Gurudwaras [5].
    • There is a strong sense of injustice and a critique of how the violence was exploited for political gain [5].
    • Alternative Views and What Could Have Been:
    • The speaker reflects on the possibility of a united India with democracy, implying that it would have been a better alternative [6].
    • The speaker suggests that if the British had stayed and trained the local people, there would not have been a need for partition, implying that the partition was not beneficial and caused devastation [6].
    • The speaker says that the partition happened without the consensus of the people, because of the British, and was not done with democratic principles [3].
    • The speaker suggests the British “were fools to let India and Pakistan become independent”, but rather should have set up a plan for a democratic separation, in order to avoid the pain of the division [3].
    • Relevance of Individuals:
    • Gandhi’s efforts to prevent Hindu-Muslim conflict are acknowledged, although ultimately he was not able to prevent the violence. He went to Kolkata to protest the Hindu-Muslim fighting [5].
    • Allama Iqbal’s realization that India would become independent is mentioned, as is his concern about the consequences of independence [4].

    In summary, the partition of India and Pakistan is portrayed as a tragic event caused by the hasty and self-interested actions of the British, exploiting existing tensions between religious communities. The partition resulted in immense suffering, displacement, and lasting trauma that continues to affect the people and relationships between India and Pakistan [1, 2].

    British Raj: Legacy of Division and Discord

    The sources discuss the British colonial impact on India and Pakistan, emphasizing both the immediate and long-lasting consequences of their rule. Here’s a breakdown of the key aspects:

    • Infrastructure and Systems: The British are credited with establishing infrastructure such as buildings, roads, and train systems in Kolkata, which reflect the story of British rule [1]. They also established the world’s first supermarket, the New Market, in Kolkata [2]. The sources acknowledge that the British implemented systems and structures in India [1].
    • Political and Social Division:
    • The sources argue that the British sowed the seeds of division by attempting to create India from their own perspective [3]. They are blamed for implementing policies that exacerbated tensions between different religious and social groups [3, 4].
    • The British are seen as having a policy to “earn their political bread” by keeping different groups troubled [5].
    • The British are criticized for ending the Mughal government and expelling Bahadur Shah Zafar from the country in a humiliating manner [5].
    • The British are blamed for the hasty partition of India and Pakistan [6]. The partition is described as a result of British self-interest and a desire to leave without a proper plan [6].
    • The partition is described as causing immense suffering, displacement, and lasting trauma that continues to affect the people and relationships between India and Pakistan [6].
    • Economic Impact:
    • The sources suggest that the British created a system that led to corruption [3].
    • The British are blamed for creating a system in which people have to bribe others for their needs [3].
    • The sources compare British contributions to those of the Mughals, concluding that the British seem “totally useless in the competition” [3].
    • Cultural and Identity Issues:
    • The sources argue that the British created a system in which people are identified by name or religion which was not the case in India previously [7].
    • The British are blamed for the two-nation theory, which created a division based on religion and led to the partition [4].
    • The speaker argues that prior to the British rule, people of all religions and languages lived together harmoniously, and that it was the British who disrupted this balance [3].
    • Critiques of British Actions:
    • The sources contain criticisms of British actions and their long-term impact on the region.
    • The speaker suggests the British “were fools to let India and Pakistan become independent,” and should have had a better plan for separation [3].
    • The sources state that the British left without principles, and that the partition was not beneficial [3, 6].
    • The sources also state that the British were driven by self interest, were weak, and did not properly plan their departure [5, 6].
    • Differing perspectives: The sources include differing opinions regarding the British.
    • One viewpoint is that the British did good by providing training and opportunities to the people of India and Pakistan and that this is how they should be remembered [2, 3].
    • Another viewpoint criticizes those who hold the British in high regard, arguing that their policies and actions led to significant problems [3].

    In summary, the sources portray the British colonial impact as a complex mix of infrastructural developments and divisive policies. The lasting impact includes the partition, ongoing tensions, and the disruption of previously harmonious social structures. The sources emphasize the negative consequences of British rule, including the creation of corrupt systems, the fostering of religious division, and the failure to plan for a peaceful transition to independence.

    Personal Reflections and Historical Contexts

    The sources contain several personal anecdotes that provide insight into the speaker’s experiences and perspectives. These anecdotes often relate to broader themes such as friendship, the impact of historical events, and the speaker’s personal connections to specific places. Here are some of the personal anecdotes discussed in the sources:

    • Friendship and Shared Memories:
    • The speaker recounts a friendship with Faheem Akhtar, noting that they became friends in Kadamba garden and then were hosted by Faheem and his family in England [1]. This anecdote illustrates the importance of personal connections and shared experiences in the speaker’s life.
    • The speaker expresses gratitude for the time they spent with Faheem, and how their relationship has impacted the speaker’s life.
    • Personal Connection to Kolkata:
    • The speaker mentions having spent 26 years in Kolkata and considers it a “love city” that “beats in my heart” [1]. This demonstrates a deep emotional connection to the city.
    • The speaker expresses interest in Kolkata’s history and culture, particularly its connection to the British, and how it was the “assembly of the British” [2].
    • The speaker mentions that in 1985, they met a person in Muktsar who they had previously met in Kolkata [3]. This connection demonstrates how the speaker’s life is intertwined with the history and people they’ve met in different places.
    • Experiences with Partition:
    • The speaker describes their personal feelings regarding the partition, explaining that their “heart does not allow” them to celebrate it due to the immense suffering it caused [3].
    • The speaker shares that they had gone to live with unhappy people in order to help them after the partition, noting that this personal experience impacted them deeply [4].
    • The speaker explains that their marriage procession was based on their thoughts about the partition and that they had not thought about it before that, but were moved to do so by the event [5].
    • Personal Encounters and Observations
    • The speaker recalls seeing a picture of Mother Teresa on their pillow as a child, with the words “I am Mother” written below it [2]. This personal anecdote demonstrates the admiration the speaker held for her.
    • The speaker describes witnessing an incident where people were being chased away and their homes were being ruined, which led them to question the meaning of freedom [4]. This personal observation highlights the speaker’s empathy and critical perspective.
    • The speaker recounts seeing a video of a police officer behaving badly on the train and states that this behavior is an example of the type of behavior that is creating divisions in the country [6].
    • The speaker refers to the way that the British changed India so that people are judged by their names, implying that this was a very negative change, and was also a result of the British system [6].
    • Experiences of Living in England
    • The speaker mentions that they moved to England when they were 26 years old, and that they have been living there for 30 years [1].
    • The speaker mentions that the government paid for their social science degree, which then enabled them to work as a professional [1].
    • Other personal connections:
    • The speaker mentions that they are a “big gram eater” and had an interest in learning about the caste system based on that, and the things they learned about Calcutta from the book Ain-e-Akbari [2].
    • The speaker mentions that they are the son of a Syed, and therefore had a personal interest in the caste system [2].

    These personal anecdotes contribute to a richer understanding of the speaker’s viewpoints, highlighting their connections to places, people, and historical events, and how they feel about these things.

    British Colonialism and its Legacy in India and Pakistan

    The sources offer extensive political commentary, primarily focused on the British colonial impact, the partition of India and Pakistan, and the nature of democracy. Here’s a breakdown of the key political points:

    • Critique of British Colonial Rule:
    • The sources heavily criticize the British for their divisive policies and their role in creating the tensions that led to the partition [1-3]. It is argued that the British intentionally exacerbated tensions between religious and social groups to maintain their own power [1, 2].
    • The British are accused of ending the Mughal government and humiliatingly expelling Bahadur Shah Zafar [2]. This is presented as an example of the British acting unjustly and without respect for established rulers [2].
    • The sources claim that the British implemented systems that encouraged corruption [3].
    • The British are described as having left without a proper plan, leading to chaos and immense suffering [1]. The hasty partition is seen as a consequence of the British prioritizing their own interests over the well-being of the people [1].
    • The Partition of India and Pakistan:
    • The partition is portrayed as a catastrophic event caused by British self-interest and a desire to leave without principles [1]. It is noted that the partition resulted in immense suffering, displacement, and lasting trauma [1, 2].
    • The speaker believes that the partition was not a true representation of freedom and that it led to the unnecessary loss of life and property [2]. The speaker mentions that their heart does not allow them to celebrate the partition [2].
    • The speaker suggests that the British were weak and broke the back of the people. It is argued that they should have left with a better plan to avoid the resulting chaos [1].
    • Democracy and its Failures:
    • The sources offer a critical view of democracy, particularly in the context of India and Pakistan. The speaker argues that India is not a true democracy but rather a dictatorship [3].
    • The speaker notes that both countries have been trapped by the hatred created by the division and that neither country is a true democracy [4].
    • The speaker criticizes the idea of the two-nation theory, arguing that it was a political tool used to divide people and create unrest [5].
    • The speaker expresses concern that the current political climate is such that people are being identified by name and religion, which was not the case prior to the British rule [4]. They believe that this focus on identity is further dividing the people of both India and Pakistan [4].
    • The speaker suggests that people in power are using the idea of democracy to justify violence and oppression, by falsely accusing innocent people [6]. They state that instead of true democracy, they see abuse of power [4, 5].
    • The speaker questions whether the freedom that India and Pakistan achieved was worth the immense suffering and division that came with it [2].
    • Religious and Social Division:
    • The speaker argues that the British are responsible for creating divisions between Hindus and Muslims [3, 5]. They believe that prior to the British rule, people of all religions and languages lived together harmoniously [3].
    • The sources criticize the use of religion as a tool for political gain, noting that those who promote division often do so for their own benefit [5, 7]. The speaker also observes that people who incite conflict do not help those who are suffering but rather seek to gain politically from these actions [7].
    • The speaker notes that people are now being defined by their names and religion, which was not the case previously [4]. This is stated to be a negative consequence of British rule [4].
    • The sources highlight the suffering that individuals and communities have faced as a result of the political and religious divisions created [1, 2].
    • Other political commentary:
    • The speaker mentions that the Aligarh movement did not change the situation of India and Pakistan [4].
    • The speaker states that Pakistan was formed because of the idea that they should be separate, which goes against the way that people have lived in the area for centuries [3, 4].
    • The speaker notes that people with two-nation theories tend to create conflict rather than help [7].

    In summary, the political commentary in the sources is largely critical of British colonial rule and its lasting consequences. The speaker emphasizes the negative impacts of the partition, the failure of democracy to address the issues, and the ongoing religious and social divisions within India and Pakistan. The speaker does not present the British in a positive light, but rather presents them as self-serving and ultimately harmful to the region. They argue that the legacy of British rule continues to negatively impact the people and politics of both countries.

    Kolkata: A Personal History

    The speaker has significant personal experiences and connections to Kolkata, which they refer to as their “love city” [1]. Here’s a summary of the speaker’s experiences in Kolkata, based on the sources:

    • Duration of Stay: The speaker lived in Kolkata for 26 years [1]. This long period of residence has clearly shaped their perspective and emotional connection to the city [1].
    • Emotional Connection: The speaker expresses a deep emotional connection to Kolkata, stating that “Kolkata beats in my heart” [1]. This indicates a strong sense of belonging and affection for the city [1].
    • Multiculturalism: The speaker emphasizes that Kolkata is a place where “all the people live together, all the festivals of all the people are celebrated” [1]. They highlight that this inclusivity was a defining characteristic of the city, without any religious or cultural barriers [1].
    • British Influence: The speaker notes that Kolkata was the “assembly of the British” and served as their capital, and that the infrastructure there, including the buildings, roads, and trains, reflect the story of British rule [1].
    • Historical Significance: The speaker was interested in learning about Kolkata’s history, particularly its role as a capital during British rule [1, 2]. They note that the city’s infrastructure and buildings reflect this period [1]. The speaker also learned that the world’s first supermarket was made by the British in Calcutta [2].
    • Personal Encounters: In 1985, the speaker met someone in Muktsar who they had previously met in Kolkata [3]. This anecdote demonstrates how the speaker’s life is intertwined with the people and places they have encountered [3].
    • Cultural Perspective: The speaker sees Kolkata as part of the culture of India, which has a lot of variety [4]. The speaker is very interested in the culture of Kolkata, and is also interested in how it is perceived by others [1].
    • Historical Context: The speaker has a deep interest in the historical context of Kolkata, citing their interest in the book Ain-e-Akbari and how it explains the caste system, and particularly with how that information connects to Calcutta [2]. They have also been very interested in the history of how the British came to the city, and the impact of their rule there [1].

    These experiences in Kolkata have greatly impacted the speaker’s views and opinions as expressed in the sources. The city is not only a place of personal history but also a lens through which the speaker views broader issues of culture, colonialism, and identity [1].

    Kolkata and Lahore: A Comparative Reflection

    The speaker contrasts Kolkata and Lahore, highlighting their distinct characteristics and personal significance. Here’s how the speaker compares the two cities, based on the provided sources:

    • Multiculturalism and Inclusivity: The speaker emphasizes that Kolkata is a city where “all the people live together, all the festivals of all the people are celebrated,” indicating a high level of inclusivity and cultural harmony [1]. The speaker also mentions that in Kolkata, there are no specific identities that cause divisions, and that from the time that they were born to the time that they left the city after 26-27 years, all of the people lived together [1]. In contrast, the speaker does not offer this characterization of Lahore. Instead they refer to the “boxes” in Lahore, implying a city that does not share the same sense of unity as Kolkata [1].
    • Personal Connection: The speaker has a deep emotional connection with Kolkata, which they refer to as their “love city” and state that it “beats in my heart” [1]. This level of personal affection is not expressed for Lahore.
    • Historical Context: The speaker states that Kolkata was the “assembly of the British” and served as their capital [1, 2]. The infrastructure there, including buildings, roads, and trains, reflect the story of British rule [1]. The speaker notes that the British made the world’s first supermarket in Kolkata [2]. There is no equivalent discussion of the historical impact of the British in Lahore.
    • Contrasting Experiences: The speaker mentions that they lived in Kolkata for 26 years [1]. Later, they went to Lahore, and they mention witnessing the suffering of people there, especially related to the partition [3]. The speaker explains that when they have heard about the suffering that Hindu people have endured in Lahore, that they want to learn more about the people who die in buildings, and that their heart does not allow them to celebrate the division of the country. In this way, the speaker is relating how their experiences in Lahore are much different than their experiences in Kolkata, where they were not witness to this kind of suffering.
    • System of Justice: The speaker notes that the government gave them money to get a degree in social science, which they state allowed them to work in a professional job, and that this is something “very beautiful, Masha Allah, very awesome” [1]. The speaker states that these systems of justice are “not the same as in Calcutta” [1]. The speaker does not elaborate further about the differences between the system of justice in Lahore vs. Kolkata.
    • The Impact of British Rule: The speaker implies that the British rule in Kolkata, including the establishment of the New Market, was a significant development [1, 2]. Although the speaker critiques British rule generally, they don’t provide the same level of historical context regarding British rule in Lahore. However, they note that the British are responsible for the division between people in India and Pakistan [4].
    • Current Political Climate: The speaker notes that they believe that the current system of governance is making it so that people are judged by their names [5]. They suggest that this was a change that the British caused in both countries [5]. The speaker believes that this type of system is not in place in Kolkata [1], and they are very concerned about the political climate in both India and Pakistan [5]. They are very critical of the systems and policies that are in place [5].
    • Partition and Suffering: The speaker makes it clear that the partition had a profound impact on Lahore, stating that it was devastating for the people [3]. The speaker notes the suffering of the people in Lahore, and that they have gone to live with unhappy people as a result [3, 6]. They note that their heart will not allow them to celebrate the partition [6]. The speaker mentions that at the time of the partition, Bengal was broken into two parts, and the Punjab was also broken, which caused an immense amount of suffering [3]. The speaker also mentions that they believe that the British are responsible for the partition, because they left so hastily [3]. They do not refer to this kind of suffering specifically in Kolkata, and suggest that people there lived in harmony [1, 4].

    In summary, the speaker views Kolkata as a city with a rich history, multiculturalism, and personal significance, while they portray Lahore as a place marked by the trauma of partition and political and social divisions.

    Kolkata: A British Legacy

    The speaker in the sources indicates that the British played a significant role in shaping Kolkata, both in its physical infrastructure and in its social and political dynamics [1, 2]. Here’s a summary of the British impact on the city according to the speaker:

    • Capital of British India: Kolkata was the “assembly of the British,” and served as their capital [1, 2]. As the capital, it became a focal point of British administrative and colonial power, and the city’s development was directly influenced by British priorities and policies.
    • Architectural and Infrastructure Legacy: The speaker notes that the buildings, roads, and train systems in Kolkata reflect the story of British rule [1, 2]. This indicates that the British significantly invested in and shaped the city’s infrastructure. The British constructed the New Market, which the speaker notes was the world’s first supermarket [1, 2].
    • Social Impact: The speaker believes that the British influenced the way that the people of Kolkata live, and how they interact with each other. The speaker notes that in Kolkata, all the people lived together, and they celebrated each other’s festivals [1]. The speaker sees this as a very important part of the city’s identity, which was influenced by British rule [1].
    • Historical Significance: The speaker expresses an interest in the history of British rule in Kolkata. They have read about the history of Kolkata’s role as a capital during British rule. They connect their understanding of the British rule to how they view the city of Kolkata today [1, 2].
    • Partition: Although the speaker does not directly connect the British to the shaping of Kolkata at the time of the partition, they do express that they believe that the British caused the division of India and Pakistan due to the hasty way that they left [3]. The speaker is aware that the partition significantly impacted the region, and they believe that the British are at fault for this division.

    In summary, the speaker views the British as having a profound and lasting influence on Kolkata, shaping not only its physical landscape but also its social and historical context [1, 2]. The speaker’s perspective is critical, as they suggest that while the British contributed to the city’s development, their policies ultimately led to the division of the country [3].

    Calcutta: A City’s History and Identity

    The speaker’s interest in Calcutta’s history appears to stem from a combination of personal connections, a desire to understand the city’s unique identity, and a critical perspective on British colonial influence. Here’s a breakdown of what prompted their interest in Calcutta’s history, based on the sources and our conversation history:

    • Personal Connection and Identity: The speaker has a deep emotional bond with Calcutta, referring to it as their “love city” and stating that it “beats in my heart” [1]. This strong personal connection seems to have prompted an interest in learning more about the city’s past. Having lived in Calcutta for 26 years [1], the speaker’s desire to understand the historical context behind their own experiences in the city is a motivating factor.
    • Multiculturalism and Social Dynamics: The speaker is interested in the fact that, in Calcutta, “all the people live together, all the festivals of all the people are celebrated” [1]. They contrast this with other places and they seem interested in understanding how this dynamic came to be, and how this unique social dynamic was influenced by the city’s history. The speaker is interested in the fact that in Calcutta, there are no specific identities that cause division, and that from the time that they were born to the time that they left the city after 26-27 years, all the people lived together [1].
    • British Colonial Influence: The speaker notes that Calcutta was the “assembly of the British” and served as their capital, with the city’s infrastructure reflecting British rule [1]. This has sparked an interest in the impact of British colonialism on the city, including its architecture, infrastructure, and social systems. The speaker’s statement that “the buildings, the roads, the trains, the systems there, all show the story of the British rule in them” [1], shows the importance of British history to the speaker’s understanding of the city. The speaker is interested in the way that the British shaped the city, not only in terms of infrastructure, but also in terms of social norms [1].
    • Historical Texts and Accounts: The speaker mentions that they read a couplet about Calcutta and were interested in learning more about the city as a result [1]. The speaker mentions being interested in the book Ain-e-Akbari, and how that book discusses the caste system [2]. This suggests that the speaker’s historical interests also stem from a wider intellectual curiosity about the region and its history, especially as related to Calcutta [2].
    • Contrasting Calcutta with Other Places: The speaker compares the social harmony in Calcutta to the “boxes” in Lahore [1]. This contrast appears to have also heightened the speaker’s interest in understanding how the two cities came to be so different. This seems to have further motivated them to explore the historical factors that contributed to Calcutta’s unique identity.
    • The New Market: The speaker learned that the world’s first supermarket was made by the British in Calcutta [2]. This has contributed to their interest in the history of Calcutta.
    • Desire to understand the Partition: While the speaker does not directly connect their interest in Calcutta to the partition, the fact that they are interested in the suffering that was caused by the partition, and the role of the British in the partition may also be a factor in their interest in the history of Calcutta, and how it came to be a site of British rule [3].

    In summary, the speaker’s interest in Calcutta’s history is prompted by a combination of personal connections, the unique social and cultural dynamics of the city, and a desire to critically examine the impact of British colonial rule. The speaker seems motivated by the desire to understand how these historical forces have shaped the city they know and love.

    The 1947 Partition: A Tragedy of Unnecessary Division

    The speaker views the 1947 Partition with a great deal of sorrow and criticism, emphasizing the immense suffering it caused and questioning its necessity [1]. Here’s a comprehensive breakdown of their perspective:

    • Devastating Suffering: The speaker believes that the Partition resulted in an immense amount of suffering, stating that “the amount of suffering you had to bear and the amount of suffering we had to bear, I think no one else had to bear” [1]. The speaker expresses a deep sense of empathy for those who suffered, noting that the pain of the Partition “reaches till the veins” [1]. They also express that they want to learn more about the suffering that Hindu people have had to endure in Lahore, and that they cannot celebrate the division of the country because of the pain that they have witnessed. The speaker mentions that they went to live with “unhappy people” as a result of the partition, and that their heart will not allow them to celebrate it [2].
    • Unnecessary Division: The speaker questions the purpose and the necessity of the Partition, suggesting that it was a destructive event that tore the nation apart [1]. They state that “for freedom, dividing the country, ruining it so much, praying for these people… did freedom mean anything and it meant nothing” [2]. This suggests they believe that the division of the country was not a necessary component of independence.
    • Critique of British Haste: The speaker believes that the British were responsible for the hasty and poorly planned execution of the partition [1]. They believe that the British left because their “back was broken” and they no longer had the strength to rule, and that they left without establishing a proper plan. They believe that the British should not have left so quickly [1].
    • Personal Impact: The speaker’s personal experiences and observations in Lahore have clearly influenced their view of the Partition [1]. They mention seeing the suffering of people in Lahore and that their heart does not allow them to celebrate the division of the country [2]. The speaker notes that they went to Lahore to be with those who are suffering, which shows how deeply affected they have been by the devastation of the partition [2]. The speaker contrasts this with the peaceful co-existence of people in Kolkata, where the people lived in harmony [3].
    • Impact on Communities: The speaker emphasizes that the Partition caused significant disruption to communities, noting that “the families who have settled here are troubled, they are facing difficulty in coming and going” [1]. They believe that the partition caused long lasting disruptions to peoples’ lives, and that the pain and difficulty that people have experienced is still present today [1].
    • Critique of the Two-Nation Theory: The speaker questions the logic behind the Two-Nation Theory, which posited that Hindus and Muslims could not live together and needed separate nations. The speaker notes that the idea of dividing the nation based on religion caused people to view each other based on their identity rather than their shared humanity, stating that “the politics of Presto of dividing in the name of religion and presenting the two nation theory, all this started from there because when some people on both sides started believing in this They started talking like this is a Hindu, this is a Muslim…” [4]. The speaker notes that prior to the British rule, there was no conflict between people of different religions, and that the British are responsible for causing the division between people [5]. The speaker states that “before the British there was no issue” [5]. The speaker points out that the people who promote the Two-Nation Theory do not do anything to help those who are suffering, and that instead they incite more conflict [6].
    • Long-Term Consequences: The speaker suggests that the consequences of the Partition are ongoing, noting that “we have been trapped in the hatred of those” [7]. They express concern about the political climate of both India and Pakistan, and that the systems are causing people to be known by their name, rather than as individuals, and that this is a direct result of the policies that were put into place during the partition [7].
    • Missed Opportunity for Unity: The speaker notes that, despite the fact that they believe that the British should have stayed, that they should have left the region in a way that would have preserved the unity of the people [7]. They suggest that the division was not inevitable, and that the British left the region in a state of turmoil that resulted in lasting hatred and conflict [7].

    In summary, the speaker views the 1947 Partition as a profoundly tragic event, characterized by immense suffering, unnecessary division, and the long-lasting negative consequences that continue to impact the region [1]. They hold the British responsible for the hasty way that they left and for the division of the people based on religion [1, 5]. The speaker’s personal experiences, combined with their understanding of history, have led them to believe that the partition was a mistake [2].

    Kolkata, Partition, and the Shadow of Empire

    Okay, here is a discussion guide based on the sources and our conversation history, focusing on key themes and points raised by the speaker:

    Themes for Discussion

    • The Impact of British Colonial Rule:
    • How did British rule shape the physical and social landscape of Kolkata [1, 2]?
    • What does the speaker mean when they refer to Kolkata as “the assembly of the British” [1, 2]?
    • How did British rule contribute to the infrastructure of the city, such as the roads, train system, and New Market [1, 2]?
    • What is the speaker’s perspective on the long-term consequences of British rule on India [1-6]?
    • The Speaker’s Personal Connection to Kolkata:
    • What is the significance of Kolkata to the speaker [1]?
    • How has their personal history in Calcutta shaped their views [1]?
    • How does the speaker’s personal connection to Calcutta influence their interest in its history [1, 2]?
    • How does the speaker describe their love for Calcutta [1, 2]?
    • What does the speaker mean when they say that “Kolkata beats in my heart” [1]?
    • How does the speaker’s experience of living in Calcutta for 26 years affect their views [1]?
    • What is the speaker’s view of the multiculturalism of Calcutta [1]?
    • The 1947 Partition:
    • What is the speaker’s view of the 1947 Partition [3, 4]?
    • How does the speaker believe the Partition impacted the people of India and Pakistan [3]?
    • What role do they believe the British played in the Partition [3, 4, 6]?
    • What does the speaker mean when they say that the British left in a “hasty” way [3, 4]?
    • How does the speaker describe the suffering caused by the partition [3, 4]?
    • What are the speaker’s thoughts on the Two-Nation Theory [3, 7]?
    • What does the speaker mean when they say that “the amount of suffering you had to bear and the amount of suffering we had to bear, I think no one else had to bear” [3]?
    • How does the speaker’s personal experience in Lahore contribute to their views of the Partition [3, 4]?
    • What does the speaker mean when they say that “for freedom, dividing the country, ruining it so much…did freedom mean anything and it meant nothing” [4]?
    • What does the speaker mean when they state that “we have been trapped in the hatred of those” [8]?
    • Democracy and Governance:
    • What is the speaker’s perspective on the current state of democracy in India and Pakistan [6, 8]?
    • What is the speaker’s view of political leaders [4-8]?
    • How do they see the relationship between religion and politics in the region [3, 6-8]?
    • What is the speaker’s view of the systems that have been implemented by the governments of India and Pakistan [6, 8]?
    • What does the speaker mean when they say that India is not a democracy, but a dictatorship [6]?
    • What does the speaker mean when they say that “today people are knowing people by name” and that “this was not there in India earlier” [8]?
    • How does the speaker perceive the systems in place that allow for the abuse of the people [8]?
    • Historical Perspective:
    • Why is the speaker interested in the history of British rule in India [2, 4]?
    • How does the speaker’s interest in historical texts, such as the Ain-e-Akbari, influence their perspective [2]?
    • How does the speaker interpret the actions of figures like Bahadur Shah Zafar and Mahatma Gandhi [4, 5, 7]?
    • How does the speaker believe that the British used historical events to justify their rule [4, 5]?
    • What does the speaker mean when they say “before the British there was no issue” [6]?
    • The Role of Individuals in History:
    • What does the speaker think about figures like Mother Teresa, and Syed Ahmed Khan [2, 6]?
    • What is the speaker’s perspective on the role of individuals in promoting division or unity [7, 9]?
    • How does the speaker view figures who have a “two nation theory” [7, 9]?
    • What is the speaker’s view of the role that “criminals” play in society, and how do they define “criminal” [9]?
    • Social Justice and Humanity:
    • How does the speaker’s sense of social justice shape their views of the historical and political events they discuss [3, 4]?
    • How do they define the concept of humanity, and how do they believe that people have failed to uphold these ideals [1, 3, 7, 8]?
    • What is the speaker’s view of how society should treat those who are suffering [3, 8]?
    • What does the speaker mean when they say that “humanity has become lacking in us these days” [3]?
    • How does the speaker’s view of humanity influence their views of the British [6, 8]?

    Questions for Further Exploration

    • How do the speaker’s personal experiences and emotions affect their interpretation of historical events?
    • What are some of the main differences between the speaker’s view of history and other perspectives?
    • How does the speaker’s understanding of history influence their views of contemporary issues?
    • How might the speaker’s perspective challenge or confirm our own understanding of history and society?
    • What are some of the specific examples that the speaker uses to support their points, and what do these examples reveal about their perspective?
    • How does the speaker view the role of religion in the political division of the region [6-9]?

    This study guide is designed to encourage a deep and critical analysis of the speaker’s perspective, using their statements and observations in the provided sources as a starting point for a thoughtful discussion.

    A Critical Perspective on the Partition of India

    Okay, here’s a briefing document based on the provided sources and our conversation history, designed to give a comprehensive overview of the speaker’s perspectives on key topics.

    Briefing Document

    Subject: Analysis of Speaker’s Views on Kolkata, the Partition of 1947, and Related Issues

    Introduction This document provides a detailed analysis of the speaker’s viewpoints as expressed in the provided sources. The speaker offers a critical perspective on various topics including the legacy of British rule, the 1947 partition of India and Pakistan, the nature of democracy, and the importance of social justice and humanity. The analysis is based on the speaker’s statements, reflections, and personal experiences, with an emphasis on understanding their nuanced and often critical perspective.

    Key Areas of Analysis

    • Personal Connection to Kolkata
    • The speaker has a strong emotional connection to Kolkata, which they describe as their “love city” that “beats in [their] heart” [1]. They lived there for 26 years and it is a place they feel deeply connected to.
    • They emphasize the city’s multiculturalism, noting that people of all backgrounds live together and celebrate each other’s festivals [1].
    • They view Kolkata as a place where people co-exist peacefully, which contrasts with their view of the division and conflict they have witnessed in other places [1].
    • British Colonial Rule
    • The speaker acknowledges that the British made Kolkata their capital and developed its infrastructure, including buildings, roads, and the train system [1].
    • They note that the British also established the New Market, which they recognize as the world’s first supermarket [2].
    • While they acknowledge these contributions, they also criticize the British for their negative impact, particularly in causing the partition of India and Pakistan [1, 3].
    • They believe that the British ended the Mughal government and humiliated Bahadur Shah Zafar [4].
    • They also believe that the British were ultimately responsible for the division between people based on religion [5].
    • The speaker believes that the British were motivated by selfishness and did not make a well thought out plan for the end of their rule, and they left because they no longer had the ability to stay [3].
    • The 1947 Partition
    • The speaker views the Partition as a deeply tragic event that caused immense suffering and the unnecessary division of a country [3].
    • They describe the suffering as reaching “till the veins,” and express a deep empathy for those who experienced it [3].
    • They believe that the partition was a mistake, and that the division of the country was not a necessary part of independence [3].
    • They suggest that the partition created long-lasting problems, as families continue to face difficulties in traveling between India and Pakistan [3].
    • The speaker believes that the British were responsible for the hasty and poorly planned execution of the partition, and they should have left in a way that preserved the unity of the people [3].
    • The speaker notes that the suffering that resulted from the partition has caused them to feel that they cannot celebrate the division of the country [3].
    • Critique of the Two-Nation Theory
    • The speaker is critical of the Two-Nation Theory, which posited that Hindus and Muslims could not live together and needed separate nations [6].
    • They believe that this theory promoted division and caused people to view each other based on their religious identity, rather than their shared humanity [6].
    • They argue that there was no issue between people of different religions before the British rule [5].
    • The speaker states that people who promote this theory do nothing to help those who are suffering, and instead incite more conflict [7].
    • Democracy and Governance
    • The speaker expresses a critical view of democracy in India and Pakistan, suggesting that these are not true democracies but dictatorships [5].
    • They believe that the current political systems are causing people to be known by their names rather than as individuals, which is a negative outcome [8].
    • They express concern about the abuse of power by police and government officials, stating that this is a fundamental flaw in the systems [8].
    • The speaker also criticizes the way that governments use the idea of “democracy” to justify their actions [9].
    • Historical Perspective
    • The speaker is very interested in historical texts, such as the Ain-e-Akbari, and they use this knowledge to inform their perspective [2].
    • They express a critical view of historical figures, like Bahadur Shah Zafar, who they believe was wrongly punished by the British [4].
    • The speaker notes that the British used historical events to justify their rule, and that they did so by manipulating these events to achieve their own goals [5].
    • They believe that the root of many of these conflicts can be traced to the way the British altered the course of history [5].
    • The Role of Individuals in History
    • The speaker has a positive view of individuals who worked for peace and unity, like Mother Teresa [2].
    • The speaker is critical of people who promote division based on religion, and points out that these people never take any action to help those who are suffering [7].
    • They note that “criminals” are people of all religions and that they should not be seen as a reflection of their religion [7].
    • The speaker notes that people should be known for their humanity, rather than their religion or political affiliation [6].
    • Social Justice and Humanity
    • The speaker is deeply concerned with the suffering of ordinary people and emphasizes the importance of social justice and the need to protect human rights [3].
    • They believe that people have failed to uphold the ideals of humanity, as they have been divided by the political events of the time [3].
    • They are saddened by the lack of humanity that they have witnessed, and believe that the division of the region has caused people to lose sight of their shared humanity [3, 6].
    • The speaker feels that society has a responsibility to help those who are suffering [3].

    Conclusion

    The speaker’s perspective is marked by a deep sense of empathy, a critical view of colonial history, and a strong commitment to justice and humanity. They view the 1947 partition as a tragic event that continues to impact people today, and they believe that the British colonial rule played a significant role in this division. Their views are informed by their personal experiences, historical knowledge, and a profound concern for the suffering of ordinary people. They offer a nuanced perspective on the issues, and they are highly critical of the political systems that they believe are causing great harm. The speaker feels that people should be known for their humanity, and they deeply lament the loss of unity that was caused by the events that they have discussed.

    Kolkata, Partition, and Humanity

    Okay, here is an FAQ based on the provided sources and our conversation history, designed to give a comprehensive overview of the speaker’s perspectives on key topics.

    Frequently Asked Questions

    • What is the speaker’s connection to Kolkata?
    • The speaker has a very strong emotional connection to Kolkata, describing it as their “love city” that “beats in [their] heart” [1]. They lived there for 26 years and have fond memories of the city [1].
    • They highlight the city’s multicultural nature, where people of all backgrounds live together and celebrate each other’s festivals [1].
    • The speaker views Kolkata as a place of peaceful co-existence, which contrasts with the division and conflict they have witnessed elsewhere [1].
    • What are the speaker’s views on British colonial rule in India?
    • The speaker recognizes that the British made Kolkata their capital and developed its infrastructure, such as buildings, roads, and the train system [1].
    • They also acknowledge that the British established the New Market, which they note was the world’s first supermarket [1, 2].
    • However, they are critical of the British for their negative impact, particularly in causing the partition of India and Pakistan [3, 4].
    • The speaker believes that the British were selfish and did not have a good plan for the end of their rule, and that they left because they no longer had the power to stay [3, 4].
    • They criticize the British for ending the Mughal government and humiliating Bahadur Shah Zafar [4].
    • The speaker believes that the British are responsible for creating divisions between people based on religion [5].
    • What is the speaker’s perspective on the 1947 partition of India and Pakistan?
    • The speaker views the Partition as a tragic event that caused immense suffering and the unnecessary division of a country [3].
    • They describe the suffering caused by the partition as reaching “till the veins” and express empathy for those who experienced it [3].
    • They believe that the partition was a mistake, and that the division of the country was not a necessary part of independence [3].
    • The speaker also suggests that the partition created lasting problems, as families continue to face difficulties in traveling between India and Pakistan [3].
    • They believe that the British were responsible for the hasty and poorly planned execution of the partition, and they should have left in a way that preserved the unity of the people [3].
    • The speaker notes that the suffering that resulted from the partition has caused them to feel that they cannot celebrate the division of the country [4].
    • How does the speaker view the Two-Nation Theory?
    • The speaker is critical of the Two-Nation Theory, which argued that Hindus and Muslims could not live together and needed separate nations [6].
    • They believe that this theory promoted division and caused people to view each other based on their religious identity, rather than their shared humanity [6].
    • They state that there was no conflict between people of different religions before the British rule [5].
    • The speaker argues that people who promote this theory do nothing to help those who are suffering, and instead incite more conflict [7].
    • What are the speaker’s thoughts on democracy and governance?
    • The speaker expresses a critical view of democracy in India and Pakistan, suggesting that these are not true democracies, but rather dictatorships [5].
    • They believe that the current political systems cause people to be known by their names, rather than as individuals, which they see as a negative development [8].
    • They express concern about the abuse of power by police and government officials, stating that this is a fundamental flaw in the system [8].
    • The speaker also criticizes the way that governments use the idea of “democracy” to justify their actions [9].
    • How does the speaker use history to inform their perspective?
    • The speaker is very interested in historical texts, such as the Ain-e-Akbari, and they use this knowledge to inform their views [2].
    • They express a critical view of historical figures, such as Bahadur Shah Zafar, who they believe was wrongly punished by the British [4].
    • The speaker notes that the British used historical events to justify their rule, and they did so by manipulating these events to achieve their own goals [4].
    • They believe that the root of many of the conflicts can be traced to the way that the British altered the course of history [4].
    • What are the speaker’s views on the role of individuals in history?
    • The speaker has a positive view of individuals who worked for peace and unity, like Mother Teresa [2].
    • They criticize people who promote division based on religion, noting that these people never take action to help those who are suffering [7].
    • The speaker states that “criminals” come from all religions and that they should not be seen as a reflection of their religion [7].
    • The speaker believes that people should be known for their humanity, rather than their religion or political affiliation [8].
    • What does the speaker believe about social justice and humanity?
    • The speaker is deeply concerned with the suffering of ordinary people and emphasizes the importance of social justice and the need to protect human rights [3, 4].
    • They believe that people have failed to uphold the ideals of humanity, as they have been divided by the political events of the time [3].
    • They are saddened by the lack of humanity that they have witnessed, and believe that the division of the region has caused people to lose sight of their shared humanity [3].
    • The speaker feels that society has a responsibility to help those who are suffering [3].

    This FAQ provides an overview of the speaker’s complex and nuanced views on these important topics, based on the provided sources.

    India’s Partition: A Legacy of Division

    Okay, here’s a timeline of key events and periods discussed in the sources, based on the speaker’s perspective:

    • Before British Rule:The speaker states that before the British, there was no issue of division between people of different religions or languages [1]. People of all backgrounds lived together peacefully for centuries [1]. This is contrasted with the period of British rule.
    • British Colonial Rule:The British made Kolkata their capital [2, 3]. They developed infrastructure such as buildings, roads, and trains [2, 3].
    • The British also established the New Market, which the speaker notes was the world’s first supermarket [3].
    • The speaker believes the British attempted to create India based on their own perspective, which led to divisions [1].
    • The speaker says the British ended the Mughal government, humiliating Bahadur Shah Zafar [4].
    • 1926:The speaker mentions that the destruction began in Pindi, with the demolition of Hindu and Sikh Gurudwaras [5].
    • The speaker’s father died during this period [5].
    • 1946:August 16, 1946: The speaker references the Direct Action Day and the compulsions felt by Allama Iqbal, who realized the implications of India’s impending independence [6].
    • 1947: Partition of India and Pakistan:The speaker states that the British hastily partitioned India and Pakistan [7].
    • This partition resulted in immense suffering [7].
    • The speaker expresses a strong belief that the partition was a mistake, and that it should not have happened [7].
    • The speaker states that families continue to face difficulties traveling between India and Pakistan [7].
    • Post-Partition:The speaker suggests that the political systems in India and Pakistan have become like dictatorships [1, 8].
    • The speaker believes that people are now known by their names or religious affiliations, rather than their individual humanity [6, 8].
    • They criticize the abuse of power by the police and government officials [8].
    • The speaker notes that the hatred created during the partition continues to affect people today [8].
    • The speaker states that the divisions created by the British and the partition are still relevant in the current situation in India and Pakistan [6, 8].

    This timeline reflects the key events and periods discussed in the sources, as seen through the speaker’s perspective. The speaker sees British rule and the partition as a turning point that introduced conflict and division into a previously peaceful society.

    A Critical View of British Raj in India

    The speaker has a complex and critical view of the British Raj’s impact on India, acknowledging some developments while highlighting significant negative consequences [1-3].

    Positive aspects of British rule mentioned by the speaker include:

    • The British made Kolkata their capital and developed its infrastructure, such as buildings, roads, and train systems [1].
    • The establishment of the New Market in Kolkata, which the speaker notes was the world’s first supermarket [2].

    However, the speaker is primarily critical of the British for the following:

    • Creating divisions: The speaker believes that the British tried to create India from their own perspective, which led to divisions between people of different religions [3]. The speaker says that before the British, people of all religions and languages lived together peacefully [3].
    • Ending the Mughal government: The speaker is critical of the British for ending the Mughal government and humiliating Bahadur Shah Zafar [4].
    • The Partition: The speaker believes the British were responsible for the hasty and poorly planned partition of India and Pakistan in 1947, which caused immense suffering [5]. They believe that this partition was a mistake, and that it should not have happened [3, 5]. The speaker feels that the British left because they no longer had the power to stay, and they did not leave in a way that preserved the unity of the people [5].
    • Selfishness: The speaker accuses the British of being selfish, stating that their actions were motivated by their own political gain [4]. They believe the British did not have a good plan for the end of their rule [5].
    • Long-term negative impact: The speaker notes that the divisions created by the British continue to affect people in India and Pakistan today [3, 5]. They believe that the political systems in India and Pakistan have become like dictatorships, which is a negative outcome of British influence [3].

    The speaker’s overall perspective is that the British Raj had a largely negative impact on India, despite the infrastructure development and other systems that they put in place [1, 2]. They believe that the British created divisions, ended established governments, and caused the tragic partition of India and Pakistan, and that these issues are still causing problems today [3-5].

    British Rule in India: Two Critical Mistakes

    The speaker identifies two major mistakes made by the British [1].

    • First, they opposed the Mughals and ended their government, expelling Bahadur Shah Zafar from the country in a humiliating manner and punishing him despite the fact that he was not a terrorist [1]. The speaker believes that the British should have praised Bahadur Shah Zafar rather than imprisoning him [1].
    • Second, the British acted out of selfishness, which resulted in the partition of India and Pakistan. The speaker asserts that the British did not leave with a good plan for the end of their rule, and they left because they no longer had the power to stay [1, 2]. The speaker notes that the British did not leave the European Union without a plan and should have done the same in India [1].

    Kolkata’s Multicultural Harmony

    The speaker describes Kolkata as a city with a unique and cherished multicultural environment [1]. They emphasize that in Kolkata:

    • People of all backgrounds live together, and celebrate each other’s festivals [1].
    • This co-existence is presented as a norm, as the speaker lived in Kolkata for 26 years [1] and remembers the city as a place “where there is no identity” in the sense that people of different backgrounds blend together [1].
    • The speaker views this aspect of Kolkata as a model for how different groups can live together peacefully [1].
    • They suggest that this is in stark contrast to the divisions and conflicts that they have witnessed elsewhere, particularly after the partition of India and Pakistan [1, 2].

    The speaker’s description highlights Kolkata as an example of harmonious multiculturalism, where diverse communities coexist and celebrate their shared humanity [1].

    The Partition of India: A Legacy of Suffering

    The speaker views the 1947 partition of India and Pakistan as a major mistake with devastating consequences [1]. They believe that:

    • The British were responsible for the partition, carrying it out hastily and without a proper plan [1]. The speaker feels that the British were motivated by selfishness and left because they no longer had the power to stay [2].
    • The partition caused immense suffering for the people involved [1]. The speaker states that the amount of suffering endured during the partition was unlike anything else, and they do not believe that the suffering has ended [1].
    • The partition broke the country into pieces [1]. The speaker states that Bengal and Punjab were divided and the nation was torn apart [1].
    • Families continue to face difficulties traveling between India and Pakistan [1]. The speaker feels that families who settled on either side of the border continue to face hardship related to the difficulties of traveling back and forth between the countries [1].
    • The partition was a major source of conflict [1]. The speaker states that the hatred created during the partition continues to affect people today [3].
    • The speaker believes the partition should not have happened [1]. The speaker wishes the British had not divided the country [4].

    In summary, the speaker views the 1947 partition as a tragic event that resulted from the mistakes and selfishness of the British, causing immense suffering and creating lasting divisions [1, 2]. The speaker wishes the British had not divided the country and believes that this event was one of the worst things that the British did in India [4].

    By Amjad Izhar
    Contact: amjad.izhar@gmail.com
    https://amjadizhar.blog

  • Al Riyadh Newspaper, March 10, 2025 Ramadan Activities, Charity, GDP Growth

    Al Riyadh Newspaper, March 10, 2025 Ramadan Activities, Charity, GDP Growth

    These Saudi Arabian news excerpts from March 10, 2025, cover a diverse range of topics. A major focus is on Ramadan-related activities, including charitable campaigns exceeding 740 million Riyals, the King’s Iftar program providing meals and dates, and the 18th annual Charity Book Exhibition in Riyadh. Other prominent subjects include economic updates, such as a 1.3% GDP growth, increased cement sales, and Aramco’s oil pricing adjustments. The issue also reports on regional and international affairs, including discussions on Gaza, Ukrainian-American meetings in the Kingdom, and oil market fluctuations. Finally, the sources touch upon local developments like a university achieving top ranking in scientific research, environmental compliance efforts, Ramadan preparations in various cities, and updates in sports leagues.

    Study Guide: Saudi Arabia in March 2025

    This study guide is designed to help you review your understanding of the provided news excerpts from the Saudi Arabian newspaper Al Riyadh, dated Monday, March 10, 2025 (10 Ramadan 1446 AH).

    Quiz: Short Answer Questions

    Answer the following questions in 2-3 sentences each, based on the provided source material.

    1. What was the main topic of the “Word” column on page 16?
    2. What international event related to Ukraine was reportedly going to take place in Jeddah? What were some of the key issues expected to be discussed?
    3. What was the reported amount of donations raised so far by the National Campaign for Charitable Work? How was this campaign initiated?
    4. According to the article on page 3, what were the two main programs being carried out by the Ministry of Islamic Affairs during Ramadan? How many countries were involved in each?
    5. What academic achievement did Prince Sultan University reportedly attain in the 2025 Times Higher Education World University Rankings by Subject? What specific area was highlighted?
    6. What government body issued 1289 permits during January and February 2025? What was the purpose of these permits?
    7. What historical event related to Mecca is discussed on page 10? What was the immediate outcome of this event?
    8. According to Tahani Abdullah Al-Khayal’s article, what significant shift has occurred regarding women in Saudi Arabia since the launch of Vision 2030? What statistics support this claim?
    9. What was the overall trend in sales and production for Saudi cement companies during February 2025 compared to February 2024? Which company reportedly had the highest increase in sales?
    10. What initiative has the “Tirmim for Development” association in the Makkah region undertaken since 2022? What is their broader goal beyond just housing?

    Quiz: Answer Key

    1. The “Word” column on page 16 discussed Saudi Arabia’s growing international role and trust in resolving conflicts and crises. It highlighted the Kingdom’s balanced international relations, strategic neutrality, and efforts to establish global peace and stability under the current leadership.
    2. A meeting between the United States and Ukraine was reportedly planned to take place in Jeddah. Key issues expected to be discussed included regional security, trade, economic cooperation, the conflict in Ukraine, and collaboration in the energy sector.
    3. The National Campaign for Charitable Work reportedly surpassed 740 million riyals in donations. This campaign was launched following the approval of King Salman bin Abdulaziz Al Saud through the “Ihsan” platform.
    4. The two main programs were distributing dates to fasting individuals and providing iftar meals. The date distribution program covered 102 countries, while the iftar program served fasting people in 61 countries.
    5. Prince Sultan University reportedly achieved the first position in the 2025 Times Higher Education World University Rankings by Subject for the quality of its scientific research. Its performance in this area was noted to be at 90.5%.
    6. The National Center for Commitment to the Environment issued 1289 permits during January and February 2025. These permits are essential for facilities to enter the market, ensuring their commitment to environmental standards and work requirements.
    7. Page 10 discusses the re-establishment of Umayyad control over Mecca in 73 AH following a decisive battle led by Al-Hajjaj bin Yusuf Al-Thaqafi by order of Caliph Abd al-Malik bin Marwan. This marked the beginning of a new phase focused on restoring Umayyad authority and rebuilding Mecca after a period of conflict.
    8. Since the launch of Vision 2030, the role of women in Saudi Arabia has reportedly experienced qualitative leaps, moving beyond slogans to a tangible reality. Women’s participation in the labor market increased from 17% in 2017 to 37% in 2023, exceeding expectations.
    9. Overall, both sales and production for Saudi cement companies reportedly increased during February 2025 compared to February 2024. “Saudi Cement Company” reportedly had the highest increase in sales at 46%.
    10. Since 2022, the “Tirmim for Development” association in the Makkah region has been undertaking a comprehensive approach to develop places and individuals by improving housing for needy families. Their broader goal extends beyond just physical renovation to enhance the social, psychological, and economic stability of these families, aligning with Vision 2030.

    Essay Format Questions

    Consider the following essay questions and develop a structured argument for each, drawing evidence from the provided source material.

    1. Analyze the key aspects of Saudi Arabia’s foreign policy as presented in the “Word” column and the report on the US-Ukraine meeting in Jeddah. What principles guide the Kingdom’s international engagements, and what role is it attempting to play in global and regional affairs?
    2. Discuss the significance of the National Campaign for Charitable Work and the Ramadan programs of the Ministry of Islamic Affairs in the context of Saudi Arabia’s social and cultural values. How do these initiatives reflect the Kingdom’s leadership’s approach to social responsibility and religious observance?
    3. Evaluate the progress and future potential of women’s empowerment in Saudi Arabia based on the statistics and perspectives presented in Tahani Abdullah Al-Khayal’s article. What factors have contributed to this progress, and what are the broader implications for Saudi society and its Vision 2030 goals?
    4. Examine the economic trends in the Saudi cement sector as reported in the article on page 7. What factors might be influencing these trends, and what do they suggest about the broader economic activity and development within the Kingdom?
    5. Discuss the initiatives and objectives of the “Tirmim for Development” association in the context of Saudi Arabia’s Vision 2030. How does this organization contribute to the Kingdom’s broader goals of sustainable development and improving the quality of life for its citizens?

    Glossary of Key Terms

    • خادم الحرمين الشريفين (Khadim al-Haramayn al-Sharifayn): Custodian of the Two Holy Mosques, a title used by the King of Saudi Arabia signifying his role as the protector of Mecca and Medina.
    • ولي العهد (Wali al-‘Ahd): Crown Prince, the designated successor to the King.
    • رؤية 2030 (Ru’yah 2030): Vision 2030, a strategic framework launched by Saudi Arabia to diversify its economy, develop public service sectors, and position the Kingdom as a global leader.
    • قمة الجامعة العربية (Qimmat al-Jami’ah al-‘Arabiyah): Arab League Summit, a meeting of heads of state of the Arab League member countries.
    • حملة العمل الخيري (Hamlat al-‘Amal al-Khayri): Charitable Work Campaign, a national initiative to encourage and organize charitable donations and activities.
    • التصاريح البيئية (Al-Tasarih al-Bi’iyah): Environmental Permits, official authorizations issued by environmental regulatory bodies for facilities to operate while adhering to environmental standards.
    • أمراء مكة (Umara’ Makkah): Princes of Mecca, referring to the historical rulers and governors of the city of Mecca.
    • تمكين المرأة (Tamkin al-Mar’ah): Women’s Empowerment, the process of enabling women to have control over their lives and exert influence in society.
    • الإسمنت (Al-Ismant): Cement, a basic ingredient of concrete.
    • الإفطار السيار (Al-Iftar al-Sayyar): Mobile Iftar, a project providing ready-made meals to travelers at iftar time during Ramadan.
    • الرائد (Al-Ra’id): Pioneer, leader, or leading.
    • جيولوجي (Jiyuluji): Geological, relating to the study of the Earth’s physical structure and substance, its history, and the processes that act on it.
    • نزوح (Nuzuh): Displacement, the state of being forced to move from one’s home or country.
    • المخيمات (Al-Mukhayyamat): Camps, often referring to refugee camps or temporary settlements.
    • إعادة الإعمار (I’adat al-I’mar): Reconstruction, the process of rebuilding or restoring something that has been damaged or destroyed.
    • المستوطنات (Al-Mustawtanaat): Settlements, often referring to Israeli settlements in occupied Palestinian territories.
    • التنمية المستدامة (Al-Tanmiyah al-Mustadamah): Sustainable Development, development that meets the needs of the present without compromising the ability of future generations to meet their own needs.
    • القطاع الثالث غير الربحي (Al-Qita’ al-Thalith Ghair al-Ribhi): The Third Non-Profit Sector, comprising organizations that are neither government nor for-profit businesses.
    • الركود الأخير (Al-Rukud al-Akhir): The Latest Recession, referring to a recent period of economic decline.
    • المارد (Al-Marid): The Giant, often used metaphorically to describe a powerful entity or potential.

    Saudi Arabia: Global Diplomacy, Charity, and Domestic Progress

    Frequently Asked Questions about the Provided News Articles

    1. What was the main focus of the Saudi delegation’s meetings and activities mentioned in the articles? The Saudi delegation, led by Crown Prince Mohammed bin Salman, focused on international diplomacy and conflict resolution. This included mediating in the Russia-Ukraine crisis by maintaining communication with both Moscow and Kyiv, hosting Ukrainian President Zelenskyy, and preparing for political discussions between the United States and Ukraine in Jeddah. The Kingdom’s efforts aim to achieve lasting peace in the region and globally, reflecting its strategic neutrality and balanced international relations.
    2. What was the “National Campaign for Charitable Work” and how much did it raise? The “National Campaign for Charitable Work” in its fifth edition, launched with the approval of King Salman bin Abdulaziz Al Saud, is an initiative to support charitable work and its impact on society. It gathers donations from businesspeople, institutions, and individuals through the “Ehsan” platform. In its initial phase, the campaign received donations exceeding 740 million Riyals, with significant contributions from the Crown Prince and other high-ranking officials, demonstrating the leadership’s commitment to philanthropy.
    3. What was the outcome of the meeting between Ukrainian and American officials in Saudi Arabia? The articles indicate that a high-level Ukrainian delegation met with an American team in Saudi Arabia for discussions. While the specific outcomes weren’t detailed, the meeting aimed to discuss and agree on necessary decisions and steps regarding the Russia-Ukraine conflict. Expectations suggest potential progress on political dimensions, and the meeting was considered significant for the relations between the participating countries, focusing on regional security, trade, and economic cooperation. Issues like the conflict in Ukraine and energy cooperation were likely on the agenda, potentially leading to new alliances and cooperation.
    4. How is Saudi Arabia supporting Muslims internationally during Ramadan, according to the articles? During Ramadan 1446 AH, Saudi Arabia is implementing programs to distribute dates and provide iftar meals to fasting Muslims across three continents. The King’s programs are executed by the Ministry of Islamic Affairs, distributing dates in 102 countries and iftar meals in 61 countries. These efforts aim to meet the needs of Muslims globally and reflect the Kingdom’s commitment to supporting them in their religious, social, and community needs. Examples include a handover ceremony in Azerbaijan, providing five tons of dates to over 40,000 beneficiaries, and similar initiatives in Kenya and the Maldives, reaching hundreds of thousands of individuals.
    5. What initiatives are being undertaken in Medina during Ramadan to enhance the experience for visitors? The Ministry of Interior is intensifying its efforts to enhance security and manage crowds in the Prophet’s Mosque in Medina during Ramadan 1446 AH. Various security and service sectors are implementing comprehensive plans to ensure the safety of visitors, provide humanitarian support, and offer services. Additionally, the Medina Municipality is enhancing its services by deploying over 8,000 personnel to oversee cleanliness, food safety, and manage street vendors, ensuring a healthy environment for visitors. An innovative “ambulance scooter” service has also been launched to provide rapid medical assistance within the Prophet’s Mosque and its surroundings.
    6. How does the article portray the progress of women’s empowerment in Saudi Arabia in line with Vision 2030? The article highlights significant advancements in women’s empowerment in Saudi Arabia since the launch of Vision 2030. It emphasizes that empowering women is not just an option but a reality reflecting the Kingdom’s ambition to build a modern society that utilizes the potential of all its citizens. The participation of women in the labor market has increased substantially from 17% in 2017 to 37% in 2023, exceeding expectations. Saudi women are now active in various fields and achieving unprecedented accomplishments, driven by a strong political will and continuous support.
    7. What were the key points discussed regarding the global oil market and OPEC+ decisions? The articles discuss the volatility and uncertainty in the global oil market, influenced by OPEC+ decisions to increase production and concerns about oversupply amid potentially slowing global economic growth. The impact of potential US tariffs on major oil suppliers and retaliatory tariffs from countries like Canada are also highlighted as factors that could increase energy costs and negatively affect oil prices. Additionally, political efforts to resume oil exports from Iraq through Turkey have faced setbacks. OPEC maintains a forecast for increased global oil demand in 2025 and 2026, while the International Energy Agency suggests demand might peak within the decade due to the transition to cleaner fuels.
    8. What are the main developments concerning the Israeli-Palestinian conflict discussed in the articles, particularly regarding Gaza? The articles detail ongoing efforts to reach a second phase of a ceasefire agreement in Gaza, with Hamas reportedly agreeing to an independent aid committee to manage the Strip. Israel sent a delegation to Doha for further negotiations, despite reports of no significant progress yet. Key sticking points include the release of Israeli hostages and the withdrawal of Israeli forces, while Hamas insists on remaining in control of Gaza, the complete withdrawal of Israeli forces, reconstruction efforts, and financial aid. The situation in the West Bank, particularly East Jerusalem, is also tense, with a significant increase in the demolition of Palestinian homes by Israeli authorities. In Jenin, Israeli military operations have caused casualties and displacement. A controversial proposal by Donald Trump regarding the future of Gaza and its population transfer has been met with regional and international rejection.

    Saudi Arabia: Diverse Charitable Initiatives

    Based on the provided sources, there is no direct mention of a specific campaign explicitly named “National Charity Campaign”. However, the sources do highlight numerous instances of charitable activities, humanitarian aid, and social support initiatives undertaken in Saudi Arabia. These reflect a broader commitment to charity and helping those in need.

    Here are some examples of charitable actions and related concepts mentioned in the sources:

    • Humanitarian Aid for Ukraine: The Ministry of Foreign Affairs in the Kingdom expressed its welcome for the planned meeting between the United States and Ukraine in Jeddah. The Kingdom affirmed its continuous efforts to achieve a lasting peace in the Ukrainian crisis and has hosted numerous meetings over the past years. These efforts included providing humanitarian and medical aid, as well as food assistance. This demonstrates the Kingdom’s commitment to peace and stability and providing aid to those affected by conflict.
    • Efforts in the Gaza Strip: Saudi Arabia has shown enthusiasm for holding a second phase of negotiations regarding a ceasefire agreement in the Gaza Strip. Hamas expressed its commitment to the terms of the agreement, including the need for aid to enter the sector without restrictions. The Kingdom appears to be supporting efforts towards humanitarian relief in this context.
    • Support for Vulnerable Groups: The Prince of Al-Qassim participated in an iftar with orphans and people with disabilities in Buraidah. This act reflects the leadership’s concern for these groups and their well-being.
    • Support for the Elderly: A memorandum of understanding was signed between the Al-Qassim Governorate and the General Directorate of Technical and Vocational Training to support the Wafa Oasis Association for the Elderly. This aims to enhance cooperation, exchange expertise, and highlight the role of both parties in promoting social responsibility towards the elderly.
    • Ramadan Charity: During the month of Ramadan, the Kingdom organizes programs to distribute dates to fasting people in various countries. This initiative, under the patronage of the Custodian of the Two Holy Mosques and the Crown Prince, signifies the Kingdom’s care and support for Muslims around the world.
    • Charitable Associations: A meeting in Tabuk will include a visual presentation about the achievements of charitable associations in the region during the past year, and will honor the associations that won the Tabuk Charity Award. This indicates the recognition and support for organized charitable efforts within the Kingdom.
    • Culture of Giving: The “Ya Habi Lakum” event in the Eastern Province, part of the “Wa Yabqa Atharuhum” initiative, aims to promote a culture of giving and celebrate its pioneers.
    • Community Initiatives: The “Markaz Al-Balad Al-Amin” initiative in Mecca aims to enhance the exchange of opinions and experiences to boost investment and development services. While not solely a charity campaign, it fosters collaboration for the betterment of the community.
    • Sustainable Development through Charity: One article discusses a developmental project focused on sustainably addressing social issues, including the rehabilitation of dilapidated housing for low-income families. This highlights a strategic approach to charity that aims for lasting impact and social and economic stability. It emphasizes collaboration between various sectors, including government and civil society, to provide comprehensive solutions for beneficiary families.

    While these examples showcase a strong tradition of charitable work and various initiatives within Saudi Arabia, the sources do not provide specific details about a unified “National Charity Campaign.” If you have more context or a specific timeframe for this campaign, providing additional sources might help in offering a more precise discussion.

    Saudi Arabia Local Product Growth and Economic Diversification

    Based on the sources, there is significant information regarding local product growth in Saudi Arabia, particularly focusing on the expansion of non-oil activities and the overall growth of the Kingdom’s Gross Domestic Product (GDP).

    According to the report from the General Authority for Statistics, the real GDP achieved a growth rate of 1.3% during 2024 compared to the previous year. Notably, this growth was driven by a 4.3% increase in non-oil activities and a 2.6% rise in government activities, while oil activities saw a decrease of 4.5%. This highlights a clear trend towards diversification and the growing importance of local, non-oil production.

    Looking at quarterly figures, the real GDP grew by 4.5% in the fourth quarter of 2024 compared to the same quarter of the previous year, with growth across all economic activities. Specifically, non-oil activities grew by 4.7%, oil activities by 3.4%, and government activities by 2.2% on an annual basis during the fourth quarter of 2024. This consistent growth in non-oil sectors demonstrates a positive trajectory for local product expansion.

    The cement sector also provides an example of local market growth. During the first month of 2025, sales of Saudi cement companies in the local market increased by 9.1%. This improvement is attributed to progress in the real estate sector and major projects, aligning with the Kingdom’s Vision 2030. Furthermore, cement production rose by about 12.3%, and exports increased by 5.3% during the same month. This indicates a strengthening of the local building materials industry, contributing to overall economic growth.

    Saudi Vision 2030 is explicitly mentioned as a driving force behind this economic growth. The report states that the positive growth rates of most economic activities in 2024 are in line with the objectives of Vision 2030 to achieve a prosperous economy reflecting the success of the vision’s programs and major legislative reforms.

    The Kingdom’s success in economic diversification is further emphasized. There is a focus on increasing non-oil revenue sources by activating important sectors such as tourism and mining, leveraging the strong digital infrastructure. The growth of the Public Investment Fund’s assets and the increasing contribution of non-oil GDP to the total GDP (from 18.7% in 2016 to 50% in 2023) are concrete indicators of this diversification.

    The halal food industry is another area with significant local and global growth potential. The sources discuss the increasing demand for halal products from Muslim consumers living in non-Muslim countries, pushing global markets to cater to these needs. Factors contributing to the global spread of halal food include globalization, ease of trade, increased health and quality awareness among both Muslims and non-Muslims, and the rising number of Muslims worldwide. Future opportunities for the halal food industry include innovation in halal products (such as plant-based options and cosmetics) and halal tourism, suggesting potential for local businesses to capitalize on this growing market.

    Furthermore, the achievements of Saudi universities in registering patents and the high quality of scientific research at institutions like Sultan University point towards a growing local capacity for innovation, which is crucial for long-term product development and economic growth.

    In summary, the sources indicate a positive trend in local product growth in Saudi Arabia, primarily driven by the expansion of non-oil sectors in line with Vision 2030. This is evident in the overall GDP growth, the strong performance of non-oil activities, the expansion of industries like cement, and the potential of sectors like halal food. The focus on diversification and innovation further supports the prospects for continued local product growth in the Kingdom.

    Ramadan Iftar: Charity, Community, and Cuisine

    Based on the sources, the concept of Ramadan Iftar Tables is highlighted through various mentions of breaking fast during the holy month.

    • Charitable Giving during Ramadan often involves providing iftar. The National Charity Campaign, although not explicitly detailed in the sources [previous conversation], aligns with the spirit of giving seen in Ramadan, which can include supporting iftar for those in need.
    • Leaders participate in iftar with vulnerable groups. The Prince of Al-Qassim is mentioned participating in an iftar meal with orphans and people with disabilities, sharing a meal and having fatherly conversations with them. This illustrates the importance of iftar as a communal and caring event, especially for those who may be less fortunate.
    • The Kingdom organizes programs to provide iftar internationally. The Custodian of the Two Holy Mosques sponsors programs to distribute dates and provide iftar meals to fasting individuals in numerous countries across the globe during Ramadan. This demonstrates a broader commitment to supporting Muslims during Ramadan by facilitating the breaking of their fast.
    • Specific foods are strongly associated with the Ramadan iftar table in Saudi Arabia. The samboosa is highlighted as a traditional dish that is essential to the Saudi iftar spread. It is so significant that it is considered an appetizer that never disappears from the Ramadan table, with a proverb even mentioning its importance. This emphasizes the cultural and culinary significance of certain foods during iftar.
    • Decorations and symbols signify the arrival of iftar. In Ha’il, the squares are decorated with Ramadan-themed figures, including the Ramadan cannon, symbolizing the time for iftar. This indicates the public recognition and celebration of the time when fasting ends and the iftar meal begins.

    In summary, the sources portray Ramadan iftar tables as central to the observance of the holy month, emphasizing charity, community engagement with vulnerable populations, the provision of meals on both local and international levels, the importance of traditional foods, and public signals marking the time for iftar.

    East Jerusalem Housing Demolitions: Israeli Policy and Impact

    Based on the sources, the discussion of housing demolition policy is specifically focused on the actions taken by Israeli authorities in East Jerusalem. The sources do not contain information about housing demolition policies in general or in Saudi Arabia.

    Here’s what the sources indicate regarding housing demolitions in East Jerusalem:

    • Demolition as a Tactic of Control: The demolition of Palestinian homes by Israeli authorities is described as a key tactic to control the Palestinian population and alter the demographic structure of occupied Jerusalem. This is linked to efforts to increase the number of Jewish settlers in the area.
    • Reasons for Demolition: Demolitions are often carried out under the pretext of building without a permit. However, the Israeli organization “Bimkom” points out that Palestinians are often not permitted to build, contributing to a housing crisis.
    • Examples of Demolitions: The sources mention the demolition of the home of Ibrahim Shehadeh and his family in the “Jabal al-Mukaber” neighborhood in East Jerusalem. Shehadeh had been threatened with demolition since 2018 and received a formal demolition order in December 2024. He was given three weeks to evacuate.
    • Advancement of Settlement Projects: Simultaneously with demolitions, the Israeli government has advanced plans for new Jewish settlement projects in East Jerusalem, potentially leading to the construction of thousands of new settlement units. These projects were previously stalled but were reportedly revived and legalized following President Trump’s inauguration in 2017.
    • International Perspective: The United Nations and the international community consider East Jerusalem occupied territory.
    • Consequences of Demolitions: The demolitions are described as part of an ongoing housing crisis for Palestinians in East Jerusalem. The organization “Bimkom” argues that unless fair housing for Palestinians is considered, these demolitions will continue.
    • Expansion of Settlements: The Israeli government is actively seeking to expand settlements in East Jerusalem to change the demographic balance in favor of Jewish settlers. Several large settlements surrounding Jerusalem are mentioned.

    In summary, the sources highlight that the housing demolition policy discussed is specific to the actions of Israeli authorities in East Jerusalem, viewed as a tactic to control the Palestinian population and expand Jewish settlements in occupied territory. The sources do not provide any information regarding housing demolition policies outside of this specific context.

    Saudi Football League, International Players, and Club Privatization

    Based on the sources, there is extensive discussion about football league competition, particularly focusing on the Saudi Professional League (“Roshen”). The sources also touch upon the performance of Saudi players in international leagues like the Italian Serie A and the English Premier League, as well as international club competitions like the AFC Champions League.

    Here’s a breakdown of the information provided:

    Saudi Professional League (“Roshen”):

    • The competition in the Saudi Professional League (“Roshen”) is described as intense, with closely positioned teams at the top.
    • After the fourth round, the league was considered exciting, with many expecting a strong contender for the title.
    • Al-Ittihad, led by star player Karim Benzema, showed strong performance, leading for several rounds and reaching a nine-point lead at one point. They maintained a strong level with significant fan support, reaching 58 points and competing for the Custodian of the Two Holy Mosques Cup. However, they have since drawn against Al-Khaleej and lost to Al-Akhdoud, failing to capitalize on opportunities to distance themselves from their rivals.
    • Al-Hilal is in second place, four points behind Al-Ittihad with 54 points. Despite internal tension between the coach and fans, injuries, and participation in the AFC Champions League, they remain title contenders. Al-Hilal has recently benefited from rivals dropping points, closing the gap on Al-Ittihad. They are also preparing for a crucial second-leg match in the AFC Champions League after losing the first leg against Pakhtakor in Uzbekistan. The team needs fan support to raise morale and secure victory.
    • Al-Ahli, returning from Asia with a significant away win against Al-Rayyan in Qatar, drew against Al-Khaleej. These dropped points allowed Al-Hilal to close the gap.
    • Al-Nassr also drew with Al-Shabab, further contributing to the tightening competition at the top.
    • Al-Qadisiyah is mentioned as a strong team in the league, and their coach did not succeed in the first-leg cup match but believes they can win the return leg with the support of their fans and home advantage.
    • Other teams mentioned include Al-Najma, led by Portuguese coach Mário Silva and featuring players like Algerian defender Billal Aouadhiya, and Al-Adalah, coached by Slovakian Martin Solva and with players like Nigerian Antwiwaa Erkuombei. Their head-to-head record shows eight wins for Al-Adalah, eight for Al-Najma, and four draws in their 20 previous encounters.
    • Matches between Abha and Al-Jabalain, and Al-Ittihad Jeddah and Abha are also mentioned, highlighting the ongoing league fixtures. Al-Jubail defeated Al-Najma.

    Saudi Players in International Leagues:

    • Saud Abdulhamid returned to AS Roma’s starting lineup in the Italian league. Despite limited opportunities, he provided a crucial assist in a 4-1 victory, becoming the first Saudi player to assist a goal in Serie A. He also started in a Europa League match against Sporting Braga and scored, becoming the first Saudi to score in the Europa League.
    • The English Premier League is mentioned with Manchester United drawing against Arsenal, potentially paving the way for Liverpool to win the title. Manchester City defeated Nottingham Forest, while Chelsea also won.

    Saudi Club Privatization:

    • There are discussions about the privatization of Saudi football clubs, divided into two main paths.
    • The first path involves the transfer of ownership of Al-Ahli, Al-Ittihad, Al-Nassr, and Al-Hilal to royal entities.
    • The second path involves the Public Investment Fund (PIF) acquiring Al-Qadisiyah, Al-Orobah, Al-Derai’yah, and Al-Elm.
    • A second phase will offer 14 clubs for privatization to investors, with this step in its final stages.
    • The success of the initial privatization steps is noted, with Al-Qadisiyah and Al-Orobah being promoted to higher leagues after acquisition by PIF-related entities.
    • Concerns are raised about the exclusion of historically significant clubs like Al-Shabab, Al-Ettifaq, and Al-Riyadh from these initial privatization steps.

    Footballing Opinions and Analysis:

    • An opinion piece discusses Al-Hilal’s performance and their coach’s delayed corrections, leading to dropped points.
    • Another piece expresses happiness with the positive changes in Saudi football due to the privatization efforts.

    In summary, the sources provide a snapshot of the intense competition within the Saudi Professional League, highlighting the performances of top teams like Al-Ittihad and Al-Hilal. They also note the progress of Saudi players in international leagues and the significant ongoing process of privatizing Saudi football clubs.

    By Amjad Izhar
    Contact: amjad.izhar@gmail.com
    https://amjadizhar.blog