The document provides an introduction to the Java programming language. It discusses what computer programs and programming languages are, and how Java programs are compiled into bytecode that can run on any machine with a Java interpreter. It then covers basic Java concepts like variables, primitive data types, operators, and object-oriented programming principles. The document includes examples of writing a simple Java program to output "Hello World" and explanations of core Java topics to help new programmers learn the language.
This document provides an introduction to basic Java programming concepts including variables, data types, identifiers, keywords, comments, and outputting variable values. It discusses the different primitive data types in Java like int, double, char, etc. and how to declare and initialize variables of these types. The document also covers Java naming conventions for classes, methods and variables. It explains how to write single line, multi-line and javadoc comments. Finally, it demonstrates how to use System.out.println() and System.out.print() to output the values of variables.
This document discusses Java data types and variables. It defines variables as containers that hold data values and notes there are three types: local, instance, and static. Local variables are declared within methods while instance variables are declared in a class but outside methods. Static variables can be accessed by the class name. The document also outlines Java's primitive data types like int and double, and non-primitive types like Strings and Arrays. It explains type casting between primitive types and differences between primitive and non-primitive data types.
The document provides an overview of Java concepts including:
1. The structure of a basic Java program including the class, main method, and print statement.
2. Explanations of keywords like public, static, void and how the main method works.
3. A description of Java APIs and how prewritten classes and packages are used.
4. Details on Java identifiers, variables, primitive and reference data types.
This document provides an overview of Java basics including where Java is used, its key features, object-oriented programming concepts, platform independence, the structure of a basic Java program, variable types, operators, naming conventions, and constructors. Java is commonly used in desktop applications, web applications, enterprise applications, mobile apps, embedded systems, and more. It is a simple, secure, robust, portable, and interpreted language that is object-oriented, platform independent and supports multithreading. The document defines classes, inheritance, polymorphism, abstraction, and encapsulation. It also explains Java data types, variables, operators, and naming conventions. Constructors are special methods used to initialize objects that are invoked during object creation.
This document provides an overview of the Java programming language. It discusses what Java is, its platform independence, common applications, and key features such as being simple, object-oriented, robust, secure, portable, and high-performance. The document also covers Java variables, data types, operators, control statements, classes and objects, constructors, and static keywords. It provides examples of a first Java program and differences between JDK, JRE, and JVM.
The document discusses the Java Virtual Machine (JVM) and its internal architecture. It describes the JVM as an abstract machine that provides a runtime environment for executing Java bytecode. The JVM specification defines aspects like memory areas, class file format, and error handling. It also discusses the key components of the JVM architecture, including the classloader, method area, heap, stack, and execution engine.
This document provides an overview of key concepts in Java programming including:
1) The components of a Java program such as statements, blocks, classes, and methods.
2) How to structure Java source code files with classes and the main method.
3) Common elements in Java programs like variables, data types, operators, and comments.
4) Details on specific concepts like declaring and initializing variables, arithmetic operators, and increment/decrement operators.
The document provides an introduction to the Java programming language. It discusses what computer programs and programming languages are, and how Java programs are compiled into bytecode that can run on any machine with a Java interpreter. It then covers basic Java concepts like variables, primitive data types, operators, and object-oriented programming principles. The document includes examples of writing a simple Java program to output "Hello World" and explanations of core Java topics to help new programmers learn the language.
This document provides an introduction to basic Java programming concepts including variables, data types, identifiers, keywords, comments, and outputting variable values. It discusses the different primitive data types in Java like int, double, char, etc. and how to declare and initialize variables of these types. The document also covers Java naming conventions for classes, methods and variables. It explains how to write single line, multi-line and javadoc comments. Finally, it demonstrates how to use System.out.println() and System.out.print() to output the values of variables.
This document discusses Java data types and variables. It defines variables as containers that hold data values and notes there are three types: local, instance, and static. Local variables are declared within methods while instance variables are declared in a class but outside methods. Static variables can be accessed by the class name. The document also outlines Java's primitive data types like int and double, and non-primitive types like Strings and Arrays. It explains type casting between primitive types and differences between primitive and non-primitive data types.
The document provides an overview of Java concepts including:
1. The structure of a basic Java program including the class, main method, and print statement.
2. Explanations of keywords like public, static, void and how the main method works.
3. A description of Java APIs and how prewritten classes and packages are used.
4. Details on Java identifiers, variables, primitive and reference data types.
This document provides an overview of Java basics including where Java is used, its key features, object-oriented programming concepts, platform independence, the structure of a basic Java program, variable types, operators, naming conventions, and constructors. Java is commonly used in desktop applications, web applications, enterprise applications, mobile apps, embedded systems, and more. It is a simple, secure, robust, portable, and interpreted language that is object-oriented, platform independent and supports multithreading. The document defines classes, inheritance, polymorphism, abstraction, and encapsulation. It also explains Java data types, variables, operators, and naming conventions. Constructors are special methods used to initialize objects that are invoked during object creation.
This document provides an overview of the Java programming language. It discusses what Java is, its platform independence, common applications, and key features such as being simple, object-oriented, robust, secure, portable, and high-performance. The document also covers Java variables, data types, operators, control statements, classes and objects, constructors, and static keywords. It provides examples of a first Java program and differences between JDK, JRE, and JVM.
The document discusses the Java Virtual Machine (JVM) and its internal architecture. It describes the JVM as an abstract machine that provides a runtime environment for executing Java bytecode. The JVM specification defines aspects like memory areas, class file format, and error handling. It also discusses the key components of the JVM architecture, including the classloader, method area, heap, stack, and execution engine.
This document provides an overview of key concepts in Java programming including:
1) The components of a Java program such as statements, blocks, classes, and methods.
2) How to structure Java source code files with classes and the main method.
3) Common elements in Java programs like variables, data types, operators, and comments.
4) Details on specific concepts like declaring and initializing variables, arithmetic operators, and increment/decrement operators.
OCA Java SE 8 Exam Chapter 1 Java Building Blocksİbrahim Kürce
The document discusses key concepts in Java including classes, objects, fields, methods, variables, primitive types, reference types, and memory management. It explains that classes are the basic building blocks in Java programs and contain fields and methods. Objects are instances of classes that exist in memory. The document also covers variable scope, default initialization, and garbage collection in Java.
Full CSE 310 Unit 1 PPT.pptx for java languagessuser2963071
This document discusses Java programming fundamentals including naming conventions, data types, literals, and writing a basic Java program. It covers lowercase and uppercase naming rules for variables, methods, and classes. It also describes numeric, boolean, character, and string literals. Key data types like int, float, char, and their ranges are explained. The document provides examples of type conversion, casting, and type promotion in expressions. It concludes with steps for compiling and running a Java program.
Structured Languages- Need and Characteristics of OOP, Data Types and Modifiers, Arrays, Classes, Objects, Pointers, References, Difference between Pointers and References, Inheritance, Constructors, Destructors, and Polymorphism.
E learning excel vba programming lesson 3Vijay Perepa
The document discusses VBA procedures and data types. It defines sub procedures and functions, explaining that functions can return values while subs do not. Examples are provided of how to write subs and functions. The document also discusses public and private procedures, and different variable data types in VBA like Byte, Boolean, Integer, Long, Currency, Single, Double, Date, String, Object, and Variant. It provides the valid value ranges for each data type. The next class will cover all the data types with examples.
This document provides an introduction to the Java Development Kit (JDK). It discusses the key components of the JDK including the Java compiler (javac), Java Virtual Machine (JVM), Java API, and Java Runtime Environment (JRE). It also covers Java bytecode, data types in Java, type conversion and casting, ASCII vs Unicode encodings, and differences between J2SE, J2ME, and J2EE.
Many students reach out to me asking for project ideas they can do as a summer project for learning. Here is an interesting project idea - implement your own java disassembler (and expand it to a VM later).
The document discusses Java programming language. It begins by asking what Java is and then answering that Java is a high-level programming language. It then discusses key Java concepts like what a programming language is, the different types of programming languages (low-level, middle-level, high-level), and defines Java as a platform-independent, object-oriented, robust, and secure high-level programming language. The document also covers Java history, features, basic program structure, variables, data types, operators, and conditional statements.
Object-Oriented Programming with Java UNIT 1SURBHI SAROHA
This document provides an introduction and syllabus for an Object-Oriented Programming with Java course. The syllabus covers key Java concepts like keywords, variables, data types, operators, decision making, classes, objects, methods, inheritance, and arrays. It also describes the importance and features of Java, including being platform independent, secure, portable, robust, and high performance. The document includes code examples for a first Java program and demonstrates various operators.
This document provides lecture notes on computer programming using object-oriented Java. It begins with a brief history of Java, explaining that it was developed in 1991 and renamed to Java in 1995. It then discusses why Java is a popular programming language due to its portability, memory management, extensibility, security, simplicity, and robustness. The document proceeds to cover integrated development environments, object-oriented programming concepts, data types in Java including primitive and reference types, operators, variables, and the basic components of a Java application program.
Introduction to Java Object Oiented Concepts and Basic terminologiesTabassumMaktum
The document discusses the basic concepts of object-oriented programming including objects, classes, abstraction, encapsulation, inheritance, and polymorphism. It defines objects as entities with attributes and behaviors. Classes are templates that describe common properties and behaviors of objects. Abstraction hides unnecessary details and focuses on important attributes. Encapsulation binds code and data together and restricts access. Inheritance creates a parent-child relationship between classes where subclasses inherit attributes of base classes. Polymorphism allows the same operation to be applied to different types.
Java is an object-oriented programming language that was developed by James Gosling at Sun Microsystems to allow programs to be executed on the web, it has features like being simple, object-oriented, distributed, architecture neutral, robust, interpreted and compiled, and secure. Java programs use variables and operators to store and manipulate data, which can be of primitive types like int and double or non-primitive types like classes, and keywords are reserved words in Java that cannot be used as names.
This document introduces key concepts in Java programming including data types, identifiers, variable declarations, constants, comments, arithmetic operations, input/output, and the Scanner and JOptionPane classes. It defines identifiers as names for classes, methods, and variables that must start with a letter or underscore. It describes primitive and non-primitive data types. It explains that variables store values in memory locations and are declared with a type and name. Constants are variables that cannot change value once assigned. Comments are used to explain code. The Scanner class reads input and JOptionPane displays dialog boxes.
The document discusses various Java programming concepts including comments, identifiers, keywords, primitive data types, variables, objects, and access modifiers. It provides examples and definitions for each concept. The key points covered are the eight primitive data types in Java (boolean, char, byte, short, int, long, float, double), how to declare and initialize variables, how to construct objects using the new keyword, and the differences between public, private, protected, default, final, and abstract access modifiers.
The document provides an overview of the Java programming language and platform. It discusses the Java language basics including variables, operators, control flow statements, and primitive data types. It also covers object-oriented programming concepts, classes and objects, exceptions, and concurrency. Finally, it outlines the Java platform components including the Java Virtual Machine and Java API.
The document discusses various .NET programming concepts like variables, data types, loops, and keywords. It provides definitions and examples of concepts like value types vs reference types, constants vs read-only variables, and syntax for if/else, while, for, and switch statements. Key differences between functions and sub-procedures are outlined as well as boxing and unboxing.
This document discusses naming conventions and data types in Java. It provides guidelines for naming classes, methods, variables and packages using camel case and other conventions. It also describes the different primitive and non-primitive data types in Java like integer, floating point, character, boolean, and object reference types. Local, instance, and static variables are explained. The document also covers the different types of literals in Java including integer, floating point, character, string, and boolean literals.
This document provides an introduction to Java. It discusses the history of Java, noting it was developed by James Gosling at Sun Microsystems in 1991. It states that Java resides on many platforms like mobile devices, desktops, servers, embedded devices, and the cloud. The key principle of Java is "write once, run anywhere." It also discusses Java libraries, versions of Java, features of Java like being object-oriented and portable, and how to install and set up Java. It provides an example of a simple "Hello World" Java program. It also covers Java data types, variables, typecasting, arrays, comments, and the Scanner class.
Strategies for Effective Upskilling is a presentation by Chinwendu Peace in a Your Skill Boost Masterclass organisation by the Excellence Foundation for South Sudan on 08th and 09th June 2024 from 1 PM to 3 PM on each day.
The simplified electron and muon model, Oscillating Spacetime: The Foundation...RitikBhardwaj56
Discover the Simplified Electron and Muon Model: A New Wave-Based Approach to Understanding Particles delves into a groundbreaking theory that presents electrons and muons as rotating soliton waves within oscillating spacetime. Geared towards students, researchers, and science buffs, this book breaks down complex ideas into simple explanations. It covers topics such as electron waves, temporal dynamics, and the implications of this model on particle physics. With clear illustrations and easy-to-follow explanations, readers will gain a new outlook on the universe's fundamental nature.
More Related Content
Similar to 2.Lesson Plan - Java Variables and Data types.pdf.pdf
OCA Java SE 8 Exam Chapter 1 Java Building Blocksİbrahim Kürce
The document discusses key concepts in Java including classes, objects, fields, methods, variables, primitive types, reference types, and memory management. It explains that classes are the basic building blocks in Java programs and contain fields and methods. Objects are instances of classes that exist in memory. The document also covers variable scope, default initialization, and garbage collection in Java.
Full CSE 310 Unit 1 PPT.pptx for java languagessuser2963071
This document discusses Java programming fundamentals including naming conventions, data types, literals, and writing a basic Java program. It covers lowercase and uppercase naming rules for variables, methods, and classes. It also describes numeric, boolean, character, and string literals. Key data types like int, float, char, and their ranges are explained. The document provides examples of type conversion, casting, and type promotion in expressions. It concludes with steps for compiling and running a Java program.
Structured Languages- Need and Characteristics of OOP, Data Types and Modifiers, Arrays, Classes, Objects, Pointers, References, Difference between Pointers and References, Inheritance, Constructors, Destructors, and Polymorphism.
E learning excel vba programming lesson 3Vijay Perepa
The document discusses VBA procedures and data types. It defines sub procedures and functions, explaining that functions can return values while subs do not. Examples are provided of how to write subs and functions. The document also discusses public and private procedures, and different variable data types in VBA like Byte, Boolean, Integer, Long, Currency, Single, Double, Date, String, Object, and Variant. It provides the valid value ranges for each data type. The next class will cover all the data types with examples.
This document provides an introduction to the Java Development Kit (JDK). It discusses the key components of the JDK including the Java compiler (javac), Java Virtual Machine (JVM), Java API, and Java Runtime Environment (JRE). It also covers Java bytecode, data types in Java, type conversion and casting, ASCII vs Unicode encodings, and differences between J2SE, J2ME, and J2EE.
Many students reach out to me asking for project ideas they can do as a summer project for learning. Here is an interesting project idea - implement your own java disassembler (and expand it to a VM later).
The document discusses Java programming language. It begins by asking what Java is and then answering that Java is a high-level programming language. It then discusses key Java concepts like what a programming language is, the different types of programming languages (low-level, middle-level, high-level), and defines Java as a platform-independent, object-oriented, robust, and secure high-level programming language. The document also covers Java history, features, basic program structure, variables, data types, operators, and conditional statements.
Object-Oriented Programming with Java UNIT 1SURBHI SAROHA
This document provides an introduction and syllabus for an Object-Oriented Programming with Java course. The syllabus covers key Java concepts like keywords, variables, data types, operators, decision making, classes, objects, methods, inheritance, and arrays. It also describes the importance and features of Java, including being platform independent, secure, portable, robust, and high performance. The document includes code examples for a first Java program and demonstrates various operators.
This document provides lecture notes on computer programming using object-oriented Java. It begins with a brief history of Java, explaining that it was developed in 1991 and renamed to Java in 1995. It then discusses why Java is a popular programming language due to its portability, memory management, extensibility, security, simplicity, and robustness. The document proceeds to cover integrated development environments, object-oriented programming concepts, data types in Java including primitive and reference types, operators, variables, and the basic components of a Java application program.
Introduction to Java Object Oiented Concepts and Basic terminologiesTabassumMaktum
The document discusses the basic concepts of object-oriented programming including objects, classes, abstraction, encapsulation, inheritance, and polymorphism. It defines objects as entities with attributes and behaviors. Classes are templates that describe common properties and behaviors of objects. Abstraction hides unnecessary details and focuses on important attributes. Encapsulation binds code and data together and restricts access. Inheritance creates a parent-child relationship between classes where subclasses inherit attributes of base classes. Polymorphism allows the same operation to be applied to different types.
Java is an object-oriented programming language that was developed by James Gosling at Sun Microsystems to allow programs to be executed on the web, it has features like being simple, object-oriented, distributed, architecture neutral, robust, interpreted and compiled, and secure. Java programs use variables and operators to store and manipulate data, which can be of primitive types like int and double or non-primitive types like classes, and keywords are reserved words in Java that cannot be used as names.
This document introduces key concepts in Java programming including data types, identifiers, variable declarations, constants, comments, arithmetic operations, input/output, and the Scanner and JOptionPane classes. It defines identifiers as names for classes, methods, and variables that must start with a letter or underscore. It describes primitive and non-primitive data types. It explains that variables store values in memory locations and are declared with a type and name. Constants are variables that cannot change value once assigned. Comments are used to explain code. The Scanner class reads input and JOptionPane displays dialog boxes.
The document discusses various Java programming concepts including comments, identifiers, keywords, primitive data types, variables, objects, and access modifiers. It provides examples and definitions for each concept. The key points covered are the eight primitive data types in Java (boolean, char, byte, short, int, long, float, double), how to declare and initialize variables, how to construct objects using the new keyword, and the differences between public, private, protected, default, final, and abstract access modifiers.
The document provides an overview of the Java programming language and platform. It discusses the Java language basics including variables, operators, control flow statements, and primitive data types. It also covers object-oriented programming concepts, classes and objects, exceptions, and concurrency. Finally, it outlines the Java platform components including the Java Virtual Machine and Java API.
The document discusses various .NET programming concepts like variables, data types, loops, and keywords. It provides definitions and examples of concepts like value types vs reference types, constants vs read-only variables, and syntax for if/else, while, for, and switch statements. Key differences between functions and sub-procedures are outlined as well as boxing and unboxing.
This document discusses naming conventions and data types in Java. It provides guidelines for naming classes, methods, variables and packages using camel case and other conventions. It also describes the different primitive and non-primitive data types in Java like integer, floating point, character, boolean, and object reference types. Local, instance, and static variables are explained. The document also covers the different types of literals in Java including integer, floating point, character, string, and boolean literals.
This document provides an introduction to Java. It discusses the history of Java, noting it was developed by James Gosling at Sun Microsystems in 1991. It states that Java resides on many platforms like mobile devices, desktops, servers, embedded devices, and the cloud. The key principle of Java is "write once, run anywhere." It also discusses Java libraries, versions of Java, features of Java like being object-oriented and portable, and how to install and set up Java. It provides an example of a simple "Hello World" Java program. It also covers Java data types, variables, typecasting, arrays, comments, and the Scanner class.
Similar to 2.Lesson Plan - Java Variables and Data types.pdf.pdf (20)
Strategies for Effective Upskilling is a presentation by Chinwendu Peace in a Your Skill Boost Masterclass organisation by the Excellence Foundation for South Sudan on 08th and 09th June 2024 from 1 PM to 3 PM on each day.
The simplified electron and muon model, Oscillating Spacetime: The Foundation...RitikBhardwaj56
Discover the Simplified Electron and Muon Model: A New Wave-Based Approach to Understanding Particles delves into a groundbreaking theory that presents electrons and muons as rotating soliton waves within oscillating spacetime. Geared towards students, researchers, and science buffs, this book breaks down complex ideas into simple explanations. It covers topics such as electron waves, temporal dynamics, and the implications of this model on particle physics. With clear illustrations and easy-to-follow explanations, readers will gain a new outlook on the universe's fundamental nature.
Executive Directors Chat Leveraging AI for Diversity, Equity, and InclusionTechSoup
Let’s explore the intersection of technology and equity in the final session of our DEI series. Discover how AI tools, like ChatGPT, can be used to support and enhance your nonprofit's DEI initiatives. Participants will gain insights into practical AI applications and get tips for leveraging technology to advance their DEI goals.
How to Make a Field Mandatory in Odoo 17Celine George
In Odoo, making a field required can be done through both Python code and XML views. When you set the required attribute to True in Python code, it makes the field required across all views where it's used. Conversely, when you set the required attribute in XML views, it makes the field required only in the context of that particular view.
it describes the bony anatomy including the femoral head , acetabulum, labrum . also discusses the capsule , ligaments . muscle that act on the hip joint and the range of motion are outlined. factors affecting hip joint stability and weight transmission through the joint are summarized.
Main Java[All of the Base Concepts}.docxadhitya5119
This is part 1 of my Java Learning Journey. This Contains Custom methods, classes, constructors, packages, multithreading , try- catch block, finally block and more.
How to Add Chatter in the odoo 17 ERP ModuleCeline George
In Odoo, the chatter is like a chat tool that helps you work together on records. You can leave notes and track things, making it easier to talk with your team and partners. Inside chatter, all communication history, activity, and changes will be displayed.
A review of the growth of the Israel Genealogy Research Association Database Collection for the last 12 months. Our collection is now passed the 3 million mark and still growing. See which archives have contributed the most. See the different types of records we have, and which years have had records added. You can also see what we have for the future.
This presentation was provided by Steph Pollock of The American Psychological Association’s Journals Program, and Damita Snow, of The American Society of Civil Engineers (ASCE), for the initial session of NISO's 2024 Training Series "DEIA in the Scholarly Landscape." Session One: 'Setting Expectations: a DEIA Primer,' was held June 6, 2024.
How to Manage Your Lost Opportunities in Odoo 17 CRMCeline George
Odoo 17 CRM allows us to track why we lose sales opportunities with "Lost Reasons." This helps analyze our sales process and identify areas for improvement. Here's how to configure lost reasons in Odoo 17 CRM
This presentation includes basic of PCOS their pathology and treatment and also Ayurveda correlation of PCOS and Ayurvedic line of treatment mentioned in classics.
2. Cracking the Coding Interview in JAVA - Foundation
List of Concepts Involved:
Topic: Variables
Variables
Identifiers
Data types
Sample output program
How does a program work
A computer program/code consists of various components viz. variables, data types, identifiers, keywords, etc
which help us to build a successful program. Let us learn each one of them in detail and then move to our first
program.
A variable is the title of a reserved region allocated in memory. In other words, it may be referred to as the
name of a memory location.
It is a container that holds the value while the Java program is executed.
Each variable should be given a unique name to indicate the storage area.
A variable is assigned with a data type(we will learn about it after this topic).
Syntax for Declaring a Variable:
Type variable_name [= value];
The variable_name is the name of a variable. We can initialize the variable by specifying an equal sign and a
value (initialization i.e. assigning an initial value, is optional). However, the compiler never assigns a default
value to an uninitialized local variable in Java.
int rate = 40;
datatype variable_name
RAM
Reserved Memory for variable
value
40
Here, rate is an int data type variable with the value 40 assigned to it.
In the example above, the variable can only hold integer values, as indicated by the int data type.
Here, we assigned a value to the variable during the declaration process. However, as stated before, it is
optional.
Variables can be declared and assigned separately. Example,
int rate;
rate = 40;
3. Cracking the Coding Interview in JAVA - Foundation
Topic 3: Identifiers
Changing values of variables
Interestingly, a variable's value can also be changed in the program. Look at the example below :
int rate = 50;
System.out.println(rate); // 50
rate = 60;
System.out.println(rate); // 60
Initially, the value of rate was 50 but it has changed to 60 after the last updation, rate=60.
Naming Conventions for variables in Java
Like us, all java components are identified with their names. There are a few points to remember while naming
the variable. They are as follows -
Variable names should not begin with a number. For example
int 2var;
Whitespaces are not permitted in variable names. For example,
int cricket score;
There is a gap/whitespace between cricket and score.
A java keyword (reserved word) cannot be used as a variable name. For example, int float; is an invalid
expression as float is a pre-defined as a keyword(we will learn about them) in java.
As per the latest coding practices, for variable names with more than one word the first word has all
lowercase letters and the first letter of subsequent words are capitalized. For example, cricketScore,
codePracticeProgram etc. This type of format is called camel case
While creating variables, it's preferable to give them meaningful names like- ‘age’, ‘earning’, ‘value’ etc. for
instance, makes much more sense than variable names like a, e, and v.
We use all lowercase letters when creating a one-word variable name. It's preferable(and in practice) to use
physics rather than PHYSICS or pHYSICS.
// 2var is an invalid variable .
// invalid variables.
An identifier is a name given to a package, class, interface, method, or variable. All identifiers must have
different names.
In Java, there are a few points to remember while dealing with identifiers :
Rule 1 − All identifiers should begin with a letter (A to Z or a to z), $ and _ and must be unique.
Rule 2 − After the first character/letter, identifiers can have any combination of characters.
Rule 3 − A keyword cannot be used as an identifier.
Rule 4 − The identifiers are case-sensitive.
Rule 5 – Whitespaces are not permitted.
Examples of legal identifiers: rank, $name, _rate, __2_mark.
Examples of illegal identifiers: 102pqr, -name.
4. Cracking the Coding Interview in JAVA - Foundation
Topic: Data Types
These variables, identifiers etc. consume memory units. Before proceeding ahead, let us have a look at the
memory unit concept too. Here, we will only focus on the relevant concept of memory.
Basic Memory units:
It refers to the amount of memory or storage used to measure data.
Basic memory units are:
1.Bit
A bit (binary digit 0 or 1) is the smallest unit of data that a computer can process and store.
Symbols 0 and 1 are known as bits.Here, 0 indicates the passive state of signal and 1 indicates the active state
of signal.
At a time, a bit can store only one value i.e 0 or 1. To have a greater range of value, we combine multiple bits.
2.Byte
A byte is a unit of memory/data that is equal to 8 bits.
You may think of a byte as one letter. For example, the letter 'f' is one byte or eight bits.
The bigger units are :
3.Kilobyte
A Kilobyte is a unit of memory data equal to 1024 bytes.
4.Megabyte
A Megabyte is a unit of memory data equal to 1024 kilobytes.
5.Gigabyte
A Gigabyte is a unit of memory data equal to 1024 Megabytes.
Lets us now move to the most important concept - data type
Data types specify the different sizes and values that can be stored in the variable. Based on the data type of a
variable, the operating system allocates memory and decides what can be stored in the reserved memory.
Hence, by assigning different data types to variables, we can store integers, decimals, or characters in these
variables.
There are two types of data types in Java:
Primitive data types: The primitive data types include boolean, char, byte, short, int, long, float and double.
Non-primitive data types: The non-primitive data types include Classes, Strings,Interfaces, and Arrays.
5. Cracking the Coding Interview in JAVA - Foundation
Primitive data types
A primitive type is predefined by the language and is named by a reserved keyword.
1. Boolean Typ
The Boolean data type can have two values– true or false and hence are typically used in true/false
situations.
For example,
Boolean flag=true;
2. Byte Typ
Values for the byte data type range from -128 to 127 (8-bit signed two's complement integer, you will
know more about it once we move to programs and applications).
A byte type is used in place of an int to save memory when it is certain that the value of a variable will be
between -128 and 127.
For example,
byte range=105;
Java Data Types
Primitive
Integer
short double
float
Char boolean
String
Array
Classes
Etc
byte
int
long
Characters Boolean
Floating-Point Number
Non-Primitive
6. Cracking the Coding Interview in JAVA - Foundation
3. Short Typ
The short data type can have values ranging from -32768 to 32767 (16-bit signed two's complement
integer).
If the value of a variable is certain to be between -32768 and 32767, short is used in place of other integer
data types (int, long).
For example,
short loss=-50;
4. Int Typ
Values for the int data type range from -231
to 231
-1(32-bit signed two's complement integer, you will know
about it as we move to programs)
In Java SE 8 and later, you can use the int data type to represent an unsigned 32-bit integer, which has a
minimum value of 0 and a maximum value of 232
-1.
For example,
int profit=5000;
5. Long Typ
Values for the long data type range from - 263
to 263
-1 (64-bit signed two's complement integer).
You can use an unsigned 64-bit integer with a minimum value of 0 and a maximum value of 264
-1, if
you're using Java 8 or later.
For example:
long profit=455559990;
6. Double Typ
The double data type is a 64-bit floating-point data type with double precision.
It should never be used for exact values like currency.
For example:
double height=12.5;
7. Float Typ
The float data type is a 32-bit single-precision floating-point value. If you're curious, you can learn more
about single-precision and double-precision floating-point.
It should never be used for precise values like money.
For example:
float depth=-32.3f;
8. Char Typ
It's a Unicode (an international character encoding standard that provides a unique number for every
character across languages and scripts) 16-bit character.
The char data type has a minimum value of 'u0000' (0) and a maximum value of 'uffff'.
For example:
char temp=’a’;
7. Cracking the Coding Interview in JAVA - Foundation
Topic: Java Output/Display Program
How Does this program Work?
The non-primitive data types are a little advanced concepts which we will cover once we have mastered the
primitives and are well versed with the programming principles of Java.
Now that we have learned all the relevant concepts, let us go ahead and write our very first program!
Let us take a look at how the Java ‘HelloWorldJava’ program works.
class HelloWorldJava {
public static void main(String[] args)
{
System.out.println("Hello World Program in Java");
}}
Output
Hello World Program in Java
// First Program
Compiler:- In computing, a compiler is a computer program that is primarily used to translate source code
from a high-level programming language to a lower-level language to create an executable program.
1. // First Program
Any line that begins with // is a comment. Comments are intended to help users reading the code
understand the program's intent and functionality. The Java compiler completely disregards it.
2. class HelloWorldJava
Every Java application starts with a class definition. The class in the program is called HelloWorldJava, and
its definition is as follows:
class HelloWorldJava {
…..
}
We have to keep in mind that every Java application has a class definition, and the class name should
match the name of the file in Java.
3. Public static void main(String[] args) { ... }
This is the most widely used method. The main method is required in every Java application. All Java
programs begin execution by calling the main() function.
Let’s understand the key terms:
8. Cracking the Coding Interview in JAVA - Foundation
Public: This is a visibility/access specifier that defines the component's visibility. The term ‘public’ refers to
a parameter or component that is visible to everyone.
Static: The keyword ‘static’ indicates that the method/ object/ variable that follows this keyword is static
and can be invoked/called without the object or the dot (.) operator. The presence of the static keyword
before the main method indicates that the main method is static
Void: The keyword ‘void’ indicates that the method returns nothing
Main: The keyword ‘main’ denotes the main method, which is the starting point for any Java program. As
mentioned before, a Java program's execution begins with the main method. The curly braces {}
indicate start and end of main.
String[] args: The command line arguments are stored in the string array args.
4. System.out.println (IMPORTANT)
System.out.println() function is used to print messages on the screen. In Java, the system is a class. The
PrintStream class is represented by the parameters "out" and "println." Println is a method, whereas "out" is an
object.
The built-in method print() is used to display the string which is passed to it.
This output string is not followed by a newline, i.e. the next output will start on the same line.The built-in
method println() is similar to print(), except that println() prints the output in a newline after each call.
Example Code:
public static void main(String[] args) {
System.out.println("Hello World");
System.out.println(“Welcome to Physics Wallah");
}
Output:
Hello World
Welcome to Physics Wallah
Run these examples on your system and check for outputs.
Congratulations! You are officially a programmer now !
9. Cracking the Coding Interview in JAVA - Foundation
MCQs
1. Compiler assigns a default value to uninitialized local variables in Java Programming.
This statement is true or false ?
True
False
Ans b) false
Explanation:
In java, it's mandatory to initialize any local variable before using it because compilers don't assign any default
value to variables.
2. Which of the following data type can store the longest decimal number ?
Options:
boolean
double
float
long
Ans : b) double
Explanation:
Out of all given options, only float and double can hold decimal numbers and double is the longest data type
with 64-bit defined by Java to store floating-point values.
3. Which of the following cannot be stored in character data type?
Options
Special symbols
Letter
String
Digit
Ans c) String
Explanation:
String is a collection of characters and is stored in a variable of String data type.
Upcoming Class Teasers
Taking input from the user