Monday, December 19, 2016

Java Viva Voce -2



1. What is a variable?
Name which refers memory locations and it can hold a value which can be changed at runtime is called Variable.

2. What are primitive data types?
A primitive type is predefined by the language and is named by a reserved keyword.

3. How many primitive data types are there in Java?
There are 8 primitive data types and they are byte, int, short, long, float, double, char and Boolean.

4. Does Java has any unsigned types?
No, Java does not have any unsigned types.

5. What do the floating-point numbers without an F suffix indicate?
Floating-point numbers without an F suffix indicate to be of type double. We can optionally supply the D suffix also (ex. 3.402D).

6. What are identifiers?
Identifiers are the names of variables, methods, classes, packages and interfaces. Unlike literals they are not the things themselves, just ways of referring to them.

7. Why do we use Unicode in Java?
Most of the countries now use Unicode so we use them in Java too.

8. What is Escape sequence for special character in Java? List some of them.
A character preceded by a backslash (\) is an escape sequence and has special
meaning to the compiler. \b, \t, \n, \r etc. are some escape sequences in Java.

9. Can you use a Java reserved word for a variable name?
No, we cannot use a Java reserved word for a variable name.

10. Why do we use the keyword final in Java?
In Java, you use the keyword final to denote a constant. The keyword final indicates that you can assign to the variable once, and then its value is set once and for all. It is compulsory to name constants in all uppercase.

11. How can you avoid the Math prefix for the mathematical methods and constants?
By importing the package:
 import static java.lang.Math.*; we can avoid the Math prefix for the mathematical methods and constants.

12. Does Java has built in String type?
 Java does not have a built-in string type. Instead, the standard Java library contains a predefined class called String.

13. how is Instance variable declared?
Instance variables are created when an object is created with the use of the keyword 'new' and destroyed when the object is destroyed.

14. What is the difference between class variable and instance variable?
An instance variable is a variable which has one copy for an object.
A class variable is a variable which has one copy per class. The class variables will not have a copy in the object.

15. What are the default values for numbers, Boolean values and Object references?
For numbers, the default value is 0, for Booleans it is false and for object references it is null.

16. What is naming convention?
Java naming convention is a rule to follow as you decide what to name your identifiers such as class, package, variable, constant, method etc.

 17. What is the naming convention used for a class and a method?
Class name should start with an Uppercase and method name should start with Lowercase.

18. What is Literals?
A literal is a value assigned to a variable or a constant is called a literal. Java language specifies five major types of literals: Integer literals, Floating literals, Character literals, String literals, Boolean literals.

19. What is Type casting?
When the data is converted from one data type to another data type, then it is called type casting. Type casting is nothing but changing the type of the data.

20.  What are the types of casting?
There are two types of casting.
             1) Primitive Casting: When the data is casted from one primitive type (like int, float,                          double etc…) to another primitive type, then it is called Primitive Casting.
            2) Derived Casting: When the data is casted from one derived type to another derived type, then it is called derived casting.

21. What is precedence of java operators?
Operator precedence determines the grouping of terms in an expression. This affects how an expression is evaluated.  For example, the multiplication operator has higher precedence than the addition operator.

22. What are Control flow statements?
Control flow statements, however, break up the flow of execution by employing decision making, looping, and branching, enabling your program to conditionally execute particular blocks of code.

23. What are Branching Statements?
Break, continue and return are Branching statement.

24. Why do we use continue statement?
You use the continue statement to skip the current iteration of a for, while , or do-while loop.

25. Why do we use loops in program?
A loop statement allows us to execute a statement or group of statements multiple times which reduces the size of program.

26.  What are access modifiers in java?
These are the modifiers which are used to restrict the visibility of a class or a field or a method or a constructor.

27. How many access modifiers are there in Java?
Java supports 4 access modifiers.
a) Private: private fields or methods or constructors are visible within the class in which they    are defined.
b) Protected: Protected members of a class are visible within the package but they can be inherited to sub classes outside the package.
c) Public: public members are visible everywhere.
d) Default or No-access modifiers: Members of a class which are defined with no access modifiers are visible within the package in which they are defined.

28. Can we declare a class as protected?
We can’t declare an outer class as protected but we can declare an inner class (class as a member of another class) as protected.

29.  What are non-access modifiers in java?
These are the modifiers which are used to achieve other functionalities like static, final, abstract.

30. What is Class and Object?
A class is a program construct which encapsulates data and operations on data. In object oriented programming, the class can be viewed as a blue print of an object. An object is a program construct that falls under a ‘classification’ (of a class) which has state and behavior.

31. How to create an object in a Java Program?
There are three steps to create an object from a class −
Declaration − A variable is declared with an object type.
Instantiation − the 'new' keyword is used to create the object.
Initialization − the 'new' keyword is followed by a call to a constructor. This call initializes the new object.

