Skip to the content

onlineexamguide

  • Home
  • Courses
  • Engg. Interview
    • Electrical Engineering
    • Mechanical Engineering
    • Automobile Engineering
    • Civil Engineering
    • Computer Science Engineering
    • Chemical Engineering
  • Online Exam
    • Aptitude Tricks
    • Computer Knowledge
    • Logical Reasoning Tricks
    • Networking
  • Ghatna Chakra
  • Register
    • Instructor Registration
    • Student Registration
  • User Login
  • Home
  • Courses
  • Engg. Interview
    • Electrical Engineering
    • Mechanical Engineering
    • Automobile Engineering
    • Civil Engineering
    • Computer Science Engineering
    • Chemical Engineering
  • Online Exam
    • Aptitude Tricks
    • Computer Knowledge
    • Logical Reasoning Tricks
    • Networking
  • Ghatna Chakra
  • Register
    • Instructor Registration
    • Student Registration
  • User Login

Java Program Structure tutorial and MCQ

Java Program Structure

Table of Contents

  • Java Program Structure
    • Java Program Structure Observations are below.
    • 1) Every statement in Java language should end with a?
    • 15) Choose a correct version of Java Documentation Comment?

Study and learn Java Program Structure questions and answers on basic program structure and syntax. Attend job interviews easily with these MCQs.

All java programs contain some class definition. All functions or methods are kept inside the class. You need to know how to place a main method with public static void inside Class definition. Let us know the basic structure of a Java Program for better understanding next Java Tutorials in the queue.

Java Program Structure

Here is the sample Hello Java program. Check the tutorial on installing and running Java.

We shall see each line and analyse.

class HelloWorld
{
  /* Class variables (static)
      can come here */
  // instance variables (non static) come here
  public static void main(String args[])
  {
    int a=10;
    float b=12.345;
    System.out.println("Hello World Java");
  }
}

Java Program Structure Observations are below.

  1. Keywords appearing in the above example are class, public, static, void, int and float.
  2. A Class is like an enclosure or a bigger block definition with inner members. A Class can contain variables and methods. It has opening and closing braces { }.
  3. HelloWorld is the name or identifier given to the class.
  4. main() is a function. In Java, you should call a function as Method. It has opening and closing braces { }.
  5. A multiline comment with /* and */ can contain any dummy info which is not processed.
  6. A single line comment with // allows us to write a single line comment.
  7. Every statement in Java must end with a Semicolon (;).
  8. Static variables and methods inside a class are called Static members or Class Members. Members can be Variables or Methods.
  9. Non static variables and methods inside a class are called Instance Members ( Instance Variables, Instance Methods).
  10. public before main method is an access modifier that exposes a method to be called from outside.
  11. static before main method makes it to be called even without instantiating an object.
  12. void before main method tells that the method does not return anything.
  13. Main method is taking an argument or paramter as a String Array – args[]. It allows the main method to take arguments from Command Line when running the program.
  14. Variables a and b are local variables that die after main method finishes execution.
  15. System.out has methods to read and print. Here we are using println which prints a new line after printing text.
  16. A Class can, in turn, contain variables of another class type similar to a Structure Type Variable in C language.
[WpProQuiz 51]

Java Program Structure MCQ

1) Every statement in Java language should end with a?

A) Dot or Period

B) Comma

C) Semicolon

D) Colon

Answer [=] C

2) A function in C language is similar to what in Java language?

A) Method

B) Member

C) Variable

D) None of the above

Answer [=] A

3) All methods and variables in Java language are kept inside a?

A) File

B) Class or Interface

C) static method

D) main

Answer [=] B

4) What is the need to mention “static” before main method?

A) To call main method without creating an object of class

B) To make main method as class method common to all instances

C) Both A and B

D) None of the above

Answer [=] C

5) In standalone Java applications, which method is mandatory?

A) main method

B) show method

C) display method

D) print method

Answer [=] A

Explanation:

