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

Complete Java Answers

The document provides a comprehensive overview of command prompt commands and basic Java programming concepts. It covers topics such as directory structures, Java class members, tokens, and the syntax for various commands and programming constructs. Key commands for file management and Java program execution are also included.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Complete Java Answers

The document provides a comprehensive overview of command prompt commands and basic Java programming concepts. It covers topics such as directory structures, Java class members, tokens, and the syntax for various commands and programming constructs. Key commands for file management and Java program execution are also included.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Comprehensive Answers to Java Questions

COMMAND PROMPT

What is command Prompt?


A command-line interface used to execute commands for managing and troubleshooting
systems.

What is Directory?
A structure in a file system to organize files and other directories.

What is Working Directory?


The current directory in which the user is working and executing commands.

What is Root Directory?


The top-level directory in a file system that contains all other files and directories.

What is Absolute Path?


A complete path from the root directory to the target file or directory.

What is Relative Path?


A path relative to the working directory to reach a file or directory.

By using which command we can clear the screen?


The 'cls' command is used to clear the command prompt screen.

By using which command we can change the drive?


Typing the drive letter followed by a colon (e.g., D:) changes the drive.

By using which command we can create a folder?


The 'mkdir' or 'md' command is used to create a new folder.

By using which command we can rename the folder?


The 'ren' command is used to rename a folder.

By using which command we can remove the folder?


The 'rmdir' or 'rd' command is used to remove a folder.

By using which command we can list the folders?


The 'dir' command lists files and folders in a directory.

By using which command we can navigate the next single folder?


The 'cd <folder_name>' command navigates to a specified folder.
By using which command we can navigate the more than one next folder?
The 'cd <path>' command navigates through a hierarchy of folders.

By using which command we can navigate the previous folder?


The 'cd ..' command navigates to the parent directory.

By using which command we can navigate the more than one previous folder?
The 'cd ..\..' command navigates multiple levels up in the hierarchy.

By using which command we can exit the command Prompt?


The 'exit' command closes the command prompt.

BASIC STRUCTURE OF JAVA PROGRAM

Can we create a class without a main method?


Yes, but it will not execute independently. The main method is required for the program to
run.

Explain about Class Members?


Class members include fields (variables) and methods that define the properties and
behavior of a class.

What is Class block?


The class block is the body of the class enclosed within curly braces, where members are
defined.

What is the syntax to create a Class Block?


class ClassName { // class body }

What is Method Block?


A method block is a part of a class that contains a sequence of statements to perform a
specific task.

Why do we need the Main Method?


The main method serves as the entry point for program execution in Java.

List the statements used to print data in Java?


'System.out.println()', 'System.out.print()', and 'System.out.printf()'.

List the differences between System.out.println() and System.out.print()?


'println()' prints the data and moves to the next line, whereas 'print()' does not.

Can we write more than one semicolon at the end of printing statements?
Yes, but it is unnecessary and considered bad practice.

By using which command can we compile the Java source file?


'javac FileName.java' compiles the source file.
By using which command can we execute the Java .class file?
'java ClassName' runs the compiled .class file.

COMMAND PROMPT

What is command Prompt?


A command-line interface used to execute commands for managing and troubleshooting
systems.

What is Directory?
A structure in a file system to organize files and other directories.

What is Working Directory?


The current directory in which the user is working and executing commands.

What is Root Directory?


The top-level directory in a file system that contains all other files and directories.

What is Absolute Path?


A complete path from the root directory to the target file or directory.

What is Relative Path?


A path relative to the working directory to reach a file or directory.

By using which command we can clear the screen?


The 'cls' command is used to clear the command prompt screen.

By using which command we can change the drive?


Typing the drive letter followed by a colon (e.g., D:) changes the drive.

By using which command we can create a folder?


The 'mkdir' or 'md' command is used to create a new folder.

By using which command we can rename the folder?


The 'ren' command is used to rename a folder.

By using which command we can remove the folder?


The 'rmdir' or 'rd' command is used to remove a folder.

By using which command we can list the folders?


The 'dir' command lists files and folders in a directory.

By using which command we can navigate the next single folder?


The 'cd <folder_name>' command navigates to a specified folder.

By using which command we can navigate the more than one next folder?
The 'cd <path>' command navigates through a hierarchy of folders.
By using which command we can navigate the previous folder?
The 'cd ..' command navigates to the parent directory.

By using which command we can navigate the more than one previous folder?
The 'cd ..\..' command navigates multiple levels up in the hierarchy.

By using which command we can exit the command Prompt?


The 'exit' command closes the command prompt.

BASIC STRUCTURE OF JAVA PROGRAM

Can we create a class without a main method?


Yes, but it will not execute independently. The main method is required for the program to
run.

Explain about Class Members?


Class members include fields (variables) and methods that define the properties and
behavior of a class.

What is Class block?


The class block is the body of the class enclosed within curly braces, where members are
defined.

What is the syntax to create a Class Block?


class ClassName { // class body }

What is Method Block?


A method block is a part of a class that contains a sequence of statements to perform a
specific task.

Why do we need the Main Method?


The main method serves as the entry point for program execution in Java.

List the statements used to print data in Java?


'System.out.println()', 'System.out.print()', and 'System.out.printf()'.

List the differences between System.out.println() and System.out.print()?


'println()' prints the data and moves to the next line, whereas 'print()' does not.

Can we write more than one semicolon at the end of printing statements?
Yes, but it is unnecessary and considered bad practice.

By using which command can we compile the Java source file?


'javac FileName.java' compiles the source file.

By using which command can we execute the Java .class file?


'java ClassName' runs the compiled .class file.
TOKENS

What is Tokens and How many types are there?


Tokens are the smallest elements of a program, such as keywords, identifiers, literals,
operators, and separators.

Explain about Keywords?


Keywords are reserved words in Java with predefined meanings, such as 'int', 'class', and
'return'.

Can we pass keywords for printing statements?


No, keywords cannot be used as variable names or passed directly to printing statements.

What is an Identifier?
Identifiers are the names given to variables, methods, and classes in Java.

Explain about rules of an Identifier?


Identifiers must begin with a letter, underscore, or dollar sign and cannot contain spaces or
reserved keywords.

Explain about conventions of an Identifier?


Identifiers should follow naming conventions such as camelCase for variables and methods,
and PascalCase for classes.

What is the difference between rules and conventions of an Identifier?


Rules are mandatory syntax requirements, while conventions are recommended practices.

What is Literal? How many types are there?


Literals represent constant values in a program. Types include integer, floating-point,
character, string, and boolean literals.

What is Primitive Literal? How many types are there?


Primitive literals include values like numbers (integer, float) and characters. Types are int,
float, char, and boolean.

What is Non-Primitive Literal? Explain in detail.


Non-primitive literals include strings and arrays, representing complex objects rather than
single values.

What is Character Literal?


Character literals represent single characters enclosed in single quotes, e.g., 'A'.

Explain about boolean literals?


Boolean literals represent true/false values in Java.

What is String literal?


String literals represent sequences of characters enclosed in double quotes, e.g., "Hello".

You might also like