0% found this document useful (0 votes)
23 views7 pages

Java Full Stack Internship Notes

The document provides a series of questions and answers related to Java Full Stack concepts, covering topics such as packages, encapsulation, constructors, exception handling, and CSS. It includes explanations of key Java features like the 'this' keyword, constructor chaining, and the differences between methods and constructors. Additionally, it offers insights into HTML and CSS usage, including background images and styling techniques, along with a promotional internship opportunity.

Uploaded by

Latha Parthiban
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)
23 views7 pages

Java Full Stack Internship Notes

The document provides a series of questions and answers related to Java Full Stack concepts, covering topics such as packages, encapsulation, constructors, exception handling, and CSS. It includes explanations of key Java features like the 'this' keyword, constructor chaining, and the differences between methods and constructors. Additionally, it offers insights into HTML and CSS usage, including background images and styling techniques, along with a promotional internship opportunity.

Uploaded by

Latha Parthiban
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

Java Full Stack – Doubts & Answers – PART I

1) What is the use of package in Java?


A java package is a group of similar types of classes, interfaces and sub-packages.
Package in java can be categorized in two form, built-in package and user-defined
package. There are many built-in packages such as java, lang, awt, javax, swing, net, io,
util, sql etc.
2) Why we need to use encapsulation concept?
Encapsulation in Java is a mechanism of wrapping the data (variables) and code acting
on the data (methods) together as a single unit. In encapsulation, the variables of a class
will be hidden from other classes, and can be accessed only through the methods of
their current class.
3) What is the use of this keyword?
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)
4 ) What is the use of constructors in Java?
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.
5)What is the use of nested constructors in Java?
Constructor chaining is the process of calling one constructor from another
constructor with respect to current object.
One of the main use of constructor chaining is to avoid duplicate codes while
having multiple constructor (by means of constructor overloading) and make
code more readable.

JOIN IN ONE MONTH JAVA FULL STACK INTERNSHIP @Rs 999 – Reg Link – ‘[Link]
USE COUPON : JFSMC
// Java program to illustrate Constructor Chaining
// within same class Using this() keyword
class Temp
{
// default constructor 1
// default constructor will call another constructor
// using this keyword from same class
Temp()
{
// calls constructor 2
this(5);
[Link]("The Default constructor");
}

// parameterized constructor 2
Temp(int x)
{
// calls constructor 3
this(5, 15);
[Link](x);
}

// parameterized constructor 3
Temp(int x, int y)
{
[Link](x * y);
}

public static void main(String args[])


{
// invokes default constructor first
new Temp();
}
}

6) Why we are using constructors without any access modifiers?


If you declare constructor without any access modifier, it is a default access modifier.
When you declare a constructor with a default access modifier, you will not be able to
instantiate that class using that constructor outside of its current package.

JOIN IN ONE MONTH JAVA FULL STACK INTERNSHIP @Rs 999 – Reg Link – ‘[Link]
USE COUPON : JFSMC
7) What is the difference between a method and a
constructor?
In Java, constructors must be called with the same name as the name of the class in
which they live, whereas methods can have any name and can be called directly either
with a reference to the class or an object reference. Constructors are an exception to this
rule.
The major difference between constructor and method is that method is called during the
program and not in the beginning whereas a constructor is called in the initialization of
the program. The constructor is a class used in the initialization.

8) What is the use of new keyword?


It is used for initializing an object.

9) Why we used +a +i+ +j in output mam?

The values are appended by + sign.

10) Is it possible to convert “Integer a” to “int a”?


Yes ,it is possible to convert Integer to int datatype.

11)What do you mean by encapsulation?


Encapsulation is nothing but a data hiding mechanism.

12) What is the use of try and catch blocks?


The exceptional code is enclosed inside the try block and if there are any exceptions , it
will be caught in the corresponding catch block.

