Wednesday, 25 July 2018
Tuesday, 24 July 2018
Summary table of Java Modifiers and Access Specifiers.
- The only applicable modifier for the local variable is final.
- The only applicable modifiers for constructor are public, private, default, protected.
- The modifiers which are applicable only to the method is native.
- The modifiers which are applicable only for variables volatile and transient.
- The modifiers which are applicable for classes but not for an interface is final.
- The modifier which is applicable for classes but not for enum is final, abstract.
Tuesday, 10 July 2018
//Array of ArrayList Demonstration in java
import java.util.*;
public class ArrayOfArrayList
{
public static void main(String args[])
{
ArrayList listArray[] = new ArrayList[2];
ArrayList firstList = new ArrayList();
firstList.add("Java");
firstList.add("Technology");
ArrayList secondList = new ArrayList();
secondList.add("Govind");
secondList.add("Ballabh");
secondList.add("Khan");
listArray[0] = firstList;
listArray[1] = secondList;
System.out.println(listArray[0]);
System.out.println(listArray[1]);
}
}
// Java program to illustrate creating an array of objects
class Student
{
public int roll_no;
public String name;
Student(int roll_no, String name)
{
this.roll_no = roll_no;
this.name = name;
}
}
// Elements of array are objects of a class Student.
public class StudentDemo
{
public static void main (String[] args)
{
// declares an Array of Student Object.
Student[] arr;
// allocating memory for 5 objects of type Student.
arr = new Student[5];
// initialize the first elements of the array
arr[0] = new Student(1,"govind");
// initialize the second elements of the array
arr[1] = new Student(2,"ajit");
// so on...
arr[2] = new Student(3,"mani");
arr[3] = new Student(4,"dinesh");
arr[4] = new Student(5,"sanjay");
// accessing the elements of the specified array
for (int i = 0; i < arr.length; i++)
System.out.println("Element at " + i + " : " +
arr[i].roll_no +" "+ arr[i].name);
}
}
class Student
{
public int roll_no;
public String name;
Student(int roll_no, String name)
{
this.roll_no = roll_no;
this.name = name;
}
}
// Elements of array are objects of a class Student.
public class StudentDemo
{
public static void main (String[] args)
{
// declares an Array of Student Object.
Student[] arr;
// allocating memory for 5 objects of type Student.
arr = new Student[5];
// initialize the first elements of the array
arr[0] = new Student(1,"govind");
// initialize the second elements of the array
arr[1] = new Student(2,"ajit");
// so on...
arr[2] = new Student(3,"mani");
arr[3] = new Student(4,"dinesh");
arr[4] = new Student(5,"sanjay");
// accessing the elements of the specified array
for (int i = 0; i < arr.length; i++)
System.out.println("Element at " + i + " : " +
arr[i].roll_no +" "+ arr[i].name);
}
}
One Dimensional Array in java
public class OneDimensionalArray
{
public static void main(String args[])
{
int marks[] = new int[5];
System.out.println("Elements are " + marks.length);
// Now assign values
marks[0] = 68;
marks[1] = 70;
marks[2] = 76;
marks[3] = 85;
marks[4] = 94;
System.out.println("Value of 1st element: " + marks[0]);
System.out.println("Value of 2nd element: " + marks[1]);
System.out.println("Value of 3rd element: " + marks[2]);
System.out.println("Value of 4th element: " + marks[3]);
System.out.println("Value of 5th element: " + marks[4]);
System.out.println("Printing through for loop ");
for(int i = 0; i < marks.length; i++)
{
System.out.println(marks[i] );
}
System.out.println("Printing through for each loop");
for(int k : marks)
{
System.out.println(k);
}
}
}
Monday, 9 July 2018
//String array in java
public class Demo
{
public static void main(String args[ ])
{
String fname = "Govind";
String mname = "Ballabh";
String lname = "Khan";
public class Demo
{
public static void main(String args[ ])
{
String fname = "Govind";
String mname = "Ballabh";
String lname = "Khan";
System.out.println("========================Names===============================");
String names[] = {fname, mname, lname};
for(int i = 0; i < names.length; i++)
{
System.out.println(names[i]);
}
System.out.println("========================Cities===============================");
// we can create like this also
String cities[ ] = {"patna", "Bhopal", "Delhi"};
for(int i = 0; i < cities.length; i++)
{
System.out.println(cities[i]);
}
// we can create like this also
String cities[ ] = {"patna", "Bhopal", "Delhi"};
for(int i = 0; i < cities.length; i++)
{
System.out.println(cities[i]);
}
System.out.println("========================Language===============================");
// we can do like this also
String languages[ ] = new String[6];
languages[0] = "C";
languages[1] = "C++";
languages[2] = "Java";
languages[4] = ".Net";
languages[5] = ".Php";
for(int i = 0; i <languages.length; i++)
{
System.out.println(languages[i]);
}
}
}
// we can do like this also
String languages[ ] = new String[6];
languages[0] = "C";
languages[1] = "C++";
languages[2] = "Java";
languages[4] = ".Net";
languages[5] = ".Php";
for(int i = 0; i <languages.length; i++)
{
System.out.println(languages[i]);
}
}
}
Saturday, 9 June 2018
//create simple form using bootstrap and validate their field using java script..........
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css">
<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<!-- Popper JS -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js"></script>
<!-- Latest compiled JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<h1 class="text-success text-center">User Registration Form</h1>
<div class="col-lg-8 m-auto d block">
<form action="#" onsubmit="return validation()" class="bg-light">
<div class="form-group">
<label>User Name:</label>
<input type="text" name="user" class="form-control" id="user" autocomplete="off">
<span id="username" class="text-danger font-weight-bold"></span>
</div>
<div class="form-group">
<label>Password:</label>
<input type="text" name="pass" class="form-control" id="pass" autocomplete="off">
<span id="password" class="text-danger font-weight-bold"></span>
</div>
<div class="form-group">
<label>Confirm Password:</label>
<input type="text" name="cnfpass" class="form-control" id="cnfpass" autocomplete="off">
<span id="cnfpassword" class="text-danger font-weight-bold"></span>
</div>
<div class="form-group">
<label>Mobile No:</label>
<input type="text" name="mobile" class="form-control" id="mobile" autocomplete="off">
<span id="mobileno" class="text-danger font-weight-bold"></span>
</div>
<div class="form-group">
<label>Email:</label>
<input type="text" name="email" class="form-control" id="email" autocomplete="off">
<span id="emailid" class="text-danger font-weight-bold"></span>
</div>
<input type="submit" name="submit" value="submit" class="btn btn-success">
</form>
</div>
</div>
<script type="text/javascript">
function validation() {
var user=document.getElementById('user').value;
var pass=document.getElementById('pass').value;
var cnfpass=document.getElementById('cnfpass').value;
var mobile=document.getElementById('mobile').value;
var email=document.getElementById('email').value;
if(user==' ')
{
document.getElementById('username').innerHTML="** please fill the User Name field";
//alert('required');
return false;
}
if(pass==' ')
{
document.getElementById('password').innerHTML="** please fill the Password field";
//alert('required');
return false;
}
if(cnfpass==' ')
{
document.getElementById('cnfpassword').innerHTML="** please fill the Confirm Password field";
//alert('required');
return false;
}
if(mobile==' ')
{
document.getElementById('mobileno').innerHTML="** please fill the mobile number field";
return false;
}
if(email==' ')
{
document.getElementById('emailid').innerHTML="** please fill the email field";
return false;
}
}
</script>
</body>
</html>
Subscribe to:
Posts (Atom)






