/* related posts with thumb nails */

OOPS, Java Basics:

1. OOPS stands for what?

OOPS stands for Object Oriented Programming System. It is the most popular approach followed by programming languages. Java is one such language which follows OOPS.

2. What are the other languages that support OOP concepts?

C, C++, Java, VB, C# and etc.

3. What are the concepts of OOPS?

The six important concepts of OOPS are

1. Data Encapsulation: Ability to combine several properties into a single unit.

2. Data abstraction: Ability to hide implementation details of member functions.

3. Data Hiding: Ability to hide members of a class so that they are not accessible with objects.

4. Inheritance: Deriving properties of an existing class or object

5. Polymorphism: Different behavior of objects, functions and operators at different situations.

6. Message Passing: Making an object perform a specific action.

4. What is data encapsulation?

Encapsulation means “combining”. This feature allows you to combine several related properties (attributes) and functions (methods) into a single unit as its members. The members of that unit are accessible to its instances depending up on their accessibility conditions.

5. What is Data Hiding?

Data Hiding allows us to make the members of a class not accessible outside. In Java, the accessibility of the members can be controlled by the keywords public, private and protected. When the members are private they are said to be hidden members i.e. not accessible outside the class.

6. What is Data abstraction?

Data Abstraction is an ability to represent a class in shortest possible form. To achieve this developer hides implementation details of the functions but provides list of member variables and prototypes of member functions.

7. What is an abstract data type?

A datatype that allows us to defines members and operations on it. In Java, we use classes to prepare ADTs. In ADT, the internal representation is fully transparent to the user. It is a model for a group of objects which behave same. For example, Stack is an ADT with two operations: 1. Push, to insert elements into a sack and 2. Pop, to delete top most element from the stack.

8. What is Inheritance?

Inheritance allows us to derive the properties of an existing object. It allows extending operations on an object by inheriting the existing properties instead of writing everything from scratch.

9. What is Polymorphism?

Polymorphism means “many forms”. Different behavior of functions or operators or objects at different situations can be called as “polymorphism”. Polymorphism can be exhibited in three different ways: Function Overloading, Operator overloading and Dynamic binding.

10. What is Function Overloading?

Function Overloading allows you to have any number of functions with the same name provided they take different number of arguments or different types of arguments.

11. What is Operator Overloading?

Creating new meaning to the existing operators is operator overloading such that the same opearator behaves differently when used on different operands.

Note: Java does not support explicit operator overloading.

12. What is Dynamic binding?

Linking objects at run-time is dynamic binding.

13. What is Message Communication?

The communication takes place among objects is called message communication. Objects communicate with one another by sending and receiving information with the help of methods.

14. What are the applications of OOP?

The different areas for application of OOP include:

· Real-time systems

· Simulation and modeling

· Object-oriented databases

· Hypertext, hypermedia

· AI and Expert systems

· Neural networks and parallel programming

· Decision support and office automation systems

· CIM/CAD/CAM systems

15. What are the features of Java.

Java has many advanced features when compared to other programming languages.

· Compiled and Interpreted

· Platform-Independent and Portable

· Object-Oriented

· Robust and Secure

· Distributed

· Familiar, Simple and Small

· Multithreaded and Interactive

· High Performance

· Dynamic and Extensible

16. How Java is both Compiled and Interpreted? Justify.

Java programs cannot be executed directly. It involves two-step process. First it gets compiled then it is interpreted i.e. First, Java compiler translates source code into bytecode instructions. Bytecodes are not machine instructions and therefore, in the second stage, Java interpreter generates machine code that can be directly executed by the machine that is running the Java program. We can thus say that Java is both a compiled and an interpreted language. The executin process is shown below.



Java Program


ByteCode (class file)



17. How Java is portable?

Java programs can be easily moved from one computer system to another, anywhere and anytime. Changes and upgrades in operating systems, processors and system resources will not force any changes in Java programs.

18. Why Java is true object oriented programming language.

Java is a true object-oriented language. Almost everything in Java is an object. All program code and data reside within objects and classes. All the variables and functions must be members of some or other classes.

19. What are the differences between C and Java?

Java does not include the C unique statement keywords sizeof, and typedef.

Java does not contain the data types struct and union.

Java does not define the type modifiers keywords auto, extern, register, signed, and unsigned,

Java does not support an explicit pointer type.

Java does not have a preprocessor and therefore we cannot use # define, # include, and # ifdef statements.

Java requires that the functions with no arguments must be declared with empty parenthesis and not with the void keyword as done in C.

Java adds new operators such as instanceof and >>>.

Java adds labelled break and continue statements.

Java does not have “goto” control structure.

Java adds many features required for object-oriented programming.

20. What are the differences between C++ and Java?

Java does not support operator overloading.

Java does not have template classes as in C++.

Java does not support multiple inheritance of classes. This is accomplished using a new feature called "interface".

Java does not support global variables. Every variable and method is declared within a class and forms part of that class.

Java does not use pointers.

Java has replaced the destructor function with a finalize() function.

There are no header files in Java.

21. What are hardware and software requirements to run java programs

IBM-compatible 486 system

Minimum of 8 MB memory

Windows 95 software

A Windows-compatible sound card, if necessary

A hard drive

CD-ROM drive

Microsoft-compatible mouse

22. What is JDK? What are the tools of JDK?

JDK stands for Java Development Kit. It includes the following tools.

appletviewer (for viewing Java applets)

javac (Java compiler)

Java (Java interpreter)

javap (Java disassemble)

javah (for C header files)

javadoc (for creating HTML documents)

