About this ebook
This book helps you to understand each and every topic of java practically. It will help you in developing software and websites because one should have sound practical knowledge. It covers all the topics which are important from the point of view of the interview, certification and examinations and no topic is left untouched.
Read more from Swati Saxena
Python Interview Questions: Brush up for your next Python interview with 240+ solutions on most common challenging interview questions (English Edition) Rating: 0 out of 5 stars0 ratingsCracking Kotlin Interview: Solutions to Your Basic to Advanced Programming Questions Rating: 5 out of 5 stars5/5Kotlin at a Glance: Use of Lambdas and higher-order functions to write more concise, clean, reusable, and simple code Rating: 0 out of 5 stars0 ratings
Related to Java
Related ebooks
Java Spring Framework: From Basics to Expert Proficiency Rating: 0 out of 5 stars0 ratingsJava EE 7 Development with NetBeans 8 Rating: 5 out of 5 stars5/5Learn JSP in 24 Hours Rating: 0 out of 5 stars0 ratingsIntroduction to Java Programming, 2nd Edition Rating: 5 out of 5 stars5/5RESTful Java Web Services Interview Questions You'll Most Likely Be Asked: Second Edition Rating: 0 out of 5 stars0 ratingsJava for Web Development: Create Full-Stack Java Applications with Servlets, JSP Pages, MVC Pattern and Database Connectivity Rating: 0 out of 5 stars0 ratingsSpring MVC Beginner’s Guide Rating: 2 out of 5 stars2/5Mockito for Spring Rating: 0 out of 5 stars0 ratingsProgramming Backend with Go Rating: 0 out of 5 stars0 ratingsCode with Java 21: A practical approach for building robust and efficient applications (English Edition) Rating: 0 out of 5 stars0 ratingsPractical C++ Backend Programming: Crafting Databases, APIs, and Web Servers for High-Performance Backend Rating: 0 out of 5 stars0 ratingsJava / J2EE Interview Questions You'll Most Likely Be Asked Rating: 0 out of 5 stars0 ratingsDistributed Computing in Java 9 Rating: 0 out of 5 stars0 ratingsSpring 2.5 Aspect Oriented Programming Rating: 0 out of 5 stars0 ratingsJump Start PHP Environment: Master the World's Most Popular Language Rating: 0 out of 5 stars0 ratingsJavaScript for Modern Web Development: Building a Web Application Using HTML, CSS, and JavaScript Rating: 0 out of 5 stars0 ratingsSpring Integration Essentials Rating: 3 out of 5 stars3/5JAVA Programming Simplified: From Novice to Professional - Start at the Beginning and Learn the World of Java Rating: 0 out of 5 stars0 ratingsPractical Java Programming for IoT, AI, and Blockchain Rating: 0 out of 5 stars0 ratingsJava: Best Practices to Programming Code with Java: Java Computer Programming, #3 Rating: 0 out of 5 stars0 ratings100+ Solutions in Java: A Hands-On Introduction to Programming in Java (English Edition) Rating: 0 out of 5 stars0 ratingsCrystal Clear Java: 1St Edition Rating: 0 out of 5 stars0 ratingsMastering NetBeans Rating: 0 out of 5 stars0 ratingsAmazing Java: Learn Java Quickly Rating: 0 out of 5 stars0 ratingsJava 9 Concurrency Cookbook - Second Edition Rating: 0 out of 5 stars0 ratingsCore Java Professional: For First Time Learner's. Rating: 0 out of 5 stars0 ratingsAndroid Application Development with Maven Rating: 0 out of 5 stars0 ratingsJava Web Developer A Complete Guide Rating: 0 out of 5 stars0 ratings
Programming For You
Python: Learn Python in 24 Hours Rating: 4 out of 5 stars4/5SQL QuickStart Guide: The Simplified Beginner's Guide to Managing, Analyzing, and Manipulating Data With SQL Rating: 4 out of 5 stars4/5Python Programming : How to Code Python Fast In Just 24 Hours With 7 Simple Steps Rating: 4 out of 5 stars4/5Excel : The Ultimate Comprehensive Step-By-Step Guide to the Basics of Excel Programming: 1 Rating: 5 out of 5 stars5/5Microsoft Azure For Dummies Rating: 0 out of 5 stars0 ratingsCoding All-in-One For Dummies Rating: 4 out of 5 stars4/5JavaScript All-in-One For Dummies Rating: 5 out of 5 stars5/5Linux: Learn in 24 Hours Rating: 5 out of 5 stars5/5Beginning Programming with C++ For Dummies Rating: 4 out of 5 stars4/5C All-in-One Desk Reference For Dummies Rating: 5 out of 5 stars5/5Learn to Code. Get a Job. The Ultimate Guide to Learning and Getting Hired as a Developer. Rating: 5 out of 5 stars5/5Python Data Structures and Algorithms Rating: 5 out of 5 stars5/5Excel 101: A Beginner's & Intermediate's Guide for Mastering the Quintessence of Microsoft Excel (2010-2019 & 365) in no time! Rating: 0 out of 5 stars0 ratingsLearn SQL in 24 Hours Rating: 5 out of 5 stars5/5SQL All-in-One For Dummies Rating: 3 out of 5 stars3/5The 1 Page Python Book Rating: 2 out of 5 stars2/5Learn PowerShell in a Month of Lunches, Fourth Edition: Covers Windows, Linux, and macOS Rating: 5 out of 5 stars5/5PYTHON PROGRAMMING Rating: 4 out of 5 stars4/5
Reviews for Java
0 ratings0 reviews
Book preview
Java - Swati Saxena
HISTORY IN BRIEF:
Java is a general purpose, class based, object oriented, platform independent, portable, architecturally neutral, multithreaded, dynamic, distributed, portable, and robust interpreted programming language.
Java was originally designed for interactive television, but it was too advanced technology for the digital cable television industry at the time.
Java was started as a green project by James Gosling , Patrick Naughton, Chris Warth, Mike Sheridan, and Ed Frank at Sun Microsystem in June 1991.
Team members of green project starts this project to develop a language for digital devices such as set-top boxes, televisions, and so on. But, it was suited for internet programming.
Firstly it was called as GreenTalk . language was initially called oak but was renamed as Java in 1995. It made the promise of Write Once, Run Anywhere, with free runtimes on popular platforms.
It was fairly secure and its security was configurable, allowing for network and file access to be limited.
KeyPoints
Versions of Java:
MAGIC CODE : BYTECODE:
Java Byte Code is the language to which Java source is compiled and the Java Virtual Machine understands. Unlike compiled languages that have to be specifically compiled for each different type of computers, a Java program only needs to be converted to byte code once, after which it can run on any platform for which a Java Virtual Machine exists.
Bytecode is a set of instruction designed to be executed by the java run time system, which is called JVM.
JVM is an interpreter of bytecode.
Features of Java:
both ✓ Supports networking
Requirement for Java Example
For executing any java program, you need to,
For basic, looping, conditional question, and example please refer : C Programming and Coding, Question Bank with Solution by swati saxena (BpB)
1. Write a simple java program to print a message?
class First
{
public static void main(String [] arg)
{
System.out.println(Welcome to Swati Computers
);
}
}
Save it as : First.java
Compile: C:\>javac First.java (it will create a First.class file that contains bytecode)
Run: c:\> java First
Keywords in java:
Data Types in Java:
Data types represent the different values to be stored in the variable. In java, there are two types of data types:
Datatype
1. Primitive
A) Boolean
boolean
B) Numeric
Character
char
Integeral
Integer
byte
short
int
long
Floating point
float
double
2. Non primitive
A) String
B) Array
C) etc.
Types of Variable:
There are three types of variables in Java:
2. Write a Java program to interchange values of two variable without using any third variable?
class Swap
{
public static void main(String [] arg)
{
int a=2,b=3;
a=a+b;
b=a-b;
a=a-b;
System.out.println(A=
+a+\nb=
+b);
}
}
3. Write a Java program to check whether main() function can overload or not?
class Overload
{
public static void main(Integer [] aq)
{
System.out.println(hi
);
}
public static void main(String [] ar)
{
System.out.println(Hello
);
}
}
4. Write a program to input length and breadth of rectangle and calculate the area ( Input through command line argument)?
class Rect_area
{
public static void main(String [] aa)
{
int length= Integer.parseInt(aa[0]);
int breath= Integer.parseInt(aa[1]);
int area=length*breath;
System.out.println(the output is
+area);
}
}
import java.util.*;
class notes
{
public static void main(String [] ar)
{
int thousand_2,hundred_5,hundred_1,fifty,ten,five,note;
Scanner sc=new Scanner(System.in);
System. out.println(Enter Rupees
);
note=sc.nextInt();
thousand_2=note/2000;
note=note%2000;
hundred_5=note/500;
note=note%500;
hundred_1=note/100;
note=note% 100;
fifty=note/50;
note=note%50;
ten=note/10;
note%=10;
five=note/5;
note=note%5;
System.out.println(We need \n2000rs note:
+thousand_2+\ n500rs note:
+hundred_5+\n100rs note:
+hundred_1+\n50rs note:
+fifty+\n10rs note:
+ten+\n5 rs note:
+five+\nextra:
+note);}
}
class SI
{
public static void main(String [] aa)
{
int principal= Integer.parseInt(aa[0]);
int time= Integer.parseInt(aa[1]);
double rate=Double.parseDouble(aa[2]);
double si=(principal*time*rate)/100;
System.out.println(the SI is
+si);
}
}
import java.util.*;
class inp
{
public static void main(String [] ar)
{
Scanner sc; //reference variable
sc=new Scanner(System.in);//object
String name;
String lname;
int age,i,count=0;
System.out.println(enter ur name
);
name=sc.next();
System.out.println(enter last name
);
lname=sc.next();
System. out.println(enter age
);
age=sc.nextInt();
System. out.println(Age:
+age);
System. out.println(Hello
+name);
int len=name.length()+lname.length();
System. out.println(len);
}
}
//import java.util.*;
class Stu
{
String n,cou;
java.util.Scanner sc;
public void read()
{
sc=new java.util.Scanner(System.in);
System.out.println(Enter name and course
);
n=sc.next();
cou=sc.next();
}
public void inp(String n,String course)
{
this.n=n;
cou=course;
}
public String name()
{
return n;
}
public void disp()
{
System.out.println(Hello
+n+ u r doing
+cou);
}
}
class Stu_demo
{
public static void main(String [] sd)
{
Stu p=new Stu();
//p.read();
p.inp( swati
, java
); p.disp();
System.out.println(bye
+p.name());
}
}
import java.io.*;
class Inp
{
public static void main(String [] arg) //throws IOException
{
int n;
try{
BufferedReader br=new BufferedReader(new
InputStreamReader(System.in));
System.out.println(enter a no
);
n=Integer.parseInt(br.readLine());
System.out.println(u input :
+n);
}
catch(IOException e)
{
System.out.println(err
);
}
System.out.println(byeee.
);
}
}
10. Write a program to input name and print length of name?
import java.util.*;
class inp
{
public static void main(String [] ar)
{
Scanner sc; //reference variable
sc=new Scanner(System.in);//object
String name;
String lname;
System.out.println(enter ur name
);
name=sc.next();
System.out.println(enter last name
);
lname=sc.next();
System. out.println(Hello
+name);
int len=name.length()+lname.length();
System.out.println(len);
}
}
class Nums
{
public static void main(String [] aa)
{
int sum=0;
int a= Integer.parseInt(aa[0]);
int b= Integer.parseInt(aa[1]);
int c= Integer.parseInt(aa[2]);
sum=a+b+c;
System.out.println(the output is
+sum);
}
}
OPERATORS IN JAVA:
11. Write a program to implement unary operator?
class UnaryExample{
public static void main(String args[])
{
int x=10;
System.out.println(x++);//10 (11)
System.out.println(++x);//12
System.out.println(x--);//12 (11)
System.out.println(--x);//10
}
}
class OperatorExample
{
public static void main(String args[])
{
int a=2;
int b=5;
int min=(a
System.out.println(min);
}
}
JAVA COMMENT:
Comments are non executable code. They can be used to provide information or explanation about the variable, method, class, or any statement.
Types of Java Comments:
There are 3 types of comments in Java:
Single Line Comment: //
Multi Line Comment: /*-------*/
Documentation Comment: /**------*/
Control statement
Syntax:
if (expression1)
{
// codes
}
else if(expression2)
{
// codes
}
else if (expression3)
{
// codes
}
.
.
else
{
// codes
}
Syntax:
switch (variable/expression)
{
case value1:
// statements break;
case value2:
// statements
break;
.. .. ...
.. .. ...
default:
// statements
}
13. Write a Java program to check whether two String variable are equal
or not?
{ class String_Demo
public static void main(String []
ar) {
String a,b=hi
;
a=ar[0];
System.out.println(address of a:
+a.hashCode());
System.out.println(address of b:
+b.hashCode());
if(a==b)
System.out.println(equal
);
else
System.out.println(not equal
);
if(a.equals(b))
System.out.println(equal
);
else
System.out.println(not equal
);
String c=new String(sub
);
String s=new String(b);
System.out.println(address of c:
+c.hashCode());
System.out.println(address of s:
+s.hashCode());
if(a==c)
System.out.println(equal
);
else
System.out.println(not equal
);
if(a.equals(c))
System. out.println(equal
);
else
System. out.println(not equal
);
}
}
14. Write a program to fin d out maximum out of three?
public class JavaExample
{
public static void main(String[] args)
{
int num1 = 10, num2 = 20, num3 = 7;
if( num1 >= num2 && num1 >= num3)
System.out.println(num1+ is the largest Number
);
else if (num2 >= num1 && num2 >= num3)
System.out.println(num2+ is the largest Number
);
else
System.out.println(num3+ is the largest Number
);
}
}
import java.util.Scanner;
class Calculator
{
public static void main (String[] args) {
char operator;
Double number1,nymber2,result;
Scanner scanner = new Scanner(System.in);
System.out.print(Enter operator (either +, -, * or /):
);
operator = scanner.next().charAt(0);
System.out.print(Enter number1 and number2 respectively:
);
number1 = scanner.nextDouble();
number2 = scanner.nextDouble();
switch (operator) {
case ‘+’:
result = number1 + number2;
System.out.print(number1 + +
+ number2 + =
+ result);
break;
case ‘-’:
result = number1 - number2;
System.out.print(number1 + -
+ number2 + =
+ result);
break;
case ‘*’:
result = number1 * number2;
System.out.print(number1 + *
+ number2 + =
+ result);
break;
case '/':
result = number1 / number2;
System.out.print(number1 + /
+ number2 + =
+ result);
break;
default:
System.out.println(Invalid operator!
);
break;
}
}
}
import java.util.Scanner;
class Calculator
{
public static void main(String[] args)
{
int chk_year;
Scanner scanner = new Scanner(System.in);