0% found this document useful (0 votes)
3 views

JAVA UNIT-1 2MARKS

The document provides a comprehensive overview of fundamental concepts in Java programming, including Object Oriented Programming, data types, variables, type casting, and input methods. It outlines various types of variables (instance, local, and class), explains command line arguments, escape sequences, and the use of the final keyword. Additionally, it covers operators and control statements that dictate the flow of execution in Java programs.

Uploaded by

aghjk7712
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

JAVA UNIT-1 2MARKS

The document provides a comprehensive overview of fundamental concepts in Java programming, including Object Oriented Programming, data types, variables, type casting, and input methods. It outlines various types of variables (instance, local, and class), explains command line arguments, escape sequences, and the use of the final keyword. Additionally, it covers operators and control statements that dictate the flow of execution in Java programs.

Uploaded by

aghjk7712
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

UNIT-1 (2 MARKS)

Q1. What is meant by Object Oriented Programming?

☛OOP is a method of programming in which programs are organised as cooperative collections of


objects. Each object is an instance of a class and each class belong to a hierarchy
Q2. What is token in Java?

☛Token means the smallest individual units of program. In java the following tokenare available
1. Comments
2. Identifiers
3. Separators
4. literals
5. Keywords
Q3. What is type casting in Java?

☛Type casting is the process of converting the one data type of a variable intoanother data type. In
java, there are two types of type casting
 1.Implicit (or) Widening Type Casting
 2.Explicit (or) Narrow Type Casting
Syntax: <datatype> variableName = (<datatype>) value;

Q4.What is widening type casting?

☛ A lower data type is transformed into a higher one by a process known as widening type casting.
Implicit type casting and casting down are some names for it.
Syntax: larger_data_type variable_name = smaller_data_type_variable;

Q.5. What is Narrow type casting


The process of downsizing a bigger data type into a smaller one is known as narrowing type casting.
Casting up or explicit type casting are other names for it. It doesn’t just happen by itself. If we don’t
explicitly do that, a compile-time error willoccur.
Syntax:
smaller_data_type variable_name = (smaller_data_type) larger_data_type_variable;

Q6. What is a variable?

☛ Variable is like a container which can hold some values. Variables are locations inthe memory that
can hold values. Java has three kind of variables.
 Instance variables
 Local variables
 Class variables

Q7. What is Local variable in java?

☛ Local variable is a variable declared inside a method body, block or constructor. These variables are
created when the method, constructor, or block is entered and are destroyed once it exits. Local
variables are only accessible within the scope theyare declared in and cannot be accessed outside of
that scope. It means variable is only accessible inside the method block or constructor that declared it.
Q8. What is a Class variable?

☛Class variable is also known as static variable.

Class variable is a variable defined in a class but outside of any class methodsand shared by all
instances of that class.
Class variables are declared using the static keyword.
Q9. What is instance variable?

☛ Instance variables are non-static variables and are declared in a class outside of any method,
constructor, or block.
 As instance variables are declared in a class, these variables are created whenan object of the
class is created and destroyed when the object is destroyed.
Q10. How to take input from user in JAVA?

☛Java Scanner class allows the user to take input from the console. It belongs to java.util package. It is
used to read the input of primitive types like int, double, long, short, float, and byte. It is the easiest way
to read input in Java program.
Syntax:
Scanner objectname=new Scanner(System.in);

Q11. What is command line argument in java?

☛Command line arguments in Java are parameters passed to the program at the time of execution.
These arguments are received in the main() method as a string array and can be used as input within
the program.
Q12. What are escape sequences in java?
Escape sequences in Java are special characters preceded by a backslash (\) that havea specific
meaning to the compiler. They are used to represent characters that are otherwise difficult to include in
a string, such as newlines, tabs, or quotation marks.
There are eight primary escape sequences in Java, each serving a unique purpose. Common Escape
Sequences