32. What is a method?
A method (function) is a collection of statements that are grouped together to perform an operation.

33. What is constructor?
Constructor is a special type of method that is used to initialize the object. Java constructor is invoked at the time of object creation.

34. How many types of constructors are there in java?
There are two types of constructors:
Default constructor (no-argument constructor), Parameterized constructor.

35.  What is Constructor Overloading?

Constructor overloading is a technique in Java in which a class can have any number of constructors that differ in parameter lists.
36. What is Garbage Collection?
Garbage Collection is process of reclaiming the runtime unused memory automatically. In other words, it is a way to destroy the unused objects.

37.  What is the advantage of Garbage Collection?

It makes java memory efficient because garbage collector removes the unreferenced objects from heap memory.

38. What is finalize method?
The finalize method is invoked each time before the object is garbage collected. This method can be used to perform cleanup processing.

39. What is static keyword?
The static keyword in java is used for memory management mainly. We can apply java static keyword with variables, methods, blocks and nested class.

40. What is a static variable?
If you declare any variable as static, it is known static variable. The static variable can be used to refer the common property of all objects.

41. What is static method?
If you apply static keyword with any method, it is known as static method.

42.What is java command line argument?
Java command line argument is an argument i.e. passed at a time of running the java program.

43. Where the arguments are received and used?
The arguments passed from the console can be received in the java program and it can be used as an input.

44.How the arguments are useful?
They provide a convenient way to check the behaviour of the program for different values.

45.What is an ARRAY?
An array stores the fixed size sequential collection of elements of the same type.

46.How is an array used?
An array is used to store a collection of data, but it is often more useful to think of an array as a collection of variables of same data type.

47.What is for each loop also known as?
Enhanced for loop.

48.What is the use of for each loop?
It enables us to traverse the complete array sequentially without using an index variable.

49.What is an ARRAY CLASS?
This class contains various static methods for sorting and searching arrays, comparing and filling array elements.

50.What is This keyword in java?
THIS keyword is used as a reference to the object of the current class, with in an instance method or a constructor.

51.What is use of this keyword?
Differentiate the instance variables from local variables if they have some names, within a constructor or a method.

52.  Can we call method with this keyword from constructor?
           Yes, we can call non static methods from constructor using this keyword.

53. Is it possible to assign reference to this?
No we cannot assign any value to "this" because it’s always points to current object      and it is a final reference in java. If we try to change or assign value to this compile time error will come.

54. Can we use this in static methods? 
No we cannot use this in static methods. if we try to use compile time error will come: Cannot use this in a static context.
































Labels:

Java Viva Voce

1. Who designed the java programming?
A.   James Gosling at Sun microsystems, Inc. in 1991.

2. In the beginning what was the main intention behind creating Java?
A. To connect many household machines.

3. What was the earlier name of Java programming language?
A. Oak

4. Why Oak was renamed to Java?
A. It is because there already existed a language by that name.

5. What are the difference between Java and other programming languages?
A. Java does not have pointers. We are forced to write the object oriented code in Java.

6. What features of Java are considered as the Java essentials?
A. High level language, Java Bytecode, Java Virtual Machine.

7. What is the Java Bytecode?
A. It is an intermediate code generated by compiler which is executed by the JVM.

8. What is JVM?
A. It acts as an interpreter for the bytecode, which takes bytecodes as input and executes it.

9. What is the full form of JRE?
A. Java runtime environment.

10. What does the JRE consist of?
A. JVM and core Java API libraries.

11. What is the JDK consist of?
A. JRE and development tools like compilers.

12. What are the main features of Java?
A. Platform independent, object oriented, incorporates both interpretation and compilation, is robust and multithreaded.

 13. What is an object in Java?
A.  It is an instance of the class. An instance contains members (fields and methods)

14. What is a field?
A. A field is one that holds a value.

15. What is  a method?
A. A method defines operations on the fields and values that are passed as arguments to the method.

16. What is a sandbox?
A.  It is a security model that Java uses, which makes it easier to work with untrusted softwares by restricting codes.

17. What is the sandbox made of?
A. It consists of Class loader, Bytecode verifier and Security manager.

18. What is a class Loader?
A.  It is the first link in the security chain that fetches executable codes from networks.

19. What is a Bytecode verifier?
A.  It checks for any violations.

20. What is security manager?
A.  It enforces the boundary of the sandbox. It decides if the action performed by applet is approved or not.

21. Why save a Java program with class name?
A. Every class is placed in its own output file named after the class and using the .class extension.



Labels:

Wednesday, November 30, 2016

looping with goto

looping with goto

syntax:

label: 
if ( condition?)
{
.
.
.
goto label;
}
writing loop using goto is non standard c language programming practice.
nowadays computers uses virtual Memory Systems(Hard disk assumed as RAM)