main() is the starting point of execution.

6) What is the use of Access modifier “pubic” in Java language?

A) To hide the main method from misuse

B) To call the main method outside of Class or Package by JVM

C) To protect main method

D) None of the above

Answer [=] B

7) Choose a Single Line Comment in Java Language below?

A) //Some comments

B) Some comments//

C) /*Some comments*/

D) */Some comments/*

Answer [=] A

8) Choose a multiline comment in Java language below?

A)

/*comments are going
cars are moving*/

B)

*/comments are going
cars are moving/*

C)

//comments are going
cars are moving//

D) None of the above

Answer [=] A

9)

String args[] in main method are used for?
public static void main(String args[])
{
  //
}

A) Passing arguments at compile time

B) Passing arguments at run time

C) Counting number of words

D) Nothing

Answer [=] B

Explanation:

C:/>java Hello AFRICA GOLDMINE
Hello - Class name
AFICA - First argument
GOLDMINE - Second argument

10) What is the default return type of a method in Java language?

A) void

B) int

C) short

D) None of the above

Answer [=] D

Explanation:

You have to explicitly mention a return type.

11) Name of a Class, Variable, Method or an Interface in Java language is called?

A) Argument

B) Value

C) Identifier

D) None of the above

Answer [=] C

12) A valid identifier in Java language may contain which characters?

A) 0-9

B) A-Z, a-z

C) $, _ (Underscore)

D) All the above

Answer [=] D

13) A valid Identifier or name in Java language can start with which character?

A) a-z, A-Z

B) $, _

C) 0-9

D) A and B

Answer [=] D

Explanation:

Up to JDK 8, only a single underscore symbol can be used as an identifier of a class, method or a variable. JDK 9 does not allow.

14) What are the valid White Spaces available in Java language?

A) Space

B) Enter

C) Tab

D) All the above

Answer [=] D

15) Choose a correct version of Java Documentation Comment?

A)

/*
comments
*/

B)

/**
comments
*/

C)

/*
comments
**/

D)

/**
comments
**/

Answer [=] B

Explanation:

Documentation comment allows writing notes about the program. javadoc commmand on the source java file generates a HTML Java documentation with the embedded comments.

Write a comment Cancel reply

You must be logged in to post a comment.

