DEV Community

Arun Kumar
Arun Kumar

Posted on

Today Test questions

Today test questions trainer give 7 questions i write the answer in 2to3 lines so i learn from full details about this question so i referred some web sites

**_1) compiler and interpreter?_**

In the article Introduction to programming — What is programming?, I briefly explained that Programming languages are used to write code which is then translated into machine-level code which is understood by the computer. This translation is done with the help of tools such as compilers or interpreters.

COMPILER
A compiler is a translator that takes a high-level programming language such as Java as input and produces an output of low-level language (like an assembly or machine language).
It is basically a computer program used to transform codes written in a programming language into machine code (human-readable code to a binary 0 and 1 bits language for a computer processor to understand).

The computer then processes the machine code for performing the corresponding tasks.

The compiler takes the whole code, checks all types of errors, limits, and ranges, and compiles it into machine code which is then executed by the computer. If any changes are made to the code, then the whole code needs to be re-compiled only then will the changes reflect.

INTERPRETER
Interpreter is a program that functions for the translation of a programming language into a comprehensible one. It is a computer program used for converting high-level program statements into machine codes. It includes pre-compiled code, source code, and scripts.

Interpreter is similar to compiler as it also translates high-level programming languages into machine code but the difference is that unlike compiler, interpreter reads the code line by line, check for any error in that line and then convert that line or statement to machine code.

Interpreter does not store the machine level code, so it takes less memory but since the code is not stored, it is generated every time the code is run.

2) Features of Java?
• Java is platform independent
• Java is robust. Robust means powerful.
• Why is it powerful?
• Because java works in multiple platforms like linux, windows, etc
• Memory allocation and it will automatic collects the garbage
• Error handling or exceptional handling
• Java is secured because compile-time checks work perfectly
• No pointers concept in java and security APIs
• Java is distributed because it can be connected with two or three devices at the same time, but Java can be performed in multiple systems.
• Java is multithreading, which means it can perform without affecting any tasks and performs very fast
• Java is mainly an OOPs programming language [class, objects, inheritance, polymorphism, abstraction, encapsulation, interface].

3) Deceleration and initialuzation?
A variable provides us with named storage that our programs can manipulate. Each variable in Java has a specific type, which determines the size and layout of the variable's memory; the range of values that can be stored within that memory; and the set of operations that can be applied to the variable.

You must declare all variables before they can be used. Following is the basic form of a variable declaration − data type variable [ = value][, variable [ = value] ...] ;

Here data type is one of Java's datatypes and variable is the name of the variable. To declare more than one variable of the specified type, you can use a comma-separated list.

Following are valid examples of variable declaration and initialization in Java −

Example
int a, b, c; // Declares three ints, a, b, and c.
int a = 10, b = 10; // Example of initialization
byte B = 22; // initializes a byte type variable B.
double pi = 3.14159; // declares and assigns a value of PI.
char a = 'a';

_
4) ASCII And Unicode?_

ASCII (American Standard Code for Information Interchange) is a character encoding standard that defines 128 characters:

0–31: Control characters (e.g., newline, tab).
32–126: Printable characters (e.g., letters, digits, symbols).
127: The DEL character.
Each ASCII character is represented using 7 bits (or 1 byte with padding). ASCII strings are limited to English alphabets, digits, and basic symbols. They are simple and efficient but not suitable for multilingual or special character support.

Unicode ?
Unicode is a universal character encoding standard that supports virtually all written languages, symbols, and emojis. Unlike ASCII, Unicode provides:

A vast range of characters (over 143,000).
Compatibility with multiple encoding formats such as UTF-8, UTF-16, and UTF-32.
The ability to handle multilingual text and complex scripts.
Java internally uses UTF-16 encoding for strings, allowing it to seamlessly work with Unicode characters.
5)Define class and methods?
The class methods are methods that are declared within a class. They perform specific operations and can access, modify the class attributes.
Class methods declaration is similar to the user-defined methods declaration except that class methods are declared within a class.
The class methods are declared by specifying the access modifier followed by the return type, method_name, and parameters list.
**
6)Identifiers and indentifer rules?**

Java Identifiers
Java identifiers are names given to various elements in a Java program, such as variables, methods, classes, packages, and interfaces.

All Java variables must be identified with unique names.

These unique names are called identifiers.

Rules for Java Identifiers:

Starting Characters: Identifiers must begin with a letter (a-z or A-Z), a dollar sign ($), or an underscore (_). They cannot start with a digit or any other special character.
Subsequent Characters: After the initial character, identifiers may contain letters, digits, underscores, or dollar signs. They cannot contain spaces or other special characters.
Case Sensitivity: Java identifiers are case-sensitive, meaning uppercase and lowercase letters are distinct. For example, “myVariable” and “MyVariable” are treated as different identifiers.
Reserved Keywords: Identifiers cannot be Java keywords or reserved words, as these have predefined meanings in the language. Attempting to use a reserved word as an identifier will result in a compilation error.
Length: Identifiers can be of any length, but it’s advisable to keep them concise and meaningful for improved code readability. Excessively long identifiers may hinder readability and comprehension.

Top comments (0)