0% found this document useful (0 votes)
83 views11 pages

Java Programming Language Overview

Java is a cross-platform, object-oriented programming language released in 1995, essential for running various applications. Key features include simplicity, portability, security, and multithreading, while concepts such as OOP, inheritance, and exception handling are fundamental to its structure. The document also covers Java's architecture, threading, applets, AWT, Swing, and various programming constructs, providing a comprehensive overview of Java programming.

Uploaded by

bewakoof061
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
83 views11 pages

Java Programming Language Overview

Java is a cross-platform, object-oriented programming language released in 1995, essential for running various applications. Key features include simplicity, portability, security, and multithreading, while concepts such as OOP, inheritance, and exception handling are fundamental to its structure. The document also covers Java's architecture, threading, applets, AWT, Swing, and various programming constructs, providing a comprehensive overview of Java programming.

Uploaded by

bewakoof061
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

1. What is java?

Ans: Java is a cross-platform object-oriented programming language that was released by Sun
Microsystems in the year [Link], Java is needed to run various applications such as
games, social media applications, audio and video applications, etc.

2. What are features of java or What are java buzzwords?


Ans: 1. Simple
[Link] oriented
[Link]
[Link] independent
[Link]
[Link]
[Link]
[Link]
[Link]
[Link]

3. What is bytecode?
Ans: Bytecode is a highly optimized set of instructions that is executed by the Java Virtual
Machine. Bytecode helps Java achieve both portability and security.

4. Why java is called platform independent?


Ans: JAVA is platform independent because it having its own JVM so that it can run on any
platform. Java is platform independent, which means once written you can run it anywhere.

5. What is JVM?
Ans: Java Virtual Machine (JVM) is a engine that provides runtime environment to drive the
Java Code or applications. It converts Java byte code into machines language.

6. Importance of setting path and CLASSPATH?


Ans: Setting path: used to locate the JDK packages that are used to convert the java source
code into the machine-readable binary format. Tools like javac and java can be used by setting
the path.
Setting CLASSPATH: CLASSPATH is an environment variable which is used by Application Class
Loader to locate and load the .class.

7. Differences between C and Java?


Ans: C is structure/procedure oriented programming language whereas Java is object oriented
programming language.
C language program design is top down approach whereas Java is using bottom up approach.
C language is middle level language whereas Java is high level language.

8. What do you mean by Constructor? Types of Constructors?


Ans: A constructor in Java is a special method that is used to initialize objects. The constructor
is called when an object of a class is created.
Types of constructors:
• No-Arg Constructor.
• Parameterized Constructor.
• Default Constructor.
9. Constructor vs method?
Ans: Constructor is used to initialize an object whereas method is used to exhibits
functionality of an object.
Constructors are invoked implicitly whereas methods are invoked explicitly.
Constructor does not return any value where the method may/may not return a value.

10. What are different types of variables in java?


Ans: Local variable: A variable declared inside the body of the method is called local variable.
Instance variable: Instance variable is a variable defined in a class(i.e. a member variable)in
which each instantiated object of the class has a separate copy, or instance.
Static variable: A variable which is declared as static is called static variable. It cannot be local.

11. What are OOPs concepts


Ans: Object-oriented programming has four basic concepts:
• Encapsulation
• Abstraction
• Inheritance
• Polymorphism.

12. What is Inheritance? Types of Inheritances.


Ans: Inheritance in Java is a mechanism in which one object acquires all the properties and
behaviours of a parent object.
TYPES OF INHERITANCE:
1. Single inheritance
2. Multi level inheritance
3. Hierarchical inheritance
4. Multiple inheritance
5. Hybrid inheritance

13. What is meant by Method Overriding?


Ans: If subclass(child class) has the same method as declared in the parent class, it is known as
method overriding in Java.

14. What is meant by Method Overloading?


Ans: If a class has multiple methods having same name but different in parameters, it is
known as Method Overloading.

15. What is meant by Interface?


Ans: An interface is an abstract class that is used to group related methods with empty
bodies:
{OR}
An interface in Java is a blue print of a class. It has static constants and abstract methods.

16. How we can achieve multiple inheritances in java?


Ans: We can achieve multiple inheritance in java through interfaces.
17. What is a package?
Ans: A java package is a group of similar types of classes, interfaces and sub-packages.

18. Compilation process of a package


Ans: [Link]

19. What is meant by Abstract class?


Ans: A class which is declared with the abstract keyword is known as an abstract class in Java.
It can have abstract and non-abstract methods (method with the body).

20. What is Dynamic method Dispatch?