*
  • किस राज्य/केंद्र शासित प्रदेश ने ‘कोडवा हॉकी महोत्सव’ (Kodava Hockey Festival) की मेजबानी की?

  • उत्तर – कर्नाटक

  • हाल ही में खबरों में रहा बरदा वन्यजीव अभयारण्य (Barda Wildlife Sanctuary) किस राज्य/केंद्र शासित प्रदेश में स्थित है?

  • उत्तर – गुजरात

  • किस देश ने ‘सऊदी-ईरान सम्बन्ध सामान्यीकरण’ शांति समझौते की मध्यस्थता की?

  • उत्तर – चीन

  • ‘संयुक्त राष्ट्र 2023 जल सम्मेलन’ (United Nations 2023 Water Conference) का मेजबान कौन सा देश है?

  • उत्तर – अमेरिका

  • ‘अल-मोहद-अल हिंदी-23’ (Al-Mohed-Al Hindi-23) अभ्यास भारत और किस देश के बीच आयोजित किया जा रहा है?

  • उत्तर – सऊदी अरब

  • सेमी-हाई-स्पीड वंदे भारत एक्सप्रेस ट्रेन चलाने वाली पहली महिला लोको पायलट कौन हैं?

  • उत्तर – सुरेखा यादव

  • भारतीय रिजर्व बैंक ने 2023 तक कितने देशों के बैंकों को रुपये में व्यापार करने की अनुमति दी थी?

  • उत्तर – 18

  • MD15 बसों का प्रायोगिक परीक्षण और M100 (100% मेथनॉल) का प्रोटोटाइप किस शहर में लॉन्च किया गया?

  • उत्तर – बेंगलुरु

  • फरवरी 2023 में भारत में थोक मूल्य सूचकांक (WPI) आधारित मुद्रास्फीति कितनी है?

  • उत्तर – 3.85%

  • किस संस्थान ने एक व्यापक स्व-निगरानी ढांचा ‘ATL सारथी’ लॉन्च किया है?

  • उत्तर – नीति आयोग

  • उस चक्रवात का क्या नाम है जिससे मलावी और मोज़ाम्बिक में तेज़ हवाएँ चलीं और मूसलाधार बारिश हुई?

  • उत्तर – फ्रेडी

  • ऑस्कर 2023 इवेंट के दौरान किस फिल्म ने सात पुरस्कार जीते?

  • उत्तर – Everything Everywhere All at Once

  • MoSPI के हालिया आंकड़ों के अनुसार, फरवरी 2023 में भारत की खुदरा मुद्रास्फीति कितनी दर्ज की गई?

  • उत्तर – 6.44%

  • कौन सा राज्य/केंद्र शासित प्रदेश ‘साझा बौद्ध विरासत पर पहला अंतर्राष्ट्रीय सम्मेलन’ का मेजबान है?

  • उत्तर – नई दिल्ली

  • किस राज्य ने राज्य के कार्यकर्ताओं को राज्य सरकार की नौकरी में 10% क्षैतिज आरक्षण को मंजूरी दी?

  • उत्तर – उत्तराखंड

  • Unique Land Parcel Identification Number (ULPIN) कितने अंकों वाला एक अल्फा-न्यूमेरिक नंबर है?

  • उत्तर – 14

  •  किस संस्था ने ‘Landslide Atlas of India’ जारी किया?

  • उत्तर – इसरो

  • किस केंद्रीय मंत्रालय ने ‘लीन योजना’ (LEAN Scheme) शुरू की?

  • उत्तर – MSME मंत्रालय

  • कौन सा केंद्रीय मंत्रालय ‘World Food India-2023’ कार्यक्रम की मेजबानी करने जा रहा है?

  • उत्तर – खाद्य प्रसंस्करण उद्योग मंत्रालय

  • माधव राष्ट्रीय उद्यान (Madhav National Park), जो हाल ही में खबरों में था, किस राज्य/केंद्र शासित प्रदेश में है?

  • उत्तर – मध्य प्रदेश

  • किस राज्य/केंद्र शासित प्रदेश ने विभिन्न क्षेत्रों में शहर के विकास का मार्गदर्शन करने के लिए ‘2041 के लिए मास्टर प्लान’ जारी किया?

  • उत्तर – नई दिल्ली

  • हाल ही में ख़बरों में रहा ‘Safe Harbour Principle’ किस अधिनियम से संबंधित है?

  • उत्तर – सूचना प्रौद्योगिकी अधिनियम, 2000

  • 2023 में शंघाई सहयोग संगठन (SCO) की अध्यक्षता किस देश के पास है?

  • उत्तर – भारत

  • हाल ही में खबरों में रहा टोरिनो स्केल (Torino Scale) किस क्षेत्र से जुड़ा है?

  • उत्तर – अंतरिक्ष विज्ञान

  • कृत्रिम बुद्धि (artificial intelligence) द्वारा संचालित दुनिया के पहले रेडियो प्लेटफॉर्म का नाम क्या है?

  • उत्तर – RadioGPT

  • नासा के क्यूरियोसिटी रोवर (Curiosity Rover) ने हाल ही में किस ग्रह पर क्रिपस्कुलर किरणों (crepuscular rays) को कैप्चर किया है?

  • उत्तर – मंगल

  • कौन सा केंद्रीय मंत्रालय ‘स्वदेश दर्शन 2.0 कार्यक्रम’ लागू करता है?

  • उत्तर – पर्यटन मंत्रालय

  • हाल ही में Prevention of Money Laundering Act को किन उत्पादों को शामिल करने के लिए विस्तारित किया गया था?

  • उत्तर – वर्चुअल डिजिटल संपत्ति

  • किस देश ने National Platform for Disaster Risk Reduction (NPDRR) के तीसरे सत्र की मेजबानी की?

  • उत्तर – भारत

  • किस राज्य के राज्यपाल ने राज्य मंत्रिमंडल द्वारा पारित ऑनलाइन जुआ निषेध विधेयक (Prohibition of Online Gambling Bill) को लौटा दिया है?

  • उत्तर – तमिलनाडु

  • भारत में पहली बार माइम्युसेमिया सीलोनिका (Mimeusemia ceylonica), दुर्लभ पतंगे की प्रजाति को किस राज्य में देखा गया है?

  • उत्तर – केरल

  • किस देश ने ‘Illegal Migration Bill’ पेश किया?

  • उत्तर – यूके

  • किस देश ने 25 वर्षों में पहली बार महिलाओं के लिए सैन्य सेवा खोली है?

  • उत्तर – कोलंबिया

  • केंद्र ने हाल ही में NAFED, NCCF को किस उत्पाद की खरीद के लिए बाजार में तत्काल हस्तक्षेप करने का निर्देश दिया है?

  • उत्तर – लाल प्याज

  • ‘ट्रोपेक्स 2023’ किस देश द्वारा आयोजित एक प्रमुख परिचालन स्तर का अभ्यास है?

  • उत्तर – भारत

  • किस संस्था ने ‘Global Greenhouse Gas Monitoring Infrastructure’ पेश किया?

  • उत्तर – WMO

  • किस केंद्रीय मंत्रालय ने ‘स्वच्छोत्सव’ महिलाओं के नेतृत्व में स्वच्छता अभियान शुरू किया?

  • उत्तर – आवास और शहरी मामलों के मंत्रालय

  • सल्हौतुओनुओ क्रूस (Salhoutuonuo Kruse) ने किस राज्य की पहली महिला कैबिनेट मंत्री बनकर इतिहास रचा है?

  • उत्तर – नागालैंड

  • कौन सा शहर वित्तीय समावेशन के लिए वैश्विक भागीदारी की दूसरी बैठक का मेजबान था?

  • उत्तर – हैदराबाद

  • डॉ माणिक साहा ने 2023 में किस भारतीय राज्य के मुख्यमंत्री के रूप में शपथ ली?

  • उत्तर – त्रिपुरा

  • ‘डिजिटल इंडिया बिल’ किस केंद्रीय मंत्रालय से जुड़ा है?

  • उत्तर – इलेक्ट्रॉनिक्स और आईटी मंत्रालय

  • ड्राफ्ट केंद्रीय विद्युत प्राधिकरण विनियम (Draft Central Electricity Authority Regulations) हाल ही में किस प्रजाति की रक्षा के लिए जारी किया गया था?

  • उत्तर – ग्रेट इंडियन बस्टर्ड

  • किस देश ने ‘International Big Cat Alliance’ बनाने का प्रस्ताव दिया है?

  • उत्तर – भारत

  • ब्रह्मोस मिसाइल को रूस के NPO मशीनोस्ट्रोयेनिया और भारत के किस संगठन के बीच साझेदारी से विकसित किया गया है?

  • उत्तर – DRDO

  • दुनिया का पहला 200 मीटर लंबा बैंबू क्रैश बैरियर ‘बाहु बल्ली’ किस राज्य में स्थापित किया गया है?

  • उत्तर – महाराष्ट्र

  • किस देश ने लगभग 8.5 मिलियन मीट्रिक टन लिथियम अयस्क की खोज करने का दावा किया है?

  • उत्तर – ईरान

  • किस संस्था ने ‘Women, Business and the Law Index’ जारी किया?

  • उत्तर – विश्व बैंक

  • 2021-22 के लिए आवधिक श्रम बल सर्वेक्षण (PLFS) रिपोर्ट के अनुसार, कृषि क्षेत्र में रोजगार का अंश कितना है?

  • उत्तर – 45.5%

  • किस संस्था ने ‘Advanced Towed Artillery Gun System (ATAGS)’ डिजाइन किया है?

  • उत्तर – DRDO

  • हाल ही में खबरों में रहा HUID नंबर किस तत्व/उत्पाद से जुड़ा है?

  • उत्तर – सोना

  • किन संस्थानों ने ‘More than a billion reasons: The urgent need to build universal social protection’ शीर्षक से रिपोर्ट जारी की?

  • उत्तर – UNICEF- ILO

  • केंद्रीय सिंचाई एवं विद्युत बोर्ड (CBIP) पुरस्कार किस संस्था को प्रदान किया गया?

  • उत्तर – NTPC

  • किस संस्था ने ‘Mind the Gender Gap’ रिपोर्ट जारी की?

  • उत्तर – CFA Institute

  • हाल ही में खबरों में रही ‘समर्थ योजना’ (SAMARTH scheme) किस मंत्रालय से जुड़ी है?

  • उत्तर – कपड़ा मंत्रालय

  • राष्ट्रीय सुरक्षा दिवस (National Safety Day) 2023 की थीम क्या है?

  • उत्तर – Our Aim – Zero Harm

  • कौन सा शहर ‘G20 विदेश मंत्रियों की बैठक (FMM)’ का मेजबान है?

  • उत्तर – नई दिल्ली

  • किस देश ने इंडो-पैसिफिक टेक दूत (Indo-Pacific tech envoy) की घोषणा की?

  • उत्तर – यूके

  • किस बैंक ने सिटीग्रुप के भारतीय उपभोक्ता कारोबार का अधिग्रहण पूरा कर लिया है?

  • उत्तर – Axis Bank

  • किस केंद्रीय मंत्रालय ने ‘Grievance Appellate Committee (GAC)’ लॉन्च की?

  • उत्तर – इलेक्ट्रॉनिक्स और आईटी मंत्रालय

  • ‘Indian States’ Energy Transition’ रिपोर्ट के अनुसार, किन राज्यों ने स्वच्छ बिजली में परिवर्तन में सबसे अधिक प्रगति की है?

  • उत्तर – कर्नाटक और गुजरात

  • धरोई आर्द्रभूमि (Dharoi wetland), जहाँ हाल ही में एक पक्षी सर्वेक्षण किया गया था, किस राज्य में स्थित है?

  • उत्तर – गुजरात

  • IMF के अनुसार, किस देश में 2023 में वैश्विक विकास में 15% योगदान देने की क्षमता है?

  • उत्तर – भारत

  • भारत के किस पड़ोसी देश ने सौर ऊर्जा के उपयोग को बढ़ाने के लिए ISA के साथ समझौता ज्ञापन पर हस्ताक्षर किए?

  • उत्तर – बांग्लादेश

  • अंतर्राष्ट्रीय बौद्धिक संपदा सूचकांक 2023 में भारत का रैंक क्या है?

  • उत्तर – 42

  • कौन सा राज्य ‘वैश्विक उत्तरदायी पर्यटन शिखर सम्मेलन’ (Global Responsible Tourism Summit) का मेजबान है?

  • उत्तर – केरल

  • ‘UPI LITE पेमेंट्स’ लॉन्च करने वाला पहला प्लेटफॉर्म कौन सा है?

  • उत्तर – पेटीएम पेमेंट्स बैंक

  • किस संस्था ने भारत का पहला म्यूनिसिपल बॉन्ड इंडेक्स लॉन्च किया?

  • उत्तर – NSE

  • किस शहर का नाम बदलकर ‘छत्रपति संभाजीनगर’ कर दिया गया है?

  • उत्तर – औरंगाबाद

  • भारत की G-20 अध्यक्षता के तहत W20 इंसेप्शन मीटिंग की मेजबानी कौन सा शहर कर रहा है?

  • उत्तर – औरंगाबाद

  • कौन सा शहर ‘International Bio-resource Conclave & Ethno-pharmacology Congress 2023’ का मेजबान है?

  • उत्तर – इंफाल

  • फेंटानिल और पशु ट्रैंक्विलाइज़र का मिश्रण जिसे ज़ाइलाज़ीन कहा जाता है, जिसे ‘ट्रांक डोप’ के रूप में जाना जाता है, किस देश में चिंता पैदा कर रहा है?

  • उत्तर – अमेरिका

  • किस राज्य को ‘Foundational Literacy and Numeracy Index 2022’ में शीर्ष प्रदर्शन करने वाला स्थान मिला?

  • उत्तर – पश्चिम बंगाल

  • किस देश ने ‘National Green Fiscal Incentives Policy Framework’ लॉन्च किया?

  • उत्तर – केन्या

  • काजीरंगा राष्ट्रीय उद्यान किस राज्य में स्थित है?

  • उत्तर – असम

  • ‘राष्ट्रीय स्वास्थ्य प्राधिकरण की स्कैन एंड शेयर सर्विस’ किस योजना के तहत शुरू की गई थी?

  • उत्तर – आयुष्मान भारत डिजिटल मिशन

  • किस देश ने ‘कमर्शियल आर्म्स ट्रांसफर (CAT) पॉलिसी’ लॉन्च की है?

  • उत्तर – अमेरिका

  • हाल ही में खबरों में रही ‘INS सिंधुकेसरी’ क्या है?

  • उत्तर – पनडुब्बी

  • 2022 में किस देश की प्रजनन दर दुनिया में सबसे कम 0.78 है?

  • उत्तर – दक्षिण कोरिया

  • हाल ही में खबरों में रहा रिड्यू कैनाल स्केटवे (Rideau Canal Skateway) किस देश में है?

  • उत्तर – कनाडा

