JAVA Programming (314317) | Program Codes | Question And Answers

---------------×------------------××--------------------×---------------


---------------×------------------××--------------------×---------------

Java Programming (314317)

---------------×------------------××--------------------×---------------



3. Questions And Answers
---------------×------------------××--------------------×---------------

Syllabus

java








Click on Above Button To Download Syllabus of Java Programming (314317)

---------------×------------------××--------------------×---------------

About CO4K Syllabus

    In the fourth semester of the MSBTE diploma in Computer Engineering (CO) students will appear for MSBTE theory exams of 70 marks for three subjects - Java Programming, Data Communication & Computer Network and Microprocessor. MSBTE's Online exam of 70 marks for one subject - Environment Education & Sustainability. External MSBTE practical exam of 25 marks for Python Programming. Internal MSBTE practical exam of 25 marks for User Interface & Design. More emphasis is given on a practical-oriented study approach.

    As you all know, the curriculum for MSBTE's K scheme makes passing simple. According to the K Scheme Curriculum of MSBTE, the minimum passing score is 40 out of 100. The K Scheme Curriculum at MSBTE uses a 30-70 mark assessment for a total of 100 marks, where the theory assessment is based on formative (FA-TH) and summative (SA-TH) evaluations. FA-TH represents the average of two class tests of 30 marks each conducted during the semester at the institute. SA-TH represents the theory paper with 70 marks conducted by MSBTE at the end of the semester. MSBTE has revised the curriculum of the Diploma, called the 'K' Scheme Curriculum, for the academic year 2023-24. MSBTE has officially announced the second semester curriculum in the month of November 2023. MSBTE has displayed the draft curriculum until the sixth semester, and the syllabus for all third and fourth semesters is now available. Now students will learn more technical subjects from the second year onward.

---------------×------------------××--------------------×---------------


---------------×------------------××--------------------×---------------

Questions And Answers

---------------×------------------××--------------------×---------------

1. List any eight features of Java.
Ans.
Features of Java: 
1. Data Abstraction and Encapsulation 
2. Inheritance 
3. Polymorphism 
4. Platform independence 
5. Portability 
6. Robust 
7. Supports multithreading 
8. Supports distributed applications 
9. Secure 
10. Architectural neutral 
11.  Dynamic 

---------------×------------------××--------------------×---------------

2. Define stream class. List its types.
Ans. 
Definition of stream class: 
An I/O Stream represents an input source or an output destination. A 
stream can represent many different kinds of sources and 
destinations, including disk files, devices, other programs, and 
memory arrays. Streams support many different kinds of data, 
including simple bytes, primitive data types, localized characters, and 
objects. Java’s stream based I/O is built upon four abstract classes: 
InputStream, OutputStream, Reader, Writer. 
 
Types of stream classes: 
i. Byte stream classes 
ii. Character stream classes. 
 
---------------×------------------××--------------------×---------------

3. Explain the four access specifiers in Java.
Ans.
There are 4 types of java access modifiers:  
1. private 2. default 3. Protected 4. public  
 
1) private access modifier: The private access modifier is accessible 
only within class. 
2) default access specifier: If you don’t specify any access control 
specifier, it is default, i.e. it becomes implicit public and it is 
accessible within the program. 
3) protected access specifier: The protected access specifier is 
accessible within package and outside the package but through 
inheritance only. 
4) public access specifier: The public access specifier is accessible 
everywhere. It has the widest scope among all other modifiers. 
 
---------------×------------------××--------------------×---------------

4. List any four Java API packages.
Ans.
1.java.lang 
2.java.util 
3.java.io 
4.java.awt 
5.java.net 
6.ava.applet
 
---------------×------------------××--------------------×---------------

5. Define array. List its types.
Ans.
An array is a homogeneous data type where it can hold only 
objects of one data type. 
Types of Array:
1)One-Dimensional 
2)Two-Dimensional 
 
---------------×------------------××--------------------×---------------

6. List access specifiers in Java.
Ans.
1)public 
2)private 
3)friendly 
4)protected 
5)Private Protected 
 
---------------×------------------××--------------------×---------------

7. Explain the following classes. 
i)Byte stream class 
ii)Character Stream Class

Ans.
i)Byte stream class: 
1) InputStream and OutputStream are designed for byte 
streams 
2) Use the byte stream classes when working with bytes or other 
binary objects. 
3) Input Stream is an abstract class that defines Java’s model of 
streaming byte input 
4)The Input stream class defines methods for performing input 
function such as reading bytes, closing streams, Marking 
position in stream. 
5) Output Stream is an abstract class that defines streaming byte 
output.   
6) The output stream class defines methods for performing 
output function such as writing bytes, closing streams.

ii)Character Stream Class: 
1. Reader and Writer are designed for character streams. 
2. Use character stream classes when working with characters or 
strings. 
3. Writer stream classes are designed to write characters. 
4. Reader stream classes are designed to read characters. 
5The two subclasses used for handling characters in file are 
FileReader (for reading characters) and FileWriter (for writing 
characters).
 
---------------×------------------××--------------------×---------------

8. Differentiate between String and String Buffer.
Ans.

String String Buffer
String is a major class String Buffer is a peer class of String
Length is fixed (immutable) Length is flexible (mutable)
Contents of object cannot be modified Contents of object can be modified
Object can be created by assigning String constants enclosed in double quotes. Objects can be created by calling constructor of String Buffer class using “new”
Ex:- String s = "abc"; Ex:- StringBuffer s = new StringBuffer("abc");

 
---------------×------------------××--------------------×---------------

9. What is scope of variable ?
Ans.
Scope of a variable refers to areas or sections of a program in which the variable can be accessible and lifetime of a variable refers to how long the variable stays alive in the memory.
Scope of a local variable is within the block in which it is declared.