Ans: Dynamic method dispatch is the mechanism by which a call to an overridden method is
resolved at run time, rather than compile time.

21. What is garbage collection?


Ans: Java garbage collection is the process by which Java programs perform automatic
memory management.

22. Difference between String, and StringBuffer?


Ans: String is immutable whereas StringBuffer are mutable classes.
StringBuffer is faster than String when performing simple concatenations.

23. Explain about access specifiers?


Ans: Public-visible to all classes.
Private-visible within the class which we created
Protected-visible to subclasses where we defined it in super class (within same package or
different package)
Default-visible to subclasses where we defined it in super class(within Same package)

24. Difference between Abstract class and Interface?


Ans: Classes can implement multiple interfaces, but only one abstract class.
Abstract class can have final, non-final, static and non-static variables. Interface has only static
and final variables.

25. What is meant by Exception? Explain the keywords used in Exception handling?
Ans: Exception: Exception is a runtime error that occurs during the execution of a program
that disrupts the normal flow of instructions.
Examples of pre-defined exceptions:

Keywords
[Link]-used to enclose the code that might throw an exception.
[Link]-used to catch the exception occur in try block.
[Link]-used to execute important code such as closing connection, stream etc.
[Link]-used to declare an exception.
[Link]-throw keyword in Java is used to explicitly throw an exception.

26. What are the types of Exceptions?


Ans: There are mainly two types of exceptions in Java as follows:
[Link].
[Link]

27. Explain about final, this, super, static keywords in Java?


Ans: SUPER: Super keyword is used to access upper class variables and methods by subclass
object when they are overridden by subclass.
FINAL: Final is used in three places in Java with different jobs. Final variable cannot be
reassigned (like const of C/C++)
STATIC: The static keyword in Java is used for memory management mainly. We can apply
static keyword with variables, methods, blocks and nested classes.
THIS: The this keyword refers to the current object in a method or constructor. The most
common use of the this keyword is to eliminate the confusion between class attributes and
parameters with the same name (because a class attribute is shadowed by a method or
constructor parameter).

28. What is a Thread? How to create thread in java.


Ans: A thread is the unit of execution within a process. A thread can be created by
implementing the Runnable interface and overriding the run()method or it can be created by
extending Thread class and overriding run() method.

29. Thread VS Process.


Ans: 1) A program in execution is often referred as process. A thread is a subset(part) of the
process.
2) A process consists of multiple threads. A thread is a smallest part of the process that can
execute concurrently with other parts(threads)of the process

30. Explain about join()method.


Ans: Thread class provides the join() method which allows one thread to wait until another
thread completes its execution.

31. Difference between notify() method and notifyAll() method in Java?


Ans: In multi threading notify() method sends notification only to one single thread among all
the waiting threads. notifyAll() method sends notification to all the waiting threads instead of
single thread.

32. What is Deadlock in java ?


Ans: If threads are waiting for each other to finish, then the condition is known as Deadlock

33. Explain the thread life cycle in Java?


Ans: Life cycle of thread-1.)New 2.)Runnable 3.)Running 4.)Non-Runnable 5.)Terminated.
34. What is Synchronization?
Ans: Synchronization is capability to control the access of multiple threads.

35. What is the use of synchronized keyword in threads ?


Ans: Synchronized keyword ensures that there is no deadlock.

36. What is an applet? Applet Life cycle. Explain ways to execute applet?
Ans: An applet is a java program that can be embedded into a html file.

Life cycle of an Applet:-1.) init() 2.) start() 3.) stop() 4.) paint() 5.) destroy().
Applet code is executed using appletviewer tool or by using java compatible web-browser.

37. What is the importance of paint() method in Applet?


Ans: Paint() method is used to print a message or draw geometrical shapes on applet window.

38. What is the importance of repaint() method in Applet?


Ans: The repaint() method causes the AWT runtime system to execute the update() method of
the component class which clears the window with the background color of the applet and
then calls the paint()method.

39. What is the use of AWT?


Ans: AWT(Abstract Window Toolkit) is a java Foundation class that is used to create the
graphical user interface(GUI) objects that allows user to create labels, buttons, scrollbars and
windows.

40. What are the different AWT Components?


Ans: AWT components:- Labels, Buttons, Checkboxes, Textareas, Choices, etc.

41. List out different Layout managers?


Ans: Different layout managers:- Box Layout, Border Layout, Card Layout, Flow Layout, Grid
Layout, GridBag Layout, Group Layout, Spring Layout.

42. What is Delegation Event model?


Ans: Delegation event model defines the standard and consistent mechanism to generate and
process events.