Recent Posts

  • Phasor Diagram of 3 Phase Induction Motor
  • बौद्ध कालीन शिक्षा
  • Rotating Magnetic Field in 3 Phase Induction Motor
  • Squirrel Cage Induction Motor
  • वैदिक कालीन शिक्षा
  • Slip Ring Induction Motor
  • 3 phase induction motor Definition & Working Principle
  • Synchronous Motors – Important Questions and Answers
  • Starting Methods of Synchronous Motor
  • Torque and Power Relation
  • Phasor Diagram for Synchronous Motor
  • Synchronous Motor: Applications, Starting Methods & Working Principle
  • Prime mover
  • Parallel Operation of Alternators
  • Slip Test on Synchronous Machine

onlineexamguide

onlineexamguide.com is the ultimate guide that will keep you updated about almost every Exam & Interviews . We aim to provide our readers with an informative details that have been occurring in Examination . Here at onlineexamguide.com , we focus on delivering our readers with the latest exam Pattern Mock test

We Provide Free online test to practice for Competitive exams , Online Exam, Entrance and Interview. Learn and Practice online test for Free and Prepare for your exam online with us

Quick links

  • About us
  • Privacy Policy
  • Instructor Registration
  • Student Registration
  • Java Programming
  • C programming
  • C++ programming
  • Aptitude Tricks

Follow us

Free Online Mock Test

  • UPTET PRIMARY Online Test Series
  • Super TET Mock Test in Hindi 2023
  • CTET Mock Test 2022 Paper 1
  • SSC CHSL Online Mock Test
  • SSC MTS Mock Test 2023
  • SSC CGL Mock Test
  • SSC GD Mock Test
  • ccc online test

Search

Learn and Earn

Register as Instructor - Create and sell online courses and coaching services with the best online platform onlineexamguide.com . Build a course, build a brand, earn money

Contact us

For any queries

Email us on - admin@onlineexamguide.com

We will response fast as much as we can
Copyright © 2023 onlineexamguide.com - All Rights Reserved.
error: Content is protected !!

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.