Basic Concepts of Java Programming

Basic Concepts of Java Programming


What is Java programming language ?

Ans: Java was originally a programming language invented by Sun Microsystems, by James Gosling. Today Oracle owns Sun, and therefore Java too. Java is thus Oracle's trademark. Over time Java has evolved into more than just a language. It is a full platform.

Why is Java often termed as a platform?

Ans: Platform is the environment in which programs execute. Instead of interacting with the Operating System directly, Java programs runs on a virtual machine provided by Java, therefore Java is often referred to as a platform also.

Why Use Java?

What is a bytecode?

Ans: Bytecode is a set of pseudo mechanic language instructions that are understood by the JVM (Java Virtual Machine) and are independent of the underlying hardware.

What do you understand by JVM?

Ans: JVM or Java Virtual Machine is an abstract machine designed to be implemented on top of existing processors. It hides the underlying OS from Java application. Programs written in Java are compiled into Java byte-code, which is then interpreted by a special java Interpreter for a specific platform. Actually this Java interpreter is known as Java Virtual Machine (JVM).

What is JDK (Java Development Kit)?

Ans: The Java development kit comes with a collection of tools that are used for developing and running java programs.

What are Java APIs?

Ans: The Java APIs (Application Program Interface) consist of libraries of pre-compiled code that programmers can use in their application.

Write the five characteristics of Java/BlueJ?

Ans: 1. Write Once Run Anywhere 2. Light weight code 3. Security 4. Built in Graphics 5. Object Oriented Language 6. Support Multimedia 7. Platform Independent. 8. Open Product.

What do you know about BlueJ?

Ans: BlueJ is a Java development environment. It is an IDE (Integrated Development Environment), which includes an editor a debugger and a viewer.

How you create, compile and execute a program in Java or BlueJ? Explain your answer?

Ans: Create: Click on new class button from BlueJ editor, then type the class name a program icon will be created. double click on it, a program editor will be open, erase the code and type your program coding. Compile: click the compile button on the left of the window or right click on the class icon and select compile from the menu options. Execute: Right click on the class icon and select new class name option. A dialogue box appears type the name of the object. A object icon will be created at the bottom. Right click on the object icon and select the method we want to execute.

The two types of Java programs/applications are?

Ans: The two types of Java Applications are ‘Internet Applets’ and ‘Stand alone application’.

State the distinguishing features of Java and C++?

Ans: (i) Java does not support operator overloading. (ii) Java does not use pointers. (iii) There are no header files in Java. (iv) Java does not have template classes as in C++.

State the differences between Syntax errors and Logical errors.

Ans: The compiler can only translate a program if the program is syntactically correct; otherwise the compilation fails and you will not be able to run your program. Syntax refers to the structure of your program and the rules about that structure.

The second type of error is a run-time error, so-called because the error does not appear until you run the program. In Java, run-time errors occur when the interpreter is running the byte code and something goes wrong.

“Object is an instance of a class”, explain

Ans: Object of a class contains data and functions provided in a class. it possesses all the features of a class. Hence object is termed as instance of a class.

Name four basic features of JAVA.

Ans: Basic features of Java as follows:

  1. i) It is an object oriented language.
  2. ii) Java program is both compiled and interpreted.

iii) Java program can be application or applet.

  1. iv) java is case sensitive language, i.e. it distinguished upper and lower case letters.

Differentiate between Compiler and Interpreter.

Ans: Compiler convert source code to machine language whole at a time. Interpreter converts program from high level language to machine level language line by line or statement by statement.

Java uses compiler as well as interpreter, explain.

Ans: Java compiler converts Java source code to byte code. This byte code is further converted into machine code to make it applicable for the specific platform by using interpreter.

Differentiate between Source code and Byte code.

Ans: Source code is the program developed in Java Language, which is input to a computer through the keyboard. Compiler converts source code to byte code for interpretation.

Differentiate between Testing and Debugging.

Ans: Testing is the process of checking program logic manually to ensure whether it contains any error or not. Debugging is the process of removing errors from a program.

Elementary Concepts of Object & Class

Modeling entities and their behavior by objects. A class as a specification of objects and as an object factory, computation as message passing/function call between objects (many example should be done to illustrate this). Object encapsulate state (attribute) and have behaviors (functions). Class as a user defined type.

What is an Object? 

Ans: An Object is an identifiable entity with some characteristics and behavior. E.g. take a class ‘Car’. A car class has characteristics like colour, gears, power, length etc. now we create the object of that class ‘Car’ namely ‘Indica’.

What is OOP? What are the features/concepts in OOP’s?  OR Name any two OOP’S principles

Ans: The Object Oriented Programming Paradigm is the latest in the software development and the most adopted one in the programming development. The Paradigm means organising principle of a program. It is an approach to programming. The concepts of OOP’s are: (1) Data Abstraction (2) Data Encapsulation (3) Modularity (4) Inheritance (5) Polymorphism.

Explain all the Concepts of OOP’s?

Ans: Abstraction: It refers to the act of representing essential features without including the background details or explanation. Encapsulation: It is the way of combining both data and the function that operates on the data under a single unit. Modularity: It is the property of a system that has been decomposed into a set of cohesive and loosely couple modules. Inheritance: It is the capability of one class of thing to inherit properties from another class. Polymorphism: It is the ability for a message or data to be processed in more then one form.