43. Difference between AWT and Swing?


Ans: AWT:-AWT is used to create graphical user interfaces. Window based applications in
java. It contains large number of classes and methods that are used for creating and managing
the GUI.
Components of AWT are: Labels, Buttons, Checkboxes, Textareas, Choices, etc.
Swing:-Swing is used to create various applications. It is platform independent. It is used to
create buttons and scrollbars in desktop applications.
Components of swing are: JButton, JLabel, JTextField, JTextArea, JCheckBox, JRadioButton,
JList, JComboBox, JTabbedPane

44. Explain Generics in Java.


Ans: Generics means parameterized types that can work with different data types.
• T – Type
• E – Element
• K – Key
• N – Number
• V – Value

45. What are Collections ? Given any two examples


Ans: Collection is a group of objects. List, Set, Map and Queue are some examples of
collection.

46. What is meant by Event Handling ?


Ans: Event Handling is the mechanism that controls the event and decides what should
happen if an event occurs.

47. Explain about Window Event and its methods, Listener.


Ans: A low-level event that indicates that a window has changed its status is called Window
Event.
Methods: public void windowClosing(WindowEvent we){}
public void windowDeactivated(WindowEvent we){}
public void windowActivated(WindowEvent we){}
public void windowDeiconified(WindowEvent we){}
public void windowIconified(WindowEvent we){}
public void windowOpened(WindowEvent we){}
public void windowClosed(WindowEvent we){}
Interface: WindowListener

48. Explain about Window Event and its methods, Listener.


Ans: Action event is a semantic event which indicates that a component-defined action
occurred.
Methods: public void actionPerformed(ActionEvent ae){}
Interface: ActionListener

49. Explain about Item Event and its methods, Listener.


Ans: Item event is a semantic event which indicates that an item was selected or deselected.
Methods: public void itemStateChanged(ItemEvent ie){}
Interface: ItemListener

50. Explain about Mouse Event and its methods, Listener.


Ans: An event which indicates that a mouse action occurred in a component.
Methods: Different mouse events:-mouse up, mouse down, click, double click, mouseover,
mouse move, mouse leave, and mouse enter etc. and its Interface is MouseListener or
MouseMotion Listener

51. Explain about Keyboard Event and its methods, Listener.


Ans: A keyboard event is generated when a key is pressed, released, or typed. The relevant
method in the listener object is then invoked, and the KeyEvent is passed to it.
Methods: Key pressed, Key released, Key typed.
Interface: keyListener.

52. What is GUI?


Ans: GUI, which stands for Graphical User Interface, is a user-friendly visual experience builder
for Java applications.

53. Write about conditional operators in java.


Ans: Conditional operators check the condition and decides the desired result on the basis of
both conditions. In this section, we will discuss the conditional operator in Java.
Types of Conditional Operator
There are three types of the conditional operator in Java:
• Conditional AND(&&)
• Conditional OR(||)
• Ternary Operator(?:)

54. What is Transient variable?


Ans: Transient variables are special types of variables created by using the transient keyword.
An instance of this type of variable does not have its value serialized at the time of
serialization.

55. What is the use of destroy() function?


Ans: The destroy() method is used to stop the execution of thread groups and subgroups after
the completion of the run() method, which executes without any cleanup. It can also cause
deadlock during thread execution similar to suspend() .

56. How can we create and import packages in java?


Ans: Packages in java can be created using package keyword, imported using import keyword
respectively.
Syntax for creating a package: package package_name;
Remaining code
.
.
Compile using javac -d . file_name.java
Syntax for importing a package: import package_name;

57. Mention various JDK tools.


Ans: appletviewer, java, javac, javah, javap, jar etc.

58. What is the purpose of appletviewer


Ans: Applet viewer is a command line program to run Java applets. To execute the applet by
appletviewer tool, create an applet that contains applet tag in comment and compile it.

59. How to declare a nested class in java?


Ans: Syntax for declaring nested class:
class OuterClass
{
...
class NestedClass
{
...
}
}

60. What are command line arguments?


Ans: The java command-line argument is an argument i.e. passed at the time of running the
java program. The arguments passed from the console can be received in the java program
and it can be used as an input.

61. What is the syntax for declaring Generic class and Generic method.
Ans: Syntax for declaring generic class:
class ClassName<T>{
……..
}
Syntax for declaring generic method:
public static <T> T MethodName(parameter 1, parameter 2,…..) {
………….
}

62. What is an iterator?


Ans: An Iterator is an object that can be used to loop through collections, like ArrayList
and HashSet. It is called an "iterator" because "iterating" is the technical term for looping.