if we use goto it need  more swappings from RAM to HARD DISK vice versa.

That's why goto is not preferred.

Labels:

Tuesday, November 8, 2016

C VIVA QUESTIONS PART 2

C VIVA QUESTIONS PART 2

1. Structure of C Program.


2. Taxonomy of C.




3. Characteristics of C?
  • Small size
  • Extensive use of function calls
  • Loose typing - unlike PASCAL
  • Structured language
  • Low level (BitWise) programming readily available
  • Pointer implementation - extensive use of pointers for memory, array, structures and functions.

4. Applications of C Language?

1. C language is used for creating computer applications
2. Used in writing Embedded softwares
3. Firmware for various electronics, industrial and communications products which use micro-controllers.
4. It is also used in developing verification software, test code, simulators etc. for various applications and hardware products.
5. For Creating Compiles of different Languages which can take input from other language and convert it into lower level machine dependent language.
6. C is used to implement different Operating System Operations.
7. UNIX kernel is completely developed in C Language


5.  Advantages and disadvantages of  C Language.

Advantages of C Language
1. C language is a building block for many other currently known languages. C language has variety of data types and powerful operators. Due to this, programs written in C language are efficient, fast and easy to understand.
2. C is highly portable language. This means that C programs written for one computer can easily run on another computer without any change or by doing a little change.
3. There are only 32 keywords in ANSI C and its strength lies in its built-in functions. Several standard functions are available which can be used for developing programs.
4. Another important advantage of C is its ability to extend itself. A C program is basically a collection of functions that are supported by the C library this makes us easier to add our own functions to C library. Due to the availability of large number of functions, the programming task becomes simple.
5. C language is a structured programming language. This makes user to think of a problem in terms of function modules or blocks. Collection of these modules makes a complete program. This modular structure makes program debugging, testing and maintenance easier.

Disadvantages of C Language

1. C does not have concept of OOPs, that’s why C++ is developed.
2. There is no runtime checking in C language.
3. There is no strict type checking. For example, we can pass an integer value.
4. for the floating data type.
5. C doesn’t have the concept of namespace.
6. C doesn’t have the concept of constructor or destructor.

6. Files used in C Language?

1. Source Files:
Contains Source Program (  .C Extension)
2. Header Files:
A header file is a file with extension .h which contains C function declarations and macro definitions to be shared between several source files. There are two types of header files: the files that the programmer writes and the files that comes with your compiler.
3. Object Files( .o/.obj) :
Object files are generated by the compiler as a result of processing the source code file.
Object files contain compact binary code of function definitions. Linker uses these Object files  to produce an executable file (.exe).
4. Binary Executable files( .exe )
The Binary Executable file is generated by a Linker. The Linker links the various object files to produce binary files that can be directly executed.

7. Compiling and Executing(Running)?

In Linux:

Compiling:
cc program_name.c

Executing:

./a.out

Or


Compiling:
cc –o   object_file_name   program_name.c

Executing:

./object_file_name

 





8. What is a Token?

A Smallest individual Unit in C Program.
·         Keywords
·         Variables
·         Constants
·         Strings
·         Special Characters
·         Operators
9. what  is an Identifier?
Identifier refers to name given to entities such as variables, functions, structures etc.

Rules for writing an identifier

  1. A valid identifier can have letters (both uppercase and lowercase letters), digits and underscores.
  2. The first letter of an identifier should be either a letter or an underscore. However, it is discouraged to start an identifier name with an underscore.
  3. There is no rule on length of an identifier. However, the first 31 characters of identifiers are discriminated by the compiler.
10. Data Types in c?




11. What is Constant?

Constants are identifiers which values do not change.

12. Operators in C?

Operators are the symbols which tell the computer to execute certain mathematical or logical operations.
1.Arithmetic ( +,-,*,/,% )
2. Relational ( <,<=,>,>=,==,!= )
3. Logical ( &&,||,! )
4. Unary Operators  ( -)
5. Increment  /  Decrement  Operators  (  ++ , -- )
6. Conditional   /   Ternary Operator    ( ? : )
7. Bitwise Operators   (  & , | , ^  )
8. Shift Operators  ( <<  ,   >>  )
9. Assignment Operators  ( +=  , -= , *=  ,  /=  ,  %= )
10.Special Operators   ( comma, sizeof )

13. Define Precedence and Associativity?
Precedence :
Operator precedence determines which operator is performed first in an expression with more than one operators with different precedence. For example 10 + 20 * 30 is calculated as 10 + (20 * 30) and not as (10 + 20) * 30.
Associativity:
associativity is used when two operators of same precedence appear in an expression. Associativity can be either Left to Right or Right to Left. For example ‘*’ and ‘/’ have same precedence and their associativity is Leftto Right, so the expression “100 / 10 * 10” is treated as “(100 / 10) * 10”.


Labels: