Model Question Solution Java

Model Question Solution
class Bike{ 
final int speedLimit=90; //final variable
void ride(){
speedLimit=900;
}
public static void main(String[] args){
Bike obj=new Bike();
obj.ride();
}
}
Output : Compile Time error
class Bike{
final void ride() //final method
{
System.out.println("Riding");
}
class Gixxer extends Bike{
void ride (){
System.out.println("I am riding bike with speed of 80km/h");
}
public static void main(String[] args)
{
Gixxer gixxer=new Gixxer();
gixxer.ride();
}
}
Output : Compile Time error
final class Bike{} //final classclass Gixxer extends Bike{
void ride(){
System.out.println("Riding safely with 100km/h");
}
public static void main(String[] args){
Gixxer gixxer=new Gixxer();
gixxer.ride();
}
}
Output : Compile Time error
index.html
input html form
Output
Output
Output
Output
import java.io.*;
import java.net.*;

public class MyServer {
public static void main(String[] args) throws IOException {
ServerSocket ss=new ServerSocket(1234);
System.out.println("Waiting for client request");
Socket s=ss.accept();

String str;
BufferedReader br=new BufferedReader(new InputStreamReader(s.getInputStream()));

str=br.readLine();

System.out.println("value received");

int number=Integer.parseInt(str);
int i,fact = 1;
for(i=1;i<=number;i++){
fact=fact*i;
}

PrintStream ps=new PrintStream(s.getOutputStream());
ps.println(fact);
br.close();
ps.close();
s.close();
ss.close();
}
}
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.net.Socket;

public class MyClient {
public static void main(String[] args) throws IOException {
Socket s = new Socket("localhost", 1234);
String str;
System.out.println("Enter any number :");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

str = br.readLine();
PrintStream ps = new PrintStream(s.getOutputStream());
ps.println(str);
BufferedReader fs = new BufferedReader(new InputStreamReader(s.getInputStream()));
String result = fs.readLine();
System.out.println("Factorial is :" + result);
br.close();
fs.close();
ps.close();
s.close();
}
}
Ouptut
Difference Between Swing and JavaFX
import javafx.application.Application;public class HelloWorld extends Application {
public void start(Stage primaryStage)
{
//Other steps ...
}
}
Button btn=new Button("Say, Hello World");
StackPane root =new StackPane();
root.getChildren().add(btn);
Scene scene =new Scene (root,400,300);
primaryStage.setScene(scene);
primaryStage.setTitle("First JavaFX Application");
primaryStage.show();
button.setOnAction(new Handler());
}
class Handler implements EventHandler<ActionEvent>
{
@Override
public void handle(ActionEvent ae)
{
System.out.println("Hello World");
}
}
public static void main(String[] args)
{
launch(args)
}
import javax.servlet.http.*;
import javax.servlet.*;
import java.io.*;
public class DemoServlet extends HttpServlet
{
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException
{
res.setContentType("text/html"); //setting the content type
PrintWriter pw=res.getWriter(); //get the stream to write the data

//writing the html in stream
pw.println("<html><body>");
pw.println("Welcome to servlet");
pw.println("</body></html>);
pw.close(); //closing the stream
}
}
Difference of RMI and CORBA
float calculate_tax(in float amount);
Consistent output using synchronized method

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store