What are the advantages of OOP’s?

Ans: (1) Elimination of redundant coding system and usage of existing classes through inheritance. (2) Program can be developed by sharing existing modules. (3) Possibilities of multiple instance of an objects without any interference. (4) Security of data values from other segment of the program through data hiding.

What is Class? How Object is related to the Class?

Ans: A Class represent a set of Objects that share common characteristics and behavior. Objects are instance of a class. The Object represents the abstraction representation by the class in the real sense.

What is the need of a class in Java?

Ans: Classes in Java are needed to represent real-world entities, which have data type properties. Classes provide convenient methods for packing together a group of logical related data items and functions that work on them. In java the data items are called fields & the functions are called methods.

What are Methods? How are these related to an Objects?

Ans: A Method is an operation associated to an Object. The behavior of an Object is represented through associated function, which are called Methods.

Point out the differences between Procedural Programming and Object Oriented Programming.

Ans: Procedural programming aims more at procedures. The emphasis is a doing things rather then the data being used. In procedural Programming parading data are shared among all the functions participating thereby risking data safety and security. Object Oriented Programming is based on principles of data hiding, abstraction, inheritance and polymorphism. It implements programs using classes and objects, In OOP’s data and procedure both given equal importance. Data and functions are encapsulated to ensure data safety and security.

What is an abstraction?

Ans: An abstraction is a named collection of attributes and behaviors required to represent an entity or concept for some particular problem domain.

What is inheritance and how it is useful in Java.

Ans: It is process by which objects of one class acquire the properties of objects of another class. Inheritance supports the concepts of hierarchical representation. In OOP the concepts of inheritance provides the idea of reusability.

What role does polymorphism play as java feature?

Ans: It mean the ability to take more than one form. For example, an operation, many types of data used in the operation.

What is Data hiding?

Ans: Data Hiding means restricting the accessibility of data associated with an object in such a way that it can be used only through the member methods of the object.

What are nested classes?

Ans: It is possible to define a class within another class, such classes are known as nested classes. A nested class has access to the members including private members of the class in which it is nested. However the enclosing class not have access to the members of the nested class.

What are keywords? can keywords be used as a identifiers?

Ans: Keywords are the words that convey a special meaning to the language compiler. No, keywords can never be used as identifiers.

What is an identifier? What is the identifier formatting rule of Java? OR What are the rules for naming a variable?

Ans: Identifiers are names given to different parts of a program e.g. variables, functions, classes etc. The identifiers in Java.

(i) Can contains alphabets, digits, dollar sign and underscore.

(ii) Must not start with a digit.

(iii) Can not be a Java keywords.

(iv) Can have any length and are case-sensitive.

Why keyword is different from identifiers?

Ans: Keywords are predefine sets of words that have a special meaning for the Java compiler. Identifiers on the other hand are created by Java programmers in order to give names to variables, function, classes etc.

State the difference between Token and Identifier.

Ans: The smallest individual unit of a program is known as Token. The following Tokens are available in Java: Keywords, Identifiers, Literals, Punctuations, Operators. Identifiers are names given to different parts of a program e.g. variables, functions, classes etc. The identifiers in Java.

What are literals? How many types of integer literals are available in Java?

Ans: A literal is sequence of characters used in a program to represent a constant value. For example ‘A’ is a literal that represents the value A of type char, and 17L is a literal that represents the number 17 as value of type long. Different types of literals available in Java, they are: Integer literal, Float literal, Boolean literal, Character literal, String literal and null literal.

What is an integer constant? Write integer forming rule of Java.

Ans: Integer constants are whole numbers without any decimal part. The rule for forming an integer constants is: An integer constant must have at least one digit and cannot contain a decimal point. It may contains + or – sign. A number with no sign is interpreted to be positive.

What do you mean by Escape sequence and name few escape sequences in Java?

Ans: Java have certain nongraphic characters (nongraphic characters are those characters that can not be typed directly from keyboard e.g. backspace, tab, carriage return etc.). Those nongraphic character can be represented by escape sequence. An escape sequence is represented by backslash followed by one or more character. The few escape sequence characters are: \n for new line, \t for Horizontal Tab, \v for Vertical Tab, \b for Backspace, \” for Double Quotes etc.

How many integer constants are allowed in Java? How are they written?

Ans: Java allows three types of integer constants: Octal (base 8), Decimal (base 10), and Hexadecimal (base 16). An Octal integer must be started with a zero ‘0’, a Hexadecimal integer starts with a ‘0X’, all others are treated as decimal integer constant.

What is meant by a floating constant in Java? How many ways can a floating constant be represented into?

Ans: Floating constants are real numbers. A floating constant can either be a fractional or in exponent form.

Differentiate between Integer and Floating type constants.

Ans: Integer constants are the whole numbers (without decimal points). e.g. 1231. Floating point constants are fractional numbers (number with decimal points). e.g. 14.2356

Write the following real constants into fractional form: 0.113E04, 0.417E-04, 0.4E-05, 0.123E02

Ans: 0.113E04 becomes 1130, 0.417E-04 becomes .0000417, 0.4E-05 becomes .000004, 0.123E02 becomes 12.3