---------------×------------------××--------------------×---------------

10. Write a program to generate Fibonacci Series : 1 1 2 3 5 8 13 21 34 55 89 
Ans.
class testpr
{
public static void main(String args[ ])
{
    int a,b,c,i;
    a=1;
    b=2;
    i=1;
    System.out.print("1 1 2");
    do
    {
        c=a+b;
        System.out.print(" "+c);
        a=b;
        b=c;
        i=i+1;
    }while(i<9);
}
}

---------------×------------------××--------------------×---------------

Some Notes for Java Programming

---------------×------------------××--------------------×---------------

    Java Supports all the object oriented concepts such as Object ,Class, Encapsulation, Inheritance, Polymorphism, Abstraction, etc.
    Java is fully or purely object oriented programming language. Everything in Java is considered as an object. Everything in Java is included in a class.
    Java use both compiler as well as interpreter. In Java the source code is not directly transferred into machine code. First it is transformed into byte code and then into machine code. The source code is transformed into byte code by compiler while the byte code is then Transformed into Machine code by the interpreter. The byte code can be interpreted on any machine. 

    JVM means Java Virtual Machine.

    

Java Program to print Hello world message
    public class FirstJava
    {
       	    public static void main(String args[])
            {
            	System.out.println("Hello World");
            }
    }
        

Java Program using for loop
  public class FirstJavaProgram  
  {
  	public static void main(String args[])
        {
            for(int i=1;i<=5;i++)
            {
                System.out.println("Show count i="+i);
            }
        }
  }
  

Floyd's Triangle Pattern Program using Java
*
* *
* * *
* * * *

public class Pattern1
{
	public static void main(String args[])
    {
    	for(int i=1;i<=5;i++)
        {
        	for(int j=1;j<=i;j++)
            {
            	System.out.print("* ");
            }
            System.out.println();
        }
    }
}

Command Line Arguments using Java Program
(When we run this program we need to pass arguments in command line while running the program
Like This -> java CommandLineArguments1 77 88)

public class CommandLineArguments1 
{

  public static void main(String args[]) 
  {

    int x = Integer.parseInt(args[0]);
    int y = Integer.parseInt(args[1]);

    int c = x + y;

    System.out.println("addition of numbers:" + c);
  }

}
  


GCD of two numbers using Java

/*	GCD of two numbers using Java	*/
import java.util.*;
public class GCD
{
	public static void main(String args[])
	{
		int num1,num2,g,i;
		Scanner sc = new Scanner(System.in);
		System.out.println("Greatest Common Division (GCD) ");
		System.out.print("Enter 1st number = ");
		num1=sc.nextInt();
		System.out.print("Enter 2nd number = ");
		num2=sc.nextInt();
		g=gcd(num1,num2);
		System.out.println("\nGCD of "+num1+" and "+num2+" = "+g);
	}
	
	public static int gcd(int a,int b)
	{
		while(a!=b)
		{
			if(a>b)
			{
				return gcd((a-b),b);
			}
			else
			{
				return gcd(a,(b-a));
			}
		}
		return a;
	}
}

Java Program for array of Object to get employee details from user

import java.util.*;
class Employee
{
	int eid;
	String ename;
	double salary;

	public Employee(int eid,String ename,double salary)
	{
		this.eid=eid;
		this.ename=ename;
		this.salary=salary;
	}
	public void display()
	{
		System.out.println(" Empid = "+eid+"\n Ename = "+ename+"\n Salary = "+salary);
	} 
}
class EmpMaster
{
	public static void main(String args[])
	{
		/* Employee emp1=new Employee(1111,"Soham",25000);
		   emp1.display();  */
		Scanner s1=new Scanner(System.in);
		int i;
		System.out.print("Enter no. of Employee Details you want to enter = ");
		int n=s1.nextInt();
		
		Employee emp[]=new Employee[n];

		for(i=0;i<n;i++)
		{
			System.out.println("\nEnter Details of Employee "+(i+1));
			System.out.print("Employee ID = ");
			int d1=s1.nextInt();
			System.out.print("Employee Name = ");
			String d2=s1.next();
			System.out.print("Employee Salary = ");
			double d3=s1.nextDouble();
			
			emp[i]=new Employee(d1,d2,d3);
		}
		for(i=0;i<n;i++)
		{
			System.out.println("\nDetails of Employee "+(i+1));
			emp[i].display();
		}
	}
}

Command Line Arguments using Java Program


import java.io.*;
public class javacmd2
{
	public static void main(String args[])
	{
		int sum=0,a;
		for(int i=0;i<args.length;i++)
		{
			a=Integer.parseInt(args[i]);
			sum=sum+a;
		}
		System.out.println("Addition = "+sum);
	}
}
  


Fatorial Program using Java Programming

import java.util.Scanner;
class java3
{
	public static void main(String args[])
	{
		int a,r;
		Scanner sc=new Scanner(System.in);
		System.out.print("Enter value = ");
		a=sc.nextInt();
		r=fact(a);
		System.out.println("Factorial of "+a+" = "+r);
	}
	public static int fact(int n)
	{
		if(n==1)
		{
			return 1;
		}
		else
		{
			return (n*fact(n-1));
		}
	}
}

Write a program to implement multidimensional array. -- Link


Write a program to display array elements using for-each loop-- Link 


Write a program to insert different elements in the Vector & display them -- Link 


Write a program to use different methods of Vector class. -- Link 


---------------×------------------××--------------------×---------------
---------------×------------------××--------------------×---------------

---------------×------------------××--------------------×---------------




---------------×------------------××--------------------×---------------
---------------×------------------××--------------------×---------------

Post a Comment

0 Comments