+ 1

A small query related Java

Sorry for the off-topic question. If I have to, I'll delete this thread after I got my answer :) I recently switched from C++ to Java (I had to, because of my college syllabus). I thought it'll be easier to adopt since I know C++ good. But the hello world program was like a nightmare to me. Why do we need put everything inside classes?? When I googled it, it said that everything has to be inside classes, but that doesn't make any sense does it? And as I was progressing, I saw the string data type being "String". It starts with a capital letter! Though, we don't need to include any header files to work with String class. It just looks weird. And, what about semicolons at the end of the classes? And "boolean" could have better been "bool", but that's acceptable though. Can anyone help me with changing my mindset from C++ to Java? And also, suggest me a good side-source to learn the little extras in Java. Like, I was using www.learncpp.com to learn C++ side by side while using sololearn. Thank you already :)

18th Aug 2021, 12:27 PM
Rishi
Rishi - avatar
10 Respuestas
+ 2
Embrace the difference, I don't think you have to change your mindset, you just inevitably have to go through a lot of "oh okay" sessions as you find more differences in these languages 👌
18th Aug 2021, 12:39 PM
Ipang
+ 2
Java is Object Oriented Programming Language. OOP relies solely on classes and object concept. That's how it is stuctured. The program is broken into small blueprints called classes and smoothly can be used again and again by creating objects. Advantages of having classes are well explained in four pillars of OOP. In Mathematics you study Calculus and Algebra. Do you mix the concepts? No. You use the similar operations but both the subjects are stuctured differently. Same way use you data stuctures, sorting, searching techniques to build a logic but do not restrict the language with comparision! All the best learning Java!
19th Aug 2021, 5:43 AM
S_sid
S_sid - avatar
+ 1
Ipang I mean a template of similar behavior . In short a sample. Class is a blueprint of an object
18th Aug 2021, 3:37 PM
Atul [Inactive]
+ 1
Well, it's called syntax.. it's obvious programming languages have different ways to approach. They all have the same concepts though, OOP - arrays - loops - exceptions - files - database access - multithreading - regex - sockets etc. I'm telling you first you will find some problems switching from C++ to Java, but you'll get it after some time and Java is friendlier to use than C++(trust me pointers are a huge deal). I liked to throw some notes: Speaking of `String` and why it's first letter is capital, from my POV, all primitive data types are lower case in all languages, String is not a primitive type. For example In C++, it's not "string" rather it is "std::string", and so it is in Java(String class). Happy coding.
19th Aug 2021, 6:46 PM
Maher Al Dayekh
Maher Al Dayekh - avatar
+ 1
These r the rules of java language meaning you have to follow it
20th Aug 2021, 3:19 AM
ᴀʀᴜꜱʜBooSΓ.java
ᴀʀᴜꜱʜBooSΓ.java - avatar
0
Class is a collection of similar objects. That's why you can't write a program without class
18th Aug 2021, 2:35 PM
Atul [Inactive]
0
https://www.javatpoint.com/ https://www.geeksforgeeks.org/ You can refer these websites incase of any doubts or examples along with stackoverflow
18th Aug 2021, 2:37 PM
Atul [Inactive]
0
Atul [Inactive] thank you :)
18th Aug 2021, 2:41 PM
Rishi
Rishi - avatar
0
Atul, What did you mean "Class is a collection of similar objects"? It sounded more of an array rather than a class.
18th Aug 2021, 2:58 PM
Ipang