JOIN IN ONE MONTH JAVA FULL STACK INTERNSHIP @Rs 999 – Reg Link – ‘[Link]
USE COUPON : JFSMC
13) Advantages of checked and unchecked exceptions:

A checked exception is caught at compile time whereas a runtime or unchecked


exception is, as it states, at runtime. A checked exception must be handled either by re-
throwing or with a try catch block, whereas an unchecked isn't required to be handled.

14) How to measure the width and height in html?


The width and height attributes of image tags are used to measure the width and height
of an image.

15) Explain about absolute and relative image url.


The difference between an absolute URL and a relative URL is that absolute URLs are
the entire URL and relative URLs are only a portion of the URL. Examples: Absolute:
<img src "[Link]

16) What is the use of doctype tag?

All HTML documents must start with a <! DOCTYPE> declaration. The declaration is not
an HTML tag. It is an "information" to the browser about what document type to expect.

16) How many keywords are there in Java?


There are 52 keywords in Java.

17 ) What do you mean by 2px?


In CSS , padding refers space around an element's content, inside of any defined
borders. It is generally expressed in pixels. the order is top, right, bottom, and left.

JOIN IN ONE MONTH JAVA FULL STACK INTERNSHIP @Rs 999 – Reg Link – ‘[Link]
USE COUPON : JFSMC
18) How to apply background image in html?
<!DOCTYPE html>
<html>
<body>

<h2>Background Image</h2>

<p>A background image for a p element:</p>

<p style="background-image: url('img_girl.jpg');">


You can specify background images<br>
for any visible HTML element.<br>
In this example, the background image<br>
is specified for a p element.<br>
By default, the background-image<br>
will repeat itself in the direction(s)<br>
where it is smaller than the element<br>
where it is specified. (Try resizing the<br>
browser window to see how the<br>
background image behaves.
</p>

</body>
</html>

JOIN IN ONE MONTH JAVA FULL STACK INTERNSHIP @Rs 999 – Reg Link – ‘[Link]
USE COUPON : JFSMC
18) How css is useful in html?
CSS (Cascading Style Sheets) is used to style and layout web pages — for example, to
alter the font, color, size, and spacing of your content, split it into multiple columns, or
add animations and other decorative features.
19) What is external css?
An external style sheet is a separate CSS file that can be accessed by creating a link
within the head section of the webpage. Multiple webpages can use the same link to
access the stylesheet. The link to an external style sheet is placed within the head
section of the page.
20) What is internal CSS?
Internal CSS is a form of CSS using which you can add CSS to HTML documents. It
helps to design the layout of a single HTML web page and change the styles of a web
page within HTML code.

21) What is the difference between predefined function and user-defined function?
The major difference between both these method types is that a predefined method is
already defined method in any programming language and ready to use anywhere in the
program while a user-defined method is defined by the user/programmer as and when
required.

22) How to get the input array from the user?

import [Link];
public class ArrayInputExample1
{
public static void main(String[] args)
{
int n;
Scanner sc=new Scanner([Link]);
[Link]("Enter the number of elements you want to store: ");
//reading the number of elements from the that we want to enter
n=[Link]();

JOIN IN ONE MONTH JAVA FULL STACK INTERNSHIP @Rs 999 – Reg Link – ‘[Link]
USE COUPON : JFSMC
//creates an array in the memory of length 10
int[] array = new int[10];
[Link]("Enter the elements of the array: ");
for(int i=0; i<n; i++)
{
//reading array elements from the user
array[i]=[Link]();
}
[Link]("Array elements are: ");
// accessing array elements using the for loop
for (int i=0; i<n; i++)
{
[Link](array[i]);

}
}

23) How many case blocks does a switch statement have?


A switch statement can have multiple case blocks.

JOIN IN ONE MONTH JAVA FULL STACK INTERNSHIP @Rs 999 – Reg Link – ‘[Link]
USE COUPON : JFSMC

Common questions

Powered by AI