Here are some of the most commonly used escape sequences in Java:
1. \t: Inserts a tab in the text. System.out.println("Hello\tWorld!");Output: Hello World!
2. \b: Inserts a backspace in the text. System.out.println("Hello\bWorld!");Output: HellWorld!
3. \n: Inserts a newline in the text. System.out.println("Hello\nWorld!");Output: //Hello // World!
4. \r: Inserts a carriage return in the text. System.out.println("Hello\rWorld!");Output: World!
5. \f: Inserts a form feed in the text. System.out.println("Hello\fWorld!");Output: Hello // World!
6. \': Inserts a single quote character in the text. System.out.println("Hello\'World!");Output:
Hello'World!
7. \": Inseíts a double quote chaíacteí in the text.
8. \\: Inseíts a backslash chaíacteí in the text.

Q13. What is data type in java?

☛Data type defines the values that a variable can take, for example if a variable has int data type, it can
only take integer values. In java we have two categories of data type:

1) Primitive data types 2) Non-primitive data types

Q14. What are the primitive data types in java?

☛Primitive types in Java are predefined and built into the language. In Java, we have eight primitive
data types: boolean, char, byte, short, int, long, float and double.
 byte, short, int and long data types are used for storing whole numbers.

 float and double are used for fractional numbers.

 char is used for storing characters(letters).

 boolean data type is used for variables that holds either true or false.
Q15. What are non-primitive datatypes in java?

☛Non-primitive data types are called reference types because they refer to objects. Non-primitive types
can be used to call methods to perform certain operationsExamples of non-primitive types are Strings,
Arrays, Classes etc.

Q16. What is scope of a variable in java?

☛The variable's scope refers to the region where they are created and accessed in a given program or
function. The variable scope also refers to its lifetime.
In Java, all identifiers are statically scoped, i.e.scope of a variable can be determinedat compile time
and independent of function call stack.
Q17. What is symbolic constant in java?

☛In Java, a symbolic constant is a named constant value defined once and used
throughout a program. Symbolic constants are declared using the final keyword.
 Which indicates that the value cannot be changed once it is initialized.
 The naming convention for symbolic constants is to use all capital letters withunderscores
separating words.
Syntax : final data_type CONSTANT_NAME = value;
Q18. Define formatted output with printf() method?

☛In Java, the printf() method is used to format output in a way similar to
the printf() function in C. This method is part of the java.io.PrintStream class and allows you to create
formatted strings using various format specifiers.
Syntax:
System.out.printf("Hello, %s!%n", "World");Output:
Hello, World!
Q19. What is static variable in java?

☛In Java, static variables are variables that belong to the class rather than any specific instance of the
class. This means that there is only one copy of the static variable, regardless of how many instances of
the class are created. Static variablesare also known as class variables.
Q20. What is static methods in java?

☛A static method in Java is a method that is part of a class rather than an instance of thatclass

 Every instance of a class has access to the method.


 Static methods have access to class variables (static variables) without using the class’s
object (instance).
 Only static data may be accessed by a static method. It is unable to access data that is not
static (instance variables).
 In both static and non-static methods, static methods can be accessed directly.
Q21. Define final keyword?
In Java, the final keyword is used to indicate that a variable, method, or class cannot be modified or
extended.
Here are some of its characteristics:
 Final variables: When a variable is declared as final, its value cannot be changed once it has been
initialized. This is useful for declaring constants or other values that should not be modified.
 Final methods: When a method is declared as final, it cannot be overridden by a subclass.This is useful
for methods that are part of a class’s public API and should not be modified by subclasses.
 Final classes: When a class is declared as final, it cannot be extended by a subclass. This is useful for
classes that are intended to be used as is and should not be modified or extended.
Q22. Define operators in java?

☛Operators are used to perform operations on variables and values. Operatorsmake tasks like addition,
multiplication, etc
Types of Operators in Java
1. Arithmetic Operators
2. Unary Operators
3. Assignment Operator
4. Relational Operators
5. Logical Operators
6. Ternary Operator
7. Bitwise Operators
8. Shift Operators
9. instance of operator
Q23.Define control statement?
☛The statements that control the execution flow of the program are known as control statements.

Java provides three types of control flow statements.


1. Decision Making statements
2. Loop statements
3. Jump statements

You might also like