#5 Variables in Java

#5 Variables in Java

Understanding Java Development Process

Overview of Java Compilation and Execution

  • The process begins with writing Java code, which is saved with a .java extension. This code is compiled using the javac compiler.
  • Upon compilation, the output is bytecode stored in a .class file, which can be executed on the Java Virtual Machine (JVM) as part of the Java Runtime Environment (JRE).
  • Developers require the Java Development Kit (JDK), which includes an updated JRE and JVM. The current version discussed is JDK 17, known for its long-term support (LTS).
  • Each new version of Java introduces minor updates while maintaining core concepts from earlier versions, ensuring foundational knowledge remains relevant over time.

Purpose of Software Development

  • Software is developed to solve real-world problems by providing virtual solutions; examples include online shopping through Amazon and ride-hailing via Uber.
  • The shift from physical to digital solutions highlights the importance of data management in software applications.

Data Management in Applications

  • Effective software development revolves around data processing; applications must handle user input and perform operations on this data.
  • Data storage occurs primarily in databases for permanent storage, allowing information to persist even after system shutdown.

Temporary vs Permanent Storage

  • While databases serve as permanent storage solutions, temporary data during processing is held in variables.
  • Variables are conceptualized as boxes that store various types of data—numeric values, text strings, images, etc.

Understanding Variables

  • A variable has a name and value; it acts as a container for storing different types of data such as integers or strings.
  • Examples include storing numeric values like 5, decimal numbers like 6.5, or text such as names within appropriately named variables.

Understanding Data Types and Variable Assignment in Java

Introduction to Data Types

  • In Java, data can be categorized into different types. Text is represented as a string, while numbers are classified under numeric types.
  • The integer type (int) is used for whole numbers. It cannot store decimal values like 6.5, which are considered real numbers.
  • Negative and positive integers can be stored using the int type, allowing for a broader range of numerical representation.

Basic Operations and Compilation

  • To perform operations such as addition (e.g., 2 + 2 or 5 + 6), one must first compile the code after making changes to ensure it runs correctly.
  • Multiple statements can be executed sequentially; however, it's important to manage output formatting for clarity.

Output Formatting with Print Statements

  • Using print will display results on the same line, while println allows outputs to appear on new lines for better readability.
  • Transitioning from print to println enhances output organization by ensuring each result appears distinctly.

Variable Declaration and Assignment

  • Variables in Java require declaration of their type before assignment. For example, declaring an integer variable named num1 with a value of 3 involves specifying both the type (int) and the variable name.
  • Each statement in Java must end with a semicolon (;). This signifies the end of that particular instruction.

Creating and Using Multiple Variables

  • When creating variables like num1, it’s essential to declare their types first (e.g., int num1 = 3;). This establishes what kind of data they will hold.
  • The assignment operator (=) assigns values from the right side to variables on the left side.

Performing Calculations with Variables

  • Additional variables can be created (e.g., num2 = 5) and used in calculations directly (e.g., adding two variables).
  • Instead of performing calculations inline, it's advisable to store results in separate variables (like result) for clarity and future use.

How to Create Variables in Programming

Understanding Variable Creation

  • The process of creating a variable involves performing an operation, such as addition, and storing the result in that variable.
  • Instead of printing intermediate results, you can directly print the final result stored in the variable.
  • In this example, adding two values resulted in a total of eight when compiled and run successfully.
Video description

Check out our courses: Complete Java Developer Course Batch-4: https://go.telusko.com/Complete4 Coupon: TELUSKO10 (10% Discount) Spring Boot 3 and Spring AI - Live Course :- https://go.telusko.com/spring3springAI Coupon: TELUSKO10 (10% Discount) Master Java Spring Development : https://go.telusko.com/masterjava Coupon: TELUSKO20 (20% Discount) Udemy Courses: Spring: https://go.telusko.com/udemyteluskospring Java:- https://go.telusko.com/udemyteluskojava Java Spring:- https://go.telusko.com/Udemyjavaspring Java For Programmers:- https://go.telusko.com/javaProgrammers Python : https://go.telusko.com/udemyteluskopython Git : https://go.telusko.com/udemyteluskogit Docker : https://go.telusko.com/udemyteluskodocker For More Queries WhatsApp or Call on : +919008963671 website : https://courses.telusko.com/ In this lecture we will learn: - Working of Java code - How is data stored in a database? - What are variables? - Syntax of variables #1 -As a Java developer you write a Java code that will be having .java extension and that gets compiled by javac. - When you compile that code what you get in output is a byte code that has .class file. - Whenever you run .class file in the JVM, it means that it's a part of JRE that has JVM as well as libraries and a lot of classes, and JRE is installed on the OS. - So, you need a hardware or machine having OS and then OS will have JRE and it has JVM. As a developer, one more tool is required known as JDK. When you will install the new JDK, you will get updated JRE and JVM with it. - We are using JDK version 17 in this course because of its long-term support. - We develop software to solve real-world problems using the virtual world. e.g., Amazon #2 - Whenever we build a project or an application what we are doing is we are processing the data. - Data may come from the user and then we do processing on it. A database is used to store the data and processing done on it. - Database is permanent or persistent storage which means data will remain there if the machine gets shut down. #3 Variables:- - Variable is used to store the data temporarily while processing. - Variable is a type of box in which you store data and a type is attached to it such as type can be number, text, image, etc. Thus, a box is known as a variable and a name and value are present with it. - A variable is a container that holds the value while the Java program is executed. - Java is a strongly-typed language as it demands the declaration of every variable with a data type. - Syntax of creating a variable: datatype variable name = value; int num1= 3; - Here, (=) is the assignment operator that takes the right-hand side value and assigns it to the left-hand side. - println is used to go or print on the new line. - In Java, every statement ends with a semicolon except blocks. Github repo : https://github.com/navinreddy20/Javacode.git Java:- https://bit.ly/JavaUdemyTelusko Spring:- https://bit.ly/SpringUdemyTelusko More Learning : Java :- https://bit.ly/3x6rr0N Python :- https://bit.ly/3GRc7JX Django :- https://bit.ly/3MmoJK6 JavaScript :- https://bit.ly/3tiAlHo Node JS :- https://bit.ly/3GT4liq Rest Api :-https://bit.ly/3MjhZwt Servlet :- https://bit.ly/3Q7eA7k Spring Framework :- https://bit.ly/3xi7buh Design Patterns in Java :- https://bit.ly/3MocXiq Docker :- https://bit.ly/3xjWzLA Blockchain Tutorial :- https://bit.ly/3NSbOkc Corda Tutorial:- https://bit.ly/3thbUKa Hyperledger Fabric :- https://bit.ly/38RZCRB NoSQL Tutorial :- https://bit.ly/3aJpRuc Mysql Tutorial :- https://bit.ly/3thpr4L Data Structures using Java :- https://bit.ly/3MuJa7S Git Tutorial :- https://bit.ly/3NXyCPu Donation: PayPal Id : navinreddy20 https://www.telusko.com