Constructors in Java are special methods that are used to initialize objects. Unlike regular methods, constructors have the same name as the class in which they are defined, and they do not have a return type. Constructors are called at the moment an object is created. Methods, on the other hand, can have any name, can be called multiple times throughout the lifecycle of an object, and can return a value. This difference is crucial in class design, as constructors set up initial conditions and constraints essential for the object's behavior, whereas methods define ongoing interactions and operations .

Encapsulation in Java is primarily used for data hiding, ensuring that the internal representation of an object is hidden from outside. It wraps the data and the methods that operate on the data into a single unit, typically a class. By only allowing access and modification of the data through methods, encapsulation enforces a controlled interaction, protecting the integrity and security of the data . This contributes to object-oriented programming by supporting modularity, maintainability, and reducing system complexity.

The 'this' keyword in Java is a reference to the current object, used to resolve ambiguity between instance variables and parameters with the same name. It is vital in constructor chaining, where one constructor calls another constructor in the same class. For example, in constructor chaining, 'this()' can be used to call another constructor from a constructor, reducing code duplication and enhancing readability . In the example class 'Temp', 'this(5);' in the default constructor points to another constructor, calling a more specific one which in turn initiates further chaining.

Constructor chaining is a process in Java where one constructor calls another, either within the same class or between a superclass and a subclass using 'this()' or 'super()'. This process can significantly reduce code redundancy and improve readability, as shared initialization logic can be maintained in one constructor. Consequently, it ensures consistency in object creation and facilitates easier code maintenance .

Checked exceptions in Java must be declared in a method or constructor's 'throws' clause if they can be thrown by the execution of that method or constructor and propagate outside the method or constructor boundary. They are checked at compile-time, ensuring the programmer handles error conditions gracefully. Unchecked exceptions, meanwhile, are not checked during compilation; they represent scenarios like programming bugs or errors that a kernel usually considers non-recoverable like divide-by-zero or null pointer access. The key advantage of checked exceptions is compelment to acknowledge potential error sources, promoting robust error handling, while unchecked exceptions remove boilerplate catch-or-throw behavior, focusing on unlikely error paths .

Java packages serve as a namespace that organizes related classes and interfaces, promoting better code management and avoiding naming conflicts. They facilitate encapsulation and access control, only exposing class functionality that is necessary for external interaction and keeping internal details hidden. Built-in packages, like java.lang, java.util, and others, provide standard classes for common tasks. User-defined packages are custom-organized collections of classes created by developers to group together code base related to specific functionalities or modules .

CSS, or Cascading Style Sheets, is beneficial for web page design as it allows separation of content from design. This separation of concerns facilitates easier maintenance and updates to design across multiple pages. CSS also helps in designing aesthetically pleasing web layouts through flexible styling elements like fonts, colors, margins, and more. External CSS is a separate file linked to HTML files, enabling style consistency across different pages, while internal CSS is embedded within an HTML file and is used for page-specific styling, affecting only that document .

A constructor without any access modifiers is assigned the default access level. This means that it is only accessible within its own package and not from other packages. Declaring a constructor without access modifiers can limit the instantiation of a class to only those classes within the same package, ensuring controlled access and modularization within package boundaries . This practice can help manage dependencies and encapsulate class usage to its originating module.

The 'new' keyword in Java is used to create new objects. When an object is instantiated using 'new', memory is allocated for the new object, and the constructor is called to initialize the object. This is fundamental in object-oriented programming as it allows the creation of instances of classes (objects), enabling encapsulation, inheritance, and polymorphism to be manifested in practical applications . It is the mechanism through which an abstraction in a class is given a physical form in memory.

The <!DOCTYPE> declaration in HTML is not an HTML tag, but a declaration to the web browser about what version of HTML the page is written in. Its purpose is to ensure that web browsers render the page according to the standards of that version, thereby promoting consistency across browsers. The <!DOCTYPE> declaration is crucial for eliminating quirks mode in browsers, which can lead to inconsistent rendering and unexpected behavior .

You might also like