Está en la página 1de 6

---------------********************-----------------Basics of Java------------

******************

1. What is Java?Basic syntax.


 Java is a programming language and a platform.
 Java is a high level, robust, object-oriented and secure programming language.
 Platform: Any hardware or software environment in which a program runs, is known as a
platform. Since Java has a runtime environment (JRE) and API, it is called a platform.

2. Features of java, Tools required to set up java project?

A list of most important features of Java language is given below:

 Simple
 Object-Oriented
 Portable
 Platform independent
 Secured
 Robust
 Architecture neutral
 Interpreted
 High Performance
 Multithreaded
 Distributed
 Dynamic

3. Java Comments & variables

 Comments can be used to explain Java code, and to make it more readable. It can also be
used to prevent execution when testing alternative code.
 Single-line comments start with two forward slashes (//).
 Any text between // and the end of the line is ignored by Java (will not be executed).

4. Difference between Java, C++ & Python?


 Operator in java is a symbol that is used to perform operations. For example:
+, -, *, / etc.
 There are many types of operators in java which are given below:
1. Unary Operator
2. Arithmetic Operator
3. Shift Operator
4. Relational Operator
5. Bitwise Operator
6. Logical Operator
7. Ternary Operator and
8. Assignment Operator
Unary

Arithmetic

5. Difference between JDK, JRE, and JVM?


6. Explain public static void main(String args[]) in Java.
7. java datatypes, type casting and Operators.
8. Operator in java is a symbol that is used to perform operations. For
example: +, -, *, / etc.
9. Java Control Statements(all) with examples.
10. Java Constructors and types.
11. Java Date and Time.
12. Java Class
13. What is an object in Java and how is it created?
14. Difference between object and class
Object Class
1) An object in Java is the physical as well as a 1) A class in Java is a logical entity only.
logical entity.
2) It is an instance of object. 2) It is a template or blueprint from which
objects are created.
3) Object acts as a variable of the class. 3) A class is used to bind data as well as
methods together as a single unit.
4) Objects can be declared several times 4) The class has to be declared only once.
depending on the requirement.

15. What are access modifiers in Java?


16. Java Map and collections
17. Java OOPs Concepts(all) with examples.
18. What is multiple inheritance? Is it supported by Java?
19. Memory allocation in java,Heap and Stack Memory in Java.
20. Java data Structure.
21. Java Multithreading.
22. Java Serialization.
23. Java Association.
24. Java Package.
25. Java JDBC
26. Java Swing
27. method overloading and method overriding in java with example.

28. What is final keyword in Java?


29. Used with exceptions, a block of code that will be executed no matter if there
is an exception or not

30. What is the difference between an array and an array list?


31. What is the difference between this() and super() in Java?
32. What is the difference between break and continue statements?
33. Differentiate between the constructors and methods in Java?
34. Java Exception Handling

---------------********************-----------------Programs------------
******************

1. Write a Java Program to find whether a number is prime or not.


//using for loop:
public class Prime {
public static void main(String[] args) {
int num = 29;
boolean flag = false;
for(int i = 2; i <= num/2; ++i)
{
// condition for nonprime number
if(num % i == 0)
{
flag = true;
break;
}
}
if (!flag)
System.out.println(num + " is a prime number.");
else
System.out.println(num + " is not a prime number.");
}
}

//using while loop:

public class Prime {


public static void main(String[] args) {
int num = 33, i = 2;
boolean flag = false;
while(i <= num/2)
{
// condition for nonprime number
if(num % i == 0)
{
flag = true;
break;
}
++i;
}
if (!flag)
System.out.println(num + " is a prime number.");
else
System.out.println(num + " is not a prime number.");
}
}

2. Write a Java Program for Fibonacci series.


class Fibonacci
{
public static void main(String args[]) {
int n1=0,n2=1,n3,i,count=10;
System.out.print(n1+" "+n2);//printing 0 and 1
for(i=2;i<count;++i)//loop starts from 2 because 0 and 1 are already printed
{
n3=n1+n2;
System.out.print(" "+n3);
n1=n2;
n2=n3;
}
}
}
3. Write a Java Program to open all links of gmail.com.
package Codes;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;

public class openAllLinks {

public static void main(String[] args) {


// TODO Auto-generated method stub
System.setProperty("webdriver.chrome.drive",
"C:\\webdriver\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
driver.manage().window().maximize();
driver.get("https://www.gmail.com/");
java.util.List<WebElement> link = driver.findElements(By.tagName("a"));
System.out.println(link.size());

for (WebElement link2: link) {

//print the links i.e. http://google.com or https://www.gmail.com


System.out.println(link2.getAttribute("href"));

//print the links text


System.out.println(link2.getText());
}
}
}
4. Write a Java Program to find the duplicate characters in a string.
public class DuplicateCharacters {

public static void main(String[] args) {


// TODO Auto-generated method stub
String str = new String("Sakkett");
int count = 0;
char[] chars = str.toCharArray();
System.out.println("Duplicate characters are:");
for (int i=0; i<str.length();i++) {
for(int j=i+1; j<str.length();j++) {
if (chars[i] == chars[j]) {
System.out.println(chars[j]);
count++;
break;
}
}
}
}

5. Write a Java Program to reverse a string without using String inbuilt function
reverse().
public class FinalReverseWithoutUsingInbuiltFunction
{
public static void main(String[] args)
{
String str = "Saket Saurav";
char chars[] = str.toCharArray(); // converted to character array and
printed in reverse order
for(int i= chars.length-1; i>=0; i--)
{
System.out.print(chars[i]);
}
}
}

6]Write a Java Program to find the Leap year?

public class LeapYear


{
public static void main(String[] args)
{
int year = 1900;
boolean leap = false;
if(year % 4 == 0)
{
if( year % 100 == 0)
{
// year is divisible by 400, hence the year is a leap year
if ( year % 400 == 0)
leap = true;
else
leap = false;
}
else
leap = true;
}
else
leap = false;
if(leap)
System.out.println(year + " is a leap year.");
else
System.out.println(year + " is not a leap year.");
}
}

6. Write a Java Program to find the Leap year


public class LeapYear {
public static void main(String[] args) {
int year = 1900;
boolean leap = false;
if(year % 4 == 0)
{
if( year % 100 == 0)
{
// year is divisible by 400, hence the year is a leap year
if ( year % 400 == 0)
leap = true;
else
leap = false;
}
else
leap = true;
}
else
leap = false;
if(leap)
System.out.println(year + " is a leap year.");
else
System.out.println(year + " is not a leap year.");
}
}
7. Write a Java Program to find the String Palindrome
public class Palindrome
{
public static void main(String args[])
{
String a, b = "";
Scanner s = new Scanner(System.in);
System.out.print("Enter the string you want to check:");
a = s.nextLine();
int n = a.length();
for(int i = n - 1; i >= 0; i--)
{
b = b + a.charAt(i);
}
if(a.equalsIgnoreCase(b))
{
System.out.println("The string is palindrome.");
}
else
{
System.out.println("The string is not palindrome.");
}
}
}

También podría gustarte