63. List some predefined exceptions in java.


Ans: Some of predefined functions are:
• NullPointerException.
• ArrayIndexOutOfBoundsException.
• IllegalStateException.
• ClassNotFoundException.
• ArithmeticException.
• IllegalArgumentException.
• InterruptedException,
• IOExcpetion.
64. What is <param> tag in java?
Ans: The PARAM element is used to provide "command-line" arguments to a Java applet,
which is embedded in a document with the APPLET element. It has two attributes: NAME
specifies the name of the argument, and VALUE specifies the value for this argument.

65. What are adapter classes and mention its uses.


Ans: In JAVA, an adapter class allows the default implementation of listener interfaces.
An adapter class in JAVA is therefore used to implement an interface having a set of dummy
methods. If a programmer chooses to inherit an adapter class, they will not be forced to
implement all the methods listed under a particular listener interface.
Example: If we want to implement WindowListener interface we don’t need to implement
all the methods in it. We can implement only methods we need.

66. How is java architecture neutral?


Ans: Java is architecture neutral because there are no implementation dependent features,
for example, the size of primitive types is fixed.

67. What are Jagged arrays?


Ans: A jagged array is an array of arrays such that member arrays can be of different sizes,
i.e., we can create a 2-D array but with a variable number of columns in each row.

68. What is Multi Threading in java?


Ans: A jagged array is an array of arrays such that member arrays can be of different sizes,
i.e., we can create a 2-D array but with a variable number of columns in each row.

69. List out parameter passing techniques.


Ans: Pass by value and pass by reference.

70. What is Object class?


Ans: Object class is super class of every other class.

Any Question from below:

Date:
Available in [Link] package.
Constructors:
Date() : Creates date object representing current date and time.
Date(long milliseconds) : Creates a date object for the given milliseconds since January 1,
1970, [Link] GMT.
Methods:
boolean after(Date date) : Tests if current date is after the given date.
boolean before(Date date) : Tests if current date is before the given date.
int compareTo(Date date) : Compares current date with given date. Returns 0 if the
argument Date is equal to the Date; a value less than 0 if the Date is before the Date
argument; and a value greater than 0 if the Date is after the Date argument.
long getTime() : Returns the number of milliseconds since January 1, 1970, [Link] GMT
represented by this Date object.
void setTime(long time) : Changes the current date and time to given time

Random:
Available in [Link] package.

Constructors:
Random(): Creates a new random number generator
Random(long seed): Creates a new random number generator using a single long seed
Methods:
nextBoolean(): This method returns next pseudorandom which is a boolean value from
random number generator sequence.
nextDouble(): This method returns next pseudorandom which is double value between 0.0
and 1.0.
nextFloat(): This method returns next pseudorandom which is float value between 0.0 and
1.0.
nextInt(): This method returns next int value from random number generator sequence.
nextInt(int n): This method return a pseudorandom which is int value between 0 and
specified value from random number generator sequence.

Scanner:
Available in [Link] package.
Constructors:
Scanner(File source): It constructs a new Scanner that produces values scanned from the
specified file.
Scanner(String source): It constructs a new Scanner that produces values scanned from the
specified string.
Scanner(Path source): It constructs a new Scanner that produces values scanned from the
specified file.
Methods:
Void close(): It is used to close this scanner.
String next(): It is used to get the next complete token from the scanner which is in use.
boolean nextBoolean(): It scans the next token of the input into a boolean value and
returns that value.
byte nextByte(): It scans the next token of the input as a byte.
double nextDouble(): It scans the next token of the input as a double.
float nextFloat(): It scans the next token of the input as a float.
int nextInt(): It scans the next token of the input as an Int.
String nextLine(): It is used to get the input string that was skipped of the Scanner object.
long nextLong(): It scans the next token of the input as a long.
short nextShort(): It scans the next token of the input as a short.
Calender:
Available in [Link].
Constructors:
[Link](): return a Calendar instance based on the current time in
the default time zone with the default locale.
[Link](TimeZone zone)
[Link](Locale aLocale)
[Link](TimeZone zone, Locale aLocale)
Methods:
abstract void add(int field, int amount): It is used to add or subtract the specified amount
of time to the given calendar field, based on the calendar’s rules.
int get(int field): It is used to return the value of the given calendar field.
abstract int getMaximum(int field): It is used to return the maximum value for the given
calendar field of this Calendar instance.
abstract int getMinimum(int field): It is used to return the minimum value for the given
calendar field of this Calendar instance.
Date getTime(): It is used to return a Date object representing this Calendar’s time value.

You might also like