jdb (Java debugger)

23. What is the structure of a Java program?

Documentation Section


Package Statement


Import Statements


Interface Statements


Class Definitions


main Method Class


Main Method Definition



24. What are Java Tokens?

Tokens are the ones, which are used to prepare a program. The following are the different tokens available in Java.

1. Reserved Keywords

2. Identifiers

3. Literals

4. Operators

5. Separators

25. What is Unicode character set?

The Unicode is a 16-bit character coding system and currently supports more than 34,000 defined characters derived from 24 languages.

26. What are keywords? How many keywords Java has?

Keywords are Java language reserved words. It has 50 keywords.

27. What are the thumb rules to be followed when declaring identifiers?

They can have alphabets, digits, and the underscore and dollar sign characters.

They must not begin with a digit.

Uppercase and lowercase letters are distinct.

They can be of any length.

28. What is JVM?

All language compilers translate source code into machine code for a specific computer. But, Java compiler produces an intermedia code known as bytecode for a machine that does not exist. This machine is called the Java Virtual Machine and it exists only inside the computer memory. It is a simulated computer within the computer and does all major functions of a real computer

29. What are Command line arguments?

Command line arguments are the parameters passed to the executable java program in the form of strings.Command line arguments are collected in main function itself.

30. What is a variable?

A variable is an identifier that denotes a storage location used to store a data value.

31. What are the rules to be followed when declaring variables?

1. They must not begin with a digit.

2. Uppercase and lowercase are distinct. This means that the variable Total is not the same as total or TOTAL.

3. It should not be a keyword.

4. White space is not allowed.

5. Variable names can be of any length.

32. What is a constant?

Constants are values which can never be changed. Constants can be directly used in expressions or they are assigned to variables.

33. What are the differences between constants and variables?

Variable: A variable is an identifier that denotes a storage location used to store a data value. It is a place holder of a value which can be changed. Every variable in a program has to be declared.

Constants are values which can never be changed. Constants can be directly used in expressions or they are assigned to variables. These can be assigned to variables or can be used in expressions.

34. What are the types of constants in Java?

o Integer constants: An integer type of variables can hold integer constants. There are three types of integers, namely, decimal, octal and hexadecimal integers.

Ex: int x=30

o Real (Float) constants: A real variable can hold float constants. They are whole numbers followed by a decimal point and fractional part. They may be expressed in scientific (exponential) notation.

Ex: float pi=3.14, x=0.64e4

o Char constants: A character variable can hold only one character. Character constant must be enclosed in single quotes.

Ex: char ch= ‘Q’

o String constants: String constant is a character array that can hold string values. Strings must be enclosed in double quotes.

Ex: String s= “kiran”, s1=”1234”;

o Boolean (logical) constants: Boolean constants are true and false. Unlike java, languages like C, C++ use integers to represent true or false.

Ex: boolean x=true

o Backslash Character Constants: These are used in output for formatting.






form feed


new line


carriage return


horizontal tab


single quote


double quote



35. What is a data type? What are the data types in Java?

Data-type specifies what type of value a variable can store. It also specifies its size.


MEMORY (bytes)










-128 to 127

-32768 to 32767

-231 to 231-1

-263 to 263-1

36. What are instance variables?

Instance variables are created when the objects are instantiated and therefore they are associated with the objects. They take different values for each object.

37. What are Class variables?

Class variables are global to a class for which only one memory location is created for each of these. These are basically static data members of a class. They take common value for all the objects.

38. What are Local variables?

Variables declared and used inside methods are called local variables.

39. What are Symbolic Constants

The variables defined with ‘final’ are called symbolic constants. They cannot be modified at later stages in a program. (example: final double PI=3.14)

final float PI=3.14159

final int STRENGTH=50

40. What is Type Casting?

Type casting is a process to convert one data type to another. It makes the variable compatible temporarily. Type casting can be of two types:

Implicit type Casting (Automatic Conversion): when constants and variables of different types are mixed in an expression they are converted to the same type. This conversion is done implicitly by the C compiler. The C compiler converts all the operands to the type of the largest operand. For example if an expression involves int and float, int type gets converted to float type.

Explicit type Casting: if a user forcefully changes the data type into other allowable data type it is said to be explicit type casting.

41. What are the naming conventions followed in Java.

Naming Convention: Naming conventions are a set of rules to be followed to give names to the variables, classes and other tokens of a Java program. It is a better programming practice to follow the naming conventions. One can easily differentiate or understand what are classes, what are methods and etc. It facilitates easy reference i.e. when one refers back to a program, one can easily understand what is what. These are not mandatory but suggested. The following are the naming conventions suggested in Java.

1. Package names in java are written in all small letters

Example: java.awt, java.io, javax.swing , java.mypackage

2. Each word of a class name and interface name starts with a capital letter.

Example: String, DataInputStream, ActionListener

3. Method names starts with a small letter, then each word that follows starts with a capital letter.

Example: readLine( ) , toCharArray()

4. Variable names also follow the above rules as those of methods; words may be separated by underscores (_).

Example: age, empName, employee_Net_Sal;

5. Constants should be written using all capital letters, words are separated by underscores (_) .

Example: PI, MAX_VALUE

6. All key words should be written in all small letters.

Example: public, static, void, main etc…

42. What are comments?

Comment is a non-executable statement in ‘java’ and it is ignored by java compiler. Java allows three different ways to write comments.

1. /*……. */ multi-line commenting.

2. // ……. single line commenting.

3. /**....*/ documentation comment.

Related Topics:


Post a Comment